H.4. bash script – Pololu Maestro User Manual

Page 49

Advertising
background image

putc(0xAA);

putc(0x0C);

putc(0x04);

putc(0x00);

putc(0x70); // Target position = 1500 us (typical neutral for servos)

putc(0x2E);

delay_ms(1000);

}

}

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() {

printf "\\x$(printf "%x" $1)"

}

{

byte 0x84

byte $CHANNEL

byte $((TARGET & 0x7F))

byte $((TARGET >> 7 & 0x7F))

} > $DEVICE

This script can also be run on Windows, but since Windows does not have bash installed by default it is easier to use
UscCmd.

Pololu Maestro Servo Controller User's Guide

© 2001–2014 Pololu Corporation

5. Serial Interface

Page 49 of 73

Advertising