Board Commands - WE-Bots/ServoControl GitHub Wiki
This page will attempt to outline the commands that can be sent to the servo board over a serial connection, as well as common use cases. It will be of little interest to a user of the program the inner workings of the commands, but useful for developers or users who wish to interface with the board through an embedded system.
##Table of Contents
- [Physical Layer](#Physical Layer)
- [Basic Commands](#Basic Commands)
- [Command Format](#Command Format)
- [Change PWM Commands](#Change PWM Commands)
- [Example Change PWM Commands](#Example Change PWM Commands)
- [Special Commands](#Special Commands)
- [Loading to RAM Sequence](#Loading to RAM Sequence)
- Sweep
- Sequence
- Freeze
- [PWM Repeat and Sequence Replay Chart](#PWM Repeat and Sequence Replay Chart)
Communication is done using a TTL serial connection. There is a FTDI chip on the board that acts as a serial emulator for use with computers, but for communications from another board, you can connect directly to the Rx line.
Parameter | Value |
Baud Rate | 9600 |
Stop Bits | 1 |
Parity | None |
Flow Control | None |
The commands are sent to the board in a standard format of one address byte and then one data byte. The address byte is sent first, and must have the MSb set high. The data byte directly follows and must have the MSb set low.
## Basic CommandsThe basic command sent to the board is the command to move a servo to a set position. On startup, the default values will be sent to the servos, and will change unless another command is received. It is recommended to leave a 1.5 - 2 ms gap between the address and data byte to ensure that there are no errors with reading the incoming data.
The address bytes starts with the MSb being set high, to indicate that it is an address. The next three bits are the address of the board. The default will be 1 and is unlikely to ever be different. This is intended for use in applications where there are a number of boards tied to the same communication line. The low nibble is the address of the servo that is being addressed, between 0 and B. Values between D and F in the low nibble are used for special commands, outlined below.
1BBB SSSS BBB - board address (normally one) SSSS - servo address (between 0 and B)
This contains the data for the pulse width that will be sent to the servo in the normal modes. The MSb must be low to indicate that it is a data byte. If the data if for the servos, the value must be less than 97, as beyond those values the pulse width becomes too long for the servos to understand.
Note that for some servos, the behaviour near the extremes of the pulse width can become erratic, it is recommended to avoid going near the extremes without thorough testing first.
0DDD DDDD DDD DDDD - data for the PWM (generally less than 97)
An example command would be to instruct the board to move servo 5 to the position 49. Remember that there should be a 1.5 to 2 ms gap between the command being sent to ensure that there are no errors receiving the data.
Address Data 1001 0101 0011 0001 BBB SSSS DDD DDDD Board Address (BBB) = 001b = 1. -- This is the default value, you should rarely have to change this. Servo Address (SSSS) = 0100 = 4. --It is a zero based counting system for numbering the servos. Data (DDD DDDD) = 011 0001 = 49. -- The position the servo will be moved to.## Change PWM Commands
The standard commands are used to put the board in direct run mode and then send commands which will be executed immediately. The address byte is made up a 3 fields, the address flag, the board number and the servo number.
Parameter | Length | Value | Description |
Address Flag | 1 bit | High (1) | This indicates that this byte is to be read as an address |
Board Number | 3 bits | Between 0 and 7 | This is used in case there are multiple boards connected to a single data line they can be individually addressed. |
Servo Number | 4 bits | Between 0 and 11 (to address servos 1 - 12) | This is the address of the servo connection that the data will be passed to. Note that the servos are numbered starting at 1 and the addresses start at 0. |
The data byte is made of 2 fields, the data flag and the data value.
Parameter | Length | Value | Description |
Data Flag | 1 bit | Low (0) | This indicates that this byte is to be read as an data |
Data Value | 7 bits | 0 - 97 (base 10) 0 - 61 (base 16) | This is the width of the pulse in units that will be sent to the addressed servo |
This will move servo 3 on board 1 to the position 49 units
Address Data binary 1001 0010 0011 0001 hex 92 31 decimal 146 49## Special Commands
[The amount of storage is questionable, Eugen is checking] Direct Run and Data Bank are used for storing values in the RAM that will be cycled through when the button is pressed. Sequence 12 stores 3 sets of 12 servo positions, Sequence 3 stores 12 sets of 3 servo positions, Sequence 1 stores 36 single instructions. All slots must be filled on load for it to work.
## Loading to RAM Sequence1. Loop (While empty space to fill, it must all be filled)
1. Banksel (Address(156) Data(Bank Number * 12))
2. Data (Address-Data pairs, reverse order to be played)
End Loop
2. Sequence Value
3. Delay value
4. Load Command (Address(159.) Data([135]))
Data - 1 = sequence 12
3 = sequence 3
5 = sequence 1
PWM Repeat and PWM Sweep are for sweeps, sweep in the value that is added/subtracted to the PWM value every 8 ms until it gets to the target. The PWM repeat is the number of times that the PWM value is repeated before the sweep value is added/subtracted from it.
The effect of a sweep is that the the servo will move SWEEP (1 - 15) steps to toward the final position, stop for REPEAT time increments before repeating again. The possible repeat time increments can be found at the bottom of this document.
This means that to have the servo take more time to get to the final position, you can either increase the repeat value or decrease the sweep value. By decreasing the sweep value and the repeat value results in a smoother motion towards to the final target position. The optimal values to use will depend on the servos and their environment.
Address(158.) Data(0RRR SSSS) RRR- 3 bit unsigned, number of times PWM value is repeated(PWM Sweep)(Converted by chart below) SSSS - 4 bit unsigned step value (PWM Sweep)
To have servos move in 5 unit steps and hold after each step for 400 ms. The information being sent to the board would be.
Address - 158. - 0x9E Data - 69. - 0x45 - 0101 0101
The address is preset and must be sent at stated to communicate to the board that the data is referring to sweeping. The high nibble states that the servos will move in 5 unit steps (RRR = 101 = 5) and the low nibble indicates that it will move every 400 ms ( 0101 -> 5 -> 50(see mapping chart below) -> 50 * 8ms = 400 ms)
## SequenceSequence Delay is the number of seconds between steps in the sequence are run on the board. Sequence replay is the number of times the complete sequence is repeated by the board.
Address(157.) Data(0RRR DDDD) RRR - 3 bit unsigned, number of times the seqence is repeated (Converted by chart below) DDDD - 4 bit unsigned, number of seconds between steps## Freeze
Stops the board from sending any changes to the servos until unfreeze is sent.
Address (159.) Data(15.)## PWM Repeat and Sequence Replay Chart
The left value is the one that is sent over the serial connection. The value on the right is the once that is used by micro after a lookup operation is done.
0=======1 1=======2 2=======10 3=======25 4=======50 5=======100 6=======150 7=======200