Skip to content

Canandmag

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.

PropertyValue
FRC CAN Device Type0x7
DBC FileLink
Inherits from[CanandDevice]

The DBC files assumes a device id of 0. For more information on the CAN device type, see CanandDevice

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
0x1fPOSITION_OUTPUTPosition frame
0x1eVELOCITY_OUTPUTVelocity frame
0x1dRAW_POSITION_OUTPUTRaw position frame
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

Periodic frame with relative position and absolute position registers read by the device.

Absolute and relative position operate (mostly) independently; absolute position has a persistent zero offset that is subtracted from the raw zero reading and is limited to a single rotation whereas relative position always initializes to 0 on boot and counts across multiple turns.

Both absolute and relative position have their outputs set to 0 when the zero button is pressed for 2 seconds, and both absolute and relative position will always count up and count down in the same direction at the same rate.

The absolute position value is also what gets sent over PWM, and so will also be affected by the zero offset.

For both relative (unwrapped) and absolute position, one device tick is 1/16384-th of a rotation.

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

Properties

PropertyValue
API Index0x1f
Message length6 bytes
Transmission directionDevice -> robot
Frame period settingPOSITION_FRAME_PERIOD
Default frame period20 milliseconds

Signals

Signal nameSignal typeOptionalDescription
relative_positionrelative_position32-bit signed relative position in 1/16384-ths of a rotation. This value does not persist on reboots.
magnet_statusmagnet_status2-bit magnet status. If both bits are zero, the magnet is in range.
absolute_positionabsolute_position14-bit unsigned absolute position in 1/16384-ths of a rotation. The zero offset of the absolute encoder will preserve through reboots.

Periodic frame containing the currently calculated velocity.

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

Properties

PropertyValue
API Index0x1e
Message length3 bytes
Transmission directionDevice -> robot
Frame period settingVELOCITY_FRAME_PERIOD
Default frame period20 milliseconds

Signals

Signal nameSignal typeOptionalDescription
velocityvelocityVelocity as a 22-bit signed integer. One velocity tick corresponds to 1/1024th of a rotation per second.
magnet_statusmagnet_status2-bit magnet status. If both bits are zero, the magnet is in range.

Periodic frame containing a raw absolute reading that does not account for the zero offset or inversion settings. Additionally includes a reading timestamp in milliseconds and magnet status data.

By factory default, this frame is disabled (0 ms) — it needs to be explicitly enabled to be used.

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

Properties

PropertyValue
API Index0x1d
Message length6 bytes
Transmission directionDevice -> robot
Frame period settingRAW_POSITION_FRAME_PERIOD
Default frame period0 milliseconds

Signals

Signal nameSignal typeOptionalDescription
raw_positionabsolute_position14-bit raw absolute position in 1/16384-ths of a rotation.
magnet_statusmagnet_status2-bit magnet status. If both bits are zero, the magnet is in range.
timestampuint32_t32-bit sensor reading timestamp in microseconds since device boot.

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 status frame containing active and sticky fault data as well as temperature.

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
faultsfaults8-bit active faults bitfield
sticky_faultsfaults8-bit sticky faults bitfield
temperatureint8_t8-bit signed temperature byte in Celsius
reservedpad40_tReserved bits

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
0xffZERO_OFFSETzero_offsetType defaultEncoder zero offset
0xfeVELOCITY_WINDOWvelocity_window100Velocity window width (value*250us)
0xfdPOSITION_FRAME_PERIODframe_period20Position frame period (ms)
0xfcVELOCITY_FRAME_PERIODframe_period20Velocity frame period (ms)
0xfbRAW_POSITION_FRAME_PERIODframe_period0Raw position frame period (ms)
0xfaINVERT_DIRECTIONbool0Invert direction (0=ccw, 1=cw)
0xf9RELATIVE_POSITIONrelative_positionn/aSet relative position value
0xf8DISABLE_ZERO_BUTTONbool0Disable the zero button
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][0x6d, 0x61, 0x67, 0x0, 0x0, 0x0]device_name[6:11]
0x1NAME_0uint8_t[6][0x43, 0x61, 0x6e, 0x61, 0x6e, 0x64]device_name[0:5]
0x0CAN_IDcan_device_id0CAN Device ID

This setting is used to update the absolute position broadcasted by the position message and over PWM.

Absolute position is calculated as:

$$\text{absolute position} = (\text{raw IC reading} - \text{saved zero offset}) \mod (1 \text{ rotation})$$

with some additional logic to handle direction inversion.

There are two methods to updating the absolute position:

  • Updating the zero offset (saved in flash) subtracted from the raw encoder IC reading directly
  • Taking a new intended absolute encoder reading and calculating the zero offset required to read the new value

The former has some niche uses but the latter is by far the most common application (e.g. to zero the encoder position).

This setting can update the zero offset via either approach via the position bit. If the position bit is set, the sent value is treated as a new absolute position, but if unset, the sent value is treated as a new zero offset.

If this setting is read from, the zero offset is always returned with the position bit unset.

PropertyValue
Setting index0xff
Typezero_offset
Default valueType default
Readable
Writable
Resets on factory default

Controls the number of samples used to average in the velocity window. Samples occur once every 250 microseconds.

PropertyValue
Setting index0xfe
Typevelocity_window
Default value100
Readable
Writable
Resets on factory default

Period between each transmission of POSITION_OUTPUT messages.

PropertyValue
Setting index0xfd
Typeframe_period
Default value20
Readable
Writable
Resets on factory default

Period between each transmission of VELOCITY_OUTPUT messages.

PropertyValue
Setting index0xfc
Typeframe_period
Default value20
Readable
Writable
Resets on factory default

Period between each transmission of RAW_POSITION_OUTPUT messages.

PropertyValue
Setting index0xfb
Typeframe_period
Default value0
Readable
Writable
Resets on factory default

This setting whether counter clockwise or clockwise relative to the Canandmag’s sensor face (the side opposite its LED) should be positive for position (both relative and absolute) and velocity.

This will additionally invert the direction of the absolute PWM output as well.

False (0) means counter clockwise is positive, true (1) specifies clockwise is positive.

This setting affects the direction of both absolute and relative position.

PropertyValue
Setting index0xfa
Typebool
Default value0
Readable
Writable
Resets on factory default

This setting can be used to update the value of the relative position broadcasted by the periodic position frame.

This current position register does not have an offset saved to non-volatile flash but is rather initialized to 0 on device boot and updated as the encoder IC reading changes.

Writing to this settings with a signed 32-bit integer will update the current relative position to the new value in the payload, using the lowest 32 bits as a signed integer.

Reading from this settings index is not valid and will produce 0xffffffffffff — use the periodic position frame to read relative position data instead.

PropertyValue
Setting index0xf9
Typerelative_position
Default valuen/a
Readable
Writable
Resets on factory default

This setting controls whether the onboard zero button functions.

By default, this setting is set to false (0). Pressing the zero button for 2 seconds will set both absolute and relative position values to zero.

When the zero button is enabled (when this setting is set to 0), pressing it for 2 seconds will set both absolute and relative position values to zero for both CAN and PWM, and pressing the button for 15 seconds will reset the device to factory default settings.

When the zero button is disabled (when this setting is set to 1), inputs to the button will be completely ignored — factory resets and zeroing must be performed over CAN or other supported message layers.

PropertyValue
Setting index0xf8
Typebool
Default value0
Readable
Writable
Resets on factory default

Read-only device type identifier.

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.

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.

PropertyValue
Setting index0x2
Typeuint8_t[6]
Default value[0x6d, 0x61, 0x67, 0x0, 0x0, 0x0]
Readable
Writable
Resets on factory default

First 6 bytes of the device name.

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.

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

Data types associated with messages and/or settings.

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

See CanandDevice setting_flags

See CanandDevice setting_report_flags

See CanandDevice firmware_version

PropertyValue
Base typebitset
Bit width8

Flags:

Flag indexFlag nameDefault valueDescription
0power_cycle0The power cycle fault flag, which is set to true when the encoder first boots.
1can_id_conflict0The CAN ID conflict flag, which is set to true if there is a CAN id conflict.
2can_general_error0The CAN general error flag, which will raise if the device encounters a CAN fault.
3out_of_temperature_range0The temperature range flag (0-70°C).
4hardware_fault0The hardware fault flag.
5magnet_out_of_range0The magnet out of range flag.
6under_volt0The undervolt flag.

Data encapsulated by the zero offset setting.

If sent with the position bit set, the offset_or_position field is treated as an absolute position. If sent with the position bit unset, the offset_or_position field updates zero offset directly. On operations that report settings, the read setting is always the zero offset.

PropertyValue
Base typestruct
Bit width15

Signals:

NameTypeDefault valueDescription
offset_or_positionabsolute_position0Zero offset or position
position_bitbool0True to set position instead of a zero offset.
PropertyValue
Base typesint
Bit width22
Minimum value-2097152
Maximum value2097151
Default value0
Conversion factor1 LSB = 1/1024 rotation/second
PropertyValue
Base typesint
Bit width32
Minimum value-2147483648
Maximum value2147483647
Default value0
Conversion factor1 LSB = 1/16384 rotation
PropertyValue
Base typeuint
Bit width14
Minimum value0
Maximum value16383
Default value0
Conversion factor1 LSB = 1/16384 rotation
PropertyValue
Base typeuint
Bit width2
Minimum value0
Maximum value3
Default value0
PropertyValue
Base typeuint
Bit width8
Minimum value1
Maximum value255
Default value100
Conversion factor1 LSB = 1/4 millisecond
PropertyValue
Bit width8
Default enum

Enum variants:

Enum indexVariant nameDescription
0x0FETCH_SETTINGSFetch all settings from device via a series of REPORT_SETTING messages.
0x1RESET_FACTORY_DEFAULTReset all resettable settings to factory default.
0x2FETCH_SETTING_VALUERequests to fetch a single setting from device.
0xffRESET_FACTORY_DEFAULT_KEEP_ZEROReset to factory defaults, but keep encoder zero offset