Sept
20
Sun

Renbotics Servo Shield Sequencer

While thinking of exciting things to do with the new Renbotics Servo Shield an easy to use sequencer came to mind. Searching around did not deliver anything suitable, thus we created the Renbotics Servo Sequencer serial protocol.

The first challenge was; how to store the sequence? We decided to use the Arduino's internal EEPROM to store the sequences in a simple command 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 an 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 we put together a simple serial 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

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) open the Arduino Serial Monitor and send the following commands:

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

Code: