--------------------------------------------------------------- -- Toggle A Axis Continuous rotation On/Off --------------------------------------------------------------- function A_AxisOnOff() local inst = mc.mcGetInstance("A_AxisOnOff()") if (A_Axis_State == nil) then A_Axis_State = 0 --initialize it to OFF from screen load script run elseif (A_Axis_State == 0) then --turn in ON --Get Rotation Direction from screen button DirButtonState = scr.GetProperty('togReverse', 'Button State') if (DirButtonState == "0") then RotationDirection = mc.MC_JOG_NEG else RotationDirection = mc.MC_JOG_POS end --Get RPM from DRO local A_Axis_rpm = scr.GetProperty('droA_Axis_rpm', 'Value') --gets dro rpm setting A_Axis_rpm = tonumber(A_Axis_rpm) --convert string to number --Check that DRO setting is valid if ((A_Axis_rpm < 1) or (A_Axis_rpm > 200)) then --check for valid rpm input wx.wxMessageBox("rpm must be between 1 and 200") do return end end --set up the A Axis to a OB motor mc.mcAxisEnable(inst, mc.A_AXIS, false) mc.mcAxisUnmapMotor(inst, mc.A_AXIS, mc.MOTOR4) mc.mcAxisMapMotor(inst, mc.OB1_AXIS, mc.MOTOR4) mc.mcAxisEnable(inst, mc.OB1_AXIS, true) --start jogging local A_Axis_upm = A_Axis_rpm * 360 mc.mcJogSetFeedRate(inst, mc.OB1_AXIS, A_Axis_upm) mc.mcJogVelocityStart(inst, mc.OB1_AXIS, RotationDirection) scr.SetProperty('bmbA_Cont_rotationOnOff', 'Image', 'toggle_ON.png') A_Axis_State = 1 else --turn it OFF --stop jogging mc.mcJogVelocityStop(inst, mc.OB1_AXIS) --wait until the motor is stopped IsStopping = mc.mcJogIsStopping(inst, mc.OB1_AXIS) while (IsStopping == 1) do IsStopping = mc.mcJogIsStopping(inst, mc.OB1_AXIS) end --revert motor back to A-axis mc.mcAxisEnable(inst, mc.OB1_AXIS, false) mc.mcAxisUnmapMotor(inst, mc.OB1_AXIS, mc.MOTOR4) wx.wxMilliSleep(75) --wait a little so the motor doesn't clunk when it gets remapped mc.mcAxisMapMotor(inst, mc.A_AXIS, mc.MOTOR4) mc.mcAxisEnable(inst, mc.A_AXIS, true) scr.SetProperty('bmbA_Cont_rotationOnOff', 'Image', 'toggle_OFF.png') mc.mcAxisDeref(inst,mc.A_AXIS) --deref A axis since its position is now unknown A_Axis_State = 0 end end