Page 1 of 1
Regarding estop making in for loop
Posted: Mon Dec 30, 2019 1:37 pm
by AmitKumar171
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.
Re: Regarding estop making in for loop
Posted: Mon Dec 30, 2019 9:45 pm
by TomKerekes
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;
}
Re: Regarding estop making in for loop
Posted: Thu Jan 02, 2020 5:57 am
by AmitKumar171
Hi tom,
thanks for the reply.
I will test and keep you updated.