60
« on: July 29, 2014, 02:01:12 AM »
Actually Scott, I realized that loop was running in an even more aggressive loop of the PLC script. No wonder it was locking up. I modified my approach to remove the while loop and to only issue the gcode to move off the limit switches when there was no movement. This should avoid stacking gcode calls to move off the limit switches.
I haven't tested this yet.
-Freeman
----
-- Test if specified motor is on limit switch (due to homing) and move
-- in appropriate direction to move off of limit switch if needed.
--
-- WARNING : At the moment I am assuming a one-to-one mapping between
-- motors and axis (ie. motor 0 -> axis 0, motor 1 -> axis 1, ...)
--
-- @param motor (number) motor selector, 0-6
--
function MyStdMill.MoveMotorOffLimitSwitch (motor)
local inst = mc.mcGetInstance()
local directionToMoveOffLimit, isOnLimitSwitch;
if (DSC.GetFunc('ISAXENBL', motor)) then
if (DSC.IsPlusLim (motor)) then
directionToMoveOffLimit = MyStdMill.DIR_NEGATIVE;
elseif (DSC.IsMinusLim (motor)) then
directionToMoveOffLimit = MyStdMill.DIR_POSITIVE;
else
return;
end
local axis = { [0]="X", "Y", "Z", "A" };
local gcode = string.format("G90 G01 %s%d F5", axis[motor], directionToMoveOffLimit);
mc.mcCntlSetLastError(inst, string.format("Moving motor %d off axis %s, direction = %d",
motor, axis[motor], directionToMoveOffLimit));
if (DSC.GetFunc('ISAXSTILL', motor)) then
mc.mcCntlGcodeExecute (inst, gcode); -- only move if other movement is in process
end
end
end