Skip to content

CanandDevice

Message/wire format spec, version 2024-offseason.

The device spec for Redux products will not change in a backwards-incompatible fashion in-season, from the first official release for a given year until after the FIRST Championship.

Summary of the CAN address scheme and packet format

Section titled “Summary of the CAN address scheme and packet format”

Redux CAN devices conform to the 29-bit FRC CAN message address scheme, with a very specific rearrangement of the API identifier/class field.

A full CAN arbitration id that actually gets put on the bus can be broken down into four components:

  1. A 5 bit device type (devType) that is product specific (the Canandmag is 7 for “gear tooth sensor”)
  2. An 8-bit manufacturer code unique to each vendor (the Redux code is 14 in decimal or 0xE)
  3. 10 bits of API identifier
  4. A 6-bit device number (devId) that is user-configurable so you can have multiple of a device on a bus — this is what the “CAN ID” in robot code and vendor tuners usually refer to.

The WPILib docs elaborates on this in a bit more detail. Of note is that it breaks down the 10-bit API identifier into a 6-bit API class and 4-bit API index.

Redux products break it down into a 2 bit API page (currently always 0) and an 8 bit API index (apiIndex).

The breakdown can be seen in the diagram provided below for a Party Mode packet sent to Canandmag device 4:

CAN ID Breakdown Example

Based on diagram from: WPILib Docs

Redux CAN device have a series of settings that are up to 6 bytes in length, that are managed using the SET_SETTING, SETTING_COMMAND and REPORT_SETTING messages. Exact format and functionality of each setting field is generally device dependent.

Sending a SET_SETTING packet, will trigger a REPORT_SETTING message as a reply to confirm the transaction and success or failure. The SETTING_COMMAND packet can be used to either report settings, reset to default settings, or perform other device-specific actions.

All value fields are default unsigned little-endian unless otherwise specified.

This document uses the following conventions for notating field types:

TypeDescription
boolSingle-bit boolean
float:24IEEE 754 single-precision float with the least significant 8 bits of mantissa stripped to fit in 3 bytes
float:32IEEE 754 single-precision (32-bit) float
float:64IEEE 754 double-precision (64-bit) float
uintN_tUnsigned integer of bit width N
intN_tSigned integer of bit width N
padN_tN bits of padding bits that should be left zero.
uint8_t[N]N bytes of a byte array

Additionally, when literals are specified for default values,

  • true and false are defined as bit values 1 and 0 respectively
  • For a byte array specified as {0x1, 0x2, 0x3, 0x4} the first (index zero) byte is 0x1 and the last is 0x4.

These are the definitions of messages sent over CAN, USB, or other encapsulation mechanisms.

Message summary:

API IndexMessageDescription
0xbENUMERATEDevice enumerate response
0x7PARTY_MODEParty mode
0x6STATUSStatus frame
0x5CLEAR_STICKY_FAULTSClear device sticky faults
0x4REPORT_SETTINGSetting value report from device
0x3SET_SETTINGUpdate setting on device
0x2SETTING_COMMANDSetting control command

Sent by the device upon an enumerate request, or every 100 milliseconds if the device is stuck in OTA bootloader.

The exact format of enumerate request may vary between communication mediums:

  • For a CAN bus an enumerate request is a message with an extended (29-bit) arbitration ID of 0xE0000

Properties

PropertyValue
API Index0xb
Message length8 bytes
Transmission directionDevice -> robot

Signals

Signal nameSignal typeOptionalDescription
serialuint8_t[6]Device-unique serial number
is_bootloaderboolDevice is in bootloader.
reservedpad15_tReserved

Configures party mode to the device.

Non-zero values will prompt the onboard RGB LED of the device to cycle various colors to help identify where it physically sits on a robot.

A zero value stops the cycling.

Properties

PropertyValue
API Index0x7
Minimum message length1 bytes
Maximum message length8 bytes
Transmission directionRobot -> device

Signals

Signal nameSignal typeOptionalDescription
party_leveluint8_tParty level. 0 disables the strobe, whereas each increased value up to 10 increases strobe period by 50 ms.

Periodic frame containing status information about the device.

Typically this contains active and sticky faults as well as environmental information such as device temperature. The actual composition of this message will vary from device to device, but it is guaranteed to be 8 bytes long. Consult individual device documentation pages for more information.

This frame cannot be disabled.

The period at which this message is broadcasted at is controlled by the STATUS_FRAME_PERIOD setting.

Properties

PropertyValue
API Index0x6
Message length8 bytes
Transmission directionDevice -> robot
Frame period settingSTATUS_FRAME_PERIOD
Default frame period1000 milliseconds

Signals

Signal nameSignal typeOptionalDescription
dev_specificuint8_t[8]Device-specific status data. See device pages for more information.

Sent to device to clear all sticky faults (sets the sticky faults to 0 until faults become active again)

Properties

PropertyValue
API Index0x5
Minimum message length0 bytes
Maximum message length8 bytes
Transmission directionRobot -> device

Sent to report a setting value from the device.

These messages can be triggered by:

The setting flags include information on whether or not the setting set was successful as well as the setting data that was sent.

Sent after a setting change via or on the fetch settings and factory reset. Setting changes (as of v2024) will always include the “settings flag” field.

Properties

PropertyValue
API Index0x4
Message length8 bytes
Transmission directionDevice -> robot

Signals

Signal nameSignal typeOptionalDescription
addressSetting indexSetting index to write to
valuesetting_data6-byte setting value
flagssetting_report_flagsSetting receive status

Sent to device to change a setting by address.

If the setting exists, a REPORT_SETTING packet will be sent in reply, with the data of the setting echoed back and information on whether or not the setting set succeeded.

Properties

PropertyValue
API Index0x3
Message length8 bytes
Transmission directionRobot -> device

Signals

Signal nameSignal typeOptionalDescription
addressSetting indexSetting index to write to
valuesetting_data6-byte setting value
flagssetting_flagsSetting flags

Sent to the device to operate on the settings subsystem.

Devices may add their own setting commands but they will typically at least have:

  • Fetch all settings (id 0x0)
  • Reset all applicable settings to factory default (id 0x1)
  • Fetch setting value (id 0x2)

Most setting commands (e.g. reset to factory default and get all settings) are allowed to have a data length code of 1, however, the fetch setting value command requires a data length of at least 2 bytes to also specify the setting index to fetch.

The most typical use case is likely to fetch a specific setting value; to fetch firmware version for example one might send this packet with the payload {0x2, 0x6} and wait for a REPORT_SETTING to report the setting.

Properties

PropertyValue
API Index0x2
Minimum message length1 bytes
Maximum message length8 bytes
Transmission directionRobot -> device

Signals

Signal nameSignal typeOptionalDescription
control_flagSETTING_COMMAND (Enum)Setting command index
setting_indexSetting indexSetting index to fetch

Settings hold and manipulate the configuration of the device.

Most settings are saved to non-volatile flash, are saved on device reboot, are considered both readable and writable, and will be reset to a default value when a reset to factory default setting command is issued.

Some settings are read-only as they contain device or firmware specific information such as serial number or firmware version.

Other settings may be write-only as they command the device to do something specific; e.g. update an offset. In practice, settings get used whenever an infrequent (non-periodic) call-response architecture makes sense spec-wise.

Each setting is associated with an 8-bit unsigned setting index byte. Setting data is encoded as 48-bit (6 byte) fields. Both setting index and encoded setting data are sent in SET_SETTING and REPORT_SETTING messages, whereas the FETCH_SETTING_VALUE setting command only requires an index.

If a type associated with a setting is less than 48 bits wide (e.g. a float32), the rest of the data field during encode/decode can be assumed to be padding and left as zero.

Setting summary:

Setting indexNameTypeDefault valueReadableWritableResets to factory defaultDescription
0x8DEVICE_TYPEuint16_tn/aDevice-specific type identifier
0x6FIRMWARE_VERSIONfirmware_versionn/aFirmware version
0x5SERIAL_NUMBERuint8_t[6]n/aSerial number
0x4STATUS_FRAME_PERIODstatus_frame_period1000Status frame period (ms)
0x3NAME_2uint8_t[6][0x0, 0x0, 0x0, 0x0, 0x0, 0x0]device_name[12:17]
0x2NAME_1uint8_t[6][0x44, 0x65, 0x76, 0x69, 0x63, 0x65]device_name[6:11]
0x1NAME_0uint8_t[6][0x43, 0x61, 0x6e, 0x61, 0x6e, 0x64]device_name[0:5]
0x0CAN_IDcan_device_id0CAN Device ID

Read-only device type identifier.

If multiple types of device share the same FRC-CAN device class, e.g. two device variants that do similar things but may or may not have the same message API, this setting can be used to disambiguate between them.

PropertyValue
Setting index0x8
Typeuint16_t
Default valuen/a
Readable
Writable
Resets on factory default

Read-only setting value of the device’s firmware version.

PropertyValue
Setting index0x6
Typefirmware_version
Default valuen/a
Readable
Writable
Resets on factory default

Read-only setting of the device’s serial number.

PropertyValue
Setting index0x5
Typeuint8_t[6]
Default valuen/a
Readable
Writable
Resets on factory default

Period between the transmission of STATUS messages in milliseconds. This frame cannot be disabled (as Alchemist uses it to detect devices).

PropertyValue
Setting index0x4
Typestatus_frame_period
Default value1000
Readable
Writable
Resets on factory default

Last 6 bytes of the name field. Having a null byte will terminate the name field at that byte. All 6 bytes can be non-null and the name will be 18 characters long.

PropertyValue
Setting index0x3
Typeuint8_t[6]
Default value[0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
Readable
Writable
Resets on factory default

Middle 6 bytes of the device name. Having a null byte will terminate the name field at that byte.

PropertyValue
Setting index0x2
Typeuint8_t[6]
Default value[0x44, 0x65, 0x76, 0x69, 0x63, 0x65]
Readable
Writable
Resets on factory default

First 6 bytes of the device name. Having a null byte will terminate the name field at that byte.

PropertyValue
Setting index0x1
Typeuint8_t[6]
Default value[0x43, 0x61, 0x6e, 0x61, 0x6e, 0x64]
Readable
Writable
Resets on factory default

Sets the 6-bit device id, ranging from 0 to 63. This allows multiple of a device to share a bus. Defaults to 0 but does not reset on factory resets.

PropertyValue
Setting index0x0
Typecan_device_id
Default value0
Readable
Writable
Resets on factory default

Data types associated with messages and/or settings.

Frame period associated with some periodic data or status frame. 1 LSB equals 1 ms of period, and setting the period to 0 will disable the corresponding frame.

PropertyValue
Base typeuint
Bit width16
Minimum value0
Maximum value65535
Default value0
Conversion factor1 LSB = 1/1000 seconds

Frame period specific to the STATUS frame, as status frames cannot be set to 0 and disabled.

PropertyValue
Base typeuint
Bit width16
Minimum value1
Maximum value16383
Default value1000
Conversion factor1 LSB = 1/1000 seconds

The CAN device id used by the device. As specified by the FRC-CAN spec, this comprises the least significant 6 bits of the CAN id.

PropertyValue
Base typeuint
Bit width8
Minimum value0
Maximum value63
Default value0

Information set on the SET_SETTING message.

Setting the ephemeral bit makes the setting not save to non-volatile memory and not persist on reboot, if applicable.

Sending multiple messages with the synch hold message will queue them for application on device until a message with the bit unset and the number of messages expected to be in the queue (in synch_msg_count) is set.

If the number of settings in the queue equals the number of settings in synch_message_count, all settings are applied and a report settings message with the commit_success bit is set. Otherwise, none of them are applied and the commit success bit is unset.

Original Canandmags do not support the synch hold mechanism.

PropertyValue
Base typestruct
Bit width8

Signals:

NameTypeDefault valueDescription
ephemeralboolfalseWhether the setting should be set ephemeral
synch_holdboolfalseWhether the setting should be held until the next synch barrier
reserved_0pad2_t0Reserved
synch_msg_countuint4_t0Synch message count

Bits set by the REPORT_SETTING message to indicate success or failure

PropertyValue
Base typebitset
Bit width8

Flags:

Flag indexFlag nameDefault valueDescription
0set_success0Whether the setting set/fetch was successful
1commit_success0Whether the setting synch commit was successful

Firmware version reported by the device.

PropertyValue
Base typestruct
Bit width32

Signals:

NameTypeDefault valueDescription
firmware_patchuint8_t0Firmware version patch number
firmware_minoruint8_t0Firmware version minor number
firmware_yearuint16_t0Firmware version year

An IEEE single-precision float32 that cannot be NaN or infinite.

PropertyValue
Base typefloat
Bit width32
Minimum valuen/a
Maximum valuen/a
Default value0

An IEEE single-precision float32 that must be non-negative but may be NaN or infinite.

PropertyValue
Base typefloat
Bit width32
Minimum value0.0
Maximum valuen/a
Default value0

An IEEE single-precision float32 that must be non-negative AND cannot be NaN or infinite.

PropertyValue
Base typefloat
Bit width32
Minimum value0.0
Maximum valuen/a
Default value0

An IEEE single-precision float32 constrained between 0 and 1 inclusive.

PropertyValue
Base typefloat
Bit width32
Minimum value0.0
Maximum value1.0
Default value0

Enums associated with messages and/or settings. The backing type is always an unsigned int of some specified width.

These are setting commands issued via the SETTING_COMMAND message. The fetch setting command and reset factory settings command are common to all Redux devices.

PropertyValue
Bit width8
Default enum

Enum variants:

Enum indexVariant nameDescription
0x0FETCH_SETTINGSFetch all settings from device via a series of REPORT_SETTING messages of all indexes
0x1RESET_FACTORY_DEFAULTReset all resettable settings to factory default, and broadcast all setting values via REPORT_SETTING messages.
0x2FETCH_SETTING_VALUERequests to fetch a single setting from device, with its value reported via the REPORT_SETTING message. This requires the use of the second byte to specify the setting index to fetch.