RIC uses the basic **ROSSerial packet format**, rather than ROS's publish/subscribe mechanism. Message formats are predefined and must be understood by both RIC and the interface software. ===== Packet format ===== A ROSSerial packet has the following structure: 1st Byte - Sync Flag (Value: 0xff) 2nd Byte - Sync Flag / Protocol version 3rd Byte - Message Length (N) - Low Byte 4th Byte - Message Length (N) - High Byte 5th Byte - Checksum over message length 6th Byte - Topic ID - Low Byte 7th Byte - Topic ID - High Byte x Bytes - Serialized Message Data Byte x+1 - Checksum over Topic ID and Message Data See the [[https://wiki.ros.org/rosserial|ROS wiki's ROSSerial documentation]] for more detail. ===== Marty V2 ROSSerial interface ===== Marty V2 messages differ from Marty V1 messages. **Marty V1 messages are not supported by Marty V2.** The following messages are published by Marty. ==== smart_servos ==== **Topic code: 120.** The message contains a `SmartServo []` array. Each SmartServo entry is **6 bytes** long, with fields in this order: ^ Type ^ Field ^ Description ^ | uint8 | `IDNo` | Motor index in the order described elsewhere, with Left Hip = 0. | | int16 | `position` | Same format as commanded positions; -32768 indicates an unknown value. | | int16 | `motorCurrent` | Current in milliamps; -32768 indicates an unknown value. | | byte | `status` | Status byte reported by the servo. | ==== accel ==== **Topic code: 121.** The message reports the x, y and z values of the built-in accelerometer, using [[https://github.com/robotical/marty_msgs/blob/master/msg/Accelerometer.msg|marty_msgs/Accelerometer]]: float32 x, float32 y, float32 z ==== power_status ==== **Topic code: 122.** The message reports power and battery status, with fields in this order: ^ Type ^ Field ^ Description ^ | uint8 | `remCapPC` | Remaining battery capacity as a percentage (0..100). | | uint8 | `tempDegC` | Battery temperature in degrees Celsius. | | uint16 | `remCapMAH` | Remaining battery capacity in mAh. | | uint16 | `fullCapMAH` | Fully charged battery capacity in mAh. | | int16 | `currentMA` | Current in mA; a positive value means charging. | | uint16 | `powerOnTimeSecs` | Time the 5V supply has been on, in seconds. | | uint16 | `powerFlags` | Power flags, described below. | **powerFlags bits:** ^ Bit ^ Meaning when set ^ | 0 | On USB power. | | 1 | 5V is turned on. | | 2 | Battery information is **not valid**. | | 3 | USB power information is **not valid**. | ==== add_ons ==== The message contains an `AddOnInfo []` array. Each AddOnInfo entry is **12 bytes** long, with fields in this order: ^ Type ^ Field ^ Description ^ | uint8 | `IDNo` | Add-on IDNo. See `hwstatus` information for ordering; the IDNo is allocated dynamically. | | uint8 | `StatusFlags` | Bit 7 (mask 0x80) indicates fresh data when set, or stale data when clear. | | uint8 [10] | `RecentData` | The 10 bytes most recently read from the add-on during polling. | ==== robot_status ==== The original message was **2 bytes** long. A **24-byte** message was added to RIC firmware in 2021. **MartyPy and other interfaces must support both message lengths.** The original two fields are: ^ Type ^ Field ^ Description ^ | uint8 | `MotionFlags` | Motion flags, described below. | | uint8 | `queueLen` | Number of queued work items; 255 indicates 255 or more. | The 24-byte message adds these fields, in order: ^ Type ^ Field ^ Description ^ | uint32 | `heapFree` | Free heap space in bytes. | | uint32 | `heapMin` | Minimum free heap space (lower watermark), in bytes. | | uint32 | `pix0_RGBT` | Pixel 0 colour and state, using the RGBT format below. | | uint32 | `pix1_RGBT` | Pixel 1 colour and state, using the RGBT format below. | | uint32 | `pix2_RGBT` | Pixel 2 colour and state, using the RGBT format below. | | uint8 | `sysManLoopMsAvg` | Average SysManager main service loop time in ms; 255 indicates 255 or more. | | uint8 | `sysManLoopMsMax` | Maximum SysManager main service loop time in ms; 255 indicates 255 or more. | **MotionFlags bits:** ^ Bit ^ Meaning ^ | 0 | `ROBOT_IS_MOVING` | | 1 | `ROBOT_IS_PAUSED` | | 2 | `FIRMWARE_UPDATE_IN_PROGRESS` | **RGBT format:** the first three bytes contain the RGB value in big-endian order. The last byte contains the pixel state: ^ Value ^ State ^ | 0 | Off | | 1 | On | | 2 | Breathe | | 3 | Override |