User Manual

5.h.4. Bash script
The following shell script sends Set Target commands to the Maestro’s virtual COM port. This script
allows you to easily control a Maestro over USB from a computer running Linux or Mac OS X 10.7
(Lion) or later. To use it, you will need to first run the Maestro Control Center on a Linux or Windows
computer and set the Maestro’s serial mode to “USB Dual Port”. Then, on the computer you want to
control the Maestro from, you should copy the code below into a file named maestro-set-target.sh.
You can run it using the example commands given below. You will need to change the DEVICE
argument to be the name of the Maestro’s Command Port (see Section 5.a).
#!/bin/bash
# Sends a Set Target command to a Pololu Maestro servo controller
# via its virtual serial port.
# 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.
DEVICE=$1
CHANNEL=$2
TARGET=$3
byte() {
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include<18f4550.H>
#fuses HSPLL, NOMCLR, PUT, BROWNOUT, BORV43, NOWDT, NOPROTECT, NOLVP
#fuses NODEBUG, USBDIV, PLL5, CPUDIV1, VREGEN, CCP2B3
#use delay(clock=48000000)
#define TTL_TX1 PIN_C6
#define TTL_RX1 PIN_C7
#use rs232(xmit=TTL_TX1, rcv=TTL_RX1, bits=8, parity=N)
void main() {
delay_ms(2000);
while(true) {
// Send a Set Target command using the Pololu protocol.
putc(0xAA); // Start Byte
putc(0x0C); // Device ID = 12
putc(0x04); // Command = Set Target
putc(0x00); // Channel = 0
putc(0x20); // Target position = 1000 us (typical minimum for servos)
putc(0x1F);
delay_ms(1000);
// Send another Set Target command using the Pololu protocol.
putc(0xAA);
putc(0x0C);
putc(0x04);
putc(0x00);
putc(0x70); // Target position = 1500 us (typical neutral for servos)
putc(0x2E);
delay_ms(1000);
}
}
?
Pololu Maestro Servo Controller User’s Guide © 2001–2017 Pololu Corporation
5. Serial Interface Page 64 of 99