自动停止


利用goto ~ sw命令,当限制开关关闭时可自动停止步进电机的动作。 通过此命令电机停止后,电机的状态值变为停止状态

"goto [dir]sw(id) [speed] [accel] [decel]"

※ 注意:[dir]与sw(id)之间没有空空间。

argument 说明 必须/选项
dir direction, "+"(forward) or "-"(reverse) optional(default: "+")
id ID of a digital input port, 0/1/2/3 mandatory
speed speed(unit: pps) optional
accel acceleration(unit: pps/s) optional
decel deceleration(unit: pps/s) optional
<?php
include_once "/lib/sd_spc.php";

spc_reset();
spc_sync_baud(115200);

$sid = 1;
spc_request_dev($sid, "set vref stop 2");
spc_request_dev($sid, "set vref drive 8");
spc_request_dev($sid, "set mode full");

// rotate until digital input 0 is LOW
echo "find positive limit ...";
spc_request_dev($sid, "goto +sw0 400 0");
while((int)spc_request_dev($sid, "get state"))
    usleep(1);
echo "done\r\n";

sleep(1);

// rotate until digital input 0 is LOW
echo "find negative limit ...";
spc_request_dev($sid, "goto -sw0 400 0");
while((int)spc_request_dev($sid, "get state"))
    usleep(1);
echo "done\r\n";
?>
find positive limit ...done
find negative limit ...done