XScript 手册 · Chapter 10
title: "Motor — 运动控制对象" chapter: 10 images:
- xscript-motor-example.png
Motor — 运动控制对象
Motor[name] 用于访问设备的运动轴对象。每个轴首先在 Motor Editor 中注册(名称、板卡、初始参数),
随后在脚本中用相同名称引用。
캡처 대기
public/manual/gui/xscript-motor-example.png示例
Motor[X].SetSpeed(50.0, 200.0, 200.0); // 速度、加速度、减速度
Motor[X].MoveAbs(100.0, true); // 移至 100mm,等待完成
if (Motor[X].CheckInPosition(100.0) == false) {
ShowError("E_POS_FAIL");
return false;
}移动方法
| 签名 | 用途 |
|---|---|
bool MoveAbs(double position, bool wait) | 绝对位置移动 |
bool MoveRel(double position, bool wait) | 相对当前位置移动 |
bool MoveVel(bool plusDirection) | 速度模式连续移动 |
bool MoveSearchStop(bool plusDirection, SearchSignal signal, bool isUpEdge, bool emgStop) | 搜寻移动 — 信号到位即停 |
bool Stop(bool wait = true, bool setStopExitSignal = false) | 正常停止 |
bool StopEmergency(bool wait = true, bool setStopExitSignal = true) | 紧急停止 |
扭矩控制
| 签名 | 用途 |
|---|---|
bool SetTorqueLimit(double plusDirLimit, double minusDirLimit) | 扭矩上限 |
bool MoveTorque(bool plusDirection, double torquePercent, double velocity) | 扭矩控制移动 |
bool StopTorque(void) | 结束扭矩控制 |
等待 · 检查
| 签名 | 用途 |
|---|---|
bool Wait(int timeout = 0) | 等待当前移动结束(ms,0 = 无限) |
bool WaitPosition(double position, int timeout = 0) | 等待到达目标位置 |
bool WaitHome(int timeout = 0) | 等待回零完成 |
bool CheckInPosition(double pos) | 当前位置是否在容差内 |
uint GetEndStatus(void) | 结束状态标志(0 = 正常) |
string GetEndStatusString(uint endStatus) | 结束状态可读字符串 |
回零 · 初始化
| 签名 | 用途 |
|---|---|
bool InitBoard(void) | 板卡初始化 |
bool Home(void) | 回零(同步) |
bool ThreadHome(void) | 回零(异步,独立线程) |
HomeSubFunctionResult ApiHomeFunction(void) | 底层回零 API |
void ClearAlarm(void) | 清除伺服报警 |
速度 · 位置
| 签名 | 用途 |
|---|---|
void SetSpeed(double vel) | 仅设置速度 |
void SetSpeed(double vel, double accel, double decel = 0) | 速度与加减速 |
void SaveSpeed(void) / void RestoreSpeed(void) | 临时保存/恢复速度 |
bool OverridePos(double pos) | 强制修改当前位置(不移动) |
bool OverrideVel(double vel) | 运行中速度覆盖 |
IO · 报警
| 签名 | 用途 |
|---|---|
bool ReadInBit(int bit) / bool ReadOutBit(int bit) | 读取运动板卡数字 IO |
bool WriteOutBit(int bit, bool on) | 写入运动板卡数字输出 |
要点
MoveAbs(pos, true)阻塞直到完成。异步时使用MoveAbs(pos, false)+Wait()或WaitPosition()。- 成功与否必须用
GetEndStatus()或CheckInPosition()验证。 - 伺服报警发生后,再次运动前必须调用
ClearAlarm()。