Stop automatically


A command goto ~ sw can be used to automatically stop the stepper motor operation when the limit switch is closed.

If the motor stops by this command, the status value of the motor becomes the stopped status.

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

※ Caution: there is no space between [dir] and sw(id)

argument description mandatory/optional
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 4");

// 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 1 is LOW
echo "find negative limit ...";
spc_request_dev($sid, "goto -sw1 400 0");
while((int)spc_request_dev($sid, "get state"))
    usleep(1);
echo "done\r\n";
?>
find positive limit ...done
find negative limit ...done