Skip to content

Commit 96891de

Browse files
calcmogulpjbuterbaugh
authored andcommitted
Document all of universal heartbeat CAN packet (#2269)
1 parent 44db3c2 commit 96891de

File tree

1 file changed

+59
-21
lines changed

1 file changed

+59
-21
lines changed

source/docs/software/can-devices/can-addressing.rst

Lines changed: 59 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -191,24 +191,62 @@ For CAN Nodes to be accepted for use in the FRC System, they must:
191191
Universal Heartbeat
192192
-------------------
193193

194-
The roboRIO provides a universal CAN heartbeat that any device on the bus can listen and react to. This heartbeat is sent every 20ms. The heartbeat has a full CAN ID of ``0x01011840`` (which is the NI Manufacturer ID, RobotController type, Device ID 0 and API ID ``0x062``). It is an 8 byte CAN packet. The important byte in here is byte 5 (index 4). The layout is the following bitfield.
195-
196-
+-----------------+-------+
197-
| Description | Width |
198-
+=================+=======+
199-
| RedAlliance | 1 |
200-
+-----------------+-------+
201-
| Enabled | 1 |
202-
+-----------------+-------+
203-
| Autonomous | 1 |
204-
+-----------------+-------+
205-
| Test | 1 |
206-
+-----------------+-------+
207-
| WatchdogEnabled | 1 |
208-
+-----------------+-------+
209-
| Reserved | 3 |
210-
+-----------------+-------+
211-
212-
The flag to watch for is ``WatchdogEnabled``. If that flag is set, that means motor controllers are enabled.
213-
214-
If 100ms has passed since this packet was received, the robot program can be considered hung, and devices should act as if the robot has been disabled.
194+
The roboRIO provides a universal CAN heartbeat that any device on the bus can listen and react to. This heartbeat is sent every 20 ms. The heartbeat has a full CAN ID of ``0x01011840`` (which is the NI Manufacturer ID, RobotController type, Device ID 0 and API ID ``0x062``). It is an 8 byte CAN packet with the following bitfield layout.
195+
196+
+-----------------------+------+--------------+
197+
| Description | Byte | Width (bits) |
198+
+=======================+======+==============+
199+
| Match time (seconds) | 8 | 8 |
200+
+-----------------------+------+--------------+
201+
| Match number | 6-7 | 10 |
202+
+-----------------------+------+--------------+
203+
| Replay number | 6 | 6 |
204+
+-----------------------+------+--------------+
205+
| Red alliance | 5 | 1 |
206+
+-----------------------+------+--------------+
207+
| Enabled | 5 | 1 |
208+
+-----------------------+------+--------------+
209+
| Autonomous mode | 5 | 1 |
210+
+-----------------------+------+--------------+
211+
| Test mode | 5 | 1 |
212+
+-----------------------+------+--------------+
213+
| System watchdog | 5 | 1 |
214+
+-----------------------+------+--------------+
215+
| Tournament type | 5 | 3 |
216+
+-----------------------+------+--------------+
217+
| Time of day (year) | 4 | 6 |
218+
+-----------------------+------+--------------+
219+
| Time of day (month) | 3-4 | 4 |
220+
+-----------------------+------+--------------+
221+
| Time of day (day) | 3 | 5 |
222+
+-----------------------+------+--------------+
223+
| Time of day (seconds) | 2-3 | 6 |
224+
+-----------------------+------+--------------+
225+
| Time of day (minutes) | 1-2 | 6 |
226+
+-----------------------+------+--------------+
227+
| Time of day (hours) | 1 | 5 |
228+
+-----------------------+------+--------------+
229+
230+
.. code-block:: c++
231+
232+
struct [[gnu::packed]] RobotState {
233+
uint64_t matchTimeSeconds : 8;
234+
uint64_t matchNumber : 10;
235+
uint64_t replayNumber : 6;
236+
uint64_t redAlliance : 1;
237+
uint64_t enabled : 1;
238+
uint64_t autonomous : 1;
239+
uint64_t testMode : 1;
240+
uint64_t systemWatchdog : 1;
241+
uint64_t tournamentType : 3;
242+
uint64_t timeOfDay_yr : 6;
243+
uint64_t timeOfDay_month : 4;
244+
uint64_t timeOfDay_day : 5;
245+
uint64_t timeOfDay_sec : 6;
246+
uint64_t timeOfDay_min : 6;
247+
uint64_t timeOfDay_hr : 5;
248+
};
249+
250+
If the ``System watchdog`` flag is set, motor controllers are enabled. If 100 ms has passed since this packet was received, the robot program can be considered hung, and devices should act as if the robot has been disabled.
251+
252+
Note that all fields except ``Enabled``, ``Autonomous mode``, ``Test mode``, and ``System watchdog`` will contain invalid values until an arbitrary time after the Driver Station connects.

0 commit comments

Comments
 (0)