From 047c44201e862ee36636748a39bd88469f0c2588 Mon Sep 17 00:00:00 2001 From: Samuel Sadok Date: Wed, 1 Sep 2021 19:36:30 +0200 Subject: [PATCH] add trajectory done bit to CAN simple protocol --- Firmware/communication/can/can_simple.cpp | 18 ++++++- docs/can-protocol.md | 62 ++++++++++++----------- 2 files changed, 49 insertions(+), 31 deletions(-) diff --git a/Firmware/communication/can/can_simple.cpp b/Firmware/communication/can/can_simple.cpp index 9a1b8ad1..3a24ead1 100644 --- a/Firmware/communication/can/can_simple.cpp +++ b/Firmware/communication/can/can_simple.cpp @@ -379,7 +379,23 @@ bool CANSimple::send_heartbeat(const Axis& axis) { txmsg.len = 8; can_setSignal(txmsg, axis.error_, 0, 32, true); - can_setSignal(txmsg, axis.current_state_, 32, 32, true); + can_setSignal(txmsg, uint8_t(axis.current_state_), 32, 8, true); + + // Motor flags + uint8_t motorFlags = 0; // reserved + + // Encoder flags + uint8_t encoderFlags = 0; // reserved + + // Controller flags + uint8_t controllerFlags = 0; + uint8_t trajDone = uint8_t(axis.controller_.trajectory_done_) << 7; + controllerFlags |= trajDone; + + can_setSignal(txmsg, motorFlags, 40, 8, true); + can_setSignal(txmsg, encoderFlags, 48, 8, true); + can_setSignal(txmsg, controllerFlags, 56, 8, true); + // can_setSignal(txmsg, axis.current_state_, 32, 32, true); return canbus_->send_message(txmsg); } diff --git a/docs/can-protocol.md b/docs/can-protocol.md index 97287143..8bfaa8cb 100644 --- a/docs/can-protocol.md +++ b/docs/can-protocol.md @@ -43,36 +43,38 @@ For example, an Axis ID of `0x01` with a command of `0x0C` would be result in `0 ### Messages -CMD ID | Name | Sender | Signals | Start byte | Signal Type | Bits | Factor | Offset | Byte Order ---: | :-- | :-- | :-- | :-- | :-- | :-- | :-- | :-- | :-- -0x000 | CANOpen NMT Message\*\* | Master | - | - | - | - | - | - | - -0x001 | ODrive Heartbeat Message | Axis | Axis Error
Axis Current State | 0
4 | Unsigned Int
Unsigned Int | 32
32 | 1
1 | 0
0 | Intel
Intel -0x002 | ODrive Estop Message | Master | - | - | - | - | - | - | - -0x003 | Get Motor Error\* | Axis | Motor Error | 0 | Unsigned Int | 64 | 1 | 0 | Intel -0x004 | Get Encoder Error\* | Axis | Encoder Error | 0 | Unsigned Int | 32 | 1 | 0 | Intel -0x005 | Get Sensorless Error\* | Axis | Sensorless Error | 0 | Unsigned Int | 32 | 1 | 0 | Intel -0x006 | Set Axis Node ID | Master | Axis CAN Node ID | 0 | Unsigned Int | 32 | 1 | 0 | Intel -0x007 | Set Axis Requested State | Master | Axis Requested State | 0 | Unsigned Int | 32 | 1 | 0 | Intel -0x008 | Set Axis Startup Config | Master | - Not yet implemented - | - | - | - | - | - | - -0x009 | Get Encoder Estimates\* | Master | Encoder Pos Estimate
Encoder Vel Estimate | 0
4 | IEEE 754 Float
IEEE 754 Float | 32
32 | 1
1 | 0
0 | Intel
Intel -0x00A | Get Encoder Count\* | Master | Encoder Shadow Count
Encoder Count in CPR | 0
4 | Signed Int
Signed Int | 32
32 | 1
1 | 0
0 | Intel
Intel -0x00B | Set Controller Modes | Master | Control Mode
Input Mode | 0
4 | Signed Int
Signed Int | 32
32 | 1
1 | 0
0 | Intel
Intel -0x00C | Set Input Pos | Master | Input Pos
Vel FF
Torque FF | 0
4
6 | IEEE 754 Float
Signed Int
Signed Int | 32
16
16 | 1
0.001
0.001 | 0
0
0 | Intel
Intel
Intel -0x00D | Set Input Vel | Master | Input Vel
Torque FF | 0
4 | IEEE 754 Float
IEEE 754 Float | 32
32 | 1
1 | 0
0 | Intel
Intel -0x00E | Set Input Torque | Master | Input Torque | 0 | IEEE 754 Float | 32 | 1 | 0 | Intel -0x00F | Set Limits | Master | Velocity Limit
Current Limit | 0
4 | IEEE 754 Float
IEEE 754 Float | 32
| 1
1 | 0
0 | Intel -0x010 | Start Anticogging | Master | - | - | - | - | - | - | - -0x011 | Set Traj Vel Limit | Master | Traj Vel Limit | 0 | IEEE 754 Float | 32 | 1 | 0 | Intel -0x012 | Set Traj Accel Limits | Master | Traj Accel Limit
Traj Decel Limit | 0
4 | IEEE 754 Float
IEEE 754 Float | 32
32 | 1
1 | 0
0 | Intel
Intel -0x013 | Set Traj Inertia | Master | Traj Inertia | 0 | IEEE 754 Float | 32 | 1 | 0 | Intel -0x014 | Get IQ\* | Axis | Iq Setpoint
Iq Measured | 0
4 | IEEE 754 Float
IEEE 754 Float | 32
32 | 1
1 | 0
0 | Intel
Intel -0x015 | Get Sensorless Estimates\* | Master | Sensorless Pos Estimate
Sensorless Vel Estimate | 0
4 | IEEE 754 Float
IEEE 754 Float | 32
32 | 1
1 | 0
0 | Intel
Intel -0x016 | Reboot ODrive | Master\*\*\* | - | - | - | - | - | - | - -0x017 | Get Vbus Voltage | Master\*\*\* | Vbus Voltage | 0 | IEEE 754 Float | 32 | 1 | 0 | Intel -0x018 | Clear Errors | Master | - | - | - | - | - | - | - -0x019 | Set Linear Count | Master | Position | 0 | Signed Int | 32 | 1 | 0 | Intel -0x700 | CANOpen Heartbeat Message\*\* | Slave | - | - | - | - | - | - | - --|-|-|----------------------------------|-|--------------------|-|-|-|_ +CMD ID | Name | Sender | Signals | Start byte | Signal Type | Bits | Factor | Offset +--: | :-- | :-- | :-- | :-- | :-- | :-- | :-- | :-- +0x000 | CANOpen NMT Message\*\* | Master | - | - | - | - | - | - +0x001 | ODrive Heartbeat Message | Axis | Axis Error
Axis Current State
Controller Status | 0
4
7 | Unsigned Int
Unsigned Int
Bitfield | 32
8
8 | -
-
- | -
-
- +0x002 | ODrive Estop Message | Master | - | - | - | - | - | - +0x003 | Get Motor Error\* | Axis | Motor Error | 0 | Unsigned Int | 64 | 1 | 0 +0x004 | Get Encoder Error\* | Axis | Encoder Error | 0 | Unsigned Int | 32 | 1 | 0 +0x005 | Get Sensorless Error\* | Axis | Sensorless Error | 0 | Unsigned Int | 32 | 1 | 0 +0x006 | Set Axis Node ID | Master | Axis CAN Node ID | 0 | Unsigned Int | 32 | 1 | 0 +0x007 | Set Axis Requested State | Master | Axis Requested State | 0 | Unsigned Int | 32 | 1 | 0 +0x008 | Set Axis Startup Config | Master | - Not yet implemented - | - | - | - | - | - +0x009 | Get Encoder Estimates\* | Master | Encoder Pos Estimate
Encoder Vel Estimate | 0
4 | IEEE 754 Float
IEEE 754 Float | 32
32 | 1
1 | 0
0 +0x00A | Get Encoder Count\* | Master | Encoder Shadow Count
Encoder Count in CPR | 0
4 | Signed Int
Signed Int | 32
32 | 1
1 | 0
0 +0x00B | Set Controller Modes | Master | Control Mode
Input Mode | 0
4 | Signed Int
Signed Int | 32
32 | 1
1 | 0
0 +0x00C | Set Input Pos | Master | Input Pos
Vel FF
Torque FF | 0
4
6 | IEEE 754 Float
Signed Int
Signed Int | 32
16
16 | 1
0.001
0.001 | 0
0
0 +0x00D | Set Input Vel | Master | Input Vel
Torque FF | 0
4 | IEEE 754 Float
IEEE 754 Float | 32
32 | 1
1 | 0
0 +0x00E | Set Input Torque | Master | Input Torque | 0 | IEEE 754 Float | 32 | 1 | 0 +0x00F | Set Limits | Master | Velocity Limit
Current Limit | 0
4 | IEEE 754 Float
IEEE 754 Float | 32
| 1
1 | 0
0 +0x010 | Start Anticogging | Master | - | - | - | - | - | - +0x011 | Set Traj Vel Limit | Master | Traj Vel Limit | 0 | IEEE 754 Float | 32 | 1 | 0 +0x012 | Set Traj Accel Limits | Master | Traj Accel Limit
Traj Decel Limit | 0
4 | IEEE 754 Float
IEEE 754 Float | 32
32 | 1
1 | 0
0 +0x013 | Set Traj Inertia | Master | Traj Inertia | 0 | IEEE 754 Float | 32 | 1 | 0 +0x014 | Get IQ\* | Axis | Iq Setpoint
Iq Measured | 0
4 | IEEE 754 Float
IEEE 754 Float | 32
32 | 1
1 | 0
0 +0x015 | Get Sensorless Estimates\* | Master | Sensorless Pos Estimate
Sensorless Vel Estimate | 0
4 | IEEE 754 Float
IEEE 754 Float | 32
32 | 1
1 | 0
0 +0x016 | Reboot ODrive | Master\*\*\* | - | - | - | - | - | - +0x017 | Get Vbus Voltage | Master\*\*\* | Vbus Voltage | 0 | IEEE 754 Float | 32 | 1 | 0 +0x018 | Clear Errors | Master | - | - | - | - | - | - +0x019 | Set Linear Count | Master | Position | 0 | Signed Int | 32 | 1 | 0 +0x700 | CANOpen Heartbeat Message\*\* | Slave | - | - | - | - | - | - +-|-|-|----------------------------------|-|--------------------|-|-|- + +All multibyte values are little endian (aka Intel format, aka least significant byte first). \* Note: These messages are call & response. The Master node sends a message with the RTR bit set, and the axis responds with the same ID and specified payload. \*\* Note: These CANOpen messages are reserved to avoid bus collisions with CANOpen devices. They are not used by CAN Simple.