XScript Manual · Chapter 10

title: "Motor — motion control object" chapter: 10 images:

  • xscript-motor-example.png

Motor — motion control object

MOTOR["name"] accesses a motion axis defined in the Motor Editor.

Motor object usage

Basic example

MOTOR["M_HeadX"].Home();
if (MOTOR["M_HeadX"].WaitHome(1000) == false)
{
    Log("{0} - Home Failed", MOTOR["M_HeadX"].Description);
    return;
}
 
// Relative move — wait until complete
if (MOTOR["M_HeadX"].MoveRel(10.0, true) == false)
{
    // failure
}
 
// Absolute move — fire-and-forget
MOTOR["M_HeadX"].MoveAbs(100.0, false);

Real-world — spindle control

Adapted from Stage.xms. Dynamically overrides velocity & accel while the motor is already running.

FUNCTION RunSpindle(double rpm, double accel, double decel)
{
    double speed = rpm * ANGLE_SPD_PER_RPM;
 
    if (MOTOR["M_SpindleT"].InMotion)
    {
        if (MOTOR["M_SpindleT"].OverrideAccelVelDecel(speed, accel, decel) == false)
        {
            MOTOR["M_SpindleT"].ShowMotorError(ModuleName);
            return false;
        }
        return true;
    }
 
    MOTOR["M_SpindleT"].SetSpeed(speed, accel, 20.0);
    MOTOR["M_SpindleT"].OverrideSetMaxVel(10000);
 
    if (MOTOR["M_SpindleT"].MoveVel(true) == false)
    {
        MOTOR["M_SpindleT"].ShowMotorError(ModuleName);
        return false;
    }
 
    return true;
}

Motion methods

SignatureDescription
bool MoveAbs(double position, bool wait)Absolute move
bool MoveRel(double position, bool wait)Relative move
bool MoveVel(bool plusDirection)Velocity mode
bool MoveSearchStop(bool plusDirection, SearchSignal signal, bool isUpEdge, bool emgStop)Sensor-stop move
bool Stop(bool wait = true, bool setStopExitSignal = false)Normal stop
bool StopEmergency(bool wait = true, bool setStopExitSignal = true)Emergency stop
bool OverridePos(double pos)Force-set current position
bool OverrideVel(double vel)Override velocity while moving

Torque control

SignatureDescription
bool SetTorqueLimit(double plusDirLimit, double minusDirLimit)Per-direction torque cap
bool MoveTorque(bool plusDirection, double torquePercent, double velocity)Torque-controlled move
bool StopTorque(void)Exit torque control

Wait / check

SignatureDescription
bool Wait(int timeout = 0)Wait for current move (0 = infinite)
bool WaitPosition(double position, int timeout = 0)Wait for target position
bool WaitHome(int timeout = 0)Wait for home complete
bool CheckInPosition(double pos)Inside tolerance window
uint GetEndStatus(void)End-status flags
string GetEndStatusString(uint endStatus)Parse end-status to string

Home / init

SignatureDescription
bool InitBoard(void)Initialize board
bool Home(void)Home (synchronous)
bool ThreadHome(void)Home (async, new thread)
HomeSubFunctionResult ApiHomeFunction(void)Low-level home API
void ClearAlarm(void)Clear alarm

Speed settings

SignatureDescription
void SetSpeed(double vel)Velocity only
void SetSpeed(double vel, double accel, double decel = 0)Velocity + accel/decel
void SaveSpeed(void) / void RestoreSpeed(void)Push/pop speed

Force / calibration

SignatureDescription
bool SetForceAnalogIo(string name)Assign analog IO for force reading
bool SetForce(double value) / bool SetVoltage(double value)Force / voltage override
bool ClearForceCalibData(void)Reset calibration table
bool AddForceCalibData(double force, double volt)Add calibration sample

I/O

SignatureDescription
bool ReadInBit(int bit) / bool ReadOutBit(int bit)Read motion board DI/DO
bool WriteOutBit(int bit, bool on)Write motion board DO

Properties

PropertyTypeDescription
Name / DescriptionstringMetadata
CommandPosition / ActualPosition / TargetPositiondoublePositions
InMotionboolMotion flag
HomeDone / HomeBusyboolHome status
AlarmSignal / AlarmLevel / AlarmUseboolAlarm signal
ServoOnSignal / ServoOnLevel / ServoOnUseboolServo-on
PLimitSensorSignal / NLimitSensorSignalbool±limit
HomeSensorSignal / HomeSensorLevel / HomeSensorUseboolHome sensor
ZPhaseSignal / ZPhaseLevel / ZPhaseUseboolZ-phase
InpositionSignal / InpositionLevel / InpositionUseboolIn-position
JogVel / JogAccel / JogDeceldoubleJog params
RunVel / RunAccel / RunDeceldoubleRun params
StartSpeed / MaxSpeed / UnitPerPulsedoublePulse/velocity scaling
EncoderUse / EncoderInverse / EncoderCalibEncoder
HomeTimeOut / HomeSlowVel / HomeBackOffset / HomeAfterDelayHome sequence
HomeReverse / HomeInstantModeboolHome options
SwInpositionRange / SwInpositionUse / SwInpositionError / SwInpositionByEncoderSoft in-position
MinPos / MaxPos / MinMaxAutoSetSoft limits
GantryMode / IsGantrySlave / LinkMotorIndexGantry link
IsVelMoveMode / IsAbsMoveMode / IsRelMoveModeboolCurrent mode
ForceMode / CurrentForce / CurrentVoltageForce control
LastErrorCode / DefaultErrorCodeintError codes

Event hooks

PropertyDescription
CheckFunctionNameSafety check before move
PreHomeFunctionNameHook before home
AfterHomeFunctionNameHook after home
UseCheckFunctionOnHomeAlso run Check for home
FUNCTION M_U1CNV_Check(string name)
{
    if (IO["I_Emg"] == ON)
    {
        return false;
    }
    return true;
}

Tips

  • Use MoveAbs(pos, true) to block; MoveAbs(pos, false) + Wait() for async.
  • Always verify with GetEndStatus() or CheckInPosition().
  • After a servo alarm, call ClearAlarm() before restart.
  • Compute accel/decel from RPM delta using master-setup ratios for flexibility.