61
Mach4 General Discussion / Homing function - Is this unreasonable?
« on: July 28, 2014, 01:48:02 AM »
I'm trying to provide a generic homing procedure that would be run when an ISIG_MOTOR#_PLUS/MINUS signal gets sent while homing. When I run it on my Sieg X3 mill and trigger a limit switch (all of mine are tied to pin 11 on the BOB) Mach 4 go into lala land - CPU usage jumps to 100% and Mach 4 hangs. I have to kill the app and restart.
I wanted to make sure I'm not doing something unreasonable in my signal handling code:
In my Lau module:
Essentially in MoveMotorOffLimitswitch(), I'm checking which limit switch was triggered for the specified motor and choosing which direction to go. I set "directiontoMoveOffLimit" to a positive or negative one to use as my unit of movement and to choose the direction. I set "isOnLimitSwitch" to the DSC function for continuing to test for which limit switch we are on to use later in the while loop. In the while loop I send a "G90 G01 {axis}{direction} F5" to move off the limit switch.
-Freeman
I wanted to make sure I'm not doing something unreasonable in my signal handling code:
Code: [Select]
-- In screen signal handling
local isHoming = false;
SigLib.AddSignalHandler(mc.ISIG_MOTOR_HOME_START, function (state)
isHoming = (state == 1);
end)
-- Limit switches
SigLib.AddSignalHandler(mc.ISIG_MOTOR0_MINUS, function (state)
if (isHoming) then
MySM.MoveMotorOffLimitSwitch(MySM.MOTOR_X);
end
end)
SigLib.AddSignalHandler(mc.ISIG_MOTOR0_PLUS, function (state)
if (isHoming) then
MySM.MoveMotorOffLimitSwitch(MySM.MOTOR_X);
end
end)
SigLib.AddSignalHandler(mc.ISIG_MOTOR0_MINUS, function (state)
if (isHoming) then
MySM.MoveMotorOffLimitSwitch(MySM.MOTOR_X);
end
end)
In my Lau module:
Code: [Select]
----
-- 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;
isOnLimitSwitch = DSC.IsPlusLim;
elseif (DSC.IsMinusLim (motor)) then
directionToMoveOffLimit = MyStdMill.DIR_POSITIVE;
isOnLimitSwitch = DSC.IsMinusLim;
else
return;
end
local axis = { [0]="X", "Y", "Z", "A" }; -- Select axis for Gcode based on motor
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));
while (isOnLimitSwitch (motor))
do
mc.mcCntlGcodeExecute (inst, gcode);
end
end
end
Essentially in MoveMotorOffLimitswitch(), I'm checking which limit switch was triggered for the specified motor and choosing which direction to go. I set "directiontoMoveOffLimit" to a positive or negative one to use as my unit of movement and to choose the direction. I set "isOnLimitSwitch" to the DSC function for continuing to test for which limit switch we are on to use later in the while loop. In the while loop I send a "G90 G01 {axis}{direction} F5" to move off the limit switch.
-Freeman