Skip to content

protocol

李喆 edited this page Nov 10, 2016 · 1 revision

Overview

Our team using serial port communicated with ROS.

Protocol

  • 1st Byte - Sync Flag (Value: 0xff)
  • 2nd Byte - Device ID (Motor:0xfe)
  • 3rd Byte - Message Length (N)
  • 4th Byte - Command ID Low Byte
  • 5th Byte - Command ID Hight Byte
  • N Bytes - Message Data
  • Byte N+6 - Checksum from Device ID to Message Data

Checksum Computing:

Length Checksum = (Device_ID + Message_Length + Command_ID + Message_Date) % 256

Device ID

We establish our device tree from a motor control board

Motor Control Board | 0xFE

Message Length

The Message Length is count of Message Data number (N).

Command ID

Every Command and Sendback data has its ID and it build up by 2 bytes. We send lower byte first. The High byte is separated by 0x80, when the high byte is less than 0x80 means it is a command since it bigger than 0x80(including 0x80) means it is a sendback data.

Message Data

Message Data is quite different in type, length or meaning.

Details

Commands:

set motor speed:

0xff, 0xfe, 0x04, 0x01, 0x00,  Left_Wanted_Direction, Left_Wanted_Speed, Right_Wanted_Direction, Right_Wanted_Speed, sum_check

example

 ff fe 04 01 00 01 14 01 14 2D //20cm/s both

 ff fe 04 01 00 01 15 01 15 2F //21cm/s both

 ff fe 04 01 00 01 18 01 18 35 //24cm/s both

 ff fe 04 01 00 01 1B 01 1B 3B //28cm/s both

explain:

  • message data is "0x01 0x14 0x01 0x14" and it means both motor set to the forward direction and speed is set to 20cm/s(0x14=20).

  • message length is "0x04" which is after the header "0xff 0xfe".

  • command id is "0x01 0x00" and its high byte is 0x00 and lower byte is 0x01, again we send lower byte first.

  • sum check is "0x2D", 0xfe + 0x04 + 0x01 + 0x00 + 0x01 + 0x14 + 0x01 + 0x14 = 0x12D, 0x12D % 256 = 0x2D.

set motor work state

0xff 0xfe 0x01 0x02 0x00 State sum_check

example

 0xff 0xfe 0x01 0x02 0x00 0x01 0x02

explain:

State:

  • 0x01----work normally
  • 0x00---- stop
  • 0x02---- halt

get encoder value:

0xff 0xfe 0x00 0x03 0x00  sum_check

example

0xff 0xfe 0x00 0x03 0x00 0x01

set PID parameters

 0xff 0xfe 0x03 0x04 0x00 Proportional  Integral  Derivative  sum_check

example

 0xff 0xfe 0x03 0x04 0x00 Proportional  Integral  Derivative  sum_check

get PID parameters now using

0xff 0xfe 0x00 0x05 0x00  sum_check

get motor speed now

0xff 0xfe 0x00 0x06 0x00  sum_check

get motor speed set

 0xff 0xfe 0x00 0x07 0x00  sum_check

Sendbacks:

motor speed right now

 0xff 0xfe 0x04 0x01 0x80 Left_Direction Left_Speed  Right_Direction Right_speed  sum_check

encoder data

0xff 0xfe 0x04 0x02 0x80 Left_Encoder_Low Left_Encoder_High Right_Encoder_Low Right_Encoder_High sum_check

PID now using

0xff 0xfe 0x03 0x03 0x80 Proportional  Integral  Derivative  sum_check

motor speed wanted set

 0xff 0xfe 0x04 0x04 0x80 Left_Wanted_Direction Left_Wanted_Speed Right_Wanted_Direction Right_Wanted_Speed  sum_check