Renbotics Servo Shield Sequencer

by Adriaan | September 20, 2009

While thinking of exciting things to do with the new Renbotics Servo Shield, I realized that most of them required some sort of sequencing. Google-ing did not result in much so I decided to create my own.

The first challenge was; how to store the sequence? I decided to use the on chip EEPROM and came up with this simple structure:

Position Description Type
0 Sequence count byte
1 Length of memory used byte
n Sequence Number byte
n+1 Sequence Length byte
n+2 Sequence Interval int
n+4 Step Number byte
n+4 Servo Number byte
n+5 Servo Positon int

The first two bytes are used as a sort of allocation table to allow the system to know how many sequences there are and where the next available EEPROM byte is.

The next 4 bytes form the header of the sequence containing the sequence number, to allow multiple sequences to be stored, the amount of steps in the sequence, and the interval at which the steps should be executed.

The last 4 bytes are the step information containing the step number, servo number and position of the servo in that step. This information is repeated for each step/servo combination in the sequence.

Next, a way to program the sequences were needed, so I quickly hacked together a simple protocol:

Command Description
NS New Sequence
SI [interval in ms] Set Sequence Interval
SS [step number] [servo number] [position] Add a Sequence Step
CS Clear Sequences
DS Display Sequences
PS [sequence number] Play Sequence
SP Stop sequence Play
SB [servo number] [min pos] [max pos] Set servo Bounds
SM [servo number] [position] Move Servo

Thus to program a simple sequence to pan two servos from 0deg to 180deg stopping at 90deg and back at a 1s per step interval (for total pan time 5s):

CS
NS
SI 1000
SS 1 0 1000
SS 1 1 1000
SS 2 0 1500
SS 2 1 1500
SS 3 0 2000
SS 3 1 2000
SS 4 0 1500
SS 4 1 1500
PS 1

To use the Servo Shield Sequencer import the EEPROM and Servo Shield libraries and add EEPROM.pde and Sequencer.pde to your sketch. In your sketch's setup method initialize the sequencer first and in your loop method simply poll the serial comms and the sequencer.

e.g.

Full code is available with the Renbotics Servo Shield library: servoshield.zip

Requirements:

  • 1 x Arduino Duemilanove or Seeeduino
  • 1 x Renbotics Servo Shield
  • Min 1 x Servo
  •  

    F. A. Q. :: DISTRIBUTORS :: TERMS OF USE :: FEED