#!/bin/bash # Sends a Set Target command to a Pololu Maestro servo controller # # O L D Doc: # # Usage: maestro-set-target.sh DEVICE CHANNEL TARGET # Linux example: bash maestro-set-target.sh /dev/ttyACM0 0 6000 # Mac OS X example: bash maestro-set-target.sh /dev/cu.usbmodem00234567 0 6000 # Windows example: bash maestro-set-target.sh '\\.\USBSER000' 0 6000 # Windows example: bash maestro-set-target.sh '\\.\COM6' 0 6000 # CHANNEL is the channel number # TARGET is the target in units of quarter microseconds. # The Maestro must be configured to be in USB Dual Port mode. # # N E W Doc: # # ./stepper_moto.sh /dev/ttyACM0 0 # DEVICE=$1 CHANNEL=$2 DIRECTION=$(echo $RANDOM % 2 + 1 | bc) let DIRECTION=$DIRECTION-1 byte() { printf "\\x$(printf "%x" $1)" } i=4 if [ "${DIRECTION}" -eq 0 ]; then TARGET=4000 else TARGET=9000 fi COUNT=$(echo $RANDOM % 4 + 1 | bc) while [ "$COUNT" -gt 0 ] do { byte 0x84 byte $CHANNEL byte $((TARGET & 0x7F)) byte $((TARGET >> 7 & 0x7F)) } > $DEVICE if [ "${DIRECTION}" -eq 0 ]; then TARGET=$(($TARGET+1000)) else TARGET=$(($TARGET-1000)) fi COUNT=$(($COUNT-1)) sleep 1 echo " COUNT $COUNT DIRECTION $DIRECTION TARGET $TARGET " done