Hi Tom,

I have two questions, one following from the other. I have an axis with two motors on either side of the bed that needs to home them in case they were moved while the machine was off, usually just a small number of encoder counts. Each has a home sensor at the end of travel, and an index on the encoder. The procedure had been to drive the axes into the home sensors one at a time, then away from them into the respective indices, and the measured delta is compared to what it should be as measured with a test indicator and adjusted. Question 1 comes from accidentally commanding a G0 while the axes were still in motion (oops) and the G0 command moved only one motor until a following error fault occurred and the gantry was tweaked: is there a way in C to disable G code from executing even if the operator boneheads it in KmotionCNC before they should?

Question 2 comes from trying to fix the misalignment caused above. Earlier the homing motion would be repeated twice, once for each axis, but this doesn't work with the large alignment error as one axis would overtravel before the other found the home sensor. So I tried to have both axes drive towards their home sensors as simultaneous independent motions, and each would stop once the respective home sensor is found:

Jog(X0_AXIS,FAST_SPEED); // move towards sensor
Jog(X1_AXIS,FAST_SPEED); // move towards sensor
x0_moving = 1; //int defined above
x1_moving = 1; //int defined above


while(x0_moving || x1_moving) {
//while(!ReadBit(X0_HOME_BIT) || !ReadBit(X1_HOME_BIT)){


if (ReadBit(X0_HOME_BIT)) {
Jog(X0_AXIS,0.0); // StopMotion
home0 = chan[X0_AXIS].Position;
x0_moving = 0;
printf("Found x0 home sensor, stopping x0. Home at %f\n", home0);
}
if (ReadBit(X1_HOME_BIT)) {
Jog(X1_AXIS,0.0); // StopMotion
home1 = chan[X1_AXIS].Position;
x1_moving = 0;
printf("Found x1 home sensor, stopping x1. Home at %f\n", home1);
}
WaitNextTimeSlice();
}
printf("post loop %d %d\n", x0_moving, x1_moving);




Without the WaitNextTimeSlice(); present it would immediately skip to the post loop printf without executing anything inside the while loop.
Adding the WaitNextTimeSlice() seems to have it hang inside the loop, but it won't read the home sensors. (without any code running I can watch them change in the Kmotion Digital I/O screen as expected)
If I instead use "while(!ReadBit(X0_HOME_BIT) || !ReadBit(X1_HOME_BIT)){" instead it seems to actually evaluate the inside of the while loop, except that that isn't actually the while condition I want it to be checking.

I've been having a bunch of KFLOP crashes while debugging this as well.
One of the errors produced a small hex dump in the console: "Aborti013500AE 00000029 00000168 00000168 0000016E 00000167 0000016E 00000168 00000169 00000000 00000000 00000000 00000000 00000000 00000000 00000000"
And it often seems to hard crash the Kflop until I do a power cycle on it: "Kmotion present but not responding Correct problem and restart application"
Once, in the combo of without the WaitNextTimeSlice and with the while(x0_moving || x1_moving) it also produced brief uncommanded motion in the Y and Z axes before crashing hard enough to kill servo power (unsure if the SWE pin or a Kanalog output, both of which are driving a SSR in the e-stop chain). After this I proceeded with the servo power off until done debugging.

Update after further debugging attempts: I have a "supervisor" program in Thread 7 that loads axis/Kanalog/Konnect settings, and then starts a perpetual loop which watches coolant flow, checks for button presses, generate messages to display on KmotionCNC DROs, etc and is the first thing loaded when I power on. I had been having all the above problems while running the above code in thread 6, but the same code works fine if I run it in Threads 1-5, or if I kill thread 7 before running it in Thread 6. Is this a buffer overflow issue? If so how can I make sure I'm inside the memory space for each thread? I'm not using the TI compiler.

Thanks,
Andy