From ee7b4c947a8836b2ce0c794a748772a03e519216 Mon Sep 17 00:00:00 2001 From: Cole Date: Thu, 19 Sep 2024 09:34:15 -0400 Subject: [PATCH 01/17] it does not work :( --- common/daq/can_config.json | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/common/daq/can_config.json b/common/daq/can_config.json index 89a5eba5..1a4a7b81 100644 --- a/common/daq/can_config.json +++ b/common/daq/can_config.json @@ -997,6 +997,42 @@ {"msg_name": "daq_bl_cmd" , "callback": true} ] }, + { + "node_name": "Rhenium", + "node_ssa": 63 + "tx": [ + { + "msg_name": "AMK Actual Values 1", + "msg_desc": "Contains the status word and actual values", + "signals": [ + {"sig_name": "AMK_Status", "sig_desc": "Status word, bit field", "type":"uint16_t"}, + {"sig_name": "AMK_ActualVelocity", "sig_desc": "Actual speed value", type":"int16_t", "unit":"rpm"}, + {"sig_name": "AMK_TorqueCurrent", "sig_desc": "Raw data for calculating actual torque current", "type":"int16_t"}, + {"sig_name": "AMK_MagnetizingCurrent", "sig_desc": "Raw data for calculating actual magnetizing current", type":"int16_t"}, + ], + "msg_period": 15, + }, + { + "msg_name": "AMK Actual Values 2", + "msg_desc": "Contains actual values", + "signals": [ + {"sig_name": "AMK_TempMotor", "sig_desc": "Motor Temperature", "type":"int16_t", "unit": "C", "scale": "0.1"}, + {"sig_name": "AMK_TempInverter", "sig_desc": "Cold Plate Temperature", "type":"int16_t", "unit": "C", "scale": "0.1"}, + {"sig_name": "AMK_ErrorInfo", "sig_desc": "Diagnostic Number", "type":"uint16_t"}, + {"sig_name": "AMK_TempIGBT", "sig_desc": "IGBT Temperature", "type":"uint16_t", "unit": "C", "scale": "0.1"}, + ], + "msg_period": 15, + }, + { + "msg_name": "AMK Setpoints 1", + "msg_desc": "Contains status word and setpoints", + "signals": [ + ], + "msg_period": 15, + } + ], + "rx": [] + }, { "node_name":"BITSTREAM", "node_ssa":62, From 0a474141827fc341634b8729ee926fcb86f3e442 Mon Sep 17 00:00:00 2001 From: Cole Date: Sat, 21 Sep 2024 20:39:59 -0400 Subject: [PATCH 02/17] Messing with motors, it will compile now, just some odd W5500 error? --- common/daq/can_config.json | 18 ++++++++++++------ common/daq/per_dbc.dbc | 28 +++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 7 deletions(-) diff --git a/common/daq/can_config.json b/common/daq/can_config.json index 1a4a7b81..00be1ef2 100644 --- a/common/daq/can_config.json +++ b/common/daq/can_config.json @@ -999,29 +999,33 @@ }, { "node_name": "Rhenium", - "node_ssa": 63 + "node_ssa": 63, "tx": [ { "msg_name": "AMK Actual Values 1", "msg_desc": "Contains the status word and actual values", "signals": [ {"sig_name": "AMK_Status", "sig_desc": "Status word, bit field", "type":"uint16_t"}, - {"sig_name": "AMK_ActualVelocity", "sig_desc": "Actual speed value", type":"int16_t", "unit":"rpm"}, + {"sig_name": "AMK_ActualVelocity", "sig_desc": "Actual speed value", "type":"int16_t", "unit":"rpm"}, {"sig_name": "AMK_TorqueCurrent", "sig_desc": "Raw data for calculating actual torque current", "type":"int16_t"}, - {"sig_name": "AMK_MagnetizingCurrent", "sig_desc": "Raw data for calculating actual magnetizing current", type":"int16_t"}, + {"sig_name": "AMK_MagnetizingCurrent", "sig_desc": "Raw data for calculating actual magnetizing current", "type":"int16_t"} ], "msg_period": 15, + "msg_hlp":1, + "msg_pgn":50010 }, { "msg_name": "AMK Actual Values 2", "msg_desc": "Contains actual values", "signals": [ - {"sig_name": "AMK_TempMotor", "sig_desc": "Motor Temperature", "type":"int16_t", "unit": "C", "scale": "0.1"}, - {"sig_name": "AMK_TempInverter", "sig_desc": "Cold Plate Temperature", "type":"int16_t", "unit": "C", "scale": "0.1"}, + {"sig_name": "AMK_TempMotor", "sig_desc": "Motor Temperature", "type":"int16_t", "unit": "C", "scale": 0.1}, + {"sig_name": "AMK_TempInverter", "sig_desc": "Cold Plate Temperature", "type":"int16_t", "unit": "C", "scale": 0.1}, {"sig_name": "AMK_ErrorInfo", "sig_desc": "Diagnostic Number", "type":"uint16_t"}, - {"sig_name": "AMK_TempIGBT", "sig_desc": "IGBT Temperature", "type":"uint16_t", "unit": "C", "scale": "0.1"}, + {"sig_name": "AMK_TempIGBT", "sig_desc": "IGBT Temperature", "type":"uint16_t", "unit": "C", "scale": 0.1} ], "msg_period": 15, + "msg_hlp":1, + "msg_pgn":50011 }, { "msg_name": "AMK Setpoints 1", @@ -1029,6 +1033,8 @@ "signals": [ ], "msg_period": 15, + "msg_hlp":1, + "msg_pgn":50012 } ], "rx": [] diff --git a/common/daq/per_dbc.dbc b/common/daq/per_dbc.dbc index 4af356c4..78af3e8a 100644 --- a/common/daq/per_dbc.dbc +++ b/common/daq/per_dbc.dbc @@ -33,7 +33,7 @@ NS_ : BS_: -BU_: Main_Module a_box OrionBMS torque_vector Dashboard Steering PDU daq bootloader BITSTREAM Charger DAQ TEST_NODE TEST_NODE_2 DAQ +BU_: Main_Module a_box OrionBMS torque_vector Dashboard Steering PDU daq bootloader Rhenium BITSTREAM Charger DAQ TEST_NODE TEST_NODE_2 DAQ BO_ 2348816641 main_hb: 2 Main_Module @@ -468,6 +468,20 @@ BO_ 2217793084 daq_bl_resp: 5 bootloader SG_ data : 8|32@1+ (1,0) [0|0] "" Vector__XXX SG_ cmd : 0|8@1+ (1,0) [0|0] "" Vector__XXX +BO_ 2217793215 AMK Actual Values 1: 8 Rhenium + SG_ AMK_MagnetizingCurrent : 48|16@1- (1,0) [0|0] "" Vector__XXX + SG_ AMK_TorqueCurrent : 32|16@1- (1,0) [0|0] "" Vector__XXX + SG_ AMK_ActualVelocity : 16|16@1- (1,0) [0|0] "rpm" Vector__XXX + SG_ AMK_Status : 0|16@1+ (1,0) [0|0] "" Vector__XXX + +BO_ 2217793279 AMK Actual Values 2: 8 Rhenium + SG_ AMK_TempIGBT : 48|16@1+ (0.1,0) [0|0] "C" Vector__XXX + SG_ AMK_ErrorInfo : 32|16@1+ (1,0) [0|0] "" Vector__XXX + SG_ AMK_TempInverter : 16|16@1- (0.1,0) [0|0] "C" Vector__XXX + SG_ AMK_TempMotor : 0|16@1- (0.1,0) [0|0] "C" Vector__XXX + +BO_ 2217793343 AMK Setpoints 1: 0 Rhenium + BO_ 2214598974 bitstream_data: 8 BITSTREAM SG_ d7 : 56|8@1+ (1,0) [0|0] "" Vector__XXX SG_ d6 : 48|8@1+ (1,0) [0|0] "" Vector__XXX @@ -628,6 +642,7 @@ CM_ BU_ Steering ""; CM_ BU_ PDU ""; CM_ BU_ daq ""; CM_ BU_ bootloader ""; +CM_ BU_ Rhenium ""; CM_ BU_ BITSTREAM ""; CM_ BU_ Charger ""; CM_ BU_ DAQ ""; @@ -992,6 +1007,17 @@ CM_ SG_ 2217793020 cmd ""; CM_ BO_ 2217793084 "DAQ Bootloader response"; CM_ SG_ 2217793084 data ""; CM_ SG_ 2217793084 cmd ""; +CM_ BO_ 2217793215 "Contains the status word and actual values"; +CM_ SG_ 2217793215 AMK_MagnetizingCurrent "Raw data for calculating actual magnetizing current"; +CM_ SG_ 2217793215 AMK_TorqueCurrent "Raw data for calculating actual torque current"; +CM_ SG_ 2217793215 AMK_ActualVelocity "Actual speed value"; +CM_ SG_ 2217793215 AMK_Status "Status word, bit field"; +CM_ BO_ 2217793279 "Contains actual values"; +CM_ SG_ 2217793279 AMK_TempIGBT "IGBT Temperature"; +CM_ SG_ 2217793279 AMK_ErrorInfo "Diagnostic Number"; +CM_ SG_ 2217793279 AMK_TempInverter "Cold Plate Temperature"; +CM_ SG_ 2217793279 AMK_TempMotor "Motor Temperature"; +CM_ BO_ 2217793343 "Contains status word and setpoints"; CM_ BO_ 2214598974 "Bitstream download command"; CM_ SG_ 2214598974 d7 "Bitstream data word 7"; CM_ SG_ 2214598974 d6 "Bitstream data word 6"; From 7e1a7d242705f68e081ea368c25343cb1d9d7d52 Mon Sep 17 00:00:00 2001 From: Cole Date: Sat, 21 Sep 2024 22:06:48 -0400 Subject: [PATCH 03/17] not sure about pgn, but found default msg period in the datasheet --- common/daq/can_config.json | 12 ++++++------ common/daq/per_dbc.dbc | 28 ++++++++++++++-------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/common/daq/can_config.json b/common/daq/can_config.json index 00be1ef2..425a8e50 100644 --- a/common/daq/can_config.json +++ b/common/daq/can_config.json @@ -1010,9 +1010,9 @@ {"sig_name": "AMK_TorqueCurrent", "sig_desc": "Raw data for calculating actual torque current", "type":"int16_t"}, {"sig_name": "AMK_MagnetizingCurrent", "sig_desc": "Raw data for calculating actual magnetizing current", "type":"int16_t"} ], - "msg_period": 15, + "msg_period": 5, "msg_hlp":1, - "msg_pgn":50010 + "msg_pgn":34091 }, { "msg_name": "AMK Actual Values 2", @@ -1023,18 +1023,18 @@ {"sig_name": "AMK_ErrorInfo", "sig_desc": "Diagnostic Number", "type":"uint16_t"}, {"sig_name": "AMK_TempIGBT", "sig_desc": "IGBT Temperature", "type":"uint16_t", "unit": "C", "scale": 0.1} ], - "msg_period": 15, + "msg_period": 5, "msg_hlp":1, - "msg_pgn":50011 + "msg_pgn":34092 }, { "msg_name": "AMK Setpoints 1", "msg_desc": "Contains status word and setpoints", "signals": [ ], - "msg_period": 15, + "msg_period": 5, "msg_hlp":1, - "msg_pgn":50012 + "msg_pgn":34903 } ], "rx": [] diff --git a/common/daq/per_dbc.dbc b/common/daq/per_dbc.dbc index 78af3e8a..e62aba05 100644 --- a/common/daq/per_dbc.dbc +++ b/common/daq/per_dbc.dbc @@ -468,19 +468,19 @@ BO_ 2217793084 daq_bl_resp: 5 bootloader SG_ data : 8|32@1+ (1,0) [0|0] "" Vector__XXX SG_ cmd : 0|8@1+ (1,0) [0|0] "" Vector__XXX -BO_ 2217793215 AMK Actual Values 1: 8 Rhenium +BO_ 2216774399 AMK Actual Values 1: 8 Rhenium SG_ AMK_MagnetizingCurrent : 48|16@1- (1,0) [0|0] "" Vector__XXX SG_ AMK_TorqueCurrent : 32|16@1- (1,0) [0|0] "" Vector__XXX SG_ AMK_ActualVelocity : 16|16@1- (1,0) [0|0] "rpm" Vector__XXX SG_ AMK_Status : 0|16@1+ (1,0) [0|0] "" Vector__XXX -BO_ 2217793279 AMK Actual Values 2: 8 Rhenium +BO_ 2216774463 AMK Actual Values 2: 8 Rhenium SG_ AMK_TempIGBT : 48|16@1+ (0.1,0) [0|0] "C" Vector__XXX SG_ AMK_ErrorInfo : 32|16@1+ (1,0) [0|0] "" Vector__XXX SG_ AMK_TempInverter : 16|16@1- (0.1,0) [0|0] "C" Vector__XXX SG_ AMK_TempMotor : 0|16@1- (0.1,0) [0|0] "C" Vector__XXX -BO_ 2217793343 AMK Setpoints 1: 0 Rhenium +BO_ 2216826367 AMK Setpoints 1: 0 Rhenium BO_ 2214598974 bitstream_data: 8 BITSTREAM SG_ d7 : 56|8@1+ (1,0) [0|0] "" Vector__XXX @@ -1007,17 +1007,17 @@ CM_ SG_ 2217793020 cmd ""; CM_ BO_ 2217793084 "DAQ Bootloader response"; CM_ SG_ 2217793084 data ""; CM_ SG_ 2217793084 cmd ""; -CM_ BO_ 2217793215 "Contains the status word and actual values"; -CM_ SG_ 2217793215 AMK_MagnetizingCurrent "Raw data for calculating actual magnetizing current"; -CM_ SG_ 2217793215 AMK_TorqueCurrent "Raw data for calculating actual torque current"; -CM_ SG_ 2217793215 AMK_ActualVelocity "Actual speed value"; -CM_ SG_ 2217793215 AMK_Status "Status word, bit field"; -CM_ BO_ 2217793279 "Contains actual values"; -CM_ SG_ 2217793279 AMK_TempIGBT "IGBT Temperature"; -CM_ SG_ 2217793279 AMK_ErrorInfo "Diagnostic Number"; -CM_ SG_ 2217793279 AMK_TempInverter "Cold Plate Temperature"; -CM_ SG_ 2217793279 AMK_TempMotor "Motor Temperature"; -CM_ BO_ 2217793343 "Contains status word and setpoints"; +CM_ BO_ 2216774399 "Contains the status word and actual values"; +CM_ SG_ 2216774399 AMK_MagnetizingCurrent "Raw data for calculating actual magnetizing current"; +CM_ SG_ 2216774399 AMK_TorqueCurrent "Raw data for calculating actual torque current"; +CM_ SG_ 2216774399 AMK_ActualVelocity "Actual speed value"; +CM_ SG_ 2216774399 AMK_Status "Status word, bit field"; +CM_ BO_ 2216774463 "Contains actual values"; +CM_ SG_ 2216774463 AMK_TempIGBT "IGBT Temperature"; +CM_ SG_ 2216774463 AMK_ErrorInfo "Diagnostic Number"; +CM_ SG_ 2216774463 AMK_TempInverter "Cold Plate Temperature"; +CM_ SG_ 2216774463 AMK_TempMotor "Motor Temperature"; +CM_ BO_ 2216826367 "Contains status word and setpoints"; CM_ BO_ 2214598974 "Bitstream download command"; CM_ SG_ 2214598974 d7 "Bitstream data word 7"; CM_ SG_ 2214598974 d6 "Bitstream data word 6"; From 3c32825fc605b4c5b7b822c3b1f7a4ed9067d8fa Mon Sep 17 00:00:00 2001 From: Cole Date: Fri, 27 Sep 2024 19:30:51 -0400 Subject: [PATCH 04/17] Setting up CAN, I think I got the signals figured out in the json? --- common/daq/can_config.json | 64 ++++++++++++++++++++++++++++++++------ common/daq/per_dbc.dbc | 41 ++++++++++++++---------- source/f4_testing/main.c | 11 +++++++ 3 files changed, 91 insertions(+), 25 deletions(-) diff --git a/common/daq/can_config.json b/common/daq/can_config.json index 425a8e50..ca453917 100644 --- a/common/daq/can_config.json +++ b/common/daq/can_config.json @@ -998,7 +998,7 @@ ] }, { - "node_name": "Rhenium", + "node_name": "Inverter1", "node_ssa": 63, "tx": [ { @@ -1011,8 +1011,7 @@ {"sig_name": "AMK_MagnetizingCurrent", "sig_desc": "Raw data for calculating actual magnetizing current", "type":"int16_t"} ], "msg_period": 5, - "msg_hlp":1, - "msg_pgn":34091 + "msg_id_override": "0x283" }, { "msg_name": "AMK Actual Values 2", @@ -1024,20 +1023,67 @@ {"sig_name": "AMK_TempIGBT", "sig_desc": "IGBT Temperature", "type":"uint16_t", "unit": "C", "scale": 0.1} ], "msg_period": 5, - "msg_hlp":1, - "msg_pgn":34092 - }, + "msg_id_override": "0x285" + } + ], + "rx": [ { "msg_name": "AMK Setpoints 1", "msg_desc": "Contains status word and setpoints", "signals": [ + {"sig_name": "AMK_Control", "sig_desc": "Control word", "type":"uint16_t"}, + {"sig_name": "AMK_TargetVelocity", "sig_desc": "Speed setpoint", "type":"int16_t", "unit": "rpm"}, + {"sig_name": "AMK_TorqueLimitPositiv", "sig_desc": "Positive torque limit", "type":"int16_t", "unit": "Mn", "scale": 0.1}, + {"sig_name": "AMK_TorqueLimitNegativ", "sig_desc": "Negative torque limit", "type":"int16_t", "unit": "Mn", "scale": 0.1} ], "msg_period": 5, - "msg_hlp":1, - "msg_pgn":34903 + "msg_id_override": "0x184" + } + ] + }, + { + "node_name": "f4_testing", + "node_ssa": 61, + "tx": [ + { + "msg_name": "AMK Setpoints 1", + "msg_desc": "Contains status word and setpoints", + "signals": [ + {"sig_name": "AMK_Control", "sig_desc": "Control word", "type":"uint16_t"}, + {"sig_name": "AMK_TargetVelocity", "sig_desc": "Speed setpoint", "type":"int16_t", "unit": "rpm"}, + {"sig_name": "AMK_TorqueLimitPositiv", "sig_desc": "Positive torque limit", "type":"int16_t", "unit": "Mn", "scale": 0.1}, + {"sig_name": "AMK_TorqueLimitNegativ", "sig_desc": "Negative torque limit", "type":"int16_t", "unit": "Mn", "scale": 0.1} + ], + "msg_period": 5, + "msg_id_override": "0x184" } ], - "rx": [] + "rx": [ + { + "msg_name": "AMK Actual Values 1", + "msg_desc": "Contains the status word and actual values", + "signals": [ + {"sig_name": "AMK_Status", "sig_desc": "Status word, bit field", "type":"uint16_t"}, + {"sig_name": "AMK_ActualVelocity", "sig_desc": "Actual speed value", "type":"int16_t", "unit":"rpm"}, + {"sig_name": "AMK_TorqueCurrent", "sig_desc": "Raw data for calculating actual torque current", "type":"int16_t"}, + {"sig_name": "AMK_MagnetizingCurrent", "sig_desc": "Raw data for calculating actual magnetizing current", "type":"int16_t"} + ], + "msg_period": 5, + "msg_id_override": "0x283" + }, + { + "msg_name": "AMK Actual Values 2", + "msg_desc": "Contains actual values", + "signals": [ + {"sig_name": "AMK_TempMotor", "sig_desc": "Motor Temperature", "type":"int16_t", "unit": "C", "scale": 0.1}, + {"sig_name": "AMK_TempInverter", "sig_desc": "Cold Plate Temperature", "type":"int16_t", "unit": "C", "scale": 0.1}, + {"sig_name": "AMK_ErrorInfo", "sig_desc": "Diagnostic Number", "type":"uint16_t"}, + {"sig_name": "AMK_TempIGBT", "sig_desc": "IGBT Temperature", "type":"uint16_t", "unit": "C", "scale": 0.1} + ], + "msg_period": 5, + "msg_id_override": "0x285" + } + ] }, { "node_name":"BITSTREAM", diff --git a/common/daq/per_dbc.dbc b/common/daq/per_dbc.dbc index e62aba05..09f2c87c 100644 --- a/common/daq/per_dbc.dbc +++ b/common/daq/per_dbc.dbc @@ -33,7 +33,7 @@ NS_ : BS_: -BU_: Main_Module a_box OrionBMS torque_vector Dashboard Steering PDU daq bootloader Rhenium BITSTREAM Charger DAQ TEST_NODE TEST_NODE_2 DAQ +BU_: Main_Module a_box OrionBMS torque_vector Dashboard Steering PDU daq bootloader Inverter1 f4_testing BITSTREAM Charger DAQ TEST_NODE TEST_NODE_2 DAQ BO_ 2348816641 main_hb: 2 Main_Module @@ -468,19 +468,23 @@ BO_ 2217793084 daq_bl_resp: 5 bootloader SG_ data : 8|32@1+ (1,0) [0|0] "" Vector__XXX SG_ cmd : 0|8@1+ (1,0) [0|0] "" Vector__XXX -BO_ 2216774399 AMK Actual Values 1: 8 Rhenium +BO_ 2147484291 AMK Actual Values 1: 8 Inverter1 SG_ AMK_MagnetizingCurrent : 48|16@1- (1,0) [0|0] "" Vector__XXX SG_ AMK_TorqueCurrent : 32|16@1- (1,0) [0|0] "" Vector__XXX SG_ AMK_ActualVelocity : 16|16@1- (1,0) [0|0] "rpm" Vector__XXX SG_ AMK_Status : 0|16@1+ (1,0) [0|0] "" Vector__XXX -BO_ 2216774463 AMK Actual Values 2: 8 Rhenium +BO_ 2147484293 AMK Actual Values 2: 8 Inverter1 SG_ AMK_TempIGBT : 48|16@1+ (0.1,0) [0|0] "C" Vector__XXX SG_ AMK_ErrorInfo : 32|16@1+ (1,0) [0|0] "" Vector__XXX SG_ AMK_TempInverter : 16|16@1- (0.1,0) [0|0] "C" Vector__XXX SG_ AMK_TempMotor : 0|16@1- (0.1,0) [0|0] "C" Vector__XXX -BO_ 2216826367 AMK Setpoints 1: 0 Rhenium +BO_ 2147484036 AMK Setpoints 1: 8 f4_testing + SG_ AMK_TorqueLimitNegativ : 48|16@1- (0.1,0) [0|0] "Mn" Vector__XXX + SG_ AMK_TorqueLimitPositiv : 32|16@1- (0.1,0) [0|0] "Mn" Vector__XXX + SG_ AMK_TargetVelocity : 16|16@1- (1,0) [0|0] "rpm" Vector__XXX + SG_ AMK_Control : 0|16@1+ (1,0) [0|0] "" Vector__XXX BO_ 2214598974 bitstream_data: 8 BITSTREAM SG_ d7 : 56|8@1+ (1,0) [0|0] "" Vector__XXX @@ -642,7 +646,8 @@ CM_ BU_ Steering ""; CM_ BU_ PDU ""; CM_ BU_ daq ""; CM_ BU_ bootloader ""; -CM_ BU_ Rhenium ""; +CM_ BU_ Inverter1 ""; +CM_ BU_ f4_testing ""; CM_ BU_ BITSTREAM ""; CM_ BU_ Charger ""; CM_ BU_ DAQ ""; @@ -1007,17 +1012,21 @@ CM_ SG_ 2217793020 cmd ""; CM_ BO_ 2217793084 "DAQ Bootloader response"; CM_ SG_ 2217793084 data ""; CM_ SG_ 2217793084 cmd ""; -CM_ BO_ 2216774399 "Contains the status word and actual values"; -CM_ SG_ 2216774399 AMK_MagnetizingCurrent "Raw data for calculating actual magnetizing current"; -CM_ SG_ 2216774399 AMK_TorqueCurrent "Raw data for calculating actual torque current"; -CM_ SG_ 2216774399 AMK_ActualVelocity "Actual speed value"; -CM_ SG_ 2216774399 AMK_Status "Status word, bit field"; -CM_ BO_ 2216774463 "Contains actual values"; -CM_ SG_ 2216774463 AMK_TempIGBT "IGBT Temperature"; -CM_ SG_ 2216774463 AMK_ErrorInfo "Diagnostic Number"; -CM_ SG_ 2216774463 AMK_TempInverter "Cold Plate Temperature"; -CM_ SG_ 2216774463 AMK_TempMotor "Motor Temperature"; -CM_ BO_ 2216826367 "Contains status word and setpoints"; +CM_ BO_ 2147484291 "Contains the status word and actual values"; +CM_ SG_ 2147484291 AMK_MagnetizingCurrent "Raw data for calculating actual magnetizing current"; +CM_ SG_ 2147484291 AMK_TorqueCurrent "Raw data for calculating actual torque current"; +CM_ SG_ 2147484291 AMK_ActualVelocity "Actual speed value"; +CM_ SG_ 2147484291 AMK_Status "Status word, bit field"; +CM_ BO_ 2147484293 "Contains actual values"; +CM_ SG_ 2147484293 AMK_TempIGBT "IGBT Temperature"; +CM_ SG_ 2147484293 AMK_ErrorInfo "Diagnostic Number"; +CM_ SG_ 2147484293 AMK_TempInverter "Cold Plate Temperature"; +CM_ SG_ 2147484293 AMK_TempMotor "Motor Temperature"; +CM_ BO_ 2147484036 "Contains status word and setpoints"; +CM_ SG_ 2147484036 AMK_TorqueLimitNegativ "Negative torque limit"; +CM_ SG_ 2147484036 AMK_TorqueLimitPositiv "Positive torque limit"; +CM_ SG_ 2147484036 AMK_TargetVelocity "Speed setpoint"; +CM_ SG_ 2147484036 AMK_Control "Control word"; CM_ BO_ 2214598974 "Bitstream download command"; CM_ SG_ 2214598974 d7 "Bitstream data word 7"; CM_ SG_ 2214598974 d6 "Bitstream data word 6"; diff --git a/source/f4_testing/main.c b/source/f4_testing/main.c index 88b09c1d..584060b6 100644 --- a/source/f4_testing/main.c +++ b/source/f4_testing/main.c @@ -4,6 +4,7 @@ #include "common/phal_F4_F7/dma/dma.h" #include "common/phal_F4_F7/spi/spi.h" #include "common/phal_F4_F7/usart/usart.h" +#include "common/phal_F4_F7/can/can.h" #include "common/psched/psched.h" #include "string.h" @@ -63,6 +64,11 @@ GPIOInitConfig_t gpio_config[] = { GPIO_INIT_AF(SPI_MOSI_PORT, SPI_MOSI_PIN, 5, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_PUSH_PULL, GPIO_INPUT_PULL_DOWN), GPIO_INIT_AF(SPI_MISO_PORT, SPI_MISO_PIN, 5, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_OPEN_DRAIN), + // CAN + // FIXME: (I think these are backwards on schematic? Or are the defs different?) + GPIO_INIT_CANRX_PA11, + GPIO_INIT_CANTX_PA12, + }; #define TargetCoreClockrateHz 16000000 @@ -138,6 +144,11 @@ int main() PHAL_startTxfer(&adc_dma_config); PHAL_startADC(ADC1); PHAL_usartRxDma(&lcd, (uint16_t *) msg, 5, 1); + if(!PHAL_initCAN(CAN1, false, VCAN_BPS)) + { + HardFault_Handler(); + } + NVIC_EnableIRQ(CAN1_RX0_IRQn); /* Task Creation */ schedInit(APB1ClockRateHz); taskCreate(ledblink, 50); From f031a10ed7a6473bd2dd2441cebc18c6c315a8d0 Mon Sep 17 00:00:00 2001 From: Cole Date: Fri, 27 Sep 2024 19:49:57 -0400 Subject: [PATCH 05/17] CAN is going well, maybe not :) --- common/daq/can_config.json | 12 +-- common/daq/per_dbc.dbc | 6 +- source/f4_testing/can/can_parse.c | 99 +++++++++++++++++++ source/f4_testing/can/can_parse.h | 153 ++++++++++++++++++++++++++++++ 4 files changed, 261 insertions(+), 9 deletions(-) create mode 100644 source/f4_testing/can/can_parse.c create mode 100644 source/f4_testing/can/can_parse.h diff --git a/common/daq/can_config.json b/common/daq/can_config.json index ca453917..9715f156 100644 --- a/common/daq/can_config.json +++ b/common/daq/can_config.json @@ -1002,7 +1002,7 @@ "node_ssa": 63, "tx": [ { - "msg_name": "AMK Actual Values 1", + "msg_name": "AMK_Actual_Values_1", "msg_desc": "Contains the status word and actual values", "signals": [ {"sig_name": "AMK_Status", "sig_desc": "Status word, bit field", "type":"uint16_t"}, @@ -1014,7 +1014,7 @@ "msg_id_override": "0x283" }, { - "msg_name": "AMK Actual Values 2", + "msg_name": "AMK_Actual_Values_2", "msg_desc": "Contains actual values", "signals": [ {"sig_name": "AMK_TempMotor", "sig_desc": "Motor Temperature", "type":"int16_t", "unit": "C", "scale": 0.1}, @@ -1028,7 +1028,7 @@ ], "rx": [ { - "msg_name": "AMK Setpoints 1", + "msg_name": "AMK_Setpoints_1", "msg_desc": "Contains status word and setpoints", "signals": [ {"sig_name": "AMK_Control", "sig_desc": "Control word", "type":"uint16_t"}, @@ -1046,7 +1046,7 @@ "node_ssa": 61, "tx": [ { - "msg_name": "AMK Setpoints 1", + "msg_name": "AMK_Setpoints_1", "msg_desc": "Contains status word and setpoints", "signals": [ {"sig_name": "AMK_Control", "sig_desc": "Control word", "type":"uint16_t"}, @@ -1060,7 +1060,7 @@ ], "rx": [ { - "msg_name": "AMK Actual Values 1", + "msg_name": "AMK_Actual_Values_1", "msg_desc": "Contains the status word and actual values", "signals": [ {"sig_name": "AMK_Status", "sig_desc": "Status word, bit field", "type":"uint16_t"}, @@ -1072,7 +1072,7 @@ "msg_id_override": "0x283" }, { - "msg_name": "AMK Actual Values 2", + "msg_name": "AMK_Actual_Values_2", "msg_desc": "Contains actual values", "signals": [ {"sig_name": "AMK_TempMotor", "sig_desc": "Motor Temperature", "type":"int16_t", "unit": "C", "scale": 0.1}, diff --git a/common/daq/per_dbc.dbc b/common/daq/per_dbc.dbc index 09f2c87c..a1dedd5c 100644 --- a/common/daq/per_dbc.dbc +++ b/common/daq/per_dbc.dbc @@ -468,19 +468,19 @@ BO_ 2217793084 daq_bl_resp: 5 bootloader SG_ data : 8|32@1+ (1,0) [0|0] "" Vector__XXX SG_ cmd : 0|8@1+ (1,0) [0|0] "" Vector__XXX -BO_ 2147484291 AMK Actual Values 1: 8 Inverter1 +BO_ 2147484291 AMK_Actual_Values_1: 8 Inverter1 SG_ AMK_MagnetizingCurrent : 48|16@1- (1,0) [0|0] "" Vector__XXX SG_ AMK_TorqueCurrent : 32|16@1- (1,0) [0|0] "" Vector__XXX SG_ AMK_ActualVelocity : 16|16@1- (1,0) [0|0] "rpm" Vector__XXX SG_ AMK_Status : 0|16@1+ (1,0) [0|0] "" Vector__XXX -BO_ 2147484293 AMK Actual Values 2: 8 Inverter1 +BO_ 2147484293 AMK_Actual_Values_2: 8 Inverter1 SG_ AMK_TempIGBT : 48|16@1+ (0.1,0) [0|0] "C" Vector__XXX SG_ AMK_ErrorInfo : 32|16@1+ (1,0) [0|0] "" Vector__XXX SG_ AMK_TempInverter : 16|16@1- (0.1,0) [0|0] "C" Vector__XXX SG_ AMK_TempMotor : 0|16@1- (0.1,0) [0|0] "C" Vector__XXX -BO_ 2147484036 AMK Setpoints 1: 8 f4_testing +BO_ 2147484036 AMK_Setpoints_1: 8 f4_testing SG_ AMK_TorqueLimitNegativ : 48|16@1- (0.1,0) [0|0] "Mn" Vector__XXX SG_ AMK_TorqueLimitPositiv : 32|16@1- (0.1,0) [0|0] "Mn" Vector__XXX SG_ AMK_TargetVelocity : 16|16@1- (1,0) [0|0] "rpm" Vector__XXX diff --git a/source/f4_testing/can/can_parse.c b/source/f4_testing/can/can_parse.c new file mode 100644 index 00000000..a6c20b9f --- /dev/null +++ b/source/f4_testing/can/can_parse.c @@ -0,0 +1,99 @@ +/** + * @file can_parse.c + * @author Cole Roberts (rober638@purdue.edu) + * @brief Parsing of CAN messages using auto-generated structures with bit-fields + * @version 0.1 + * @date 2024-09-27 + * + * @copyright Copyright (c) 2024 + * + */ +#include "can_parse.h" + +// prototypes +bool initCANFilter(); + +can_data_t can_data; +volatile uint32_t last_can_rx_time_ms = 0; + +void initCANParse(void) +{ + initCANParseBase(); + initCANFilter(); +} + +void canRxUpdate(void) +{ + CanMsgTypeDef_t msg_header; + CanParsedData_t* msg_data_a; + + if(qReceive(&q_rx_can, &msg_header) == SUCCESS_G) + { + msg_data_a = (CanParsedData_t *) &msg_header.Data; + last_can_rx_time_ms = sched.os_ticks; + /* BEGIN AUTO CASES */ + switch(msg_header.ExtId) + { + case ID_AMK_SETPOINTS_1: + can_data.AMK_Setpoints_1.AMK_Control = msg_data_a->AMK_Setpoints_1.AMK_Control; + can_data.AMK_Setpoints_1.AMK_TargetVelocity = (int16_t) msg_data_a->AMK_Setpoints_1.AMK_TargetVelocity; + can_data.AMK_Setpoints_1.AMK_TorqueLimitPositiv = (int16_t) msg_data_a->AMK_Setpoints_1.AMK_TorqueLimitPositiv; + can_data.AMK_Setpoints_1.AMK_TorqueLimitNegativ = (int16_t) msg_data_a->AMK_Setpoints_1.AMK_TorqueLimitNegativ; + can_data.AMK_Setpoints_1.stale = 0; + can_data.AMK_Setpoints_1.last_rx = sched.os_ticks; + break; + default: + __asm__("nop"); + } + /* END AUTO CASES */ + } + + /* BEGIN AUTO STALE CHECKS */ + CHECK_STALE(can_data.AMK_Setpoints_1.stale, + sched.os_ticks, can_data.AMK_Setpoints_1.last_rx, + UP_AMK_SETPOINTS_1); + /* END AUTO STALE CHECKS */ +} + +bool initCANFilter() +{ + CAN1->MCR |= CAN_MCR_INRQ; // Enter back into INIT state (required for changing scale) + uint32_t timeout = 0; + while(!(CAN1->MSR & CAN_MSR_INAK) && ++timeout < PHAL_CAN_INIT_TIMEOUT) + ; + if (timeout == PHAL_CAN_INIT_TIMEOUT) + return false; + + CAN1->FMR |= CAN_FMR_FINIT; // Enter init mode for filter banks + CAN1->FM1R |= 0x07FFFFFF; // Set banks 0-27 to id mode + CAN1->FS1R |= 0x07FFFFFF; // Set banks 0-27 to 32-bit scale + + /* BEGIN AUTO FILTER */ + CAN1->FA1R |= (1 << 0); // configure bank 0 + CAN1->sFilterRegister[0].FR1 = (ID_AMK_SETPOINTS_1 << 3) | 4; + /* END AUTO FILTER */ + + CAN1->FMR &= ~CAN_FMR_FINIT; // Enable Filters (exit filter init mode) + + // Enter back into NORMAL mode + CAN1->MCR &= ~CAN_MCR_INRQ; + while((CAN1->MSR & CAN_MSR_INAK) && ++timeout < PHAL_CAN_INIT_TIMEOUT) + ; + + return timeout != PHAL_CAN_INIT_TIMEOUT; +} + + +void canProcessRxIRQs(CanMsgTypeDef_t* rx) +{ + CanParsedData_t* msg_data_a; + + msg_data_a = (CanParsedData_t *) rx->Data; + switch(rx->ExtId) + { + /* BEGIN AUTO RX IRQ */ + /* END AUTO RX IRQ */ + default: + __asm__("nop"); + } +} diff --git a/source/f4_testing/can/can_parse.h b/source/f4_testing/can/can_parse.h new file mode 100644 index 00000000..fc0ffcc1 --- /dev/null +++ b/source/f4_testing/can/can_parse.h @@ -0,0 +1,153 @@ +/** + * @file can_parse.h + * @author Cole Roberts (rober638@purdue.edu) + * @brief Parsing of CAN messages using auto-generated structures with bit-fields + * @version 0.1 + * @date 2024-09-27 + * + * @copyright Copyright (c) 2024 + * + */ +#ifndef _CAN_PARSE_H_ +#define _CAN_PARSE_H_ + +#include "common/queue/queue.h" +#include "common/psched/psched.h" +#include "common/phal_F4_F7/can/can.h" +#include "common/daq/can_parse_base.h" + +// Make this match the node name within the can_config.json +#define NODE_NAME "Inverter1" + + +// Used to represent a float as 32 bits +typedef union { + float f; + uint32_t u; +} FloatConvert_t; +#define FLOAT_TO_UINT32(float_) (((FloatConvert_t) float_).u) +#define UINT32_TO_FLOAT(uint32_) (((FloatConvert_t) ((uint32_t) uint32_)).f) + +// Message ID definitions +/* BEGIN AUTO ID DEFS */ +#define ID_AMK_ACTUAL_VALUES_1 0x283 +#define ID_AMK_ACTUAL_VALUES_2 0x285 +#define ID_AMK_SETPOINTS_1 0x184 +/* END AUTO ID DEFS */ + +// Message DLC definitions +/* BEGIN AUTO DLC DEFS */ +#define DLC_AMK_ACTUAL_VALUES_1 8 +#define DLC_AMK_ACTUAL_VALUES_2 8 +#define DLC_AMK_SETPOINTS_1 8 +/* END AUTO DLC DEFS */ + +// Message sending macros +/* BEGIN AUTO SEND MACROS */ +#define SEND_AMK_ACTUAL_VALUES_1(AMK_Status_, AMK_ActualVelocity_, AMK_TorqueCurrent_, AMK_MagnetizingCurrent_) do {\ + CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_AMK_ACTUAL_VALUES_1, .DLC=DLC_AMK_ACTUAL_VALUES_1, .IDE=1};\ + CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ + data_a->AMK_Actual_Values_1.AMK_Status = AMK_Status_;\ + data_a->AMK_Actual_Values_1.AMK_ActualVelocity = AMK_ActualVelocity_;\ + data_a->AMK_Actual_Values_1.AMK_TorqueCurrent = AMK_TorqueCurrent_;\ + data_a->AMK_Actual_Values_1.AMK_MagnetizingCurrent = AMK_MagnetizingCurrent_;\ + canTxSendToBack(&msg);\ + } while(0) +#define SEND_AMK_ACTUAL_VALUES_2(AMK_TempMotor_, AMK_TempInverter_, AMK_ErrorInfo_, AMK_TempIGBT_) do {\ + CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_AMK_ACTUAL_VALUES_2, .DLC=DLC_AMK_ACTUAL_VALUES_2, .IDE=1};\ + CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ + data_a->AMK_Actual_Values_2.AMK_TempMotor = AMK_TempMotor_;\ + data_a->AMK_Actual_Values_2.AMK_TempInverter = AMK_TempInverter_;\ + data_a->AMK_Actual_Values_2.AMK_ErrorInfo = AMK_ErrorInfo_;\ + data_a->AMK_Actual_Values_2.AMK_TempIGBT = AMK_TempIGBT_;\ + canTxSendToBack(&msg);\ + } while(0) +/* END AUTO SEND MACROS */ + +// Stale Checking +#define STALE_THRESH 30 / 2 // 5 / 2 would be 250% of period +/* BEGIN AUTO UP DEFS (Update Period)*/ +#define UP_AMK_SETPOINTS_1 5 +/* END AUTO UP DEFS */ + +#define CHECK_STALE(stale, curr, last, period) if(!stale && \ + (curr - last) > period * STALE_THRESH) stale = 1 + +/* BEGIN AUTO CAN ENUMERATIONS */ +/* END AUTO CAN ENUMERATIONS */ + +// Message Raw Structures +/* BEGIN AUTO MESSAGE STRUCTURE */ +typedef union { + struct { + uint64_t AMK_Status: 16; + uint64_t AMK_ActualVelocity: 16; + uint64_t AMK_TorqueCurrent: 16; + uint64_t AMK_MagnetizingCurrent: 16; + } AMK_Actual_Values_1; + struct { + uint64_t AMK_TempMotor: 16; + uint64_t AMK_TempInverter: 16; + uint64_t AMK_ErrorInfo: 16; + uint64_t AMK_TempIGBT: 16; + } AMK_Actual_Values_2; + struct { + uint64_t AMK_Control: 16; + uint64_t AMK_TargetVelocity: 16; + uint64_t AMK_TorqueLimitPositiv: 16; + uint64_t AMK_TorqueLimitNegativ: 16; + } AMK_Setpoints_1; + uint8_t raw_data[8]; +} __attribute__((packed)) CanParsedData_t; +/* END AUTO MESSAGE STRUCTURE */ + +// contains most up to date received +// type for each variable matches that defined in JSON +/* BEGIN AUTO CAN DATA STRUCTURE */ +typedef struct { + struct { + uint16_t AMK_Control; + int16_t AMK_TargetVelocity; + int16_t AMK_TorqueLimitPositiv; + int16_t AMK_TorqueLimitNegativ; + uint8_t stale; + uint32_t last_rx; + } AMK_Setpoints_1; +} can_data_t; +/* END AUTO CAN DATA STRUCTURE */ + +extern can_data_t can_data; +extern volatile uint32_t last_can_rx_time_ms; + +/* BEGIN AUTO EXTERN CALLBACK */ +extern void handleCallbacks(uint16_t id, bool latched); +extern void set_fault_daq(uint16_t id, bool value); +extern void return_fault_control(uint16_t id); +extern void send_fault(uint16_t id, bool latched); +/* END AUTO EXTERN CALLBACK */ + +/* BEGIN AUTO EXTERN RX IRQ */ +/* END AUTO EXTERN RX IRQ */ + +/** + * @brief Setup queue and message filtering + * + * @param q_rx_can RX buffer of CAN messages + */ +void initCANParse(void); + +/** + * @brief Pull message off of rx buffer, + * update can_data struct, + * check for stale messages + */ +void canRxUpdate(void); + +/** + * @brief Process any rx message callbacks from the CAN Rx IRQ + * + * @param rx rx data from message just recieved + */ +void canProcessRxIRQs(CanMsgTypeDef_t* rx); + +#endif From 8d69ad179ab74c972a32b9c0e483a1cae008d866 Mon Sep 17 00:00:00 2001 From: Cole Date: Fri, 11 Oct 2024 19:19:52 -0400 Subject: [PATCH 06/17] outlined steps for turning on and off motors --- common/amk/CMakeLists.txt | 13 +++++++++ common/amk/amk.c | 60 +++++++++++++++++++++++++++++++++++++++ common/amk/amk.h | 42 +++++++++++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 common/amk/CMakeLists.txt create mode 100644 common/amk/amk.c create mode 100644 common/amk/amk.h diff --git a/common/amk/CMakeLists.txt b/common/amk/CMakeLists.txt new file mode 100644 index 00000000..b94d4439 --- /dev/null +++ b/common/amk/CMakeLists.txt @@ -0,0 +1,13 @@ +set(TARGET_NAME amk) +add_library(${TARGET_NAME}) + +# Find all .c sources in project +#file(GLOB_RECURSE glob_sources "*.c") +target_sources(${TARGET_NAME} PRIVATE "amk.c") + +# Find directories for '#include' +# For libraries, these directories are all referenced to the top level firmware directory, CMAKE_SOURCE_DIR +target_include_directories(${TARGET_NAME} PUBLIC ${CMAKE_SOURCE_DIR}) + +target_link_libraries(${TARGET_NAME} "QUEUE;common_defs;PHAL_F407") + diff --git a/common/amk/amk.c b/common/amk/amk.c new file mode 100644 index 00000000..421b28e2 --- /dev/null +++ b/common/amk/amk.c @@ -0,0 +1,60 @@ +#include "amk.h" + +void turnMotorsOn() +{ + /* + * Motor Datasheet: + * https://www.amk-motion.com/amk-dokucd/dokucd/en/content/resources/pdf-dateien/pdk_205481_kw26-s5-fse-4q_en_.pdf + * + * Section 9.4 goes over turning the motors on and off + * + * Steps with the "r" suffix are requirement steps, the requirement needs to + * be met before moving onto the next step. + */ + + /* 1. Turn on 24V DC to inverters */ + /* 1r. Check AMK_bSystemReady = 1 for all inverters */ + /* 2. Charge DC caps; QUE should be set (is this just DcOn?) */ + /* 3. Set AMK_bDcOn = 1 */ + /* 3r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ + /* 3r. (QUE & AMK_bDcOn) -> Check AMK_bQuitDcOn = 1 */ + /* Does where do I check QUE??? */ + /* 4. Set AMK_TorqueLimitNegativ = 0 and AMK_TorqueLimitPositiv = 0 */ + /* 5. Set X15 hardware signals EF and EF2 = 1 */ + /* 6. Set X140 hardware signal BE1 = 1 */ + /* 7. Set AMK_bEnable = 1 */ + /* 8 Set AMK_bInverterOn = 1 */ + /* 8r. AMK_bInverterOn is mirrored in AMK_Status, so should be on there */ + /* 9. Check AMK_bQuitInverterOn = 1 */ + /* 10. Set X140 hardware signal BE2 = 1 */ + /* 11. Set setpoint settings (AMK_TargetVelocity, AMK_TorqueLimitNegativ, AMK_TorqueLimitPositiv) */ +} + +void turnMotorsOff() +{ + /* + * Motor Datasheet: + * https://www.amk-motion.com/amk-dokucd/dokucd/en/content/resources/pdf-dateien/pdk_205481_kw26-s5-fse-4q_en_.pdf + * + * Section 9.4 goes over turning the motors on and off + * + * Steps with the "r" suffix are requirement steps, the requirement needs to + * be met before moving onto the next step. + */ + + /* 1. Set setpoint settings to 0 (AMK_TargetVelocity, AMK_TorqueLimitNegativ, AMK_TorqueLimitPositiv) */ + /* 2. Set X140 hardware signal BE2 = 0 */ + /* 3 Set AMK_bInverterOn = 1 */ + /* 3r. AMK_bInverterOn is mirrored in AMK_Status, so should be on there */ + /* 4. Set AMK_bEnable = 0 */ + /* 5. Check AMK_bQuitInverterOn = 0 */ + /* 6. Set X140 hardware signal BE1 = 0 */ + /* 7. Set X15 hardware signals EF and EF2 = 0 */ + /* 8. Set AMK_bDcOn = 1 */ + /* 8r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ + /* 8r. Check AMK_bQuitDcOn = 0 */ + /* Does where do I check QUE??? */ + /* 9. Charge DC caps; QUE should be set (is this just DcOn?) */ + /* 10. Turn off 24v DC to inverters */ + +} diff --git a/common/amk/amk.h b/common/amk/amk.h new file mode 100644 index 00000000..ebad67ce --- /dev/null +++ b/common/amk/amk.h @@ -0,0 +1,42 @@ +/** + * @file amk.h + * @author Cole Roberts (rober638@purdue.edu) + * @brief Vroom + * @version 0.1 + * @date 2024-10-11 + * + * @copyright Copyright (c) 2024 + * + */ +#ifndef _AMK_H_ +#define _AMK_H_ + +#include +#include + +/* Inverter -> CAN */ +typedef struct +{ + uint16_t AMK_bReserve : 8; + uint16_t AMK_bSystemReady : 1; + uint16_t AMK_bError : 1; + uint16_t AMK_bWarn : 1; + uint16_t AMK_bQuitDcOn : 1; + uint16_t AMK_bDcOn : 1; /* Same as QUE ?? */ + uint16_t AMK_bQuitInverterOn : 1; + uint16_t AMK_bInverterOn : 1; + uint16_t AMK_bDerating : 1; +} AMK_Status_t; + +/* CAN -> Inverter */ +typedef struct +{ + uint16_t AMK_bReserve1 : 8; + uint16_t AMK_bInverterOn : 1; + uint16_t AMK_bDcOn : 1; + uint16_t AMK_bEnable : 1; + uint16_t AMK_bErrorReset : 1; + uint16_t AMK_bReserve2 : 1; +} AMK_Control_t; + +#endif /* _AMK_H_ */ From fe85dc7e91688619bd08d3825a5117960625f0f2 Mon Sep 17 00:00:00 2001 From: Cole Date: Fri, 11 Oct 2024 20:54:55 -0400 Subject: [PATCH 07/17] This datasheet sucks --- common/amk/amk.c | 58 +++++++++++++++++---- common/amk/amk.h | 46 ++++++++++------- common/daq/can_config.json | 82 ++++++++++++++---------------- common/daq/per_dbc.dbc | 25 +++++---- source/main_module/can/can_parse.c | 41 ++++++++++++--- source/main_module/can/can_parse.h | 53 ++++++++++++++++++- 6 files changed, 212 insertions(+), 93 deletions(-) diff --git a/common/amk/amk.c b/common/amk/amk.c index 421b28e2..1bf6ac1b 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -1,4 +1,5 @@ #include "amk.h" +#include "source/main_module/can/can_parse.h" void turnMotorsOn() { @@ -11,23 +12,62 @@ void turnMotorsOn() * Steps with the "r" suffix are requirement steps, the requirement needs to * be met before moving onto the next step. */ + + AMK_Control_t control = {0}; + AMK_Status_t status = {0}; + + /* + * Steps 3 and 4, both are in same CAN message, how do I do this? Can I + * just send 0 during step 3? + */ /* 1. Turn on 24V DC to inverters */ - /* 1r. Check AMK_bSystemReady = 1 for all inverters */ + /* 1r. Check AMK_bSystemReady = 1*/ /* 2. Charge DC caps; QUE should be set (is this just DcOn?) */ /* 3. Set AMK_bDcOn = 1 */ - /* 3r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ - /* 3r. (QUE & AMK_bDcOn) -> Check AMK_bQuitDcOn = 1 */ - /* Does where do I check QUE??? */ + control.fields.AMK_bDcOn = true; + SEND_AMK_SETPOINTS_1(control.bits, + DEFAULT_TARGET_VELOCITY, + DEFAULT_POSITIVE_TORQUE_LIMIT, + DEFAULT_NEGATIVE_TORQUE_LIMIT); + /* 3r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ + status.bits = can_data.AMK_Actual_Values_1.AMK_Status; + if (status.fields.AMK_bDcOn != true) { + /* FAILURE */ + /* But how do I check if it was read recently? I can wait until it is + * set but then I would have to timeout or something after the message + * period if it is never set and fail then */ + return; + } + /* 3r. (QUE & AMK_bDcOn) -> Check AMK_bQuitDcOn = 1 */ + /* Does where do I check QUE??? */ /* 4. Set AMK_TorqueLimitNegativ = 0 and AMK_TorqueLimitPositiv = 0 */ + SEND_AMK_SETPOINTS_1(control.bits, + DEFAULT_TARGET_VELOCITY, + DEFAULT_POSITIVE_TORQUE_LIMIT, + DEFAULT_NEGATIVE_TORQUE_LIMIT); /* 5. Set X15 hardware signals EF and EF2 = 1 */ /* 6. Set X140 hardware signal BE1 = 1 */ /* 7. Set AMK_bEnable = 1 */ + control.fields.AMK_bEnable = true; + SEND_AMK_SETPOINTS_1(control.bits, + DEFAULT_TARGET_VELOCITY, + DEFAULT_POSITIVE_TORQUE_LIMIT, + DEFAULT_NEGATIVE_TORQUE_LIMIT); /* 8 Set AMK_bInverterOn = 1 */ - /* 8r. AMK_bInverterOn is mirrored in AMK_Status, so should be on there */ + control.fields.AMK_bInverterOn = true; + SEND_AMK_SETPOINTS_1(control.bits, + DEFAULT_TARGET_VELOCITY, + DEFAULT_POSITIVE_TORQUE_LIMIT, + DEFAULT_NEGATIVE_TORQUE_LIMIT); + /* 8r. AMK_bInverterOn is mirrored in AMK_Status, so should be on there */ /* 9. Check AMK_bQuitInverterOn = 1 */ /* 10. Set X140 hardware signal BE2 = 1 */ /* 11. Set setpoint settings (AMK_TargetVelocity, AMK_TorqueLimitNegativ, AMK_TorqueLimitPositiv) */ + SEND_AMK_SETPOINTS_1(control.bits, + 1, + 1, + 1); } void turnMotorsOff() @@ -45,15 +85,15 @@ void turnMotorsOff() /* 1. Set setpoint settings to 0 (AMK_TargetVelocity, AMK_TorqueLimitNegativ, AMK_TorqueLimitPositiv) */ /* 2. Set X140 hardware signal BE2 = 0 */ /* 3 Set AMK_bInverterOn = 1 */ - /* 3r. AMK_bInverterOn is mirrored in AMK_Status, so should be on there */ + /* 3r. AMK_bInverterOn is mirrored in AMK_Status, so should be on there */ /* 4. Set AMK_bEnable = 0 */ /* 5. Check AMK_bQuitInverterOn = 0 */ /* 6. Set X140 hardware signal BE1 = 0 */ /* 7. Set X15 hardware signals EF and EF2 = 0 */ /* 8. Set AMK_bDcOn = 1 */ - /* 8r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ - /* 8r. Check AMK_bQuitDcOn = 0 */ - /* Does where do I check QUE??? */ + /* 8r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ + /* 8r. Check AMK_bQuitDcOn = 0 */ + /* Does where do I check QUE??? */ /* 9. Charge DC caps; QUE should be set (is this just DcOn?) */ /* 10. Turn off 24v DC to inverters */ diff --git a/common/amk/amk.h b/common/amk/amk.h index ebad67ce..e3bab0fd 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -15,28 +15,40 @@ #include /* Inverter -> CAN */ -typedef struct +/* In AMK_Actual_Values_1 */ +typedef union { - uint16_t AMK_bReserve : 8; - uint16_t AMK_bSystemReady : 1; - uint16_t AMK_bError : 1; - uint16_t AMK_bWarn : 1; - uint16_t AMK_bQuitDcOn : 1; - uint16_t AMK_bDcOn : 1; /* Same as QUE ?? */ - uint16_t AMK_bQuitInverterOn : 1; - uint16_t AMK_bInverterOn : 1; - uint16_t AMK_bDerating : 1; + struct { + uint16_t AMK_bReserve : 8; + uint16_t AMK_bSystemReady : 1; + uint16_t AMK_bError : 1; + uint16_t AMK_bWarn : 1; + uint16_t AMK_bQuitDcOn : 1; + uint16_t AMK_bDcOn : 1; /* Same as QUE ?? */ + uint16_t AMK_bQuitInverterOn : 1; + uint16_t AMK_bInverterOn : 1; + uint16_t AMK_bDerating : 1; + } fields; + uint16_t bits; } AMK_Status_t; /* CAN -> Inverter */ -typedef struct +/* In AMK_Setpoints */ +typedef union { - uint16_t AMK_bReserve1 : 8; - uint16_t AMK_bInverterOn : 1; - uint16_t AMK_bDcOn : 1; - uint16_t AMK_bEnable : 1; - uint16_t AMK_bErrorReset : 1; - uint16_t AMK_bReserve2 : 1; + struct { + uint16_t AMK_bReserve1 : 8; + uint16_t AMK_bInverterOn : 1; + uint16_t AMK_bDcOn : 1; + uint16_t AMK_bEnable : 1; + uint16_t AMK_bErrorReset : 1; + uint16_t AMK_bReserve2 : 1; + } fields; + uint16_t bits; } AMK_Control_t; +#define DEFAULT_TARGET_VELOCITY 0 +#define DEFAULT_POSITIVE_TORQUE_LIMIT 0 +#define DEFAULT_NEGATIVE_TORQUE_LIMIT 0 + #endif /* _AMK_H_ */ diff --git a/common/daq/can_config.json b/common/daq/can_config.json index 9715f156..f6a90c22 100644 --- a/common/daq/can_config.json +++ b/common/daq/can_config.json @@ -195,6 +195,18 @@ "msg_period": 15, "msg_hlp": 1, "msg_pgn": 14 + }, + { + "msg_name": "AMK_Setpoints_1", + "msg_desc": "Contains status word and setpoints", + "signals": [ + {"sig_name": "AMK_Control", "sig_desc": "Control word", "type":"uint16_t"}, + {"sig_name": "AMK_TargetVelocity", "sig_desc": "Speed setpoint", "type":"int16_t", "unit": "rpm"}, + {"sig_name": "AMK_TorqueLimitPositiv", "sig_desc": "Positive torque limit", "type":"int16_t", "unit": "Mn", "scale": 0.1}, + {"sig_name": "AMK_TorqueLimitNegativ", "sig_desc": "Negative torque limit", "type":"int16_t", "unit": "Mn", "scale": 0.1} + ], + "msg_period": 5, + "msg_id_override": "0x184" } ], "rx":[ @@ -206,7 +218,31 @@ {"msg_name": "main_module_bl_cmd" , "callback": true}, {"msg_name": "orion_currents_volts"}, {"msg_name": "throttle_vcu"}, - {"msg_name": "throttle_vcu_equal"} + {"msg_name": "throttle_vcu_equal"}, + { + "msg_name": "AMK_Actual_Values_1", + "msg_desc": "Contains the status word and actual values", + "signals": [ + {"sig_name": "AMK_Status", "sig_desc": "Status word, bit field", "type":"uint16_t"}, + {"sig_name": "AMK_ActualVelocity", "sig_desc": "Actual speed value", "type":"int16_t", "unit":"rpm"}, + {"sig_name": "AMK_TorqueCurrent", "sig_desc": "Raw data for calculating actual torque current", "type":"int16_t"}, + {"sig_name": "AMK_MagnetizingCurrent", "sig_desc": "Raw data for calculating actual magnetizing current", "type":"int16_t"} + ], + "msg_period": 5, + "msg_id_override": "0x283" + }, + { + "msg_name": "AMK_Actual_Values_2", + "msg_desc": "Contains actual values", + "signals": [ + {"sig_name": "AMK_TempMotor", "sig_desc": "Motor Temperature", "type":"int16_t", "unit": "C", "scale": 0.1}, + {"sig_name": "AMK_TempInverter", "sig_desc": "Cold Plate Temperature", "type":"int16_t", "unit": "C", "scale": 0.1}, + {"sig_name": "AMK_ErrorInfo", "sig_desc": "Diagnostic Number", "type":"uint16_t"}, + {"sig_name": "AMK_TempIGBT", "sig_desc": "IGBT Temperature", "type":"uint16_t", "unit": "C", "scale": 0.1} + ], + "msg_period": 5, + "msg_id_override": "0x285" + } ] }, { @@ -1041,50 +1077,6 @@ } ] }, - { - "node_name": "f4_testing", - "node_ssa": 61, - "tx": [ - { - "msg_name": "AMK_Setpoints_1", - "msg_desc": "Contains status word and setpoints", - "signals": [ - {"sig_name": "AMK_Control", "sig_desc": "Control word", "type":"uint16_t"}, - {"sig_name": "AMK_TargetVelocity", "sig_desc": "Speed setpoint", "type":"int16_t", "unit": "rpm"}, - {"sig_name": "AMK_TorqueLimitPositiv", "sig_desc": "Positive torque limit", "type":"int16_t", "unit": "Mn", "scale": 0.1}, - {"sig_name": "AMK_TorqueLimitNegativ", "sig_desc": "Negative torque limit", "type":"int16_t", "unit": "Mn", "scale": 0.1} - ], - "msg_period": 5, - "msg_id_override": "0x184" - } - ], - "rx": [ - { - "msg_name": "AMK_Actual_Values_1", - "msg_desc": "Contains the status word and actual values", - "signals": [ - {"sig_name": "AMK_Status", "sig_desc": "Status word, bit field", "type":"uint16_t"}, - {"sig_name": "AMK_ActualVelocity", "sig_desc": "Actual speed value", "type":"int16_t", "unit":"rpm"}, - {"sig_name": "AMK_TorqueCurrent", "sig_desc": "Raw data for calculating actual torque current", "type":"int16_t"}, - {"sig_name": "AMK_MagnetizingCurrent", "sig_desc": "Raw data for calculating actual magnetizing current", "type":"int16_t"} - ], - "msg_period": 5, - "msg_id_override": "0x283" - }, - { - "msg_name": "AMK_Actual_Values_2", - "msg_desc": "Contains actual values", - "signals": [ - {"sig_name": "AMK_TempMotor", "sig_desc": "Motor Temperature", "type":"int16_t", "unit": "C", "scale": 0.1}, - {"sig_name": "AMK_TempInverter", "sig_desc": "Cold Plate Temperature", "type":"int16_t", "unit": "C", "scale": 0.1}, - {"sig_name": "AMK_ErrorInfo", "sig_desc": "Diagnostic Number", "type":"uint16_t"}, - {"sig_name": "AMK_TempIGBT", "sig_desc": "IGBT Temperature", "type":"uint16_t", "unit": "C", "scale": 0.1} - ], - "msg_period": 5, - "msg_id_override": "0x285" - } - ] - }, { "node_name":"BITSTREAM", "node_ssa":62, diff --git a/common/daq/per_dbc.dbc b/common/daq/per_dbc.dbc index a1dedd5c..32996364 100644 --- a/common/daq/per_dbc.dbc +++ b/common/daq/per_dbc.dbc @@ -33,7 +33,7 @@ NS_ : BS_: -BU_: Main_Module a_box OrionBMS torque_vector Dashboard Steering PDU daq bootloader Inverter1 f4_testing BITSTREAM Charger DAQ TEST_NODE TEST_NODE_2 DAQ +BU_: Main_Module a_box OrionBMS torque_vector Dashboard Steering PDU daq bootloader Inverter1 BITSTREAM Charger DAQ TEST_NODE TEST_NODE_2 DAQ BO_ 2348816641 main_hb: 2 Main_Module @@ -119,6 +119,12 @@ BO_ 2214593409 rear_wheel_speeds: 8 Main_Module SG_ right_speed_mc : 16|16@1+ (1,0) [0|0] "RPM" Vector__XXX SG_ left_speed_mc : 0|16@1+ (1,0) [0|0] "RPM" Vector__XXX +BO_ 2147484036 AMK_Setpoints_1: 8 Main_Module + SG_ AMK_TorqueLimitNegativ : 48|16@1- (0.1,0) [0|0] "Mn" Vector__XXX + SG_ AMK_TorqueLimitPositiv : 32|16@1- (0.1,0) [0|0] "Mn" Vector__XXX + SG_ AMK_TargetVelocity : 16|16@1- (1,0) [0|0] "rpm" Vector__XXX + SG_ AMK_Control : 0|16@1+ (1,0) [0|0] "" Vector__XXX + BO_ 2148059649 fault_sync_main_module: 3 Main_Module SG_ latched : 16|1@1+ (1,0) [0|0] "" Vector__XXX SG_ idx : 0|16@1+ (1,0) [0|0] "" Vector__XXX @@ -480,12 +486,6 @@ BO_ 2147484293 AMK_Actual_Values_2: 8 Inverter1 SG_ AMK_TempInverter : 16|16@1- (0.1,0) [0|0] "C" Vector__XXX SG_ AMK_TempMotor : 0|16@1- (0.1,0) [0|0] "C" Vector__XXX -BO_ 2147484036 AMK_Setpoints_1: 8 f4_testing - SG_ AMK_TorqueLimitNegativ : 48|16@1- (0.1,0) [0|0] "Mn" Vector__XXX - SG_ AMK_TorqueLimitPositiv : 32|16@1- (0.1,0) [0|0] "Mn" Vector__XXX - SG_ AMK_TargetVelocity : 16|16@1- (1,0) [0|0] "rpm" Vector__XXX - SG_ AMK_Control : 0|16@1+ (1,0) [0|0] "" Vector__XXX - BO_ 2214598974 bitstream_data: 8 BITSTREAM SG_ d7 : 56|8@1+ (1,0) [0|0] "" Vector__XXX SG_ d6 : 48|8@1+ (1,0) [0|0] "" Vector__XXX @@ -647,7 +647,6 @@ CM_ BU_ PDU ""; CM_ BU_ daq ""; CM_ BU_ bootloader ""; CM_ BU_ Inverter1 ""; -CM_ BU_ f4_testing ""; CM_ BU_ BITSTREAM ""; CM_ BU_ Charger ""; CM_ BU_ DAQ ""; @@ -728,6 +727,11 @@ CM_ SG_ 2214593409 right_speed_sensor ""; CM_ SG_ 2214593409 left_speed_sensor ""; CM_ SG_ 2214593409 right_speed_mc ""; CM_ SG_ 2214593409 left_speed_mc ""; +CM_ BO_ 2147484036 "Contains status word and setpoints"; +CM_ SG_ 2147484036 AMK_TorqueLimitNegativ "Negative torque limit"; +CM_ SG_ 2147484036 AMK_TorqueLimitPositiv "Positive torque limit"; +CM_ SG_ 2147484036 AMK_TargetVelocity "Speed setpoint"; +CM_ SG_ 2147484036 AMK_Control "Control word"; CM_ BO_ 2148059649 "Fault status message"; CM_ SG_ 2148059649 latched ""; CM_ SG_ 2148059649 idx ""; @@ -1022,11 +1026,6 @@ CM_ SG_ 2147484293 AMK_TempIGBT "IGBT Temperature"; CM_ SG_ 2147484293 AMK_ErrorInfo "Diagnostic Number"; CM_ SG_ 2147484293 AMK_TempInverter "Cold Plate Temperature"; CM_ SG_ 2147484293 AMK_TempMotor "Motor Temperature"; -CM_ BO_ 2147484036 "Contains status word and setpoints"; -CM_ SG_ 2147484036 AMK_TorqueLimitNegativ "Negative torque limit"; -CM_ SG_ 2147484036 AMK_TorqueLimitPositiv "Positive torque limit"; -CM_ SG_ 2147484036 AMK_TargetVelocity "Speed setpoint"; -CM_ SG_ 2147484036 AMK_Control "Control word"; CM_ BO_ 2214598974 "Bitstream download command"; CM_ SG_ 2214598974 d7 "Bitstream data word 7"; CM_ SG_ 2214598974 d6 "Bitstream data word 6"; diff --git a/source/main_module/can/can_parse.c b/source/main_module/can/can_parse.c index f10d03b4..169be79e 100644 --- a/source/main_module/can/can_parse.c +++ b/source/main_module/can/can_parse.c @@ -91,6 +91,22 @@ void canRxUpdate(void) can_data.throttle_vcu_equal.stale = 0; can_data.throttle_vcu_equal.last_rx = sched.os_ticks; break; + case ID_AMK_ACTUAL_VALUES_1: + can_data.AMK_Actual_Values_1.AMK_Status = msg_data_a->AMK_Actual_Values_1.AMK_Status; + can_data.AMK_Actual_Values_1.AMK_ActualVelocity = (int16_t) msg_data_a->AMK_Actual_Values_1.AMK_ActualVelocity; + can_data.AMK_Actual_Values_1.AMK_TorqueCurrent = (int16_t) msg_data_a->AMK_Actual_Values_1.AMK_TorqueCurrent; + can_data.AMK_Actual_Values_1.AMK_MagnetizingCurrent = (int16_t) msg_data_a->AMK_Actual_Values_1.AMK_MagnetizingCurrent; + can_data.AMK_Actual_Values_1.stale = 0; + can_data.AMK_Actual_Values_1.last_rx = sched.os_ticks; + break; + case ID_AMK_ACTUAL_VALUES_2: + can_data.AMK_Actual_Values_2.AMK_TempMotor = (int16_t) msg_data_a->AMK_Actual_Values_2.AMK_TempMotor; + can_data.AMK_Actual_Values_2.AMK_TempInverter = (int16_t) msg_data_a->AMK_Actual_Values_2.AMK_TempInverter; + can_data.AMK_Actual_Values_2.AMK_ErrorInfo = msg_data_a->AMK_Actual_Values_2.AMK_ErrorInfo; + can_data.AMK_Actual_Values_2.AMK_TempIGBT = msg_data_a->AMK_Actual_Values_2.AMK_TempIGBT; + can_data.AMK_Actual_Values_2.stale = 0; + can_data.AMK_Actual_Values_2.last_rx = sched.os_ticks; + break; case ID_FAULT_SYNC_PDU: can_data.fault_sync_pdu.idx = msg_data_a->fault_sync_pdu.idx; can_data.fault_sync_pdu.latched = msg_data_a->fault_sync_pdu.latched; @@ -157,6 +173,12 @@ void canRxUpdate(void) CHECK_STALE(can_data.throttle_vcu_equal.stale, sched.os_ticks, can_data.throttle_vcu_equal.last_rx, UP_THROTTLE_VCU_EQUAL); + CHECK_STALE(can_data.AMK_Actual_Values_1.stale, + sched.os_ticks, can_data.AMK_Actual_Values_1.last_rx, + UP_AMK_ACTUAL_VALUES_1); + CHECK_STALE(can_data.AMK_Actual_Values_2.stale, + sched.os_ticks, can_data.AMK_Actual_Values_2.last_rx, + UP_AMK_ACTUAL_VALUES_2); /* END AUTO STALE CHECKS */ } @@ -188,18 +210,21 @@ bool initCANFilter() CAN1->sFilterRegister[3].FR2 = (ID_THROTTLE_VCU << 3) | 4; CAN1->FA1R |= (1 << 4); // configure bank 4 CAN1->sFilterRegister[4].FR1 = (ID_THROTTLE_VCU_EQUAL << 3) | 4; - CAN1->sFilterRegister[4].FR2 = (ID_FAULT_SYNC_PDU << 3) | 4; + CAN1->sFilterRegister[4].FR2 = (ID_AMK_ACTUAL_VALUES_1 << 3) | 4; CAN1->FA1R |= (1 << 5); // configure bank 5 - CAN1->sFilterRegister[5].FR1 = (ID_FAULT_SYNC_DASHBOARD << 3) | 4; - CAN1->sFilterRegister[5].FR2 = (ID_FAULT_SYNC_A_BOX << 3) | 4; + CAN1->sFilterRegister[5].FR1 = (ID_AMK_ACTUAL_VALUES_2 << 3) | 4; + CAN1->sFilterRegister[5].FR2 = (ID_FAULT_SYNC_PDU << 3) | 4; CAN1->FA1R |= (1 << 6); // configure bank 6 - CAN1->sFilterRegister[6].FR1 = (ID_FAULT_SYNC_TORQUE_VECTOR << 3) | 4; - CAN1->sFilterRegister[6].FR2 = (ID_FAULT_SYNC_TEST_NODE << 3) | 4; + CAN1->sFilterRegister[6].FR1 = (ID_FAULT_SYNC_DASHBOARD << 3) | 4; + CAN1->sFilterRegister[6].FR2 = (ID_FAULT_SYNC_A_BOX << 3) | 4; CAN1->FA1R |= (1 << 7); // configure bank 7 - CAN1->sFilterRegister[7].FR1 = (ID_SET_FAULT << 3) | 4; - CAN1->sFilterRegister[7].FR2 = (ID_RETURN_FAULT_CONTROL << 3) | 4; + CAN1->sFilterRegister[7].FR1 = (ID_FAULT_SYNC_TORQUE_VECTOR << 3) | 4; + CAN1->sFilterRegister[7].FR2 = (ID_FAULT_SYNC_TEST_NODE << 3) | 4; CAN1->FA1R |= (1 << 8); // configure bank 8 - CAN1->sFilterRegister[8].FR1 = (ID_DAQ_COMMAND_MAIN_MODULE << 3) | 4; + CAN1->sFilterRegister[8].FR1 = (ID_SET_FAULT << 3) | 4; + CAN1->sFilterRegister[8].FR2 = (ID_RETURN_FAULT_CONTROL << 3) | 4; + CAN1->FA1R |= (1 << 9); // configure bank 9 + CAN1->sFilterRegister[9].FR1 = (ID_DAQ_COMMAND_MAIN_MODULE << 3) | 4; /* END AUTO FILTER */ CAN1->FMR &= ~CAN_FMR_FINIT; // Enable Filters (exit filter init mode) diff --git a/source/main_module/can/can_parse.h b/source/main_module/can/can_parse.h index d1a87bc1..b1f3b8bf 100644 --- a/source/main_module/can/can_parse.h +++ b/source/main_module/can/can_parse.h @@ -44,6 +44,7 @@ typedef union { #define ID_SDC_STATUS 0xc000381 #define ID_REAR_MOTOR_TEMPS 0x10000301 #define ID_REAR_WHEEL_SPEEDS 0x4000381 +#define ID_AMK_SETPOINTS_1 0x184 #define ID_FAULT_SYNC_MAIN_MODULE 0x8ca01 #define ID_DAQ_RESPONSE_MAIN_MODULE 0x17ffffc1 #define ID_RAW_THROTTLE_BRAKE 0x10000285 @@ -55,6 +56,8 @@ typedef union { #define ID_ORION_CURRENTS_VOLTS 0x140006f8 #define ID_THROTTLE_VCU 0x40025b7 #define ID_THROTTLE_VCU_EQUAL 0x4002837 +#define ID_AMK_ACTUAL_VALUES_1 0x283 +#define ID_AMK_ACTUAL_VALUES_2 0x285 #define ID_FAULT_SYNC_PDU 0x8cb1f #define ID_FAULT_SYNC_DASHBOARD 0x8cac5 #define ID_FAULT_SYNC_A_BOX 0x8ca44 @@ -81,6 +84,7 @@ typedef union { #define DLC_SDC_STATUS 2 #define DLC_REAR_MOTOR_TEMPS 4 #define DLC_REAR_WHEEL_SPEEDS 8 +#define DLC_AMK_SETPOINTS_1 8 #define DLC_FAULT_SYNC_MAIN_MODULE 3 #define DLC_DAQ_RESPONSE_MAIN_MODULE 8 #define DLC_RAW_THROTTLE_BRAKE 8 @@ -92,6 +96,8 @@ typedef union { #define DLC_ORION_CURRENTS_VOLTS 4 #define DLC_THROTTLE_VCU 4 #define DLC_THROTTLE_VCU_EQUAL 4 +#define DLC_AMK_ACTUAL_VALUES_1 8 +#define DLC_AMK_ACTUAL_VALUES_2 8 #define DLC_FAULT_SYNC_PDU 3 #define DLC_FAULT_SYNC_DASHBOARD 3 #define DLC_FAULT_SYNC_A_BOX 3 @@ -229,6 +235,15 @@ typedef union { data_a->rear_wheel_speeds.right_speed_sensor = right_speed_sensor_;\ canTxSendToBack(&msg);\ } while(0) +#define SEND_AMK_SETPOINTS_1(AMK_Control_, AMK_TargetVelocity_, AMK_TorqueLimitPositiv_, AMK_TorqueLimitNegativ_) do {\ + CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_AMK_SETPOINTS_1, .DLC=DLC_AMK_SETPOINTS_1, .IDE=1};\ + CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ + data_a->AMK_Setpoints_1.AMK_Control = AMK_Control_;\ + data_a->AMK_Setpoints_1.AMK_TargetVelocity = AMK_TargetVelocity_;\ + data_a->AMK_Setpoints_1.AMK_TorqueLimitPositiv = AMK_TorqueLimitPositiv_;\ + data_a->AMK_Setpoints_1.AMK_TorqueLimitNegativ = AMK_TorqueLimitNegativ_;\ + canTxSendToBack(&msg);\ + } while(0) #define SEND_FAULT_SYNC_MAIN_MODULE(idx_, latched_) do {\ CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_FAULT_SYNC_MAIN_MODULE, .DLC=DLC_FAULT_SYNC_MAIN_MODULE, .IDE=1};\ CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ @@ -254,6 +269,8 @@ typedef union { #define UP_ORION_CURRENTS_VOLTS 32 #define UP_THROTTLE_VCU 20 #define UP_THROTTLE_VCU_EQUAL 20 +#define UP_AMK_ACTUAL_VALUES_1 5 +#define UP_AMK_ACTUAL_VALUES_2 5 /* END AUTO UP DEFS */ #define CHECK_STALE(stale, curr, last, period) if(!stale && \ @@ -407,6 +424,12 @@ typedef union { uint64_t left_speed_sensor: 16; uint64_t right_speed_sensor: 16; } rear_wheel_speeds; + struct { + uint64_t AMK_Control: 16; + uint64_t AMK_TargetVelocity: 16; + uint64_t AMK_TorqueLimitPositiv: 16; + uint64_t AMK_TorqueLimitNegativ: 16; + } AMK_Setpoints_1; struct { uint64_t idx: 16; uint64_t latched: 1; @@ -456,6 +479,18 @@ typedef union { uint64_t equal_k_rl: 16; uint64_t equal_k_rr: 16; } throttle_vcu_equal; + struct { + uint64_t AMK_Status: 16; + uint64_t AMK_ActualVelocity: 16; + uint64_t AMK_TorqueCurrent: 16; + uint64_t AMK_MagnetizingCurrent: 16; + } AMK_Actual_Values_1; + struct { + uint64_t AMK_TempMotor: 16; + uint64_t AMK_TempInverter: 16; + uint64_t AMK_ErrorInfo: 16; + uint64_t AMK_TempIGBT: 16; + } AMK_Actual_Values_2; struct { uint64_t idx: 16; uint64_t latched: 1; @@ -550,6 +585,22 @@ typedef struct { uint8_t stale; uint32_t last_rx; } throttle_vcu_equal; + struct { + uint16_t AMK_Status; + int16_t AMK_ActualVelocity; + int16_t AMK_TorqueCurrent; + int16_t AMK_MagnetizingCurrent; + uint8_t stale; + uint32_t last_rx; + } AMK_Actual_Values_1; + struct { + int16_t AMK_TempMotor; + int16_t AMK_TempInverter; + uint16_t AMK_ErrorInfo; + uint16_t AMK_TempIGBT; + uint8_t stale; + uint32_t last_rx; + } AMK_Actual_Values_2; struct { uint16_t idx; uint8_t latched; @@ -619,4 +670,4 @@ void canRxUpdate(void); */ void canProcessRxIRQs(CanMsgTypeDef_t* rx); -#endif \ No newline at end of file +#endif From 0c92262b20b1f27ffb72a8465767304ff016a5fd Mon Sep 17 00:00:00 2001 From: Cole Date: Fri, 11 Oct 2024 21:16:26 -0400 Subject: [PATCH 08/17] Either our CAN setup is not good for these motors, or I am dumb --- common/amk/amk.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/common/amk/amk.c b/common/amk/amk.c index 1bf6ac1b..0dea5332 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -22,7 +22,7 @@ void turnMotorsOn() */ /* 1. Turn on 24V DC to inverters */ - /* 1r. Check AMK_bSystemReady = 1*/ + /* 1r. Check AMK_bSystemReady = 1*/ /* 2. Charge DC caps; QUE should be set (is this just DcOn?) */ /* 3. Set AMK_bDcOn = 1 */ control.fields.AMK_bDcOn = true; @@ -32,6 +32,19 @@ void turnMotorsOn() DEFAULT_NEGATIVE_TORQUE_LIMIT); /* 3r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ status.bits = can_data.AMK_Actual_Values_1.AMK_Status; + + /* I can't even do this, can_data does not update until canRxUpdate() runs + * and it does not run in the middle of this function running. So how do I do + * what I am trying to do here? I don't necessarily have to check this, atleast + * I don't think. But later on there are some things I do need to check. + */ + uint32_t start = sched.os_ticks; + while (status.fields.AMK_bDcOn != true) { + status.bits = can_data.AMK_Actual_Values_1.AMK_Status; + if (sched.os_ticks - start >= UP_AMK_ACTUAL_VALUES_1 * STALE_THRESH) { + /* FAILURE */ + } + } if (status.fields.AMK_bDcOn != true) { /* FAILURE */ /* But how do I check if it was read recently? I can wait until it is @@ -93,7 +106,7 @@ void turnMotorsOff() /* 8. Set AMK_bDcOn = 1 */ /* 8r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ /* 8r. Check AMK_bQuitDcOn = 0 */ - /* Does where do I check QUE??? */ + /* Does where do I check QUE??? */ /* 9. Charge DC caps; QUE should be set (is this just DcOn?) */ /* 10. Turn off 24v DC to inverters */ From 130723a47dd93d1ff360ac9849bf42277bae3c8d Mon Sep 17 00:00:00 2001 From: Cole Date: Sun, 13 Oct 2024 11:30:11 -0400 Subject: [PATCH 09/17] we love state machines --- common/amk/amk.c | 80 ++++++++++++++++++++++++++++++++++++++++-------- common/amk/amk.h | 24 +++++++++++++++ 2 files changed, 92 insertions(+), 12 deletions(-) diff --git a/common/amk/amk.c b/common/amk/amk.c index 0dea5332..2be5781a 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -1,29 +1,85 @@ #include "amk.h" #include "source/main_module/can/can_parse.h" +/* + * Motor Datasheet: + * https://www.amk-motion.com/amk-dokucd/dokucd/en/content/resources/pdf-dateien/pdk_205481_kw26-s5-fse-4q_en_.pdf + * + * Section 8.1.2.1 goes over CAN messages + * Section 9.4 goes over turning the motors on and off + * + * Steps with the "r" suffix are requirement steps, the requirement needs to + * be met before moving onto the next step. + */ + +/* NOTE: + * I need change all of this to be a massive state machine in one function + * like car.c. It will have states such as init which will turn motors on, + * and a state to turn motors off and a state to actually run stuff. + * The massive state machine will run periodically (not sure how often yet, + * has to be < 50ms so that the control word can be send often) + */ + +/* NOTE: + * Step 1 is turning on LV + * Step 3 happens when HV is turned on and precharging starts + * I can check when this is done with precharge complete and then move + * onto other steps + * MAYBE we can check when AMK_bSystemReady is on and display a message + * on LCD so they know when to turn on the HV to start the precharging. + * Not sure if I need that + */ + +amk_motor_t motor; + +void motorPeriodic() +{ + switch(motor.states.stage) { + case MOTOR_STAGE_INIT: + /* turnMotorsOn logic here */ + break; + case MOTOR_STAGE_DEINIT: + /* turnMotorsOff logic here */ + break; + case MOTOR_STAGE_RUNNING: + /* torque requests and whatever else */ + break; + } +} + void turnMotorsOn() { - /* - * Motor Datasheet: - * https://www.amk-motion.com/amk-dokucd/dokucd/en/content/resources/pdf-dateien/pdk_205481_kw26-s5-fse-4q_en_.pdf - * - * Section 9.4 goes over turning the motors on and off - * - * Steps with the "r" suffix are requirement steps, the requirement needs to - * be met before moving onto the next step. - */ + /* THIS NEEDS TO BE SENT EVERY 50ms */ AMK_Control_t control = {0}; + AMK_Status_t status = {0}; /* * Steps 3 and 4, both are in same CAN message, how do I do this? Can I * just send 0 during step 3? */ + switch (motor.states.init_state) { + case MOTOR_INIT_POWER_ON: + /* 1. Turn on 24V DC to inverters */ + /* 1r. Check AMK_bSystemReady = 1*/ + + /* if AMK_bSystemReady = 1 */ + motor.states.init_state++; + + break; + case MOTOR_INIT_PRECHARGE: + /* 2. Charge DC caps; QUE should be set (is this just DcOn?) */ + /* This step happens when HV turns on. I can check the precharge + * complete GPIO pin to see when this is finished. When finished + * I move onto the next state. */ + + /* if precharge complete pin is high */ + motor.states.init_state++; + + break; + } - /* 1. Turn on 24V DC to inverters */ - /* 1r. Check AMK_bSystemReady = 1*/ - /* 2. Charge DC caps; QUE should be set (is this just DcOn?) */ /* 3. Set AMK_bDcOn = 1 */ control.fields.AMK_bDcOn = true; SEND_AMK_SETPOINTS_1(control.bits, diff --git a/common/amk/amk.h b/common/amk/amk.h index e3bab0fd..32f49244 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -14,6 +14,29 @@ #include #include +typedef struct { + uint8_t stage; + uint8_t running_state; + uint8_t init_state; + uint8_t deinit_state; +} amk_motor_states_t; + +typedef struct { + amk_motor_states_t states; +} amk_motor_t; + +typedef enum { + MOTOR_INIT_POWER_ON, + MOTOR_INIT_PRECHARGE, + +} amk_motor_init_state_t; + +typedef enum { + MOTOR_STAGE_INIT, + MOTOR_STAGE_RUNNING, + MOTOR_STAGE_DEINIT +} amk_motor_stage_t; + /* Inverter -> CAN */ /* In AMK_Actual_Values_1 */ typedef union @@ -34,6 +57,7 @@ typedef union /* CAN -> Inverter */ /* In AMK_Setpoints */ +/* THIS NEEDS TO BE SENT EVERY 50ms */ typedef union { struct { From aa8fb80acc09c76fdae15f8cc09afadad68d3945 Mon Sep 17 00:00:00 2001 From: Cole Date: Sun, 13 Oct 2024 11:42:24 -0400 Subject: [PATCH 10/17] too easy --- common/amk/amk.c | 174 ++++++++++++++++++++++++++--------------------- common/amk/amk.h | 7 +- 2 files changed, 101 insertions(+), 80 deletions(-) diff --git a/common/amk/amk.c b/common/amk/amk.c index 2be5781a..84e4cb2d 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -1,16 +1,6 @@ #include "amk.h" #include "source/main_module/can/can_parse.h" -/* - * Motor Datasheet: - * https://www.amk-motion.com/amk-dokucd/dokucd/en/content/resources/pdf-dateien/pdk_205481_kw26-s5-fse-4q_en_.pdf - * - * Section 8.1.2.1 goes over CAN messages - * Section 9.4 goes over turning the motors on and off - * - * Steps with the "r" suffix are requirement steps, the requirement needs to - * be met before moving onto the next step. - */ /* NOTE: * I need change all of this to be a massive state machine in one function @@ -30,30 +20,52 @@ * Not sure if I need that */ -amk_motor_t motor; +static amk_motor_t motor = {0}; + +/* THIS NEEDS TO BE SENT EVERY 50ms */ +static AMK_Control_t control = {0}; + +static AMK_Status_t status = {0}; + +static void turnMotorsOn(); +static void motorsRunning(); +static void turnMotorsOff(); void motorPeriodic() { switch(motor.states.stage) { case MOTOR_STAGE_INIT: - /* turnMotorsOn logic here */ - break; - case MOTOR_STAGE_DEINIT: - /* turnMotorsOff logic here */ + turnMotorsOn(); break; case MOTOR_STAGE_RUNNING: - /* torque requests and whatever else */ + motorsRunning(); + break; + case MOTOR_STAGE_DEINIT: + turnMotorsOff(); break; } } -void turnMotorsOn() +static void motorsRunning() { + /* Set setpoint settings (AMK_TargetVelocity, AMK_TorqueLimitNegativ, AMK_TorqueLimitPositiv) */ + SEND_AMK_SETPOINTS_1(control.bits, + 1, + 1, + 1); +} - /* THIS NEEDS TO BE SENT EVERY 50ms */ - AMK_Control_t control = {0}; - - AMK_Status_t status = {0}; +static void turnMotorsOn() +{ + /* + * Motor Datasheet: + * https://www.amk-motion.com/amk-dokucd/dokucd/en/content/resources/pdf-dateien/pdk_205481_kw26-s5-fse-4q_en_.pdf + * + * Section 9.4 goes over turning the motors on and off + * + * Steps with the "r" suffix are requirement steps, the requirement needs to + * be met before moving onto the next step. + */ /* * Steps 3 and 4, both are in same CAN message, how do I do this? Can I @@ -77,69 +89,73 @@ void turnMotorsOn() /* if precharge complete pin is high */ motor.states.init_state++; + break; + case MOTOR_INIT_DC_ON: + /* 3. Set AMK_bDcOn = 1 */ + control.fields.AMK_bDcOn = true; + SEND_AMK_SETPOINTS_1(control.bits, + DEFAULT_TARGET_VELOCITY, + DEFAULT_POSITIVE_TORQUE_LIMIT, + DEFAULT_NEGATIVE_TORQUE_LIMIT); + motor.states.init_state++; + break; + case MOTOR_INIT_DC_ON_CHECK: + /* 3r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ + status.bits = can_data.AMK_Actual_Values_1.AMK_Status; + + /* When will AMK_bQuitDcOn go on? Does it take some time after + * DcOn is set?? */ + /* 3r. (QUE & AMK_bDcOn) -> Check AMK_bQuitDcOn = 1 */ + /* Does where do I check QUE??? */ + + motor.states.init_state++; + break; + case MOTOR_INIT_TORQUE_INIT: + /* 4. Set AMK_TorqueLimitNegativ = 0 and AMK_TorqueLimitPositiv = 0 */ + SEND_AMK_SETPOINTS_1(control.bits, + DEFAULT_TARGET_VELOCITY, + DEFAULT_POSITIVE_TORQUE_LIMIT, + DEFAULT_NEGATIVE_TORQUE_LIMIT); + + motor.states.init_state++; + break; + case MOTOR_INIT_ENABLE: + /* 7. Set AMK_bEnable = 1 */ + control.fields.AMK_bEnable = true; + SEND_AMK_SETPOINTS_1(control.bits, + DEFAULT_TARGET_VELOCITY, + DEFAULT_POSITIVE_TORQUE_LIMIT, + DEFAULT_NEGATIVE_TORQUE_LIMIT); + + motor.states.init_state++; + break; + case MOTOR_INIT_INVERTER_ON: + /* 8 Set AMK_bInverterOn = 1 */ + control.fields.AMK_bInverterOn = true; + SEND_AMK_SETPOINTS_1(control.bits, + DEFAULT_TARGET_VELOCITY, + DEFAULT_POSITIVE_TORQUE_LIMIT, + DEFAULT_NEGATIVE_TORQUE_LIMIT); + + motor.states.init_state++; + break; + case MOTOR_INIT_INVERTER_ON_CHECK: + /* 8r. AMK_bInverterOn is mirrored in AMK_Status, so should be on there */ + + /* Same with AMK_bQuitDcOn, do we need seperate states for these quits?? */ + /* 9. Check AMK_bQuitInverterOn = 1 */ + + /* This should be the last init state, so now we move onto the stage for + * running the motors */ + + motor.states.stage++; break; } - /* 3. Set AMK_bDcOn = 1 */ - control.fields.AMK_bDcOn = true; - SEND_AMK_SETPOINTS_1(control.bits, - DEFAULT_TARGET_VELOCITY, - DEFAULT_POSITIVE_TORQUE_LIMIT, - DEFAULT_NEGATIVE_TORQUE_LIMIT); - /* 3r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ - status.bits = can_data.AMK_Actual_Values_1.AMK_Status; - - /* I can't even do this, can_data does not update until canRxUpdate() runs - * and it does not run in the middle of this function running. So how do I do - * what I am trying to do here? I don't necessarily have to check this, atleast - * I don't think. But later on there are some things I do need to check. - */ - uint32_t start = sched.os_ticks; - while (status.fields.AMK_bDcOn != true) { - status.bits = can_data.AMK_Actual_Values_1.AMK_Status; - if (sched.os_ticks - start >= UP_AMK_ACTUAL_VALUES_1 * STALE_THRESH) { - /* FAILURE */ - } - } - if (status.fields.AMK_bDcOn != true) { - /* FAILURE */ - /* But how do I check if it was read recently? I can wait until it is - * set but then I would have to timeout or something after the message - * period if it is never set and fail then */ - return; - } - /* 3r. (QUE & AMK_bDcOn) -> Check AMK_bQuitDcOn = 1 */ - /* Does where do I check QUE??? */ - /* 4. Set AMK_TorqueLimitNegativ = 0 and AMK_TorqueLimitPositiv = 0 */ - SEND_AMK_SETPOINTS_1(control.bits, - DEFAULT_TARGET_VELOCITY, - DEFAULT_POSITIVE_TORQUE_LIMIT, - DEFAULT_NEGATIVE_TORQUE_LIMIT); - /* 5. Set X15 hardware signals EF and EF2 = 1 */ - /* 6. Set X140 hardware signal BE1 = 1 */ - /* 7. Set AMK_bEnable = 1 */ - control.fields.AMK_bEnable = true; - SEND_AMK_SETPOINTS_1(control.bits, - DEFAULT_TARGET_VELOCITY, - DEFAULT_POSITIVE_TORQUE_LIMIT, - DEFAULT_NEGATIVE_TORQUE_LIMIT); - /* 8 Set AMK_bInverterOn = 1 */ - control.fields.AMK_bInverterOn = true; - SEND_AMK_SETPOINTS_1(control.bits, - DEFAULT_TARGET_VELOCITY, - DEFAULT_POSITIVE_TORQUE_LIMIT, - DEFAULT_NEGATIVE_TORQUE_LIMIT); - /* 8r. AMK_bInverterOn is mirrored in AMK_Status, so should be on there */ - /* 9. Check AMK_bQuitInverterOn = 1 */ - /* 10. Set X140 hardware signal BE2 = 1 */ - /* 11. Set setpoint settings (AMK_TargetVelocity, AMK_TorqueLimitNegativ, AMK_TorqueLimitPositiv) */ - SEND_AMK_SETPOINTS_1(control.bits, - 1, - 1, - 1); + } -void turnMotorsOff() +static void turnMotorsOff() { /* * Motor Datasheet: diff --git a/common/amk/amk.h b/common/amk/amk.h index 32f49244..f3f15401 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -28,7 +28,12 @@ typedef struct { typedef enum { MOTOR_INIT_POWER_ON, MOTOR_INIT_PRECHARGE, - + MOTOR_INIT_DC_ON, + MOTOR_INIT_DC_ON_CHECK, + MOTOR_INIT_TORQUE_INIT, + MOTOR_INIT_ENABLE, + MOTOR_INIT_INVERTER_ON, + MOTOR_INIT_INVERTER_ON_CHECK, } amk_motor_init_state_t; typedef enum { From 8c37d041b6c45f36bbbabe42651ea9f4da6f6861 Mon Sep 17 00:00:00 2001 From: Cole Date: Mon, 14 Oct 2024 13:02:53 -0400 Subject: [PATCH 11/17] deinit state machine basics are setup --- common/amk/amk.c | 161 ++++++++++++++++++++++++++++++++--------------- common/amk/amk.h | 19 ++++++ 2 files changed, 129 insertions(+), 51 deletions(-) diff --git a/common/amk/amk.c b/common/amk/amk.c index 84e4cb2d..13062709 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -22,15 +22,36 @@ static amk_motor_t motor = {0}; -/* THIS NEEDS TO BE SENT EVERY 50ms */ static AMK_Control_t control = {0}; - static AMK_Status_t status = {0}; static void turnMotorsOn(); static void motorsRunning(); static void turnMotorsOff(); +/* NOTE: As of now this is just setting everything to 0, but it may make sense + * to have it in case something changes down the line while I learn more, so + * this may end up being deleted if everything just inits to 0 */ + +/* FIXME: Move control word and status words into motor struct */ + +void motorInit(amk_motor_t* motor) +{ + *motor = (amk_motor_t){ + /* States */ + .states.stage = MOTOR_STAGE_INIT, + .states.init_state = MOTOR_INIT_POWER_ON, + /* FIXME: FILL IN ONCE I MAKE ENUMS */ + .states.deinit_state = 0, + .states.running_state = 0, + + /* Values */ + .values.target_velocity = DEFAULT_TARGET_VELOCITY, + .values.torque_limit_positive = DEFAULT_POSITIVE_TORQUE_LIMIT, + .values.torque_limit_negative = DEFAULT_NEGATIVE_TORQUE_LIMIT + }; +} + void motorPeriodic() { switch(motor.states.stage) { @@ -38,10 +59,10 @@ void motorPeriodic() turnMotorsOn(); break; case MOTOR_STAGE_RUNNING: - motorsRunning(); + motorsRunning(); break; case MOTOR_STAGE_DEINIT: - turnMotorsOff(); + turnMotorsOff(); break; } } @@ -55,7 +76,7 @@ static void motorsRunning() 1); } -static void turnMotorsOn() +static void turnMotorOn(amk_motor_t* motor) { /* * Motor Datasheet: @@ -67,17 +88,13 @@ static void turnMotorsOn() * be met before moving onto the next step. */ - /* - * Steps 3 and 4, both are in same CAN message, how do I do this? Can I - * just send 0 during step 3? - */ - switch (motor.states.init_state) { + switch (motor->states.init_state) { case MOTOR_INIT_POWER_ON: /* 1. Turn on 24V DC to inverters */ /* 1r. Check AMK_bSystemReady = 1*/ /* if AMK_bSystemReady = 1 */ - motor.states.init_state++; + motor->states.init_state++; break; case MOTOR_INIT_PRECHARGE: @@ -87,17 +104,17 @@ static void turnMotorsOn() * I move onto the next state. */ /* if precharge complete pin is high */ - motor.states.init_state++; + motor->states.init_state++; break; case MOTOR_INIT_DC_ON: /* 3. Set AMK_bDcOn = 1 */ control.fields.AMK_bDcOn = true; - SEND_AMK_SETPOINTS_1(control.bits, - DEFAULT_TARGET_VELOCITY, - DEFAULT_POSITIVE_TORQUE_LIMIT, - DEFAULT_NEGATIVE_TORQUE_LIMIT); - motor.states.init_state++; + SEND_AMK_SETPOINTS_1(control.bits, + motor->values.target_velocity, + motor->values.torque_limit_positive, + motor->values.torque_limit_negative); + motor->states.init_state++; break; case MOTOR_INIT_DC_ON_CHECK: /* 3r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ @@ -108,36 +125,39 @@ static void turnMotorsOn() /* 3r. (QUE & AMK_bDcOn) -> Check AMK_bQuitDcOn = 1 */ /* Does where do I check QUE??? */ - motor.states.init_state++; + motor->states.init_state++; break; case MOTOR_INIT_TORQUE_INIT: /* 4. Set AMK_TorqueLimitNegativ = 0 and AMK_TorqueLimitPositiv = 0 */ - SEND_AMK_SETPOINTS_1(control.bits, - DEFAULT_TARGET_VELOCITY, - DEFAULT_POSITIVE_TORQUE_LIMIT, - DEFAULT_NEGATIVE_TORQUE_LIMIT); + motor->values.torque_limit_positive = 0; + motor->values.torque_limit_negative = 0; + + SEND_AMK_SETPOINTS_1(control.bits, + motor->values.target_velocity, + motor->values.torque_limit_positive, + motor->values.torque_limit_negative); - motor.states.init_state++; + motor->states.init_state++; break; case MOTOR_INIT_ENABLE: /* 7. Set AMK_bEnable = 1 */ control.fields.AMK_bEnable = true; - SEND_AMK_SETPOINTS_1(control.bits, - DEFAULT_TARGET_VELOCITY, - DEFAULT_POSITIVE_TORQUE_LIMIT, - DEFAULT_NEGATIVE_TORQUE_LIMIT); + SEND_AMK_SETPOINTS_1(control.bits, + motor->values.target_velocity, + motor->values.torque_limit_positive, + motor->values.torque_limit_negative); - motor.states.init_state++; + motor->states.init_state++; break; case MOTOR_INIT_INVERTER_ON: /* 8 Set AMK_bInverterOn = 1 */ control.fields.AMK_bInverterOn = true; - SEND_AMK_SETPOINTS_1(control.bits, - DEFAULT_TARGET_VELOCITY, - DEFAULT_POSITIVE_TORQUE_LIMIT, - DEFAULT_NEGATIVE_TORQUE_LIMIT); + SEND_AMK_SETPOINTS_1(control.bits, + motor->values.target_velocity, + motor->values.torque_limit_positive, + motor->values.torque_limit_negative); - motor.states.init_state++; + motor->states.init_state++; break; case MOTOR_INIT_INVERTER_ON_CHECK: /* 8r. AMK_bInverterOn is mirrored in AMK_Status, so should be on there */ @@ -148,14 +168,12 @@ static void turnMotorsOn() /* This should be the last init state, so now we move onto the stage for * running the motors */ - motor.states.stage++; + motor->states.stage++; break; } - - } -static void turnMotorsOff() +static void turnMotorOff(amk_motor_t* motor) { /* * Motor Datasheet: @@ -167,19 +185,60 @@ static void turnMotorsOff() * be met before moving onto the next step. */ - /* 1. Set setpoint settings to 0 (AMK_TargetVelocity, AMK_TorqueLimitNegativ, AMK_TorqueLimitPositiv) */ - /* 2. Set X140 hardware signal BE2 = 0 */ - /* 3 Set AMK_bInverterOn = 1 */ - /* 3r. AMK_bInverterOn is mirrored in AMK_Status, so should be on there */ - /* 4. Set AMK_bEnable = 0 */ - /* 5. Check AMK_bQuitInverterOn = 0 */ - /* 6. Set X140 hardware signal BE1 = 0 */ - /* 7. Set X15 hardware signals EF and EF2 = 0 */ - /* 8. Set AMK_bDcOn = 1 */ - /* 8r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ - /* 8r. Check AMK_bQuitDcOn = 0 */ - /* Does where do I check QUE??? */ - /* 9. Charge DC caps; QUE should be set (is this just DcOn?) */ - /* 10. Turn off 24v DC to inverters */ + switch(motor->states.deinit_state) { + case MOTOR_DEINIT_SETPOINTS_DEINIT: + /* 1. Set setpoint settings to 0 (AMK_TargetVelocity, AMK_TorqueLimitNegativ, AMK_TorqueLimitPositiv) */ + motor->values.torque_limit_positive = 0; + motor->values.torque_limit_negative = 0; + + SEND_AMK_SETPOINTS_1(control.bits, + motor->values.target_velocity, + motor->values.torque_limit_positive, + motor->values.torque_limit_negative); + motor->states.deinit_state++; + break; + + case MOTOR_DEINIT_INVERTER_OFF: + /* 2. Set AMK_bInverterOn = 0 */ + control.fields.AMK_bInverterOn = true; + + SEND_AMK_SETPOINTS_1(control.bits, + motor->values.target_velocity, + motor->values.torque_limit_positive, + motor->values.torque_limit_negative); + + motor->states.init_state++; + break; + case MOTOR_DEINIT_INVERTER_OFF_CHECK: + /* 2r. AMK_bInverterOn is mirrored in AMK_Status, so should be on there */ + motor->states.init_state++; + break; + case MOTOR_DEINIT_DISABLE: + /* 3. Set AMK_bEnable = 0 */ + motor->states.init_state++; + break; + case MOTOR_DEINIT_QUIT_INVERTER_CHECK: + /* 4. Check AMK_bQuitInverterOn = 0 */ + motor->states.init_state++; + break; + case MOTOR_DEINIT_DC_OFF: + /* 5. Set AMK_bDcOn = 0 */ + motor->states.init_state++; + break; + case MOTOR_DEINIT_DC_OFF_CHECK: + /* 5r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ + /* 5r. Check AMK_bQuitDcOn = 0 */ + motor->states.init_state++; + break; + case MOTOR_DEINIT_PRECHARGE: + /* 6. Discharge DC caps; QUE should be reset (is this just DcOn?) */ + /* If discharged, move on */ + motor->states.init_state++; + break; + case MOTOR_DEINIT_POWER_OFF: + /* 7. Turn off 24v DC to inverters */ + motor->states.init_state++; + break; + } } diff --git a/common/amk/amk.h b/common/amk/amk.h index f3f15401..c9c85ac0 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -21,8 +21,15 @@ typedef struct { uint8_t deinit_state; } amk_motor_states_t; +typedef struct { + uint16_t target_velocity; + uint16_t torque_limit_positive; + uint16_t torque_limit_negative; +} amk_motor_values_t; + typedef struct { amk_motor_states_t states; + amk_motor_values_t values; } amk_motor_t; typedef enum { @@ -36,6 +43,18 @@ typedef enum { MOTOR_INIT_INVERTER_ON_CHECK, } amk_motor_init_state_t; +typedef enum { + MOTOR_DEINIT_SETPOINTS_DEINIT, + MOTOR_DEINIT_INVERTER_OFF, + MOTOR_DEINIT_INVERTER_OFF_CHECK, + MOTOR_DEINIT_DISABLE, + MOTOR_DEINIT_QUIT_INVERTER_CHECK, + MOTOR_DEINIT_DC_OFF, + MOTOR_DEINIT_DC_OFF_CHECK, + MOTOR_DEINIT_PRECHARGE, + MOTOR_DEINIT_POWER_OFF, +} amk_motor_deinit_state_t; + typedef enum { MOTOR_STAGE_INIT, MOTOR_STAGE_RUNNING, From 114d5465421212d18a839f230b5a4cb69e58108b Mon Sep 17 00:00:00 2001 From: Cole Date: Mon, 14 Oct 2024 15:11:28 -0400 Subject: [PATCH 12/17] Trying to figure out more about these motors --- common/amk/amk.c | 47 +++++++++++++++++++++++++++-------------------- common/amk/amk.h | 5 +++++ 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/common/amk/amk.c b/common/amk/amk.c index 13062709..b9b9f1ea 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -12,7 +12,7 @@ /* NOTE: * Step 1 is turning on LV - * Step 3 happens when HV is turned on and precharging starts + * Step 3 happens when HV is turned on and precharging starts (I think this is actually step 2) * I can check when this is done with precharge complete and then move * onto other steps * MAYBE we can check when AMK_bSystemReady is on and display a message @@ -20,14 +20,18 @@ * Not sure if I need that */ -static amk_motor_t motor = {0}; +/* NOTE: Page 36 says max velocity is 6000 rpm. But page 37 says that the + * default max velocity limit is ±5000 rpm */ + + +static amk_motor_t right = {0}; static AMK_Control_t control = {0}; static AMK_Status_t status = {0}; -static void turnMotorsOn(); -static void motorsRunning(); -static void turnMotorsOff(); +static void turnMotorOn(amk_motor_t* motor); +static void motorRunning(amk_motor_t* motor); +static void turnMotorOff(amk_motor_t* motor); /* NOTE: As of now this is just setting everything to 0, but it may make sense * to have it in case something changes down the line while I learn more, so @@ -41,8 +45,8 @@ void motorInit(amk_motor_t* motor) /* States */ .states.stage = MOTOR_STAGE_INIT, .states.init_state = MOTOR_INIT_POWER_ON, - /* FIXME: FILL IN ONCE I MAKE ENUMS */ - .states.deinit_state = 0, + .states.deinit_state = MOTOR_DEINIT_SETPOINTS_DEINIT, + /* FIXME: FILL IN ONCE I MAKE ENUM */ .states.running_state = 0, /* Values */ @@ -52,22 +56,25 @@ void motorInit(amk_motor_t* motor) }; } +/* FIXME: Maybe have a seperate instance of this function for each motor, or + * handle all motors in a single instance + * */ void motorPeriodic() { - switch(motor.states.stage) { + switch(right.states.stage) { case MOTOR_STAGE_INIT: - turnMotorsOn(); + turnMotorOn(&right); break; case MOTOR_STAGE_RUNNING: - motorsRunning(); + motorRunning(&right); break; case MOTOR_STAGE_DEINIT: - turnMotorsOff(); + turnMotorOff(&right); break; } } -static void motorsRunning() +static void motorRunning(amk_motor_t* motor) { /* Set setpoint settings (AMK_TargetVelocity, AMK_TorqueLimitNegativ, AMK_TorqueLimitPositiv) */ SEND_AMK_SETPOINTS_1(control.bits, @@ -207,38 +214,38 @@ static void turnMotorOff(amk_motor_t* motor) motor->values.torque_limit_positive, motor->values.torque_limit_negative); - motor->states.init_state++; + motor->states.deinit_state++; break; case MOTOR_DEINIT_INVERTER_OFF_CHECK: /* 2r. AMK_bInverterOn is mirrored in AMK_Status, so should be on there */ - motor->states.init_state++; + motor->states.deinit_state++; break; case MOTOR_DEINIT_DISABLE: /* 3. Set AMK_bEnable = 0 */ - motor->states.init_state++; + motor->states.deinit_state++; break; case MOTOR_DEINIT_QUIT_INVERTER_CHECK: /* 4. Check AMK_bQuitInverterOn = 0 */ - motor->states.init_state++; + motor->states.deinit_state++; break; case MOTOR_DEINIT_DC_OFF: /* 5. Set AMK_bDcOn = 0 */ - motor->states.init_state++; + motor->states.deinit_state++; break; case MOTOR_DEINIT_DC_OFF_CHECK: /* 5r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ /* 5r. Check AMK_bQuitDcOn = 0 */ - motor->states.init_state++; + motor->states.deinit_state++; break; case MOTOR_DEINIT_PRECHARGE: /* 6. Discharge DC caps; QUE should be reset (is this just DcOn?) */ /* If discharged, move on */ - motor->states.init_state++; + motor->states.deinit_state++; break; case MOTOR_DEINIT_POWER_OFF: /* 7. Turn off 24v DC to inverters */ - motor->states.init_state++; + motor->states.deinit_state++; break; } } diff --git a/common/amk/amk.h b/common/amk/amk.h index c9c85ac0..1a18bc38 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -56,6 +56,7 @@ typedef enum { } amk_motor_deinit_state_t; typedef enum { + MOTOR_STAGE_OFF, MOTOR_STAGE_INIT, MOTOR_STAGE_RUNNING, MOTOR_STAGE_DEINIT @@ -99,4 +100,8 @@ typedef union #define DEFAULT_POSITIVE_TORQUE_LIMIT 0 #define DEFAULT_NEGATIVE_TORQUE_LIMIT 0 +#define MAX_TARGET_VELOCITY 6000 +#define MAX_POSITIVE_TORQUE_LIMIT 1000 +#define MAX_NEGATIVE_TORQUE_LIMIT 1000 + #endif /* _AMK_H_ */ From 7b33e271eea3d4a72b326b2b3ec5f1266a56ce12 Mon Sep 17 00:00:00 2001 From: Cole Date: Sat, 19 Oct 2024 18:15:58 -0400 Subject: [PATCH 13/17] Added logic in switch statements. Also we need to move to torque control, which will require free CAN config --- common/amk/amk.c | 82 ++++++++++++++++++++++++++++++------------------ common/amk/amk.h | 8 +++-- 2 files changed, 56 insertions(+), 34 deletions(-) diff --git a/common/amk/amk.c b/common/amk/amk.c index b9b9f1ea..d8b522ac 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -1,4 +1,5 @@ #include "amk.h" +#include "source/main_module/car/car.h" #include "source/main_module/can/can_parse.h" @@ -50,7 +51,7 @@ void motorInit(amk_motor_t* motor) .states.running_state = 0, /* Values */ - .values.target_velocity = DEFAULT_TARGET_VELOCITY, + .values.torque_setpoint = DEFAULT_TORQUE_SETPOINT, .values.torque_limit_positive = DEFAULT_POSITIVE_TORQUE_LIMIT, .values.torque_limit_negative = DEFAULT_NEGATIVE_TORQUE_LIMIT }; @@ -76,11 +77,6 @@ void motorPeriodic() static void motorRunning(amk_motor_t* motor) { - /* Set setpoint settings (AMK_TargetVelocity, AMK_TorqueLimitNegativ, AMK_TorqueLimitPositiv) */ - SEND_AMK_SETPOINTS_1(control.bits, - 1, - 1, - 1); } static void turnMotorOn(amk_motor_t* motor) @@ -99,9 +95,13 @@ static void turnMotorOn(amk_motor_t* motor) case MOTOR_INIT_POWER_ON: /* 1. Turn on 24V DC to inverters */ /* 1r. Check AMK_bSystemReady = 1*/ + if (can_data.AMK_Actual_Values_1.stale) + break; - /* if AMK_bSystemReady = 1 */ - motor->states.init_state++; + status.bits = can_data.AMK_Actual_Values_1.AMK_Status; + + if (status.fields.AMK_bSystemReady) + motor->states.init_state = MOTOR_INIT_PRECHARGE; break; case MOTOR_INIT_PRECHARGE: @@ -111,20 +111,28 @@ static void turnMotorOn(amk_motor_t* motor) * I move onto the next state. */ /* if precharge complete pin is high */ - motor->states.init_state++; + /* NOTE: This is found for us in car.c. Can check the pin ourselves + * if we should not be touching this struct outside of car.c */ + if (car.pchg.pchg_complete) + motor->states.init_state = MOTOR_INIT_DC_ON; break; case MOTOR_INIT_DC_ON: /* 3. Set AMK_bDcOn = 1 */ control.fields.AMK_bDcOn = true; + SEND_AMK_SETPOINTS_1(control.bits, - motor->values.target_velocity, + motor->values.torque_setpoint, motor->values.torque_limit_positive, motor->values.torque_limit_negative); - motor->states.init_state++; + motor->states.init_state = MOTOR_INIT_DC_ON_CHECK; + break; case MOTOR_INIT_DC_ON_CHECK: /* 3r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ + if (can_data.AMK_Actual_Values_1.stale) + break; + status.bits = can_data.AMK_Actual_Values_1.AMK_Status; /* When will AMK_bQuitDcOn go on? Does it take some time after @@ -132,7 +140,9 @@ static void turnMotorOn(amk_motor_t* motor) /* 3r. (QUE & AMK_bDcOn) -> Check AMK_bQuitDcOn = 1 */ /* Does where do I check QUE??? */ - motor->states.init_state++; + if (status.fields.AMK_bQuitDcOn) + motor->states.init_state = MOTOR_INIT_TORQUE_INIT; + break; case MOTOR_INIT_TORQUE_INIT: /* 4. Set AMK_TorqueLimitNegativ = 0 and AMK_TorqueLimitPositiv = 0 */ @@ -140,42 +150,49 @@ static void turnMotorOn(amk_motor_t* motor) motor->values.torque_limit_negative = 0; SEND_AMK_SETPOINTS_1(control.bits, - motor->values.target_velocity, + motor->values.torque_setpoint, motor->values.torque_limit_positive, motor->values.torque_limit_negative); - motor->states.init_state++; + motor->states.init_state = MOTOR_INIT_ENABLE; + break; case MOTOR_INIT_ENABLE: /* 7. Set AMK_bEnable = 1 */ control.fields.AMK_bEnable = true; SEND_AMK_SETPOINTS_1(control.bits, - motor->values.target_velocity, + motor->values.torque_setpoint, motor->values.torque_limit_positive, motor->values.torque_limit_negative); - motor->states.init_state++; + motor->states.init_state = MOTOR_INIT_INVERTER_ON; break; case MOTOR_INIT_INVERTER_ON: /* 8 Set AMK_bInverterOn = 1 */ control.fields.AMK_bInverterOn = true; SEND_AMK_SETPOINTS_1(control.bits, - motor->values.target_velocity, + motor->values.torque_setpoint, motor->values.torque_limit_positive, motor->values.torque_limit_negative); - motor->states.init_state++; + motor->states.init_state = MOTOR_INIT_INVERTER_ON_CHECK; break; case MOTOR_INIT_INVERTER_ON_CHECK: /* 8r. AMK_bInverterOn is mirrored in AMK_Status, so should be on there */ + if (can_data.AMK_Actual_Values_1.stale) + break; + + status.bits = can_data.AMK_Actual_Values_1.AMK_Status; /* Same with AMK_bQuitDcOn, do we need seperate states for these quits?? */ /* 9. Check AMK_bQuitInverterOn = 1 */ /* This should be the last init state, so now we move onto the stage for * running the motors */ - - motor->states.stage++; + if (status.fields.AMK_bQuitInverterOn) { + motor->states.init_state = MOTOR_INIT_DONE; + motor->states.stage = MOTOR_STAGE_RUNNING; + } break; } } @@ -199,10 +216,11 @@ static void turnMotorOff(amk_motor_t* motor) motor->values.torque_limit_negative = 0; SEND_AMK_SETPOINTS_1(control.bits, - motor->values.target_velocity, + motor->values.torque_setpoint, motor->values.torque_limit_positive, motor->values.torque_limit_negative); - motor->states.deinit_state++; + motor->states.deinit_state = MOTOR_DEINIT_INVERTER_OFF; + break; case MOTOR_DEINIT_INVERTER_OFF: @@ -210,42 +228,44 @@ static void turnMotorOff(amk_motor_t* motor) control.fields.AMK_bInverterOn = true; SEND_AMK_SETPOINTS_1(control.bits, - motor->values.target_velocity, + motor->values.torque_setpoint, motor->values.torque_limit_positive, motor->values.torque_limit_negative); - motor->states.deinit_state++; + motor->states.deinit_state = MOTOR_DEINIT_INVERTER_OFF_CHECK; + break; case MOTOR_DEINIT_INVERTER_OFF_CHECK: /* 2r. AMK_bInverterOn is mirrored in AMK_Status, so should be on there */ - motor->states.deinit_state++; + motor->states.deinit_state = MOTOR_DEINIT_DISABLE; break; case MOTOR_DEINIT_DISABLE: /* 3. Set AMK_bEnable = 0 */ - motor->states.deinit_state++; + motor->states.deinit_state = MOTOR_DEINIT_QUIT_INVERTER_CHECK; break; case MOTOR_DEINIT_QUIT_INVERTER_CHECK: /* 4. Check AMK_bQuitInverterOn = 0 */ - motor->states.deinit_state++; + motor->states.deinit_state = MOTOR_DEINIT_DC_OFF; break; case MOTOR_DEINIT_DC_OFF: /* 5. Set AMK_bDcOn = 0 */ - motor->states.deinit_state++; + motor->states.deinit_state = MOTOR_DEINIT_DC_OFF_CHECK; break; case MOTOR_DEINIT_DC_OFF_CHECK: /* 5r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ /* 5r. Check AMK_bQuitDcOn = 0 */ - motor->states.deinit_state++; + motor->states.deinit_state = MOTOR_DEINIT_PRECHARGE; break; case MOTOR_DEINIT_PRECHARGE: /* 6. Discharge DC caps; QUE should be reset (is this just DcOn?) */ /* If discharged, move on */ - motor->states.deinit_state++; + motor->states.deinit_state = MOTOR_DEINIT_POWER_OFF; break; case MOTOR_DEINIT_POWER_OFF: /* 7. Turn off 24v DC to inverters */ - motor->states.deinit_state++; + motor->states.deinit_state = MOTOR_DEINIT_DONE; + motor->states.stage = MOTOR_STAGE_OFF; break; } } diff --git a/common/amk/amk.h b/common/amk/amk.h index 1a18bc38..6b151a46 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -22,7 +22,7 @@ typedef struct { } amk_motor_states_t; typedef struct { - uint16_t target_velocity; + uint16_t torque_setpoint; uint16_t torque_limit_positive; uint16_t torque_limit_negative; } amk_motor_values_t; @@ -41,6 +41,7 @@ typedef enum { MOTOR_INIT_ENABLE, MOTOR_INIT_INVERTER_ON, MOTOR_INIT_INVERTER_ON_CHECK, + MOTOR_INIT_DONE, } amk_motor_init_state_t; typedef enum { @@ -53,6 +54,7 @@ typedef enum { MOTOR_DEINIT_DC_OFF_CHECK, MOTOR_DEINIT_PRECHARGE, MOTOR_DEINIT_POWER_OFF, + MOTOR_DEINIT_DONE, } amk_motor_deinit_state_t; typedef enum { @@ -96,11 +98,11 @@ typedef union uint16_t bits; } AMK_Control_t; -#define DEFAULT_TARGET_VELOCITY 0 +#define DEFAULT_TORQUE_SETPOINT 0 #define DEFAULT_POSITIVE_TORQUE_LIMIT 0 #define DEFAULT_NEGATIVE_TORQUE_LIMIT 0 -#define MAX_TARGET_VELOCITY 6000 +#define MAX_TORQUE_SETPOINT 6000 #define MAX_POSITIVE_TORQUE_LIMIT 1000 #define MAX_NEGATIVE_TORQUE_LIMIT 1000 From 4c416f0e8102fdc4847bfee2b477cee4fbb4d44a Mon Sep 17 00:00:00 2001 From: Cole Date: Fri, 25 Oct 2024 20:39:24 -0400 Subject: [PATCH 14/17] Starting to add messages from my notes into the can config --- common/amk/amk.h | 82 +++++++++++++++--------------- common/daq/can_config.json | 57 +++++++++++++-------- common/daq/per_dbc.dbc | 37 +++++++------- source/f4_testing/can/can_parse.c | 20 ++++---- source/f4_testing/can/can_parse.h | 51 +++++++++++-------- source/main_module/can/can_parse.c | 34 ++++++++----- source/main_module/can/can_parse.h | 51 +++++++++++-------- 7 files changed, 189 insertions(+), 143 deletions(-) diff --git a/common/amk/amk.h b/common/amk/amk.h index 6b151a46..c8735f68 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -14,6 +14,40 @@ #include #include +/* Inverter -> CAN */ +/* In AMK_Actual_Values_1 */ +typedef union +{ + struct { + uint16_t AMK_bReserve : 8; + uint16_t AMK_bSystemReady : 1; + uint16_t AMK_bError : 1; + uint16_t AMK_bWarn : 1; + uint16_t AMK_bQuitDcOn : 1; + uint16_t AMK_bDcOn : 1; /* Same as QUE ?? */ + uint16_t AMK_bQuitInverterOn : 1; + uint16_t AMK_bInverterOn : 1; + uint16_t AMK_bDerating : 1; + } fields; + uint16_t bits; +} AMK_Status_t; + +/* CAN -> Inverter */ +/* In AMK_Setpoints */ +/* THIS NEEDS TO BE SENT EVERY 50ms */ +typedef union +{ + struct { + uint16_t AMK_bReserve1 : 8; + uint16_t AMK_bInverterOn : 1; + uint16_t AMK_bDcOn : 1; + uint16_t AMK_bEnable : 1; + uint16_t AMK_bErrorReset : 1; + uint16_t AMK_bReserve2 : 1; + } fields; + uint16_t bits; +} AMK_Control_t; + typedef struct { uint8_t stage; uint8_t running_state; @@ -21,15 +55,17 @@ typedef struct { uint8_t deinit_state; } amk_motor_states_t; -typedef struct { - uint16_t torque_setpoint; - uint16_t torque_limit_positive; - uint16_t torque_limit_negative; -} amk_motor_values_t; +// typedef struct { +// uint16_t torque_setpoint; +// uint16_t torque_limit_positive; +// uint16_t torque_limit_negative; +// } amk_motor_values_t; typedef struct { amk_motor_states_t states; - amk_motor_values_t values; + uint16_t torque_setpoint; + AMK_Status_t status; + AMK_Control_t control; } amk_motor_t; typedef enum { @@ -64,40 +100,6 @@ typedef enum { MOTOR_STAGE_DEINIT } amk_motor_stage_t; -/* Inverter -> CAN */ -/* In AMK_Actual_Values_1 */ -typedef union -{ - struct { - uint16_t AMK_bReserve : 8; - uint16_t AMK_bSystemReady : 1; - uint16_t AMK_bError : 1; - uint16_t AMK_bWarn : 1; - uint16_t AMK_bQuitDcOn : 1; - uint16_t AMK_bDcOn : 1; /* Same as QUE ?? */ - uint16_t AMK_bQuitInverterOn : 1; - uint16_t AMK_bInverterOn : 1; - uint16_t AMK_bDerating : 1; - } fields; - uint16_t bits; -} AMK_Status_t; - -/* CAN -> Inverter */ -/* In AMK_Setpoints */ -/* THIS NEEDS TO BE SENT EVERY 50ms */ -typedef union -{ - struct { - uint16_t AMK_bReserve1 : 8; - uint16_t AMK_bInverterOn : 1; - uint16_t AMK_bDcOn : 1; - uint16_t AMK_bEnable : 1; - uint16_t AMK_bErrorReset : 1; - uint16_t AMK_bReserve2 : 1; - } fields; - uint16_t bits; -} AMK_Control_t; - #define DEFAULT_TORQUE_SETPOINT 0 #define DEFAULT_POSITIVE_TORQUE_LIMIT 0 #define DEFAULT_NEGATIVE_TORQUE_LIMIT 0 diff --git a/common/daq/can_config.json b/common/daq/can_config.json index f6a90c22..69db4a47 100644 --- a/common/daq/can_config.json +++ b/common/daq/can_config.json @@ -197,13 +197,11 @@ "msg_pgn": 14 }, { - "msg_name": "AMK_Setpoints_1", - "msg_desc": "Contains status word and setpoints", + "msg_name": "AMK_Setpoints", + "msg_desc": "Contains control word and setpoints", "signals": [ {"sig_name": "AMK_Control", "sig_desc": "Control word", "type":"uint16_t"}, - {"sig_name": "AMK_TargetVelocity", "sig_desc": "Speed setpoint", "type":"int16_t", "unit": "rpm"}, - {"sig_name": "AMK_TorqueLimitPositiv", "sig_desc": "Positive torque limit", "type":"int16_t", "unit": "Mn", "scale": 0.1}, - {"sig_name": "AMK_TorqueLimitNegativ", "sig_desc": "Negative torque limit", "type":"int16_t", "unit": "Mn", "scale": 0.1} + {"sig_name": "AMK_TorqueSetpoint", "sig_desc": "Torque setpoint", "type":"int16_t", "unit":"Nm", "scale":0.1} ], "msg_period": 5, "msg_id_override": "0x184" @@ -224,9 +222,8 @@ "msg_desc": "Contains the status word and actual values", "signals": [ {"sig_name": "AMK_Status", "sig_desc": "Status word, bit field", "type":"uint16_t"}, - {"sig_name": "AMK_ActualVelocity", "sig_desc": "Actual speed value", "type":"int16_t", "unit":"rpm"}, - {"sig_name": "AMK_TorqueCurrent", "sig_desc": "Raw data for calculating actual torque current", "type":"int16_t"}, - {"sig_name": "AMK_MagnetizingCurrent", "sig_desc": "Raw data for calculating actual magnetizing current", "type":"int16_t"} + {"sig_name": "AMK_ActualTorque", "sig_desc": "Actual torque value", "type":"int16_t", "unit":"Nm", "scale":0.1}, + {"sig_name": "AMK_MotorSerialNumber", "sig_desc": "Serial number of the motor", "type":"uint32_t"} ], "msg_period": 5, "msg_id_override": "0x283" @@ -235,13 +232,23 @@ "msg_name": "AMK_Actual_Values_2", "msg_desc": "Contains actual values", "signals": [ - {"sig_name": "AMK_TempMotor", "sig_desc": "Motor Temperature", "type":"int16_t", "unit": "C", "scale": 0.1}, - {"sig_name": "AMK_TempInverter", "sig_desc": "Cold Plate Temperature", "type":"int16_t", "unit": "C", "scale": 0.1}, - {"sig_name": "AMK_ErrorInfo", "sig_desc": "Diagnostic Number", "type":"uint16_t"}, - {"sig_name": "AMK_TempIGBT", "sig_desc": "IGBT Temperature", "type":"uint16_t", "unit": "C", "scale": 0.1} + {"sig_name": "AMK_ActualSpeed", "sig_desc": "Actual speed value", "type":"int16_t", "unit": "rpm"}, + {"sig_name": "AMK_DCBusVoltage", "sig_desc": "Voltage of the DC bus", "type":"uint16_t", "unit": "V"}, + {"sig_name": "AMK_SystemReset", "sig_desc": "System reset", "type":"uint16_t"} ], "msg_period": 5, "msg_id_override": "0x285" + }, + { + "msg_name": "AMK_Temperatures_1", + "msg_desc": "Contains temperatures", + "signals": [ + {"sig_name": "AMK_MotorTemp", "sig_desc": "Motor temperature", "type":"int16_t", "unit":"C", "scale":0.1}, + {"sig_name": "AMK_InverterTemp", "sig_desc": "Inverter cold plate temperature", "type":"int16_t", "unit":"C", "scale":0.1}, + {"sig_name": "AMK_IGBTTemp", "sig_desc": "IGBT temperature", "type":"int16_t", "unit":"C", "scale":0.1} + ], + "msg_period": 5, + "msg_id_override": "0x286" } ] }, @@ -1053,24 +1060,32 @@ "msg_name": "AMK_Actual_Values_2", "msg_desc": "Contains actual values", "signals": [ - {"sig_name": "AMK_TempMotor", "sig_desc": "Motor Temperature", "type":"int16_t", "unit": "C", "scale": 0.1}, - {"sig_name": "AMK_TempInverter", "sig_desc": "Cold Plate Temperature", "type":"int16_t", "unit": "C", "scale": 0.1}, - {"sig_name": "AMK_ErrorInfo", "sig_desc": "Diagnostic Number", "type":"uint16_t"}, - {"sig_name": "AMK_TempIGBT", "sig_desc": "IGBT Temperature", "type":"uint16_t", "unit": "C", "scale": 0.1} + {"sig_name": "AMK_ActualSpeed", "sig_desc": "Actual speed value", "type":"int16_t", "unit": "rpm"}, + {"sig_name": "AMK_DCBusVoltage", "sig_desc": "Voltage of the DC bus", "type":"uint16_t", "unit": "V"}, + {"sig_name": "AMK_SystemReset", "sig_desc": "System reset", "type":"uint16_t"} ], "msg_period": 5, "msg_id_override": "0x285" + }, + { + "msg_name": "AMK_Temperatures_1", + "msg_desc": "Contains temperatures", + "signals": [ + {"sig_name": "AMK_MotorTemp", "sig_desc": "Motor temperature", "type":"int16_t", "unit":"C", "scale":0.1}, + {"sig_name": "AMK_InverterTemp", "sig_desc": "Inverter cold plate temperature", "type":"int16_t", "unit":"C", "scale":0.1}, + {"sig_name": "AMK_IGBTTemp", "sig_desc": "IGBT temperature", "type":"int16_t", "unit":"C", "scale":0.1} + ], + "msg_period": 5, + "msg_id_override": "0x186" } ], "rx": [ { - "msg_name": "AMK_Setpoints_1", - "msg_desc": "Contains status word and setpoints", + "msg_name": "AMK_Setpoints", + "msg_desc": "Contains control word and setpoints", "signals": [ {"sig_name": "AMK_Control", "sig_desc": "Control word", "type":"uint16_t"}, - {"sig_name": "AMK_TargetVelocity", "sig_desc": "Speed setpoint", "type":"int16_t", "unit": "rpm"}, - {"sig_name": "AMK_TorqueLimitPositiv", "sig_desc": "Positive torque limit", "type":"int16_t", "unit": "Mn", "scale": 0.1}, - {"sig_name": "AMK_TorqueLimitNegativ", "sig_desc": "Negative torque limit", "type":"int16_t", "unit": "Mn", "scale": 0.1} + {"sig_name": "AMK_TorqueSetpoint", "sig_desc": "Torque setpoint", "type":"int16_t", "unit":"Nm", "scale":0.1} ], "msg_period": 5, "msg_id_override": "0x184" diff --git a/common/daq/per_dbc.dbc b/common/daq/per_dbc.dbc index 32996364..90709150 100644 --- a/common/daq/per_dbc.dbc +++ b/common/daq/per_dbc.dbc @@ -119,10 +119,8 @@ BO_ 2214593409 rear_wheel_speeds: 8 Main_Module SG_ right_speed_mc : 16|16@1+ (1,0) [0|0] "RPM" Vector__XXX SG_ left_speed_mc : 0|16@1+ (1,0) [0|0] "RPM" Vector__XXX -BO_ 2147484036 AMK_Setpoints_1: 8 Main_Module - SG_ AMK_TorqueLimitNegativ : 48|16@1- (0.1,0) [0|0] "Mn" Vector__XXX - SG_ AMK_TorqueLimitPositiv : 32|16@1- (0.1,0) [0|0] "Mn" Vector__XXX - SG_ AMK_TargetVelocity : 16|16@1- (1,0) [0|0] "rpm" Vector__XXX +BO_ 2147484036 AMK_Setpoints: 4 Main_Module + SG_ AMK_TorqueSetpoint : 16|16@1- (0.1,0) [0|0] "Nm" Vector__XXX SG_ AMK_Control : 0|16@1+ (1,0) [0|0] "" Vector__XXX BO_ 2148059649 fault_sync_main_module: 3 Main_Module @@ -480,11 +478,15 @@ BO_ 2147484291 AMK_Actual_Values_1: 8 Inverter1 SG_ AMK_ActualVelocity : 16|16@1- (1,0) [0|0] "rpm" Vector__XXX SG_ AMK_Status : 0|16@1+ (1,0) [0|0] "" Vector__XXX -BO_ 2147484293 AMK_Actual_Values_2: 8 Inverter1 - SG_ AMK_TempIGBT : 48|16@1+ (0.1,0) [0|0] "C" Vector__XXX - SG_ AMK_ErrorInfo : 32|16@1+ (1,0) [0|0] "" Vector__XXX - SG_ AMK_TempInverter : 16|16@1- (0.1,0) [0|0] "C" Vector__XXX - SG_ AMK_TempMotor : 0|16@1- (0.1,0) [0|0] "C" Vector__XXX +BO_ 2147484293 AMK_Actual_Values_2: 6 Inverter1 + SG_ AMK_SystemReset : 32|16@1+ (1,0) [0|0] "" Vector__XXX + SG_ AMK_DCBusVoltage : 16|16@1+ (1,0) [0|0] "V" Vector__XXX + SG_ AMK_ActualSpeed : 0|16@1- (1,0) [0|0] "rpm" Vector__XXX + +BO_ 2147484038 AMK_Temperatures_1: 6 Inverter1 + SG_ AMK_IGBTTemp : 32|16@1- (0.1,0) [0|0] "C" Vector__XXX + SG_ AMK_InverterTemp : 16|16@1- (0.1,0) [0|0] "C" Vector__XXX + SG_ AMK_MotorTemp : 0|16@1- (0.1,0) [0|0] "C" Vector__XXX BO_ 2214598974 bitstream_data: 8 BITSTREAM SG_ d7 : 56|8@1+ (1,0) [0|0] "" Vector__XXX @@ -727,10 +729,8 @@ CM_ SG_ 2214593409 right_speed_sensor ""; CM_ SG_ 2214593409 left_speed_sensor ""; CM_ SG_ 2214593409 right_speed_mc ""; CM_ SG_ 2214593409 left_speed_mc ""; -CM_ BO_ 2147484036 "Contains status word and setpoints"; -CM_ SG_ 2147484036 AMK_TorqueLimitNegativ "Negative torque limit"; -CM_ SG_ 2147484036 AMK_TorqueLimitPositiv "Positive torque limit"; -CM_ SG_ 2147484036 AMK_TargetVelocity "Speed setpoint"; +CM_ BO_ 2147484036 "Contains control word and setpoints"; +CM_ SG_ 2147484036 AMK_TorqueSetpoint "Torque setpoint"; CM_ SG_ 2147484036 AMK_Control "Control word"; CM_ BO_ 2148059649 "Fault status message"; CM_ SG_ 2148059649 latched ""; @@ -1022,10 +1022,13 @@ CM_ SG_ 2147484291 AMK_TorqueCurrent "Raw data for calculating actual torque cur CM_ SG_ 2147484291 AMK_ActualVelocity "Actual speed value"; CM_ SG_ 2147484291 AMK_Status "Status word, bit field"; CM_ BO_ 2147484293 "Contains actual values"; -CM_ SG_ 2147484293 AMK_TempIGBT "IGBT Temperature"; -CM_ SG_ 2147484293 AMK_ErrorInfo "Diagnostic Number"; -CM_ SG_ 2147484293 AMK_TempInverter "Cold Plate Temperature"; -CM_ SG_ 2147484293 AMK_TempMotor "Motor Temperature"; +CM_ SG_ 2147484293 AMK_SystemReset "System reset"; +CM_ SG_ 2147484293 AMK_DCBusVoltage "Voltage of the DC bus"; +CM_ SG_ 2147484293 AMK_ActualSpeed "Actual speed value"; +CM_ BO_ 2147484038 "Contains temperatures"; +CM_ SG_ 2147484038 AMK_IGBTTemp "IGBT temperature"; +CM_ SG_ 2147484038 AMK_InverterTemp "Inverter cold plate temperature"; +CM_ SG_ 2147484038 AMK_MotorTemp "Motor temperature"; CM_ BO_ 2214598974 "Bitstream download command"; CM_ SG_ 2214598974 d7 "Bitstream data word 7"; CM_ SG_ 2214598974 d6 "Bitstream data word 6"; diff --git a/source/f4_testing/can/can_parse.c b/source/f4_testing/can/can_parse.c index a6c20b9f..1fba99c4 100644 --- a/source/f4_testing/can/can_parse.c +++ b/source/f4_testing/can/can_parse.c @@ -34,13 +34,11 @@ void canRxUpdate(void) /* BEGIN AUTO CASES */ switch(msg_header.ExtId) { - case ID_AMK_SETPOINTS_1: - can_data.AMK_Setpoints_1.AMK_Control = msg_data_a->AMK_Setpoints_1.AMK_Control; - can_data.AMK_Setpoints_1.AMK_TargetVelocity = (int16_t) msg_data_a->AMK_Setpoints_1.AMK_TargetVelocity; - can_data.AMK_Setpoints_1.AMK_TorqueLimitPositiv = (int16_t) msg_data_a->AMK_Setpoints_1.AMK_TorqueLimitPositiv; - can_data.AMK_Setpoints_1.AMK_TorqueLimitNegativ = (int16_t) msg_data_a->AMK_Setpoints_1.AMK_TorqueLimitNegativ; - can_data.AMK_Setpoints_1.stale = 0; - can_data.AMK_Setpoints_1.last_rx = sched.os_ticks; + case ID_AMK_SETPOINTS: + can_data.AMK_Setpoints.AMK_Control = msg_data_a->AMK_Setpoints.AMK_Control; + can_data.AMK_Setpoints.AMK_TorqueSetpoint = (int16_t) msg_data_a->AMK_Setpoints.AMK_TorqueSetpoint; + can_data.AMK_Setpoints.stale = 0; + can_data.AMK_Setpoints.last_rx = sched.os_ticks; break; default: __asm__("nop"); @@ -49,9 +47,9 @@ void canRxUpdate(void) } /* BEGIN AUTO STALE CHECKS */ - CHECK_STALE(can_data.AMK_Setpoints_1.stale, - sched.os_ticks, can_data.AMK_Setpoints_1.last_rx, - UP_AMK_SETPOINTS_1); + CHECK_STALE(can_data.AMK_Setpoints.stale, + sched.os_ticks, can_data.AMK_Setpoints.last_rx, + UP_AMK_SETPOINTS); /* END AUTO STALE CHECKS */ } @@ -70,7 +68,7 @@ bool initCANFilter() /* BEGIN AUTO FILTER */ CAN1->FA1R |= (1 << 0); // configure bank 0 - CAN1->sFilterRegister[0].FR1 = (ID_AMK_SETPOINTS_1 << 3) | 4; + CAN1->sFilterRegister[0].FR1 = (ID_AMK_SETPOINTS << 3) | 4; /* END AUTO FILTER */ CAN1->FMR &= ~CAN_FMR_FINIT; // Enable Filters (exit filter init mode) diff --git a/source/f4_testing/can/can_parse.h b/source/f4_testing/can/can_parse.h index fc0ffcc1..8dd85914 100644 --- a/source/f4_testing/can/can_parse.h +++ b/source/f4_testing/can/can_parse.h @@ -32,14 +32,16 @@ typedef union { /* BEGIN AUTO ID DEFS */ #define ID_AMK_ACTUAL_VALUES_1 0x283 #define ID_AMK_ACTUAL_VALUES_2 0x285 -#define ID_AMK_SETPOINTS_1 0x184 +#define ID_AMK_TEMPERATURES_1 0x186 +#define ID_AMK_SETPOINTS 0x184 /* END AUTO ID DEFS */ // Message DLC definitions /* BEGIN AUTO DLC DEFS */ #define DLC_AMK_ACTUAL_VALUES_1 8 -#define DLC_AMK_ACTUAL_VALUES_2 8 -#define DLC_AMK_SETPOINTS_1 8 +#define DLC_AMK_ACTUAL_VALUES_2 6 +#define DLC_AMK_TEMPERATURES_1 6 +#define DLC_AMK_SETPOINTS 4 /* END AUTO DLC DEFS */ // Message sending macros @@ -53,13 +55,20 @@ typedef union { data_a->AMK_Actual_Values_1.AMK_MagnetizingCurrent = AMK_MagnetizingCurrent_;\ canTxSendToBack(&msg);\ } while(0) -#define SEND_AMK_ACTUAL_VALUES_2(AMK_TempMotor_, AMK_TempInverter_, AMK_ErrorInfo_, AMK_TempIGBT_) do {\ +#define SEND_AMK_ACTUAL_VALUES_2(AMK_ActualSpeed_, AMK_DCBusVoltage_, AMK_SystemReset_) do {\ CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_AMK_ACTUAL_VALUES_2, .DLC=DLC_AMK_ACTUAL_VALUES_2, .IDE=1};\ CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ - data_a->AMK_Actual_Values_2.AMK_TempMotor = AMK_TempMotor_;\ - data_a->AMK_Actual_Values_2.AMK_TempInverter = AMK_TempInverter_;\ - data_a->AMK_Actual_Values_2.AMK_ErrorInfo = AMK_ErrorInfo_;\ - data_a->AMK_Actual_Values_2.AMK_TempIGBT = AMK_TempIGBT_;\ + data_a->AMK_Actual_Values_2.AMK_ActualSpeed = AMK_ActualSpeed_;\ + data_a->AMK_Actual_Values_2.AMK_DCBusVoltage = AMK_DCBusVoltage_;\ + data_a->AMK_Actual_Values_2.AMK_SystemReset = AMK_SystemReset_;\ + canTxSendToBack(&msg);\ + } while(0) +#define SEND_AMK_TEMPERATURES_1(AMK_MotorTemp_, AMK_InverterTemp_, AMK_IGBTTemp_) do {\ + CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_AMK_TEMPERATURES_1, .DLC=DLC_AMK_TEMPERATURES_1, .IDE=1};\ + CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ + data_a->AMK_Temperatures_1.AMK_MotorTemp = AMK_MotorTemp_;\ + data_a->AMK_Temperatures_1.AMK_InverterTemp = AMK_InverterTemp_;\ + data_a->AMK_Temperatures_1.AMK_IGBTTemp = AMK_IGBTTemp_;\ canTxSendToBack(&msg);\ } while(0) /* END AUTO SEND MACROS */ @@ -67,7 +76,7 @@ typedef union { // Stale Checking #define STALE_THRESH 30 / 2 // 5 / 2 would be 250% of period /* BEGIN AUTO UP DEFS (Update Period)*/ -#define UP_AMK_SETPOINTS_1 5 +#define UP_AMK_SETPOINTS 5 /* END AUTO UP DEFS */ #define CHECK_STALE(stale, curr, last, period) if(!stale && \ @@ -86,17 +95,19 @@ typedef union { uint64_t AMK_MagnetizingCurrent: 16; } AMK_Actual_Values_1; struct { - uint64_t AMK_TempMotor: 16; - uint64_t AMK_TempInverter: 16; - uint64_t AMK_ErrorInfo: 16; - uint64_t AMK_TempIGBT: 16; + uint64_t AMK_ActualSpeed: 16; + uint64_t AMK_DCBusVoltage: 16; + uint64_t AMK_SystemReset: 16; } AMK_Actual_Values_2; + struct { + uint64_t AMK_MotorTemp: 16; + uint64_t AMK_InverterTemp: 16; + uint64_t AMK_IGBTTemp: 16; + } AMK_Temperatures_1; struct { uint64_t AMK_Control: 16; - uint64_t AMK_TargetVelocity: 16; - uint64_t AMK_TorqueLimitPositiv: 16; - uint64_t AMK_TorqueLimitNegativ: 16; - } AMK_Setpoints_1; + uint64_t AMK_TorqueSetpoint: 16; + } AMK_Setpoints; uint8_t raw_data[8]; } __attribute__((packed)) CanParsedData_t; /* END AUTO MESSAGE STRUCTURE */ @@ -107,12 +118,10 @@ typedef union { typedef struct { struct { uint16_t AMK_Control; - int16_t AMK_TargetVelocity; - int16_t AMK_TorqueLimitPositiv; - int16_t AMK_TorqueLimitNegativ; + int16_t AMK_TorqueSetpoint; uint8_t stale; uint32_t last_rx; - } AMK_Setpoints_1; + } AMK_Setpoints; } can_data_t; /* END AUTO CAN DATA STRUCTURE */ diff --git a/source/main_module/can/can_parse.c b/source/main_module/can/can_parse.c index 169be79e..714862b2 100644 --- a/source/main_module/can/can_parse.c +++ b/source/main_module/can/can_parse.c @@ -100,13 +100,19 @@ void canRxUpdate(void) can_data.AMK_Actual_Values_1.last_rx = sched.os_ticks; break; case ID_AMK_ACTUAL_VALUES_2: - can_data.AMK_Actual_Values_2.AMK_TempMotor = (int16_t) msg_data_a->AMK_Actual_Values_2.AMK_TempMotor; - can_data.AMK_Actual_Values_2.AMK_TempInverter = (int16_t) msg_data_a->AMK_Actual_Values_2.AMK_TempInverter; - can_data.AMK_Actual_Values_2.AMK_ErrorInfo = msg_data_a->AMK_Actual_Values_2.AMK_ErrorInfo; - can_data.AMK_Actual_Values_2.AMK_TempIGBT = msg_data_a->AMK_Actual_Values_2.AMK_TempIGBT; + can_data.AMK_Actual_Values_2.AMK_ActualSpeed = (int16_t) msg_data_a->AMK_Actual_Values_2.AMK_ActualSpeed; + can_data.AMK_Actual_Values_2.AMK_DCBusVoltage = msg_data_a->AMK_Actual_Values_2.AMK_DCBusVoltage; + can_data.AMK_Actual_Values_2.AMK_SystemReset = msg_data_a->AMK_Actual_Values_2.AMK_SystemReset; can_data.AMK_Actual_Values_2.stale = 0; can_data.AMK_Actual_Values_2.last_rx = sched.os_ticks; break; + case ID_AMK_TEMPERATURES_1: + can_data.AMK_Temperatures_1.AMK_MotorTemp = (int16_t) msg_data_a->AMK_Temperatures_1.AMK_MotorTemp; + can_data.AMK_Temperatures_1.AMK_InverterTemp = (int16_t) msg_data_a->AMK_Temperatures_1.AMK_InverterTemp; + can_data.AMK_Temperatures_1.AMK_IGBTTemp = (int16_t) msg_data_a->AMK_Temperatures_1.AMK_IGBTTemp; + can_data.AMK_Temperatures_1.stale = 0; + can_data.AMK_Temperatures_1.last_rx = sched.os_ticks; + break; case ID_FAULT_SYNC_PDU: can_data.fault_sync_pdu.idx = msg_data_a->fault_sync_pdu.idx; can_data.fault_sync_pdu.latched = msg_data_a->fault_sync_pdu.latched; @@ -179,6 +185,9 @@ void canRxUpdate(void) CHECK_STALE(can_data.AMK_Actual_Values_2.stale, sched.os_ticks, can_data.AMK_Actual_Values_2.last_rx, UP_AMK_ACTUAL_VALUES_2); + CHECK_STALE(can_data.AMK_Temperatures_1.stale, + sched.os_ticks, can_data.AMK_Temperatures_1.last_rx, + UP_AMK_TEMPERATURES_1); /* END AUTO STALE CHECKS */ } @@ -213,18 +222,19 @@ bool initCANFilter() CAN1->sFilterRegister[4].FR2 = (ID_AMK_ACTUAL_VALUES_1 << 3) | 4; CAN1->FA1R |= (1 << 5); // configure bank 5 CAN1->sFilterRegister[5].FR1 = (ID_AMK_ACTUAL_VALUES_2 << 3) | 4; - CAN1->sFilterRegister[5].FR2 = (ID_FAULT_SYNC_PDU << 3) | 4; + CAN1->sFilterRegister[5].FR2 = (ID_AMK_TEMPERATURES_1 << 3) | 4; CAN1->FA1R |= (1 << 6); // configure bank 6 - CAN1->sFilterRegister[6].FR1 = (ID_FAULT_SYNC_DASHBOARD << 3) | 4; - CAN1->sFilterRegister[6].FR2 = (ID_FAULT_SYNC_A_BOX << 3) | 4; + CAN1->sFilterRegister[6].FR1 = (ID_FAULT_SYNC_PDU << 3) | 4; + CAN1->sFilterRegister[6].FR2 = (ID_FAULT_SYNC_DASHBOARD << 3) | 4; CAN1->FA1R |= (1 << 7); // configure bank 7 - CAN1->sFilterRegister[7].FR1 = (ID_FAULT_SYNC_TORQUE_VECTOR << 3) | 4; - CAN1->sFilterRegister[7].FR2 = (ID_FAULT_SYNC_TEST_NODE << 3) | 4; + CAN1->sFilterRegister[7].FR1 = (ID_FAULT_SYNC_A_BOX << 3) | 4; + CAN1->sFilterRegister[7].FR2 = (ID_FAULT_SYNC_TORQUE_VECTOR << 3) | 4; CAN1->FA1R |= (1 << 8); // configure bank 8 - CAN1->sFilterRegister[8].FR1 = (ID_SET_FAULT << 3) | 4; - CAN1->sFilterRegister[8].FR2 = (ID_RETURN_FAULT_CONTROL << 3) | 4; + CAN1->sFilterRegister[8].FR1 = (ID_FAULT_SYNC_TEST_NODE << 3) | 4; + CAN1->sFilterRegister[8].FR2 = (ID_SET_FAULT << 3) | 4; CAN1->FA1R |= (1 << 9); // configure bank 9 - CAN1->sFilterRegister[9].FR1 = (ID_DAQ_COMMAND_MAIN_MODULE << 3) | 4; + CAN1->sFilterRegister[9].FR1 = (ID_RETURN_FAULT_CONTROL << 3) | 4; + CAN1->sFilterRegister[9].FR2 = (ID_DAQ_COMMAND_MAIN_MODULE << 3) | 4; /* END AUTO FILTER */ CAN1->FMR &= ~CAN_FMR_FINIT; // Enable Filters (exit filter init mode) diff --git a/source/main_module/can/can_parse.h b/source/main_module/can/can_parse.h index b1f3b8bf..3084e163 100644 --- a/source/main_module/can/can_parse.h +++ b/source/main_module/can/can_parse.h @@ -44,7 +44,7 @@ typedef union { #define ID_SDC_STATUS 0xc000381 #define ID_REAR_MOTOR_TEMPS 0x10000301 #define ID_REAR_WHEEL_SPEEDS 0x4000381 -#define ID_AMK_SETPOINTS_1 0x184 +#define ID_AMK_SETPOINTS 0x184 #define ID_FAULT_SYNC_MAIN_MODULE 0x8ca01 #define ID_DAQ_RESPONSE_MAIN_MODULE 0x17ffffc1 #define ID_RAW_THROTTLE_BRAKE 0x10000285 @@ -58,6 +58,7 @@ typedef union { #define ID_THROTTLE_VCU_EQUAL 0x4002837 #define ID_AMK_ACTUAL_VALUES_1 0x283 #define ID_AMK_ACTUAL_VALUES_2 0x285 +#define ID_AMK_TEMPERATURES_1 0x186 #define ID_FAULT_SYNC_PDU 0x8cb1f #define ID_FAULT_SYNC_DASHBOARD 0x8cac5 #define ID_FAULT_SYNC_A_BOX 0x8ca44 @@ -84,7 +85,7 @@ typedef union { #define DLC_SDC_STATUS 2 #define DLC_REAR_MOTOR_TEMPS 4 #define DLC_REAR_WHEEL_SPEEDS 8 -#define DLC_AMK_SETPOINTS_1 8 +#define DLC_AMK_SETPOINTS 4 #define DLC_FAULT_SYNC_MAIN_MODULE 3 #define DLC_DAQ_RESPONSE_MAIN_MODULE 8 #define DLC_RAW_THROTTLE_BRAKE 8 @@ -97,7 +98,8 @@ typedef union { #define DLC_THROTTLE_VCU 4 #define DLC_THROTTLE_VCU_EQUAL 4 #define DLC_AMK_ACTUAL_VALUES_1 8 -#define DLC_AMK_ACTUAL_VALUES_2 8 +#define DLC_AMK_ACTUAL_VALUES_2 6 +#define DLC_AMK_TEMPERATURES_1 6 #define DLC_FAULT_SYNC_PDU 3 #define DLC_FAULT_SYNC_DASHBOARD 3 #define DLC_FAULT_SYNC_A_BOX 3 @@ -235,13 +237,11 @@ typedef union { data_a->rear_wheel_speeds.right_speed_sensor = right_speed_sensor_;\ canTxSendToBack(&msg);\ } while(0) -#define SEND_AMK_SETPOINTS_1(AMK_Control_, AMK_TargetVelocity_, AMK_TorqueLimitPositiv_, AMK_TorqueLimitNegativ_) do {\ - CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_AMK_SETPOINTS_1, .DLC=DLC_AMK_SETPOINTS_1, .IDE=1};\ +#define SEND_AMK_SETPOINTS(AMK_Control_, AMK_TorqueSetpoint_) do {\ + CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_AMK_SETPOINTS, .DLC=DLC_AMK_SETPOINTS, .IDE=1};\ CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ - data_a->AMK_Setpoints_1.AMK_Control = AMK_Control_;\ - data_a->AMK_Setpoints_1.AMK_TargetVelocity = AMK_TargetVelocity_;\ - data_a->AMK_Setpoints_1.AMK_TorqueLimitPositiv = AMK_TorqueLimitPositiv_;\ - data_a->AMK_Setpoints_1.AMK_TorqueLimitNegativ = AMK_TorqueLimitNegativ_;\ + data_a->AMK_Setpoints.AMK_Control = AMK_Control_;\ + data_a->AMK_Setpoints.AMK_TorqueSetpoint = AMK_TorqueSetpoint_;\ canTxSendToBack(&msg);\ } while(0) #define SEND_FAULT_SYNC_MAIN_MODULE(idx_, latched_) do {\ @@ -271,6 +271,7 @@ typedef union { #define UP_THROTTLE_VCU_EQUAL 20 #define UP_AMK_ACTUAL_VALUES_1 5 #define UP_AMK_ACTUAL_VALUES_2 5 +#define UP_AMK_TEMPERATURES_1 5 /* END AUTO UP DEFS */ #define CHECK_STALE(stale, curr, last, period) if(!stale && \ @@ -426,10 +427,8 @@ typedef union { } rear_wheel_speeds; struct { uint64_t AMK_Control: 16; - uint64_t AMK_TargetVelocity: 16; - uint64_t AMK_TorqueLimitPositiv: 16; - uint64_t AMK_TorqueLimitNegativ: 16; - } AMK_Setpoints_1; + uint64_t AMK_TorqueSetpoint: 16; + } AMK_Setpoints; struct { uint64_t idx: 16; uint64_t latched: 1; @@ -486,11 +485,15 @@ typedef union { uint64_t AMK_MagnetizingCurrent: 16; } AMK_Actual_Values_1; struct { - uint64_t AMK_TempMotor: 16; - uint64_t AMK_TempInverter: 16; - uint64_t AMK_ErrorInfo: 16; - uint64_t AMK_TempIGBT: 16; + uint64_t AMK_ActualSpeed: 16; + uint64_t AMK_DCBusVoltage: 16; + uint64_t AMK_SystemReset: 16; } AMK_Actual_Values_2; + struct { + uint64_t AMK_MotorTemp: 16; + uint64_t AMK_InverterTemp: 16; + uint64_t AMK_IGBTTemp: 16; + } AMK_Temperatures_1; struct { uint64_t idx: 16; uint64_t latched: 1; @@ -594,13 +597,19 @@ typedef struct { uint32_t last_rx; } AMK_Actual_Values_1; struct { - int16_t AMK_TempMotor; - int16_t AMK_TempInverter; - uint16_t AMK_ErrorInfo; - uint16_t AMK_TempIGBT; + int16_t AMK_ActualSpeed; + uint16_t AMK_DCBusVoltage; + uint16_t AMK_SystemReset; uint8_t stale; uint32_t last_rx; } AMK_Actual_Values_2; + struct { + int16_t AMK_MotorTemp; + int16_t AMK_InverterTemp; + int16_t AMK_IGBTTemp; + uint8_t stale; + uint32_t last_rx; + } AMK_Temperatures_1; struct { uint16_t idx; uint8_t latched; From 8cfcb8cdc0731edd47f821a214568068cbd66d51 Mon Sep 17 00:00:00 2001 From: Cole Date: Mon, 28 Oct 2024 13:31:23 -0400 Subject: [PATCH 15/17] Added all free signals to the config, need to change the init and deinit stuff to match --- common/daq/can_config.json | 41 +++++++++++++++++++++------ common/daq/per_dbc.dbc | 45 +++++++++++++++++++----------- common/phal_F4_F7/can/can.h | 2 +- source/f4_testing/can/can_parse.c | 2 ++ source/f4_testing/can/can_parse.h | 37 +++++++++++++++++------- source/main_module/can/can_parse.c | 33 ++++++++++++++-------- source/main_module/can/can_parse.h | 37 +++++++++++++++++------- 7 files changed, 140 insertions(+), 57 deletions(-) diff --git a/common/daq/can_config.json b/common/daq/can_config.json index 69db4a47..b1618706 100644 --- a/common/daq/can_config.json +++ b/common/daq/can_config.json @@ -201,7 +201,9 @@ "msg_desc": "Contains control word and setpoints", "signals": [ {"sig_name": "AMK_Control", "sig_desc": "Control word", "type":"uint16_t"}, - {"sig_name": "AMK_TorqueSetpoint", "sig_desc": "Torque setpoint", "type":"int16_t", "unit":"Nm", "scale":0.1} + {"sig_name": "AMK_TorqueSetpoint", "sig_desc": "Torque setpoint", "type":"int16_t", "unit":"Nm", "scale":0.1}, + {"sig_name": "AMK_PositiveTorqueLimit", "sig_desc": "Positive Torque Limit", "type":"int16_t", "unit":"Nm", "scale":0.1}, + {"sig_name": "AMK_NegativeTorqueLimit", "sig_desc": "Negative Torque Limit", "type":"int16_t", "unit":"Nm", "scale":0.1} ], "msg_period": 5, "msg_id_override": "0x184" @@ -237,7 +239,7 @@ {"sig_name": "AMK_SystemReset", "sig_desc": "System reset", "type":"uint16_t"} ], "msg_period": 5, - "msg_id_override": "0x285" + "msg_id_override": "0x284" }, { "msg_name": "AMK_Temperatures_1", @@ -248,6 +250,17 @@ {"sig_name": "AMK_IGBTTemp", "sig_desc": "IGBT temperature", "type":"int16_t", "unit":"C", "scale":0.1} ], "msg_period": 5, + "msg_id_override": "0x285" + }, + { + "msg_name": "AMK_Temperatures_2", + "msg_desc": "Contains temperatures", + "signals": [ + {"sig_name": "AMK_InternalTemp", "sig_desc": "Internal temperature", "type":"int16_t", "unit":"C", "scale":0.1}, + {"sig_name": "AMK_ExternalTemp", "sig_desc": "External temperature", "type":"int16_t", "unit":"C", "scale":0.1}, + {"sig_name": "AMK_TempSensorMotor", "sig_desc": "???", "type":"int16_t", "unit":"C", "scale":0.1} + ], + "msg_period": 5, "msg_id_override": "0x286" } ] @@ -1049,9 +1062,8 @@ "msg_desc": "Contains the status word and actual values", "signals": [ {"sig_name": "AMK_Status", "sig_desc": "Status word, bit field", "type":"uint16_t"}, - {"sig_name": "AMK_ActualVelocity", "sig_desc": "Actual speed value", "type":"int16_t", "unit":"rpm"}, - {"sig_name": "AMK_TorqueCurrent", "sig_desc": "Raw data for calculating actual torque current", "type":"int16_t"}, - {"sig_name": "AMK_MagnetizingCurrent", "sig_desc": "Raw data for calculating actual magnetizing current", "type":"int16_t"} + {"sig_name": "AMK_ActualTorque", "sig_desc": "Actual torque value", "type":"int16_t", "unit":"Nm", "scale":0.1}, + {"sig_name": "AMK_MotorSerialNumber", "sig_desc": "Serial number of the motor", "type":"uint32_t"} ], "msg_period": 5, "msg_id_override": "0x283" @@ -1065,7 +1077,7 @@ {"sig_name": "AMK_SystemReset", "sig_desc": "System reset", "type":"uint16_t"} ], "msg_period": 5, - "msg_id_override": "0x285" + "msg_id_override": "0x284" }, { "msg_name": "AMK_Temperatures_1", @@ -1076,7 +1088,18 @@ {"sig_name": "AMK_IGBTTemp", "sig_desc": "IGBT temperature", "type":"int16_t", "unit":"C", "scale":0.1} ], "msg_period": 5, - "msg_id_override": "0x186" + "msg_id_override": "0x285" + }, + { + "msg_name": "AMK_Temperatures_2", + "msg_desc": "Contains temperatures", + "signals": [ + {"sig_name": "AMK_InternalTemp", "sig_desc": "Internal temperature", "type":"int16_t", "unit":"C", "scale":0.1}, + {"sig_name": "AMK_ExternalTemp", "sig_desc": "External temperature", "type":"int16_t", "unit":"C", "scale":0.1}, + {"sig_name": "AMK_TempSensorMotor", "sig_desc": "???", "type":"int16_t", "unit":"C", "scale":0.1} + ], + "msg_period": 5, + "msg_id_override": "0x286" } ], "rx": [ @@ -1085,7 +1108,9 @@ "msg_desc": "Contains control word and setpoints", "signals": [ {"sig_name": "AMK_Control", "sig_desc": "Control word", "type":"uint16_t"}, - {"sig_name": "AMK_TorqueSetpoint", "sig_desc": "Torque setpoint", "type":"int16_t", "unit":"Nm", "scale":0.1} + {"sig_name": "AMK_TorqueSetpoint", "sig_desc": "Torque setpoint", "type":"int16_t", "unit":"Nm", "scale":0.1}, + {"sig_name": "AMK_PositiveTorqueLimit", "sig_desc": "Positive Torque Limit", "type":"int16_t", "unit":"Nm", "scale":0.1}, + {"sig_name": "AMK_NegativeTorqueLimit", "sig_desc": "Negative Torque Limit", "type":"int16_t", "unit":"Nm", "scale":0.1} ], "msg_period": 5, "msg_id_override": "0x184" diff --git a/common/daq/per_dbc.dbc b/common/daq/per_dbc.dbc index 90709150..d2b7e6ff 100644 --- a/common/daq/per_dbc.dbc +++ b/common/daq/per_dbc.dbc @@ -119,7 +119,9 @@ BO_ 2214593409 rear_wheel_speeds: 8 Main_Module SG_ right_speed_mc : 16|16@1+ (1,0) [0|0] "RPM" Vector__XXX SG_ left_speed_mc : 0|16@1+ (1,0) [0|0] "RPM" Vector__XXX -BO_ 2147484036 AMK_Setpoints: 4 Main_Module +BO_ 2147484036 AMK_Setpoints: 8 Main_Module + SG_ AMK_NegativeTorqueLimit : 48|16@1- (0.1,0) [0|0] "Nm" Vector__XXX + SG_ AMK_PositiveTorqueLimit : 32|16@1- (0.1,0) [0|0] "Nm" Vector__XXX SG_ AMK_TorqueSetpoint : 16|16@1- (0.1,0) [0|0] "Nm" Vector__XXX SG_ AMK_Control : 0|16@1+ (1,0) [0|0] "" Vector__XXX @@ -473,21 +475,25 @@ BO_ 2217793084 daq_bl_resp: 5 bootloader SG_ cmd : 0|8@1+ (1,0) [0|0] "" Vector__XXX BO_ 2147484291 AMK_Actual_Values_1: 8 Inverter1 - SG_ AMK_MagnetizingCurrent : 48|16@1- (1,0) [0|0] "" Vector__XXX - SG_ AMK_TorqueCurrent : 32|16@1- (1,0) [0|0] "" Vector__XXX - SG_ AMK_ActualVelocity : 16|16@1- (1,0) [0|0] "rpm" Vector__XXX + SG_ AMK_MotorSerialNumber : 32|32@1+ (1,0) [0|0] "" Vector__XXX + SG_ AMK_ActualTorque : 16|16@1- (0.1,0) [0|0] "Nm" Vector__XXX SG_ AMK_Status : 0|16@1+ (1,0) [0|0] "" Vector__XXX -BO_ 2147484293 AMK_Actual_Values_2: 6 Inverter1 +BO_ 2147484292 AMK_Actual_Values_2: 6 Inverter1 SG_ AMK_SystemReset : 32|16@1+ (1,0) [0|0] "" Vector__XXX SG_ AMK_DCBusVoltage : 16|16@1+ (1,0) [0|0] "V" Vector__XXX SG_ AMK_ActualSpeed : 0|16@1- (1,0) [0|0] "rpm" Vector__XXX -BO_ 2147484038 AMK_Temperatures_1: 6 Inverter1 +BO_ 2147484293 AMK_Temperatures_1: 6 Inverter1 SG_ AMK_IGBTTemp : 32|16@1- (0.1,0) [0|0] "C" Vector__XXX SG_ AMK_InverterTemp : 16|16@1- (0.1,0) [0|0] "C" Vector__XXX SG_ AMK_MotorTemp : 0|16@1- (0.1,0) [0|0] "C" Vector__XXX +BO_ 2147484294 AMK_Temperatures_2: 6 Inverter1 + SG_ AMK_TempSensorMotor : 32|16@1- (0.1,0) [0|0] "C" Vector__XXX + SG_ AMK_ExternalTemp : 16|16@1- (0.1,0) [0|0] "C" Vector__XXX + SG_ AMK_InternalTemp : 0|16@1- (0.1,0) [0|0] "C" Vector__XXX + BO_ 2214598974 bitstream_data: 8 BITSTREAM SG_ d7 : 56|8@1+ (1,0) [0|0] "" Vector__XXX SG_ d6 : 48|8@1+ (1,0) [0|0] "" Vector__XXX @@ -730,6 +736,8 @@ CM_ SG_ 2214593409 left_speed_sensor ""; CM_ SG_ 2214593409 right_speed_mc ""; CM_ SG_ 2214593409 left_speed_mc ""; CM_ BO_ 2147484036 "Contains control word and setpoints"; +CM_ SG_ 2147484036 AMK_NegativeTorqueLimit "Negative Torque Limit"; +CM_ SG_ 2147484036 AMK_PositiveTorqueLimit "Positive Torque Limit"; CM_ SG_ 2147484036 AMK_TorqueSetpoint "Torque setpoint"; CM_ SG_ 2147484036 AMK_Control "Control word"; CM_ BO_ 2148059649 "Fault status message"; @@ -1017,18 +1025,21 @@ CM_ BO_ 2217793084 "DAQ Bootloader response"; CM_ SG_ 2217793084 data ""; CM_ SG_ 2217793084 cmd ""; CM_ BO_ 2147484291 "Contains the status word and actual values"; -CM_ SG_ 2147484291 AMK_MagnetizingCurrent "Raw data for calculating actual magnetizing current"; -CM_ SG_ 2147484291 AMK_TorqueCurrent "Raw data for calculating actual torque current"; -CM_ SG_ 2147484291 AMK_ActualVelocity "Actual speed value"; +CM_ SG_ 2147484291 AMK_MotorSerialNumber "Serial number of the motor"; +CM_ SG_ 2147484291 AMK_ActualTorque "Actual torque value"; CM_ SG_ 2147484291 AMK_Status "Status word, bit field"; -CM_ BO_ 2147484293 "Contains actual values"; -CM_ SG_ 2147484293 AMK_SystemReset "System reset"; -CM_ SG_ 2147484293 AMK_DCBusVoltage "Voltage of the DC bus"; -CM_ SG_ 2147484293 AMK_ActualSpeed "Actual speed value"; -CM_ BO_ 2147484038 "Contains temperatures"; -CM_ SG_ 2147484038 AMK_IGBTTemp "IGBT temperature"; -CM_ SG_ 2147484038 AMK_InverterTemp "Inverter cold plate temperature"; -CM_ SG_ 2147484038 AMK_MotorTemp "Motor temperature"; +CM_ BO_ 2147484292 "Contains actual values"; +CM_ SG_ 2147484292 AMK_SystemReset "System reset"; +CM_ SG_ 2147484292 AMK_DCBusVoltage "Voltage of the DC bus"; +CM_ SG_ 2147484292 AMK_ActualSpeed "Actual speed value"; +CM_ BO_ 2147484293 "Contains temperatures"; +CM_ SG_ 2147484293 AMK_IGBTTemp "IGBT temperature"; +CM_ SG_ 2147484293 AMK_InverterTemp "Inverter cold plate temperature"; +CM_ SG_ 2147484293 AMK_MotorTemp "Motor temperature"; +CM_ BO_ 2147484294 "Contains temperatures"; +CM_ SG_ 2147484294 AMK_TempSensorMotor "???"; +CM_ SG_ 2147484294 AMK_ExternalTemp "External temperature"; +CM_ SG_ 2147484294 AMK_InternalTemp "Internal temperature"; CM_ BO_ 2214598974 "Bitstream download command"; CM_ SG_ 2214598974 d7 "Bitstream data word 7"; CM_ SG_ 2214598974 d6 "Bitstream data word 6"; diff --git a/common/phal_F4_F7/can/can.h b/common/phal_F4_F7/can/can.h index a690da3f..d72f2389 100644 --- a/common/phal_F4_F7/can/can.h +++ b/common/phal_F4_F7/can/can.h @@ -73,4 +73,4 @@ bool PHAL_txCANMessage(CanMsgTypeDef_t* msg, uint8_t mbx); bool PHAL_txMailboxFree(CAN_TypeDef* bus, uint8_t mbx); void PHAL_txCANAbort(CAN_TypeDef* bus, uint8_t mbx); -#endif // _PHAL_CAN_H \ No newline at end of file +#endif // _PHAL_CAN_H diff --git a/source/f4_testing/can/can_parse.c b/source/f4_testing/can/can_parse.c index 1fba99c4..109df992 100644 --- a/source/f4_testing/can/can_parse.c +++ b/source/f4_testing/can/can_parse.c @@ -37,6 +37,8 @@ void canRxUpdate(void) case ID_AMK_SETPOINTS: can_data.AMK_Setpoints.AMK_Control = msg_data_a->AMK_Setpoints.AMK_Control; can_data.AMK_Setpoints.AMK_TorqueSetpoint = (int16_t) msg_data_a->AMK_Setpoints.AMK_TorqueSetpoint; + can_data.AMK_Setpoints.AMK_PositiveTorqueLimit = (int16_t) msg_data_a->AMK_Setpoints.AMK_PositiveTorqueLimit; + can_data.AMK_Setpoints.AMK_NegativeTorqueLimit = (int16_t) msg_data_a->AMK_Setpoints.AMK_NegativeTorqueLimit; can_data.AMK_Setpoints.stale = 0; can_data.AMK_Setpoints.last_rx = sched.os_ticks; break; diff --git a/source/f4_testing/can/can_parse.h b/source/f4_testing/can/can_parse.h index 8dd85914..ecf3787e 100644 --- a/source/f4_testing/can/can_parse.h +++ b/source/f4_testing/can/can_parse.h @@ -31,8 +31,9 @@ typedef union { // Message ID definitions /* BEGIN AUTO ID DEFS */ #define ID_AMK_ACTUAL_VALUES_1 0x283 -#define ID_AMK_ACTUAL_VALUES_2 0x285 -#define ID_AMK_TEMPERATURES_1 0x186 +#define ID_AMK_ACTUAL_VALUES_2 0x284 +#define ID_AMK_TEMPERATURES_1 0x285 +#define ID_AMK_TEMPERATURES_2 0x286 #define ID_AMK_SETPOINTS 0x184 /* END AUTO ID DEFS */ @@ -41,18 +42,18 @@ typedef union { #define DLC_AMK_ACTUAL_VALUES_1 8 #define DLC_AMK_ACTUAL_VALUES_2 6 #define DLC_AMK_TEMPERATURES_1 6 -#define DLC_AMK_SETPOINTS 4 +#define DLC_AMK_TEMPERATURES_2 6 +#define DLC_AMK_SETPOINTS 8 /* END AUTO DLC DEFS */ // Message sending macros /* BEGIN AUTO SEND MACROS */ -#define SEND_AMK_ACTUAL_VALUES_1(AMK_Status_, AMK_ActualVelocity_, AMK_TorqueCurrent_, AMK_MagnetizingCurrent_) do {\ +#define SEND_AMK_ACTUAL_VALUES_1(AMK_Status_, AMK_ActualTorque_, AMK_MotorSerialNumber_) do {\ CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_AMK_ACTUAL_VALUES_1, .DLC=DLC_AMK_ACTUAL_VALUES_1, .IDE=1};\ CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ data_a->AMK_Actual_Values_1.AMK_Status = AMK_Status_;\ - data_a->AMK_Actual_Values_1.AMK_ActualVelocity = AMK_ActualVelocity_;\ - data_a->AMK_Actual_Values_1.AMK_TorqueCurrent = AMK_TorqueCurrent_;\ - data_a->AMK_Actual_Values_1.AMK_MagnetizingCurrent = AMK_MagnetizingCurrent_;\ + data_a->AMK_Actual_Values_1.AMK_ActualTorque = AMK_ActualTorque_;\ + data_a->AMK_Actual_Values_1.AMK_MotorSerialNumber = AMK_MotorSerialNumber_;\ canTxSendToBack(&msg);\ } while(0) #define SEND_AMK_ACTUAL_VALUES_2(AMK_ActualSpeed_, AMK_DCBusVoltage_, AMK_SystemReset_) do {\ @@ -71,6 +72,14 @@ typedef union { data_a->AMK_Temperatures_1.AMK_IGBTTemp = AMK_IGBTTemp_;\ canTxSendToBack(&msg);\ } while(0) +#define SEND_AMK_TEMPERATURES_2(AMK_InternalTemp_, AMK_ExternalTemp_, AMK_TempSensorMotor_) do {\ + CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_AMK_TEMPERATURES_2, .DLC=DLC_AMK_TEMPERATURES_2, .IDE=1};\ + CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ + data_a->AMK_Temperatures_2.AMK_InternalTemp = AMK_InternalTemp_;\ + data_a->AMK_Temperatures_2.AMK_ExternalTemp = AMK_ExternalTemp_;\ + data_a->AMK_Temperatures_2.AMK_TempSensorMotor = AMK_TempSensorMotor_;\ + canTxSendToBack(&msg);\ + } while(0) /* END AUTO SEND MACROS */ // Stale Checking @@ -90,9 +99,8 @@ typedef union { typedef union { struct { uint64_t AMK_Status: 16; - uint64_t AMK_ActualVelocity: 16; - uint64_t AMK_TorqueCurrent: 16; - uint64_t AMK_MagnetizingCurrent: 16; + uint64_t AMK_ActualTorque: 16; + uint64_t AMK_MotorSerialNumber: 32; } AMK_Actual_Values_1; struct { uint64_t AMK_ActualSpeed: 16; @@ -104,9 +112,16 @@ typedef union { uint64_t AMK_InverterTemp: 16; uint64_t AMK_IGBTTemp: 16; } AMK_Temperatures_1; + struct { + uint64_t AMK_InternalTemp: 16; + uint64_t AMK_ExternalTemp: 16; + uint64_t AMK_TempSensorMotor: 16; + } AMK_Temperatures_2; struct { uint64_t AMK_Control: 16; uint64_t AMK_TorqueSetpoint: 16; + uint64_t AMK_PositiveTorqueLimit: 16; + uint64_t AMK_NegativeTorqueLimit: 16; } AMK_Setpoints; uint8_t raw_data[8]; } __attribute__((packed)) CanParsedData_t; @@ -119,6 +134,8 @@ typedef struct { struct { uint16_t AMK_Control; int16_t AMK_TorqueSetpoint; + int16_t AMK_PositiveTorqueLimit; + int16_t AMK_NegativeTorqueLimit; uint8_t stale; uint32_t last_rx; } AMK_Setpoints; diff --git a/source/main_module/can/can_parse.c b/source/main_module/can/can_parse.c index 714862b2..939cce54 100644 --- a/source/main_module/can/can_parse.c +++ b/source/main_module/can/can_parse.c @@ -93,9 +93,8 @@ void canRxUpdate(void) break; case ID_AMK_ACTUAL_VALUES_1: can_data.AMK_Actual_Values_1.AMK_Status = msg_data_a->AMK_Actual_Values_1.AMK_Status; - can_data.AMK_Actual_Values_1.AMK_ActualVelocity = (int16_t) msg_data_a->AMK_Actual_Values_1.AMK_ActualVelocity; - can_data.AMK_Actual_Values_1.AMK_TorqueCurrent = (int16_t) msg_data_a->AMK_Actual_Values_1.AMK_TorqueCurrent; - can_data.AMK_Actual_Values_1.AMK_MagnetizingCurrent = (int16_t) msg_data_a->AMK_Actual_Values_1.AMK_MagnetizingCurrent; + can_data.AMK_Actual_Values_1.AMK_ActualTorque = (int16_t) msg_data_a->AMK_Actual_Values_1.AMK_ActualTorque; + can_data.AMK_Actual_Values_1.AMK_MotorSerialNumber = msg_data_a->AMK_Actual_Values_1.AMK_MotorSerialNumber; can_data.AMK_Actual_Values_1.stale = 0; can_data.AMK_Actual_Values_1.last_rx = sched.os_ticks; break; @@ -113,6 +112,13 @@ void canRxUpdate(void) can_data.AMK_Temperatures_1.stale = 0; can_data.AMK_Temperatures_1.last_rx = sched.os_ticks; break; + case ID_AMK_TEMPERATURES_2: + can_data.AMK_Temperatures_2.AMK_InternalTemp = (int16_t) msg_data_a->AMK_Temperatures_2.AMK_InternalTemp; + can_data.AMK_Temperatures_2.AMK_ExternalTemp = (int16_t) msg_data_a->AMK_Temperatures_2.AMK_ExternalTemp; + can_data.AMK_Temperatures_2.AMK_TempSensorMotor = (int16_t) msg_data_a->AMK_Temperatures_2.AMK_TempSensorMotor; + can_data.AMK_Temperatures_2.stale = 0; + can_data.AMK_Temperatures_2.last_rx = sched.os_ticks; + break; case ID_FAULT_SYNC_PDU: can_data.fault_sync_pdu.idx = msg_data_a->fault_sync_pdu.idx; can_data.fault_sync_pdu.latched = msg_data_a->fault_sync_pdu.latched; @@ -188,6 +194,9 @@ void canRxUpdate(void) CHECK_STALE(can_data.AMK_Temperatures_1.stale, sched.os_ticks, can_data.AMK_Temperatures_1.last_rx, UP_AMK_TEMPERATURES_1); + CHECK_STALE(can_data.AMK_Temperatures_2.stale, + sched.os_ticks, can_data.AMK_Temperatures_2.last_rx, + UP_AMK_TEMPERATURES_2); /* END AUTO STALE CHECKS */ } @@ -224,17 +233,19 @@ bool initCANFilter() CAN1->sFilterRegister[5].FR1 = (ID_AMK_ACTUAL_VALUES_2 << 3) | 4; CAN1->sFilterRegister[5].FR2 = (ID_AMK_TEMPERATURES_1 << 3) | 4; CAN1->FA1R |= (1 << 6); // configure bank 6 - CAN1->sFilterRegister[6].FR1 = (ID_FAULT_SYNC_PDU << 3) | 4; - CAN1->sFilterRegister[6].FR2 = (ID_FAULT_SYNC_DASHBOARD << 3) | 4; + CAN1->sFilterRegister[6].FR1 = (ID_AMK_TEMPERATURES_2 << 3) | 4; + CAN1->sFilterRegister[6].FR2 = (ID_FAULT_SYNC_PDU << 3) | 4; CAN1->FA1R |= (1 << 7); // configure bank 7 - CAN1->sFilterRegister[7].FR1 = (ID_FAULT_SYNC_A_BOX << 3) | 4; - CAN1->sFilterRegister[7].FR2 = (ID_FAULT_SYNC_TORQUE_VECTOR << 3) | 4; + CAN1->sFilterRegister[7].FR1 = (ID_FAULT_SYNC_DASHBOARD << 3) | 4; + CAN1->sFilterRegister[7].FR2 = (ID_FAULT_SYNC_A_BOX << 3) | 4; CAN1->FA1R |= (1 << 8); // configure bank 8 - CAN1->sFilterRegister[8].FR1 = (ID_FAULT_SYNC_TEST_NODE << 3) | 4; - CAN1->sFilterRegister[8].FR2 = (ID_SET_FAULT << 3) | 4; + CAN1->sFilterRegister[8].FR1 = (ID_FAULT_SYNC_TORQUE_VECTOR << 3) | 4; + CAN1->sFilterRegister[8].FR2 = (ID_FAULT_SYNC_TEST_NODE << 3) | 4; CAN1->FA1R |= (1 << 9); // configure bank 9 - CAN1->sFilterRegister[9].FR1 = (ID_RETURN_FAULT_CONTROL << 3) | 4; - CAN1->sFilterRegister[9].FR2 = (ID_DAQ_COMMAND_MAIN_MODULE << 3) | 4; + CAN1->sFilterRegister[9].FR1 = (ID_SET_FAULT << 3) | 4; + CAN1->sFilterRegister[9].FR2 = (ID_RETURN_FAULT_CONTROL << 3) | 4; + CAN1->FA1R |= (1 << 10); // configure bank 10 + CAN1->sFilterRegister[10].FR1 = (ID_DAQ_COMMAND_MAIN_MODULE << 3) | 4; /* END AUTO FILTER */ CAN1->FMR &= ~CAN_FMR_FINIT; // Enable Filters (exit filter init mode) diff --git a/source/main_module/can/can_parse.h b/source/main_module/can/can_parse.h index 3084e163..3517d539 100644 --- a/source/main_module/can/can_parse.h +++ b/source/main_module/can/can_parse.h @@ -57,8 +57,9 @@ typedef union { #define ID_THROTTLE_VCU 0x40025b7 #define ID_THROTTLE_VCU_EQUAL 0x4002837 #define ID_AMK_ACTUAL_VALUES_1 0x283 -#define ID_AMK_ACTUAL_VALUES_2 0x285 -#define ID_AMK_TEMPERATURES_1 0x186 +#define ID_AMK_ACTUAL_VALUES_2 0x284 +#define ID_AMK_TEMPERATURES_1 0x285 +#define ID_AMK_TEMPERATURES_2 0x286 #define ID_FAULT_SYNC_PDU 0x8cb1f #define ID_FAULT_SYNC_DASHBOARD 0x8cac5 #define ID_FAULT_SYNC_A_BOX 0x8ca44 @@ -85,7 +86,7 @@ typedef union { #define DLC_SDC_STATUS 2 #define DLC_REAR_MOTOR_TEMPS 4 #define DLC_REAR_WHEEL_SPEEDS 8 -#define DLC_AMK_SETPOINTS 4 +#define DLC_AMK_SETPOINTS 8 #define DLC_FAULT_SYNC_MAIN_MODULE 3 #define DLC_DAQ_RESPONSE_MAIN_MODULE 8 #define DLC_RAW_THROTTLE_BRAKE 8 @@ -100,6 +101,7 @@ typedef union { #define DLC_AMK_ACTUAL_VALUES_1 8 #define DLC_AMK_ACTUAL_VALUES_2 6 #define DLC_AMK_TEMPERATURES_1 6 +#define DLC_AMK_TEMPERATURES_2 6 #define DLC_FAULT_SYNC_PDU 3 #define DLC_FAULT_SYNC_DASHBOARD 3 #define DLC_FAULT_SYNC_A_BOX 3 @@ -237,11 +239,13 @@ typedef union { data_a->rear_wheel_speeds.right_speed_sensor = right_speed_sensor_;\ canTxSendToBack(&msg);\ } while(0) -#define SEND_AMK_SETPOINTS(AMK_Control_, AMK_TorqueSetpoint_) do {\ +#define SEND_AMK_SETPOINTS(AMK_Control_, AMK_TorqueSetpoint_, AMK_PositiveTorqueLimit_, AMK_NegativeTorqueLimit_) do {\ CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_AMK_SETPOINTS, .DLC=DLC_AMK_SETPOINTS, .IDE=1};\ CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ data_a->AMK_Setpoints.AMK_Control = AMK_Control_;\ data_a->AMK_Setpoints.AMK_TorqueSetpoint = AMK_TorqueSetpoint_;\ + data_a->AMK_Setpoints.AMK_PositiveTorqueLimit = AMK_PositiveTorqueLimit_;\ + data_a->AMK_Setpoints.AMK_NegativeTorqueLimit = AMK_NegativeTorqueLimit_;\ canTxSendToBack(&msg);\ } while(0) #define SEND_FAULT_SYNC_MAIN_MODULE(idx_, latched_) do {\ @@ -272,6 +276,7 @@ typedef union { #define UP_AMK_ACTUAL_VALUES_1 5 #define UP_AMK_ACTUAL_VALUES_2 5 #define UP_AMK_TEMPERATURES_1 5 +#define UP_AMK_TEMPERATURES_2 5 /* END AUTO UP DEFS */ #define CHECK_STALE(stale, curr, last, period) if(!stale && \ @@ -428,6 +433,8 @@ typedef union { struct { uint64_t AMK_Control: 16; uint64_t AMK_TorqueSetpoint: 16; + uint64_t AMK_PositiveTorqueLimit: 16; + uint64_t AMK_NegativeTorqueLimit: 16; } AMK_Setpoints; struct { uint64_t idx: 16; @@ -480,9 +487,8 @@ typedef union { } throttle_vcu_equal; struct { uint64_t AMK_Status: 16; - uint64_t AMK_ActualVelocity: 16; - uint64_t AMK_TorqueCurrent: 16; - uint64_t AMK_MagnetizingCurrent: 16; + uint64_t AMK_ActualTorque: 16; + uint64_t AMK_MotorSerialNumber: 32; } AMK_Actual_Values_1; struct { uint64_t AMK_ActualSpeed: 16; @@ -494,6 +500,11 @@ typedef union { uint64_t AMK_InverterTemp: 16; uint64_t AMK_IGBTTemp: 16; } AMK_Temperatures_1; + struct { + uint64_t AMK_InternalTemp: 16; + uint64_t AMK_ExternalTemp: 16; + uint64_t AMK_TempSensorMotor: 16; + } AMK_Temperatures_2; struct { uint64_t idx: 16; uint64_t latched: 1; @@ -590,9 +601,8 @@ typedef struct { } throttle_vcu_equal; struct { uint16_t AMK_Status; - int16_t AMK_ActualVelocity; - int16_t AMK_TorqueCurrent; - int16_t AMK_MagnetizingCurrent; + int16_t AMK_ActualTorque; + uint32_t AMK_MotorSerialNumber; uint8_t stale; uint32_t last_rx; } AMK_Actual_Values_1; @@ -610,6 +620,13 @@ typedef struct { uint8_t stale; uint32_t last_rx; } AMK_Temperatures_1; + struct { + int16_t AMK_InternalTemp; + int16_t AMK_ExternalTemp; + int16_t AMK_TempSensorMotor; + uint8_t stale; + uint32_t last_rx; + } AMK_Temperatures_2; struct { uint16_t idx; uint8_t latched; From 06097c08991dd0123919810ab5e85a6b667a0bb0 Mon Sep 17 00:00:00 2001 From: Cole Date: Mon, 28 Oct 2024 15:08:04 -0400 Subject: [PATCH 16/17] Just thinking about how to implement the actual torque stuff and turning off the motors --- common/amk/amk.c | 53 +++++++++++++++++++++++++++++------------------- common/amk/amk.h | 12 +++++------ 2 files changed, 38 insertions(+), 27 deletions(-) diff --git a/common/amk/amk.c b/common/amk/amk.c index d8b522ac..a65a9eb8 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -8,7 +8,7 @@ * like car.c. It will have states such as init which will turn motors on, * and a state to turn motors off and a state to actually run stuff. * The massive state machine will run periodically (not sure how often yet, - * has to be < 50ms so that the control word can be send often) + * has to be < 50ms so that the motor->control word can be send often) */ /* NOTE: @@ -27,9 +27,6 @@ static amk_motor_t right = {0}; -static AMK_Control_t control = {0}; -static AMK_Status_t status = {0}; - static void turnMotorOn(amk_motor_t* motor); static void motorRunning(amk_motor_t* motor); static void turnMotorOff(amk_motor_t* motor); @@ -38,7 +35,7 @@ static void turnMotorOff(amk_motor_t* motor); * to have it in case something changes down the line while I learn more, so * this may end up being deleted if everything just inits to 0 */ -/* FIXME: Move control word and status words into motor struct */ +/* FIXME: Move motor->control word and status words into motor struct */ void motorInit(amk_motor_t* motor) { @@ -75,8 +72,21 @@ void motorPeriodic() } } +/* So car.c has READY2DRIVE state. This calculates all of the torque values. + * The car state machine can write to the motor structs and then this can + * send them to the motors. Or we can move that login into here, not sure. + * But we will need some way to figure out when to deinit the motors, maybe + * some thing that will give it time before turning the power to the car off? + * And the driver will have to wait once initing the "turning off" sequece + * before actually turning off the car. + */ static void motorRunning(amk_motor_t* motor) { + /* Set setpoints as needed */ + SEND_AMK_SETPOINTS(motor->control.bits, + motor->values.torque_setpoint, + motor->values.torque_limit_positive, + motor->values.torque_limit_negative); } static void turnMotorOn(amk_motor_t* motor) @@ -98,9 +108,9 @@ static void turnMotorOn(amk_motor_t* motor) if (can_data.AMK_Actual_Values_1.stale) break; - status.bits = can_data.AMK_Actual_Values_1.AMK_Status; + motor->status.bits = can_data.AMK_Actual_Values_1.AMK_Status; - if (status.fields.AMK_bSystemReady) + if (motor->status.fields.AMK_bSystemReady) motor->states.init_state = MOTOR_INIT_PRECHARGE; break; @@ -119,9 +129,9 @@ static void turnMotorOn(amk_motor_t* motor) break; case MOTOR_INIT_DC_ON: /* 3. Set AMK_bDcOn = 1 */ - control.fields.AMK_bDcOn = true; + motor->control.fields.AMK_bDcOn = true; - SEND_AMK_SETPOINTS_1(control.bits, + SEND_AMK_SETPOINTS(motor->control.bits, motor->values.torque_setpoint, motor->values.torque_limit_positive, motor->values.torque_limit_negative); @@ -133,14 +143,14 @@ static void turnMotorOn(amk_motor_t* motor) if (can_data.AMK_Actual_Values_1.stale) break; - status.bits = can_data.AMK_Actual_Values_1.AMK_Status; + motor->status.bits = can_data.AMK_Actual_Values_1.AMK_Status; /* When will AMK_bQuitDcOn go on? Does it take some time after * DcOn is set?? */ /* 3r. (QUE & AMK_bDcOn) -> Check AMK_bQuitDcOn = 1 */ /* Does where do I check QUE??? */ - if (status.fields.AMK_bQuitDcOn) + if (motor->status.fields.AMK_bQuitDcOn) motor->states.init_state = MOTOR_INIT_TORQUE_INIT; break; @@ -149,7 +159,8 @@ static void turnMotorOn(amk_motor_t* motor) motor->values.torque_limit_positive = 0; motor->values.torque_limit_negative = 0; - SEND_AMK_SETPOINTS_1(control.bits, + /* Says I also need to set act speed to 0? */ + SEND_AMK_SETPOINTS(motor->control.bits, motor->values.torque_setpoint, motor->values.torque_limit_positive, motor->values.torque_limit_negative); @@ -159,8 +170,8 @@ static void turnMotorOn(amk_motor_t* motor) break; case MOTOR_INIT_ENABLE: /* 7. Set AMK_bEnable = 1 */ - control.fields.AMK_bEnable = true; - SEND_AMK_SETPOINTS_1(control.bits, + motor->control.fields.AMK_bEnable = true; + SEND_AMK_SETPOINTS(motor->control.bits, motor->values.torque_setpoint, motor->values.torque_limit_positive, motor->values.torque_limit_negative); @@ -169,8 +180,8 @@ static void turnMotorOn(amk_motor_t* motor) break; case MOTOR_INIT_INVERTER_ON: /* 8 Set AMK_bInverterOn = 1 */ - control.fields.AMK_bInverterOn = true; - SEND_AMK_SETPOINTS_1(control.bits, + motor->control.fields.AMK_bInverterOn = true; + SEND_AMK_SETPOINTS(motor->control.bits, motor->values.torque_setpoint, motor->values.torque_limit_positive, motor->values.torque_limit_negative); @@ -182,14 +193,14 @@ static void turnMotorOn(amk_motor_t* motor) if (can_data.AMK_Actual_Values_1.stale) break; - status.bits = can_data.AMK_Actual_Values_1.AMK_Status; + motor->status.bits = can_data.AMK_Actual_Values_1.AMK_Status; /* Same with AMK_bQuitDcOn, do we need seperate states for these quits?? */ /* 9. Check AMK_bQuitInverterOn = 1 */ /* This should be the last init state, so now we move onto the stage for * running the motors */ - if (status.fields.AMK_bQuitInverterOn) { + if (motor->status.fields.AMK_bQuitInverterOn) { motor->states.init_state = MOTOR_INIT_DONE; motor->states.stage = MOTOR_STAGE_RUNNING; } @@ -215,7 +226,7 @@ static void turnMotorOff(amk_motor_t* motor) motor->values.torque_limit_positive = 0; motor->values.torque_limit_negative = 0; - SEND_AMK_SETPOINTS_1(control.bits, + SEND_AMK_SETPOINTS(motor->control.bits, motor->values.torque_setpoint, motor->values.torque_limit_positive, motor->values.torque_limit_negative); @@ -225,9 +236,9 @@ static void turnMotorOff(amk_motor_t* motor) case MOTOR_DEINIT_INVERTER_OFF: /* 2. Set AMK_bInverterOn = 0 */ - control.fields.AMK_bInverterOn = true; + motor->control.fields.AMK_bInverterOn = true; - SEND_AMK_SETPOINTS_1(control.bits, + SEND_AMK_SETPOINTS(motor->control.bits, motor->values.torque_setpoint, motor->values.torque_limit_positive, motor->values.torque_limit_negative); diff --git a/common/amk/amk.h b/common/amk/amk.h index c8735f68..745c7e7d 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -55,15 +55,15 @@ typedef struct { uint8_t deinit_state; } amk_motor_states_t; -// typedef struct { -// uint16_t torque_setpoint; -// uint16_t torque_limit_positive; -// uint16_t torque_limit_negative; -// } amk_motor_values_t; +typedef struct { + uint16_t torque_setpoint; + uint16_t torque_limit_positive; + uint16_t torque_limit_negative; +} amk_motor_values_t; typedef struct { amk_motor_states_t states; - uint16_t torque_setpoint; + amk_motor_values_t values; AMK_Status_t status; AMK_Control_t control; } amk_motor_t; From d92e969297ac770a2a49e1e4efee1592ceb709ec Mon Sep 17 00:00:00 2001 From: Cole Date: Tue, 29 Oct 2024 12:10:55 -0400 Subject: [PATCH 17/17] hoping to get state machine stuff finished soon so I can move into modifying car.c --- common/amk/amk.c | 150 ++++++++++++++++++++++++++++------------------- common/amk/amk.h | 21 +++---- 2 files changed, 101 insertions(+), 70 deletions(-) diff --git a/common/amk/amk.c b/common/amk/amk.c index a65a9eb8..eb227c11 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -42,32 +42,32 @@ void motorInit(amk_motor_t* motor) *motor = (amk_motor_t){ /* States */ .states.stage = MOTOR_STAGE_INIT, - .states.init_state = MOTOR_INIT_POWER_ON, - .states.deinit_state = MOTOR_DEINIT_SETPOINTS_DEINIT, + .states.init_stage = MOTOR_INIT_POWER_ON, + .states.deinit_stage = MOTOR_DEINIT_SETPOINTS_DEINIT, /* FIXME: FILL IN ONCE I MAKE ENUM */ - .states.running_state = 0, + .states.running_stage = 0, /* Values */ - .values.torque_setpoint = DEFAULT_TORQUE_SETPOINT, - .values.torque_limit_positive = DEFAULT_POSITIVE_TORQUE_LIMIT, - .values.torque_limit_negative = DEFAULT_NEGATIVE_TORQUE_LIMIT + .torque_setpoint = DEFAULT_TORQUE_SETPOINT, + .torque_limit_positive = DEFAULT_POSITIVE_TORQUE_LIMIT, + .torque_limit_negative = DEFAULT_NEGATIVE_TORQUE_LIMIT }; } /* FIXME: Maybe have a seperate instance of this function for each motor, or * handle all motors in a single instance * */ -void motorPeriodic() +void motorPeriodic(amk_motor_t* motor) { - switch(right.states.stage) { + switch(motor->states.stage) { case MOTOR_STAGE_INIT: - turnMotorOn(&right); + turnMotorOn(motor); break; case MOTOR_STAGE_RUNNING: - motorRunning(&right); + motorRunning(motor); break; case MOTOR_STAGE_DEINIT: - turnMotorOff(&right); + turnMotorOff(motor); break; } } @@ -84,9 +84,9 @@ static void motorRunning(amk_motor_t* motor) { /* Set setpoints as needed */ SEND_AMK_SETPOINTS(motor->control.bits, - motor->values.torque_setpoint, - motor->values.torque_limit_positive, - motor->values.torque_limit_negative); + motor->torque_setpoint, + motor->torque_limit_positive, + motor->torque_limit_negative); } static void turnMotorOn(amk_motor_t* motor) @@ -101,7 +101,7 @@ static void turnMotorOn(amk_motor_t* motor) * be met before moving onto the next step. */ - switch (motor->states.init_state) { + switch (motor->states.init_stage) { case MOTOR_INIT_POWER_ON: /* 1. Turn on 24V DC to inverters */ /* 1r. Check AMK_bSystemReady = 1*/ @@ -111,7 +111,7 @@ static void turnMotorOn(amk_motor_t* motor) motor->status.bits = can_data.AMK_Actual_Values_1.AMK_Status; if (motor->status.fields.AMK_bSystemReady) - motor->states.init_state = MOTOR_INIT_PRECHARGE; + motor->states.init_stage = MOTOR_INIT_PRECHARGE; break; case MOTOR_INIT_PRECHARGE: @@ -124,7 +124,7 @@ static void turnMotorOn(amk_motor_t* motor) /* NOTE: This is found for us in car.c. Can check the pin ourselves * if we should not be touching this struct outside of car.c */ if (car.pchg.pchg_complete) - motor->states.init_state = MOTOR_INIT_DC_ON; + motor->states.init_stage = MOTOR_INIT_DC_ON; break; case MOTOR_INIT_DC_ON: @@ -132,10 +132,10 @@ static void turnMotorOn(amk_motor_t* motor) motor->control.fields.AMK_bDcOn = true; SEND_AMK_SETPOINTS(motor->control.bits, - motor->values.torque_setpoint, - motor->values.torque_limit_positive, - motor->values.torque_limit_negative); - motor->states.init_state = MOTOR_INIT_DC_ON_CHECK; + motor->torque_setpoint, + motor->torque_limit_positive, + motor->torque_limit_negative); + motor->states.init_stage = MOTOR_INIT_DC_ON_CHECK; break; case MOTOR_INIT_DC_ON_CHECK: @@ -151,42 +151,44 @@ static void turnMotorOn(amk_motor_t* motor) /* Does where do I check QUE??? */ if (motor->status.fields.AMK_bQuitDcOn) - motor->states.init_state = MOTOR_INIT_TORQUE_INIT; + motor->states.init_stage = MOTOR_INIT_TORQUE_INIT; break; case MOTOR_INIT_TORQUE_INIT: /* 4. Set AMK_TorqueLimitNegativ = 0 and AMK_TorqueLimitPositiv = 0 */ - motor->values.torque_limit_positive = 0; - motor->values.torque_limit_negative = 0; + motor->torque_limit_positive = 0; + motor->torque_limit_negative = 0; /* Says I also need to set act speed to 0? */ SEND_AMK_SETPOINTS(motor->control.bits, - motor->values.torque_setpoint, - motor->values.torque_limit_positive, - motor->values.torque_limit_negative); + motor->torque_setpoint, + motor->torque_limit_positive, + motor->torque_limit_negative); - motor->states.init_state = MOTOR_INIT_ENABLE; + motor->states.init_stage = MOTOR_INIT_ENABLE; break; case MOTOR_INIT_ENABLE: /* 7. Set AMK_bEnable = 1 */ motor->control.fields.AMK_bEnable = true; + SEND_AMK_SETPOINTS(motor->control.bits, - motor->values.torque_setpoint, - motor->values.torque_limit_positive, - motor->values.torque_limit_negative); + motor->torque_setpoint, + motor->torque_limit_positive, + motor->torque_limit_negative); + + motor->states.init_stage = MOTOR_INIT_INVERTER_ON; - motor->states.init_state = MOTOR_INIT_INVERTER_ON; break; case MOTOR_INIT_INVERTER_ON: /* 8 Set AMK_bInverterOn = 1 */ motor->control.fields.AMK_bInverterOn = true; SEND_AMK_SETPOINTS(motor->control.bits, - motor->values.torque_setpoint, - motor->values.torque_limit_positive, - motor->values.torque_limit_negative); + motor->torque_setpoint, + motor->torque_limit_positive, + motor->torque_limit_negative); - motor->states.init_state = MOTOR_INIT_INVERTER_ON_CHECK; + motor->states.init_stage = MOTOR_INIT_INVERTER_ON_CHECK; break; case MOTOR_INIT_INVERTER_ON_CHECK: /* 8r. AMK_bInverterOn is mirrored in AMK_Status, so should be on there */ @@ -201,9 +203,10 @@ static void turnMotorOn(amk_motor_t* motor) /* This should be the last init state, so now we move onto the stage for * running the motors */ if (motor->status.fields.AMK_bQuitInverterOn) { - motor->states.init_state = MOTOR_INIT_DONE; + motor->states.init_stage = MOTOR_INIT_DONE; motor->states.stage = MOTOR_STAGE_RUNNING; } + break; } } @@ -220,63 +223,90 @@ static void turnMotorOff(amk_motor_t* motor) * be met before moving onto the next step. */ - switch(motor->states.deinit_state) { + switch(motor->states.deinit_stage) { case MOTOR_DEINIT_SETPOINTS_DEINIT: /* 1. Set setpoint settings to 0 (AMK_TargetVelocity, AMK_TorqueLimitNegativ, AMK_TorqueLimitPositiv) */ - motor->values.torque_limit_positive = 0; - motor->values.torque_limit_negative = 0; + motor->torque_setpoint= 0; + motor->torque_limit_positive = 0; + motor->torque_limit_negative = 0; SEND_AMK_SETPOINTS(motor->control.bits, - motor->values.torque_setpoint, - motor->values.torque_limit_positive, - motor->values.torque_limit_negative); - motor->states.deinit_state = MOTOR_DEINIT_INVERTER_OFF; + motor->torque_setpoint, + motor->torque_limit_positive, + motor->torque_limit_negative); + + motor->states.deinit_stage = MOTOR_DEINIT_INVERTER_OFF; break; case MOTOR_DEINIT_INVERTER_OFF: /* 2. Set AMK_bInverterOn = 0 */ - motor->control.fields.AMK_bInverterOn = true; + motor->control.fields.AMK_bInverterOn = false; SEND_AMK_SETPOINTS(motor->control.bits, - motor->values.torque_setpoint, - motor->values.torque_limit_positive, - motor->values.torque_limit_negative); + motor->torque_setpoint, + motor->torque_limit_positive, + motor->torque_limit_negative); - motor->states.deinit_state = MOTOR_DEINIT_INVERTER_OFF_CHECK; + motor->states.deinit_stage = MOTOR_DEINIT_DISABLE; - break; - case MOTOR_DEINIT_INVERTER_OFF_CHECK: - /* 2r. AMK_bInverterOn is mirrored in AMK_Status, so should be on there */ - motor->states.deinit_state = MOTOR_DEINIT_DISABLE; break; case MOTOR_DEINIT_DISABLE: - /* 3. Set AMK_bEnable = 0 */ - motor->states.deinit_state = MOTOR_DEINIT_QUIT_INVERTER_CHECK; + /* 2. Set AMK_bEnable = 0 */ + + motor->control.fields.AMK_bEnable = false; + + SEND_AMK_SETPOINTS(motor->control.bits, + motor->torque_setpoint, + motor->torque_limit_positive, + motor->torque_limit_negative); + + motor->states.deinit_stage = MOTOR_DEINIT_INVERTER_OFF_CHECK; + + break; + case MOTOR_DEINIT_INVERTER_OFF_CHECK: + /* 3. AMK_bInverterOn is mirrored in AMK_Status, so should be on there */ + + motor->states.deinit_stage = MOTOR_DEINIT_DISABLE; break; case MOTOR_DEINIT_QUIT_INVERTER_CHECK: /* 4. Check AMK_bQuitInverterOn = 0 */ - motor->states.deinit_state = MOTOR_DEINIT_DC_OFF; + + if (can_data.AMK_Actual_Values_1.stale) + break; + + motor->status.bits = can_data.AMK_Actual_Values_1.AMK_Status; + + if (!(motor->status.fields.AMK_bQuitInverterOn)) { + motor->states.deinit_stage = MOTOR_DEINIT_DISABLE; + } + + motor->states.deinit_stage = MOTOR_DEINIT_DC_OFF; + break; case MOTOR_DEINIT_DC_OFF: /* 5. Set AMK_bDcOn = 0 */ - motor->states.deinit_state = MOTOR_DEINIT_DC_OFF_CHECK; + motor->states.deinit_stage = MOTOR_DEINIT_DC_OFF_CHECK; + break; case MOTOR_DEINIT_DC_OFF_CHECK: /* 5r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ /* 5r. Check AMK_bQuitDcOn = 0 */ - motor->states.deinit_state = MOTOR_DEINIT_PRECHARGE; + motor->states.deinit_stage = MOTOR_DEINIT_PRECHARGE; + break; case MOTOR_DEINIT_PRECHARGE: /* 6. Discharge DC caps; QUE should be reset (is this just DcOn?) */ /* If discharged, move on */ - motor->states.deinit_state = MOTOR_DEINIT_POWER_OFF; + motor->states.deinit_stage = MOTOR_DEINIT_POWER_OFF; + break; case MOTOR_DEINIT_POWER_OFF: /* 7. Turn off 24v DC to inverters */ - motor->states.deinit_state = MOTOR_DEINIT_DONE; + motor->states.deinit_stage = MOTOR_DEINIT_DONE; motor->states.stage = MOTOR_STAGE_OFF; + break; } } diff --git a/common/amk/amk.h b/common/amk/amk.h index 745c7e7d..3748047c 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -49,23 +49,24 @@ typedef union } AMK_Control_t; typedef struct { + // uint8_t state; uint8_t stage; - uint8_t running_state; - uint8_t init_state; - uint8_t deinit_state; + uint8_t running_stage; + uint8_t init_stage; + uint8_t deinit_stage; } amk_motor_states_t; -typedef struct { - uint16_t torque_setpoint; - uint16_t torque_limit_positive; - uint16_t torque_limit_negative; -} amk_motor_values_t; - typedef struct { amk_motor_states_t states; - amk_motor_values_t values; AMK_Status_t status; AMK_Control_t control; + int16_t torque_setpoint; + int16_t torque_limit_positive; + int16_t torque_limit_negative; + int16_t actual_torque; + int16_t actual_speed; + int16_t motor_temp; + int16_t inverter_temp; } amk_motor_t; typedef enum {