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.
캡처 대기
public/manual/gui/xscript-motor-example.pngBasic 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
| Signature | Description |
|---|---|
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
| Signature | Description |
|---|---|
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
| Signature | Description |
|---|---|
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
| Signature | Description |
|---|---|
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
| Signature | Description |
|---|---|
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
| Signature | Description |
|---|---|
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
| Signature | Description |
|---|---|
bool ReadInBit(int bit) / bool ReadOutBit(int bit) | Read motion board DI/DO |
bool WriteOutBit(int bit, bool on) | Write motion board DO |
Properties
| Property | Type | Description |
|---|---|---|
Name / Description | string | Metadata |
CommandPosition / ActualPosition / TargetPosition | double | Positions |
InMotion | bool | Motion flag |
HomeDone / HomeBusy | bool | Home status |
AlarmSignal / AlarmLevel / AlarmUse | bool | Alarm signal |
ServoOnSignal / ServoOnLevel / ServoOnUse | bool | Servo-on |
PLimitSensorSignal / NLimitSensorSignal | bool | ±limit |
HomeSensorSignal / HomeSensorLevel / HomeSensorUse | bool | Home sensor |
ZPhaseSignal / ZPhaseLevel / ZPhaseUse | bool | Z-phase |
InpositionSignal / InpositionLevel / InpositionUse | bool | In-position |
JogVel / JogAccel / JogDecel | double | Jog params |
RunVel / RunAccel / RunDecel | double | Run params |
StartSpeed / MaxSpeed / UnitPerPulse | double | Pulse/velocity scaling |
EncoderUse / EncoderInverse / EncoderCalib | Encoder | |
HomeTimeOut / HomeSlowVel / HomeBackOffset / HomeAfterDelay | Home sequence | |
HomeReverse / HomeInstantMode | bool | Home options |
SwInpositionRange / SwInpositionUse / SwInpositionError / SwInpositionByEncoder | Soft in-position | |
MinPos / MaxPos / MinMaxAutoSet | Soft limits | |
GantryMode / IsGantrySlave / LinkMotorIndex | Gantry link | |
IsVelMoveMode / IsAbsMoveMode / IsRelMoveMode | bool | Current mode |
ForceMode / CurrentForce / CurrentVoltage | Force control | |
LastErrorCode / DefaultErrorCode | int | Error codes |
Event hooks
| Property | Description |
|---|---|
CheckFunctionName | Safety check before move |
PreHomeFunctionName | Hook before home |
AfterHomeFunctionName | Hook after home |
UseCheckFunctionOnHome | Also 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()orCheckInPosition(). - After a servo alarm, call
ClearAlarm()before restart. - Compute accel/decel from RPM delta using master-setup ratios for flexibility.