Regarding estop making in for loop

Moderators: TomKerekes, dynomotion

Post Reply
AmitKumar171
Posts: 134
Joined: Tue Feb 20, 2018 7:35 am
Location: India

Regarding estop making in for loop

Post by AmitKumar171 » Mon Dec 30, 2019 1:37 pm

Hi tom,

I am using estop program for disabling all axes.

And if i release the estop all axes are still disabled.

I want to make such that if i release estop, all axes should auto enable. and if i press estop all axis should disable.

I defined bit no 16 as my estop bit.

How to make estop in infinite loop. ? as said above.

Waiting for your kind reply.
Thank You

AMIT KUMAR

User avatar
TomKerekes
Posts: 2676
Joined: Mon Dec 04, 2017 1:49 am

Re: Regarding estop making in for loop

Post by TomKerekes » Mon Dec 30, 2019 9:45 pm

Hi Amit,

It may not be a good idea to have the axes automatically enabled when EStop is released, it is up to you to add any and all safety precautions.

But here is some sample code:

Code: Select all

#include "KMotionDef.h"

#define ESTOP 16
#define XAXIS 0
#define YAXIS 1

// state variables for switch debouncing
int elast=0,elastsolid=-1,ecount=0;

int Debounce(int n, int *cnt, int *last, int *lastsolid);

void main()
{
	int result;

	for (;;) // loop forever
	{
		WaitNextTimeSlice();
		
		// Handle ESTOP debounce and detect when changed
		result = Debounce(ReadBit(ESTOP),&ecount,&elast,&elastsolid);
		if  (result == 1)  // pushed?
		{
			DisableAxis(XAXIS); 
			DisableAxis(YAXIS); 
		}
		else if  (result == 0)  // released?
		{
			EnableAxis(XAXIS); 
			EnableAxis(YAXIS); 
		}
	}
}

// Debounce a bit
//
// return 1 one time when first debounced high 
// return 0 one time when first debounced low 
// return -1 otherwise 
#define DBTIME 300

int Debounce(int n, int *cnt, int *last, int *lastsolid)
{
	int v = -1;
	
	if (n == *last)  // same as last time?
	{
		if (*cnt == DBTIME-1)
		{
			if (n != *lastsolid)
			{
				v = *lastsolid = n;  // return debounced value
			}
		}
		if (*cnt < DBTIME)	(*cnt)++;
	}
	else
	{
		*cnt = 0;  // reset count
	}
	*last = n;
	return v;
}
Regards,

Tom Kerekes
Dynomotion, Inc.

AmitKumar171
Posts: 134
Joined: Tue Feb 20, 2018 7:35 am
Location: India

Re: Regarding estop making in for loop

Post by AmitKumar171 » Thu Jan 02, 2020 5:57 am

Hi tom,

thanks for the reply.

I will test and keep you updated.
Thank You

AMIT KUMAR

Post Reply