--This macro will configure Motor 4 as an OB motor and turn on continuous rotation --The call must pass cw (1) or ccw (-1) as the rotation direction, and an rpm value between 0 and 200 --Format is m3000 D R --Example usage: m3000 D-1 R120 function m3000(hParam) local inst = mc.mcGetInstance("m3000()"); --check that passed parameters are there if (hParam == nil) then mc.mcCntlSetLastError(inst, "No parameters passed") do return end end --Get the parameters local dVal = mc.mcCntlGetLocalVar(inst, hParam, mc.SV_D) local dFlag = mc.mcCntlGetLocalVarFlag(inst, hParam, mc.SV_D) --mc.mcCntlSetLastError(inst, 'dVal handle == ' .. tostring(dVal)) --mc.mcCntlSetLastError(inst, 'dFlag handle == ' .. tostring(dFlag)) local rVal = mc.mcCntlGetLocalVar(inst, hParam, mc.SV_R) local rFlag = mc.mcCntlGetLocalVarFlag(inst, hParam, mc.SV_R) --mc.mcCntlSetLastError(inst, 'rVal handle == ' .. tostring(rVal)) --mc.mcCntlSetLastError(inst, 'rFlag handle == ' .. tostring(rFlag)) --Bail out if both parameters are not there if (dFlag ~= 1) and (rFlag ~= 1)then mc.mcCntlSetLastError(inst, "The parameters are not properly passed") do return end end mc.mcCntlSetLastError(inst, "Location 2") --Set the rot dir value if (dVal == 1.0) then RotationDirection = mc.MC_JOG_NEG elseif (dVal == -1.0) then RotationDirection = mc.MC_JOG_POS else mc.mcCntlSetLastError(inst, "rotation parameter is invalid, must be +1, or -1") do return end end --Check that DRO setting is valid if ((rVal < 1) or (rVal > 200)) then --check for valid rpm input mc.mcCntlSetLastError(inst, "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 = rVal * 360 mc.mcJogSetFeedRate(inst, mc.OB1_AXIS, A_Axis_upm) mc.mcJogVelocityStart(inst, mc.OB1_AXIS, RotationDirection) end if(mc.mcInEditor() == 1) then m3000() end