From 45fee3af5c46fdfd48ef3c3dd881c93d34059469 Mon Sep 17 00:00:00 2001 From: Paul Guenette Date: Mon, 5 Sep 2022 17:46:53 -0700 Subject: [PATCH 1/3] Add controller error message --- .gitignore | 1 + Firmware/communication/can/can_simple.cpp | 15 +++++++++++++++ Firmware/communication/can/can_simple.hpp | 1 + tools/create_can_dbc.py | 9 ++++++++- tools/odrive-cansimple.dbc | 5 ++++- 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index e536966d..7bc68002 100644 --- a/.gitignore +++ b/.gitignore @@ -65,3 +65,4 @@ GUI/node_modules GUI/build docs/reStructuredText/_build/ +tools/odrive-cansimple.ini diff --git a/Firmware/communication/can/can_simple.cpp b/Firmware/communication/can/can_simple.cpp index b413c2c3..5f375ca1 100644 --- a/Firmware/communication/can/can_simple.cpp +++ b/Firmware/communication/can/can_simple.cpp @@ -154,6 +154,9 @@ void CANSimple::do_command(Axis& axis, const can_Message_t& msg) { case MSG_GET_ADC_VOLTAGE: get_adc_voltage_callback(axis, msg); break; + case MSG_GET_CONTROLLER_ERROR: + get_controller_error_callback(axis); + break; default: break; } @@ -203,6 +206,18 @@ bool CANSimple::get_sensorless_error_callback(const Axis& axis) { return canbus_->send_message(txmsg); } +bool CANSimple::get_controller_error_callback(const Axis& axis) { + can_Message_t txmsg; + txmsg.id = axis.config_.can.node_id << NUM_CMD_ID_BITS; + txmsg.id += MSG_GET_CONTROLLER_ERROR; // heartbeat ID + txmsg.isExt = axis.config_.can.is_extended; + txmsg.len = 8; + + can_setSignal(txmsg, axis.controller_.error_, 0, 32, true); + + return canbus_->send_message(txmsg); +} + void CANSimple::set_axis_nodeid_callback(Axis& axis, const can_Message_t& msg) { axis.config_.can.node_id = can_getSignal(msg, 0, 32, true); } diff --git a/Firmware/communication/can/can_simple.hpp b/Firmware/communication/can/can_simple.hpp index 3c8192a2..a94c292e 100644 --- a/Firmware/communication/can/can_simple.hpp +++ b/Firmware/communication/can/can_simple.hpp @@ -36,6 +36,7 @@ class CANSimple { MSG_SET_POS_GAIN, MSG_SET_VEL_GAINS, MSG_GET_ADC_VOLTAGE, + MSG_GET_CONTROLLER_ERROR, MSG_CO_HEARTBEAT_CMD = 0x700, // CANOpen NMT Heartbeat SEND }; diff --git a/tools/create_can_dbc.py b/tools/create_can_dbc.py index 933545c8..e8ab74b5 100644 --- a/tools/create_can_dbc.py +++ b/tools/create_can_dbc.py @@ -161,6 +161,12 @@ setVelGainsMsg = cantools.database.can.Message(0x01B, "Set_Vel_gains", 8, [velGa adcVoltage = cantools.database.can.Signal("ADC_Voltage", 0, 32, is_float=True) getADCVoltageMsg = cantools.database.can.Message(0x01C, "Get_ADC_Voltage", 8, [adcVoltage]) +# 0x01D - Controller Error +controllerError = cantools.database.can.Signal("Controller_Error", 0, 32) +controllerErrorMsg = cantools.database.can.Message( + 0x01D, "Get_Controller_Error", 8, [controllerError] +) + db = cantools.database.can.Database( [ heartbeatMsg, @@ -189,7 +195,8 @@ db = cantools.database.can.Database( setLinearCountMsg, setPosGainMsg, setVelGainsMsg, - getADCVoltageMsg + getADCVoltageMsg, + controllerErrorMsg, ] ) diff --git a/tools/odrive-cansimple.dbc b/tools/odrive-cansimple.dbc index 01b9b816..e105921a 100644 --- a/tools/odrive-cansimple.dbc +++ b/tools/odrive-cansimple.dbc @@ -125,12 +125,15 @@ BO_ 27 Set_Vel_gains: 8 Vector__XXX SG_ Vel_Integrator_Gain : 32|32@1+ (1,0) [0|0] "" Vector__XXX SG_ Vel_Gain : 0|32@1+ (1,0) [0|0] "" Vector__XXX +BO_ 28 Get_Controller_Error: 8 Vector__XXX + SG_ Controller_Error : 0|32@1+ (1,0) [0|0] "" Vector__XXX - +BA_DEF_ BO_ "GenMsgCycleTime" INT 0 65535; +BA_DEF_DEF_ "GenMsgCycleTime" 0; SIG_VALTYPE_ 9 Pos_Estimate : 1; From 49080cb3f3715a1fda4cbdb773a895235c5d6559 Mon Sep 17 00:00:00 2001 From: Paul Guenette Date: Mon, 5 Sep 2022 17:54:30 -0700 Subject: [PATCH 2/3] Add to docs table --- docs/figures/can-protocol.csv | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/figures/can-protocol.csv b/docs/figures/can-protocol.csv index 1bf194ca..572c4046 100644 --- a/docs/figures/can-protocol.csv +++ b/docs/figures/can-protocol.csv @@ -105,4 +105,5 @@ IEEE 754 Float","32 1","0 0" 0x01C,Get ADC Voltage****,Master***,ADC Voltage,0,IEEE 754 Float,32,1,0 +0x01D,Get Controller Error*,Axis,Controller Error,0,Unsigned Int,32,1,0 0x700,CANOpen Heartbeat Message**,Slave,-,-,-,-,-,- \ No newline at end of file From 317d09a56e7edbc80fb22bf79a6cf58a73d2d010 Mon Sep 17 00:00:00 2001 From: Paul Guenette Date: Mon, 5 Sep 2022 19:11:08 -0700 Subject: [PATCH 3/3] Update .dbc --- tools/odrive-cansimple.dbc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/odrive-cansimple.dbc b/tools/odrive-cansimple.dbc index e105921a..8d0579d1 100644 --- a/tools/odrive-cansimple.dbc +++ b/tools/odrive-cansimple.dbc @@ -125,7 +125,10 @@ BO_ 27 Set_Vel_gains: 8 Vector__XXX SG_ Vel_Integrator_Gain : 32|32@1+ (1,0) [0|0] "" Vector__XXX SG_ Vel_Gain : 0|32@1+ (1,0) [0|0] "" Vector__XXX -BO_ 28 Get_Controller_Error: 8 Vector__XXX +BO_ 28 Get_ADC_Voltage: 8 Vector__XXX + SG_ ADC_Voltage : 0|32@1+ (1,0) [0|0] "" Vector__XXX + +BO_ 29 Get_Controller_Error: 8 Vector__XXX SG_ Controller_Error : 0|32@1+ (1,0) [0|0] "" Vector__XXX @@ -156,5 +159,6 @@ SIG_VALTYPE_ 23 Vbus_Voltage : 1; SIG_VALTYPE_ 26 Pos_Gain : 1; SIG_VALTYPE_ 27 Vel_Gain : 1; SIG_VALTYPE_ 27 Vel_Integrator_Gain : 1; +SIG_VALTYPE_ 28 ADC_Voltage : 1;