This is how I manipulate extra features on my lathe from gcode. For instance I use M106 to set "high gear". The HighGearRequest
? signal is an input to Ladder. M106 sets HighGearRequest
? to TRUE. Ladder waits until it's safe to switch gears (the spindle has stopped, etc.), then does it. The end result of the gear change is the HighClutch
? HAL signal is set to TRUE. M106 uses the
waitfor script to wait for this HighClutch
? signal. EMC2, in turn, waits for M106 to complete before continuing.
The contents of ~/emc2/nc_files/M106:
#!/bin/sh
halcmd sets HighGearRequest 1
~/emc2/nc_files/waitfor HighClutch TRUE
halcmd sets HighGearRequest 0
The contents of ~/emc2/nc_files/waitfor:
#!/bin/bash
if [ $# != 2 ]; then
echo usage: $0 SignalName DesiredValue
exit 1
fi
signal=$1
value=$2
while :; do
set -- $(halcmd -s show sig $signal)
if [ x"$2" == x"$value" ]; then
exit 0
fi
sleep 1
done