From ee7b4c947a8836b2ce0c794a748772a03e519216 Mon Sep 17 00:00:00 2001 From: Cole Date: Thu, 19 Sep 2024 09:34:15 -0400 Subject: [PATCH 01/36] 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/36] 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/36] 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/36] 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/36] 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/36] 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/36] 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/36] 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/36] 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/36] 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/36] 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/36] 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/36] 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/36] 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/36] 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/36] 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/36] 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 { From a61d8f4ae9e34b8bef0b3531b3ebf60a11f233c0 Mon Sep 17 00:00:00 2001 From: Cole Date: Wed, 30 Oct 2024 12:46:46 -0400 Subject: [PATCH 18/36] State machines are sort of done --- common/amk/amk.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/common/amk/amk.c b/common/amk/amk.c index eb227c11..be315b5b 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -135,6 +135,7 @@ static void turnMotorOn(amk_motor_t* motor) motor->torque_setpoint, motor->torque_limit_positive, motor->torque_limit_negative); + motor->states.init_stage = MOTOR_INIT_DC_ON_CHECK; break; @@ -223,10 +224,16 @@ static void turnMotorOff(amk_motor_t* motor) * be met before moving onto the next step. */ + /* NOTE: For some reason in the deinit state machine, we have to turn the + * inverter off, then disable, and then check for the inverter being off. + * This is different to how it is done in the init state machine but it + * is correct based on the datasheet. + */ + switch(motor->states.deinit_stage) { case MOTOR_DEINIT_SETPOINTS_DEINIT: /* 1. Set setpoint settings to 0 (AMK_TargetVelocity, AMK_TorqueLimitNegativ, AMK_TorqueLimitPositiv) */ - motor->torque_setpoint= 0; + motor->torque_setpoint = 0; motor->torque_limit_positive = 0; motor->torque_limit_negative = 0; @@ -252,7 +259,7 @@ static void turnMotorOff(amk_motor_t* motor) break; case MOTOR_DEINIT_DISABLE: - /* 2. Set AMK_bEnable = 0 */ + /* 3. Set AMK_bEnable = 0 */ motor->control.fields.AMK_bEnable = false; @@ -263,11 +270,6 @@ static void turnMotorOff(amk_motor_t* motor) 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 */ @@ -286,17 +288,42 @@ static void turnMotorOff(amk_motor_t* motor) break; case MOTOR_DEINIT_DC_OFF: /* 5. Set AMK_bDcOn = 0 */ + + motor->control.fields.AMK_bDcOn = false; + + SEND_AMK_SETPOINTS(motor->control.bits, + motor->torque_setpoint, + motor->torque_limit_positive, + motor->torque_limit_negative); + 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 */ + if (can_data.AMK_Actual_Values_1.stale) + break; + + 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 (!(motor->status.fields.AMK_bQuitDcOn)) + motor->states.init_stage = MOTOR_INIT_TORQUE_INIT; + motor->states.deinit_stage = MOTOR_DEINIT_PRECHARGE; break; case MOTOR_DEINIT_PRECHARGE: /* 6. Discharge DC caps; QUE should be reset (is this just DcOn?) */ + + /* FIXME: Will this work? Not sure if this goes low when discharged */ + if (!(car.pchg.pchg_complete)) + motor->states.init_stage = MOTOR_DEINIT_POWER_OFF; /* If discharged, move on */ motor->states.deinit_stage = MOTOR_DEINIT_POWER_OFF; @@ -304,6 +331,7 @@ static void turnMotorOff(amk_motor_t* motor) break; case MOTOR_DEINIT_POWER_OFF: /* 7. Turn off 24v DC to inverters */ + /* We don't do much here, just have to turn off the car I guess */ motor->states.deinit_stage = MOTOR_DEINIT_DONE; motor->states.stage = MOTOR_STAGE_OFF; From cf63093492ae9c6918e45061e6faae1594682d92 Mon Sep 17 00:00:00 2001 From: Cole Date: Wed, 30 Oct 2024 13:11:03 -0400 Subject: [PATCH 19/36] Starting to get data into struct, I should have it nicer but I think its okay for now, still not 100% sure on exactly what temps and stuff we need --- common/amk/amk.c | 23 +++++++++++++++++++++++ common/amk/amk.h | 4 ++++ 2 files changed, 27 insertions(+) diff --git a/common/amk/amk.c b/common/amk/amk.c index be315b5b..f0702d7a 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -30,6 +30,7 @@ static amk_motor_t right = {0}; static void turnMotorOn(amk_motor_t* motor); static void motorRunning(amk_motor_t* motor); static void turnMotorOff(amk_motor_t* motor); +static void motorGetData(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 @@ -59,6 +60,7 @@ void motorInit(amk_motor_t* motor) * */ void motorPeriodic(amk_motor_t* motor) { + motorGetData(motor); switch(motor->states.stage) { case MOTOR_STAGE_INIT: turnMotorOn(motor); @@ -72,6 +74,26 @@ void motorPeriodic(amk_motor_t* motor) } } +static void motorGetData(amk_motor_t* motor) +{ + if (!can_data.AMK_Actual_Values_1.stale) { + motor->status.bits = can_data.AMK_Actual_Values_1.AMK_Status; + motor->actual_torque = can_data.AMK_Actual_Values_1.AMK_ActualTorque; + motor->serial_num = can_data.AMK_Actual_Values_1.AMK_MotorSerialNumber; + } + + if (!can_data.AMK_Actual_Values_2.stale) { + motor->actual_speed = can_data.AMK_Actual_Values_2.AMK_ActualSpeed; + motor->dc_bus_voltage = can_data.AMK_Actual_Values_2.AMK_DCBusVoltage; + motor->system_reset = can_data.AMK_Actual_Values_2.AMK_SystemReset; + } + + if (!can_data.AMK_Temperatures_1.stale) { + motor->motor_temp = can_data.AMK_Temperatures_1.AMK_MotorTemp; + motor->inverter_temp = can_data.AMK_Temperatures_1.AMK_InverterTemp; + } +} + /* 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. @@ -87,6 +109,7 @@ static void motorRunning(amk_motor_t* motor) motor->torque_setpoint, motor->torque_limit_positive, motor->torque_limit_negative); + } static void turnMotorOn(amk_motor_t* motor) diff --git a/common/amk/amk.h b/common/amk/amk.h index 3748047c..4c1542d6 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -13,6 +13,7 @@ #include #include +#include /* Inverter -> CAN */ /* In AMK_Actual_Values_1 */ @@ -65,8 +66,11 @@ typedef struct { int16_t torque_limit_negative; int16_t actual_torque; int16_t actual_speed; + uint32_t serial_num; int16_t motor_temp; int16_t inverter_temp; + uint16_t dc_bus_voltage; + uint16_t system_reset; } amk_motor_t; typedef enum { From 7dc3c04a0b1925eaf61a3165259623a2b17c23b3 Mon Sep 17 00:00:00 2001 From: Cole Date: Wed, 30 Oct 2024 13:48:06 -0400 Subject: [PATCH 20/36] Just some notes and small changes, still figuring some stuff out --- common/amk/amk.c | 21 ++++++++------------- common/amk/amk.h | 8 ++++---- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/common/amk/amk.c b/common/amk/amk.c index f0702d7a..72a5c7c0 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -45,8 +45,7 @@ void motorInit(amk_motor_t* motor) .states.stage = MOTOR_STAGE_INIT, .states.init_stage = MOTOR_INIT_POWER_ON, .states.deinit_stage = MOTOR_DEINIT_SETPOINTS_DEINIT, - /* FIXME: FILL IN ONCE I MAKE ENUM */ - .states.running_stage = 0, + .states.running_stage = 0, /* FIXME: FILL IN ONCE I MAKE ENUM */ /* Values */ .torque_setpoint = DEFAULT_TORQUE_SETPOINT, @@ -55,12 +54,14 @@ 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 - * */ +/* TODO: Determine period of this. Should be pretty often of course. The control + * word needs to be sent every 50ms or the motors will shut off. Plettenberg did + * every 15ms so maybe we will just do that? + */ void motorPeriodic(amk_motor_t* motor) { motorGetData(motor); + switch(motor->states.stage) { case MOTOR_STAGE_INIT: turnMotorOn(motor); @@ -94,13 +95,8 @@ static void motorGetData(amk_motor_t* motor) } } -/* 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. +/* TODO: Not really sure what needs to be done here. We just need to push + * these values that are determined in car.c state machine (READY2DRIVE state) */ static void motorRunning(amk_motor_t* motor) { @@ -109,7 +105,6 @@ static void motorRunning(amk_motor_t* motor) motor->torque_setpoint, motor->torque_limit_positive, motor->torque_limit_negative); - } static void turnMotorOn(amk_motor_t* motor) diff --git a/common/amk/amk.h b/common/amk/amk.h index 4c1542d6..ea800f5b 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -13,7 +13,6 @@ #include #include -#include /* Inverter -> CAN */ /* In AMK_Actual_Values_1 */ @@ -61,12 +60,14 @@ typedef struct { amk_motor_states_t states; 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; - uint32_t serial_num; + uint32_t serial_num; // for sanity checking int16_t motor_temp; int16_t inverter_temp; uint16_t dc_bus_voltage; @@ -88,7 +89,6 @@ typedef enum { 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, @@ -109,7 +109,7 @@ typedef enum { #define DEFAULT_POSITIVE_TORQUE_LIMIT 0 #define DEFAULT_NEGATIVE_TORQUE_LIMIT 0 -#define MAX_TORQUE_SETPOINT 6000 +#define MAX_TORQUE_SETPOINT 1000 #define MAX_POSITIVE_TORQUE_LIMIT 1000 #define MAX_NEGATIVE_TORQUE_LIMIT 1000 From 76748c7b9001a1db2a1d302a7332ed2481612e66 Mon Sep 17 00:00:00 2001 From: Cole Date: Wed, 30 Oct 2024 14:14:12 -0400 Subject: [PATCH 21/36] formatting fix plus got rid of state that was unncessary --- common/amk/amk.c | 324 +++++++++++++++++++++++------------------------ 1 file changed, 162 insertions(+), 162 deletions(-) diff --git a/common/amk/amk.c b/common/amk/amk.c index 72a5c7c0..571811d5 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -120,113 +120,113 @@ static void turnMotorOn(amk_motor_t* motor) */ switch (motor->states.init_stage) { - 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; + 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; - motor->status.bits = can_data.AMK_Actual_Values_1.AMK_Status; + motor->status.bits = can_data.AMK_Actual_Values_1.AMK_Status; - if (motor->status.fields.AMK_bSystemReady) - motor->states.init_stage = MOTOR_INIT_PRECHARGE; + if (motor->status.fields.AMK_bSystemReady) + motor->states.init_stage = MOTOR_INIT_PRECHARGE; - 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 */ - /* 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_stage = MOTOR_INIT_DC_ON; + 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 */ + /* 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_stage = MOTOR_INIT_DC_ON; - break; - case MOTOR_INIT_DC_ON: - /* 3. Set AMK_bDcOn = 1 */ - motor->control.fields.AMK_bDcOn = true; + break; + case MOTOR_INIT_DC_ON: + /* 3. Set AMK_bDcOn = 1 */ + motor->control.fields.AMK_bDcOn = true; - SEND_AMK_SETPOINTS(motor->control.bits, - motor->torque_setpoint, - motor->torque_limit_positive, - motor->torque_limit_negative); + SEND_AMK_SETPOINTS(motor->control.bits, + motor->torque_setpoint, + motor->torque_limit_positive, + motor->torque_limit_negative); - motor->states.init_stage = MOTOR_INIT_DC_ON_CHECK; + motor->states.init_stage = 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; - 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; - motor->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??? */ + /* 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 (motor->status.fields.AMK_bQuitDcOn) - motor->states.init_stage = MOTOR_INIT_TORQUE_INIT; + if (motor->status.fields.AMK_bQuitDcOn) + motor->states.init_stage = MOTOR_INIT_TORQUE_INIT; - break; - case MOTOR_INIT_TORQUE_INIT: - /* 4. Set AMK_TorqueLimitNegativ = 0 and AMK_TorqueLimitPositiv = 0 */ - motor->torque_limit_positive = 0; - motor->torque_limit_negative = 0; + break; + case MOTOR_INIT_TORQUE_INIT: + /* 4. Set AMK_TorqueLimitNegativ = 0 and AMK_TorqueLimitPositiv = 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->torque_setpoint, - motor->torque_limit_positive, - motor->torque_limit_negative); + /* Says I also need to set act speed to 0? */ + SEND_AMK_SETPOINTS(motor->control.bits, + motor->torque_setpoint, + motor->torque_limit_positive, + motor->torque_limit_negative); - motor->states.init_stage = 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; + break; + case MOTOR_INIT_ENABLE: + /* 7. Set AMK_bEnable = 1 */ + motor->control.fields.AMK_bEnable = true; - SEND_AMK_SETPOINTS(motor->control.bits, - motor->torque_setpoint, - motor->torque_limit_positive, - motor->torque_limit_negative); + SEND_AMK_SETPOINTS(motor->control.bits, + motor->torque_setpoint, + motor->torque_limit_positive, + motor->torque_limit_negative); - motor->states.init_stage = MOTOR_INIT_INVERTER_ON; + motor->states.init_stage = 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->torque_setpoint, + motor->torque_limit_positive, + motor->torque_limit_negative); + + 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 */ + if (can_data.AMK_Actual_Values_1.stale) break; - case MOTOR_INIT_INVERTER_ON: - /* 8 Set AMK_bInverterOn = 1 */ - motor->control.fields.AMK_bInverterOn = true; - SEND_AMK_SETPOINTS(motor->control.bits, - motor->torque_setpoint, - motor->torque_limit_positive, - motor->torque_limit_negative); - - 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 */ - if (can_data.AMK_Actual_Values_1.stale) - break; - motor->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 */ + /* 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 (motor->status.fields.AMK_bQuitInverterOn) { - motor->states.init_stage = MOTOR_INIT_DONE; - motor->states.stage = MOTOR_STAGE_RUNNING; - } + /* 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_stage = MOTOR_INIT_DONE; + motor->states.stage = MOTOR_STAGE_RUNNING; + } - break; + break; } } @@ -249,110 +249,110 @@ static void turnMotorOff(amk_motor_t* motor) */ switch(motor->states.deinit_stage) { - case MOTOR_DEINIT_SETPOINTS_DEINIT: - /* 1. Set setpoint settings to 0 (AMK_TargetVelocity, AMK_TorqueLimitNegativ, AMK_TorqueLimitPositiv) */ - motor->torque_setpoint = 0; - motor->torque_limit_positive = 0; - motor->torque_limit_negative = 0; - - 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; + case MOTOR_DEINIT_SETPOINTS_DEINIT: + /* 1. Set setpoint settings to 0 (AMK_TargetVelocity, AMK_TorqueLimitNegativ, AMK_TorqueLimitPositiv) */ + motor->torque_setpoint = 0; + motor->torque_limit_positive = 0; + motor->torque_limit_negative = 0; + + 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; - break; + break; - case MOTOR_DEINIT_INVERTER_OFF: - /* 2. Set AMK_bInverterOn = 0 */ - motor->control.fields.AMK_bInverterOn = false; + case MOTOR_DEINIT_INVERTER_OFF: + /* 2. Set AMK_bInverterOn = 0 */ + motor->control.fields.AMK_bInverterOn = false; - SEND_AMK_SETPOINTS(motor->control.bits, - motor->torque_setpoint, - motor->torque_limit_positive, - motor->torque_limit_negative); + SEND_AMK_SETPOINTS(motor->control.bits, + motor->torque_setpoint, + motor->torque_limit_positive, + motor->torque_limit_negative); - motor->states.deinit_stage = MOTOR_DEINIT_DISABLE; + motor->states.deinit_stage = MOTOR_DEINIT_DISABLE; - break; - case MOTOR_DEINIT_DISABLE: - /* 3. Set AMK_bEnable = 0 */ + break; + case MOTOR_DEINIT_DISABLE: + /* 3. Set AMK_bEnable = 0 */ - motor->control.fields.AMK_bEnable = false; + motor->control.fields.AMK_bEnable = false; - SEND_AMK_SETPOINTS(motor->control.bits, - motor->torque_setpoint, - motor->torque_limit_positive, - motor->torque_limit_negative); + 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; + motor->states.deinit_stage = MOTOR_DEINIT_QUIT_INVERTER_CHECK; - break; - case MOTOR_DEINIT_QUIT_INVERTER_CHECK: - /* 4. Check AMK_bQuitInverterOn = 0 */ + break; + case MOTOR_DEINIT_QUIT_INVERTER_CHECK: + /* 4. Check AMK_bQuitInverterOn = 0 */ - if (can_data.AMK_Actual_Values_1.stale) - break; + if (can_data.AMK_Actual_Values_1.stale) + break; - motor->status.bits = can_data.AMK_Actual_Values_1.AMK_Status; + motor->status.bits = can_data.AMK_Actual_Values_1.AMK_Status; - if (!(motor->status.fields.AMK_bQuitInverterOn)) { - motor->states.deinit_stage = MOTOR_DEINIT_DISABLE; - } + if (!(motor->status.fields.AMK_bQuitInverterOn)) { + motor->states.deinit_stage = MOTOR_DEINIT_DISABLE; + } - motor->states.deinit_stage = MOTOR_DEINIT_DC_OFF; + motor->states.deinit_stage = MOTOR_DEINIT_DC_OFF; - break; - case MOTOR_DEINIT_DC_OFF: - /* 5. Set AMK_bDcOn = 0 */ + break; + case MOTOR_DEINIT_DC_OFF: + /* 5. Set AMK_bDcOn = 0 */ - motor->control.fields.AMK_bDcOn = false; + motor->control.fields.AMK_bDcOn = false; - SEND_AMK_SETPOINTS(motor->control.bits, - motor->torque_setpoint, - motor->torque_limit_positive, - motor->torque_limit_negative); + SEND_AMK_SETPOINTS(motor->control.bits, + motor->torque_setpoint, + motor->torque_limit_positive, + motor->torque_limit_negative); - motor->states.deinit_stage = MOTOR_DEINIT_DC_OFF_CHECK; + motor->states.deinit_stage = MOTOR_DEINIT_DC_OFF_CHECK; + break; + case MOTOR_DEINIT_DC_OFF_CHECK: + /* 6r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ + /* 6r. Check AMK_bQuitDcOn = 0 */ + if (can_data.AMK_Actual_Values_1.stale) 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 */ - if (can_data.AMK_Actual_Values_1.stale) - break; - motor->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??? */ + /* 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 (!(motor->status.fields.AMK_bQuitDcOn)) - motor->states.init_stage = MOTOR_INIT_TORQUE_INIT; + if (!(motor->status.fields.AMK_bQuitDcOn)) + motor->states.init_stage = MOTOR_INIT_TORQUE_INIT; - motor->states.deinit_stage = 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?) */ - - /* FIXME: Will this work? Not sure if this goes low when discharged */ - if (!(car.pchg.pchg_complete)) - motor->states.init_stage = MOTOR_DEINIT_POWER_OFF; + break; + case MOTOR_DEINIT_PRECHARGE: + /* 7. Discharge DC caps; QUE should be reset (is this just DcOn?) */ + + /* FIXME: Will this work? Not sure if this goes low when discharged */ + if (!(car.pchg.pchg_complete)) + motor->states.init_stage = MOTOR_DEINIT_POWER_OFF; - /* If discharged, move on */ - motor->states.deinit_stage = MOTOR_DEINIT_POWER_OFF; + /* If discharged, move on */ + motor->states.deinit_stage = MOTOR_DEINIT_POWER_OFF; - break; - case MOTOR_DEINIT_POWER_OFF: - /* 7. Turn off 24v DC to inverters */ - /* We don't do much here, just have to turn off the car I guess */ - motor->states.deinit_stage = MOTOR_DEINIT_DONE; - motor->states.stage = MOTOR_STAGE_OFF; + break; + case MOTOR_DEINIT_POWER_OFF: + /* 8. Turn off 24v DC to inverters */ + /* We don't do much here, just have to turn off the car I guess */ + motor->states.deinit_stage = MOTOR_DEINIT_DONE; + motor->states.stage = MOTOR_STAGE_OFF; - break; + break; } } From 76795003b6389af6c504e421f18a42e7e8a7ca6e Mon Sep 17 00:00:00 2001 From: Cole Date: Thu, 31 Oct 2024 20:26:16 -0400 Subject: [PATCH 22/36] Finally got AMK building in, calling stuff in car.c now. Not sure if it works but its all there, atleast the stuff I know that needs to be there :) Except for wheel speeds --- common/amk/CMakeLists.txt | 2 +- common/amk/amk.c | 27 +++++++++--- common/amk/amk.h | 14 ++++++- common/daq/can_config.json | 6 ++- common/daq/per_dbc.dbc | 14 ++++--- source/dashboard/can/can_parse.c | 6 ++- source/dashboard/can/can_parse.h | 14 ++++--- source/main_module/CMakeLists.txt | 2 +- source/main_module/can/can_parse.h | 16 ++++--- source/main_module/car/car.c | 62 ++++++++++++++++------------ source/main_module/car/car.h | 11 +++-- source/torque_vector/can/can_parse.c | 6 ++- source/torque_vector/can/can_parse.h | 14 ++++--- 13 files changed, 127 insertions(+), 67 deletions(-) diff --git a/common/amk/CMakeLists.txt b/common/amk/CMakeLists.txt index b94d4439..f9cbef87 100644 --- a/common/amk/CMakeLists.txt +++ b/common/amk/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET_NAME amk) +set(TARGET_NAME AMK) add_library(${TARGET_NAME}) # Find all .c sources in project diff --git a/common/amk/amk.c b/common/amk/amk.c index 571811d5..daa3583a 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -1,8 +1,6 @@ #include "amk.h" -#include "source/main_module/car/car.h" #include "source/main_module/can/can_parse.h" - /* 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, @@ -38,7 +36,7 @@ static void motorGetData(amk_motor_t* motor); /* FIXME: Move motor->control word and status words into motor struct */ -void motorInit(amk_motor_t* motor) +void motorInit(amk_motor_t* motor, bool* pchg_complete) { *motor = (amk_motor_t){ /* States */ @@ -50,7 +48,9 @@ void motorInit(amk_motor_t* motor) /* Values */ .torque_setpoint = DEFAULT_TORQUE_SETPOINT, .torque_limit_positive = DEFAULT_POSITIVE_TORQUE_LIMIT, - .torque_limit_negative = DEFAULT_NEGATIVE_TORQUE_LIMIT + .torque_limit_negative = DEFAULT_NEGATIVE_TORQUE_LIMIT, + + .pchg_complete = pchg_complete }; } @@ -75,6 +75,20 @@ void motorPeriodic(amk_motor_t* motor) } } +/* Sets the torque setpoint from -1000% to 1000% of nominal torque. + * But this function just takes in -100% to 100% to stay consistent */ +void motorSetTorque(amk_motor_t* motor, int16_t torque_setpoint) +{ + if (torque_setpoint > MAX_POSITIVE_TORQUE_SETPOINT + || torque_setpoint < MAX_NEGATIVE_TORQUE_SETPOINT) + return; + + /* Scale up since unit is 0.1% of nominal torque */ + torque_setpoint *= 10; + + motor->torque_setpoint = torque_setpoint; +} + static void motorGetData(amk_motor_t* motor) { if (!can_data.AMK_Actual_Values_1.stale) { @@ -92,6 +106,7 @@ static void motorGetData(amk_motor_t* motor) if (!can_data.AMK_Temperatures_1.stale) { motor->motor_temp = can_data.AMK_Temperatures_1.AMK_MotorTemp; motor->inverter_temp = can_data.AMK_Temperatures_1.AMK_InverterTemp; + motor->igbt_temp = can_data.AMK_Temperatures_1.AMK_IGBTTemp; } } @@ -141,7 +156,7 @@ static void turnMotorOn(amk_motor_t* motor) /* if precharge complete pin is high */ /* 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) + if (*motor->pchg_complete) motor->states.init_stage = MOTOR_INIT_DC_ON; break; @@ -340,7 +355,7 @@ static void turnMotorOff(amk_motor_t* motor) /* 7. Discharge DC caps; QUE should be reset (is this just DcOn?) */ /* FIXME: Will this work? Not sure if this goes low when discharged */ - if (!(car.pchg.pchg_complete)) + if (!(*motor->pchg_complete)) motor->states.init_stage = MOTOR_DEINIT_POWER_OFF; /* If discharged, move on */ diff --git a/common/amk/amk.h b/common/amk/amk.h index ea800f5b..02e5dcf8 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -68,12 +68,21 @@ typedef struct { int16_t actual_torque; int16_t actual_speed; uint32_t serial_num; // for sanity checking + int16_t motor_temp; int16_t inverter_temp; + int16_t igbt_temp; + uint16_t dc_bus_voltage; uint16_t system_reset; + + bool* pchg_complete; } amk_motor_t; +void motorInit(amk_motor_t* motor, bool* pchg_complete); +void motorPeriodic(amk_motor_t* motor); +void motorSetTorque(amk_motor_t* motor, int16_t torque_setpoint); + typedef enum { MOTOR_INIT_POWER_ON, MOTOR_INIT_PRECHARGE, @@ -109,8 +118,9 @@ typedef enum { #define DEFAULT_POSITIVE_TORQUE_LIMIT 0 #define DEFAULT_NEGATIVE_TORQUE_LIMIT 0 -#define MAX_TORQUE_SETPOINT 1000 +#define MAX_POSITIVE_TORQUE_SETPOINT 1000 +#define MAX_NEGATIVE_TORQUE_SETPOINT -1000 #define MAX_POSITIVE_TORQUE_LIMIT 1000 -#define MAX_NEGATIVE_TORQUE_LIMIT 1000 +#define MAX_NEGATIVE_TORQUE_LIMIT -1000 #endif /* _AMK_H_ */ diff --git a/common/daq/can_config.json b/common/daq/can_config.json index b1618706..f5c69ee3 100644 --- a/common/daq/can_config.json +++ b/common/daq/can_config.json @@ -176,8 +176,10 @@ "signals": [ {"sig_name": "left_mot_temp", "type":"uint8_t", "length": 8, "unit": "C"}, {"sig_name": "right_mot_temp", "type":"uint8_t", "length": 8, "unit": "C"}, - {"sig_name": "left_ctrl_temp", "type":"uint8_t", "length":8, "unit": "C"}, - {"sig_name": "right_ctrl_temp", "type":"uint8_t", "length":8, "unit": "C"} + {"sig_name": "left_inv_temp", "type":"uint8_t", "length":8, "unit": "C"}, + {"sig_name": "right_inv_temp", "type":"uint8_t", "length":8, "unit": "C"}, + {"sig_name": "left_igbt_temp", "type":"uint8_t", "length":8, "unit": "C"}, + {"sig_name": "right_igbt_temp", "type":"uint8_t", "length":8, "unit": "C"} ], "msg_period": 1000, "msg_hlp": 4, diff --git a/common/daq/per_dbc.dbc b/common/daq/per_dbc.dbc index d2b7e6ff..1c0074de 100644 --- a/common/daq/per_dbc.dbc +++ b/common/daq/per_dbc.dbc @@ -107,9 +107,11 @@ BO_ 2348811137 sdc_status: 2 Main_Module SG_ BMS : 1|1@1+ (1,0) [0|0] "" Vector__XXX SG_ IMD : 0|1@1+ (1,0) [0|0] "" Vector__XXX -BO_ 2415919873 rear_motor_temps: 4 Main_Module - SG_ right_ctrl_temp : 24|8@1+ (1,0) [0|0] "C" Vector__XXX - SG_ left_ctrl_temp : 16|8@1+ (1,0) [0|0] "C" Vector__XXX +BO_ 2415919873 rear_motor_temps: 6 Main_Module + SG_ right_igbt_temp : 40|8@1+ (1,0) [0|0] "C" Vector__XXX + SG_ left_igbt_temp : 32|8@1+ (1,0) [0|0] "C" Vector__XXX + SG_ right_inv_temp : 24|8@1+ (1,0) [0|0] "C" Vector__XXX + SG_ left_inv_temp : 16|8@1+ (1,0) [0|0] "C" Vector__XXX SG_ right_mot_temp : 8|8@1+ (1,0) [0|0] "C" Vector__XXX SG_ left_mot_temp : 0|8@1+ (1,0) [0|0] "C" Vector__XXX @@ -726,8 +728,10 @@ CM_ SG_ 2348811137 BSPD ""; CM_ SG_ 2348811137 BMS ""; CM_ SG_ 2348811137 IMD ""; CM_ BO_ 2415919873 "Temperature of motor controllers and motors"; -CM_ SG_ 2415919873 right_ctrl_temp ""; -CM_ SG_ 2415919873 left_ctrl_temp ""; +CM_ SG_ 2415919873 right_igbt_temp ""; +CM_ SG_ 2415919873 left_igbt_temp ""; +CM_ SG_ 2415919873 right_inv_temp ""; +CM_ SG_ 2415919873 left_inv_temp ""; CM_ SG_ 2415919873 right_mot_temp ""; CM_ SG_ 2415919873 left_mot_temp ""; CM_ BO_ 2214593409 "Rear Wheel speeds from motor controllers"; diff --git a/source/dashboard/can/can_parse.c b/source/dashboard/can/can_parse.c index 71e6eb2d..daa9b6e0 100644 --- a/source/dashboard/can/can_parse.c +++ b/source/dashboard/can/can_parse.c @@ -120,8 +120,10 @@ void canRxUpdate() case ID_REAR_MOTOR_TEMPS: can_data.rear_motor_temps.left_mot_temp = msg_data_a->rear_motor_temps.left_mot_temp; can_data.rear_motor_temps.right_mot_temp = msg_data_a->rear_motor_temps.right_mot_temp; - can_data.rear_motor_temps.left_ctrl_temp = msg_data_a->rear_motor_temps.left_ctrl_temp; - can_data.rear_motor_temps.right_ctrl_temp = msg_data_a->rear_motor_temps.right_ctrl_temp; + can_data.rear_motor_temps.left_inv_temp = msg_data_a->rear_motor_temps.left_inv_temp; + can_data.rear_motor_temps.right_inv_temp = msg_data_a->rear_motor_temps.right_inv_temp; + can_data.rear_motor_temps.left_igbt_temp = msg_data_a->rear_motor_temps.left_igbt_temp; + can_data.rear_motor_temps.right_igbt_temp = msg_data_a->rear_motor_temps.right_igbt_temp; can_data.rear_motor_temps.stale = 0; can_data.rear_motor_temps.last_rx = sched.os_ticks; break; diff --git a/source/dashboard/can/can_parse.h b/source/dashboard/can/can_parse.h index 9d0f1351..b306e50d 100644 --- a/source/dashboard/can/can_parse.h +++ b/source/dashboard/can/can_parse.h @@ -87,7 +87,7 @@ typedef union { #define DLC_ORION_CURRENTS_VOLTS 4 #define DLC_ORION_ERRORS 4 #define DLC_MAX_CELL_TEMP 2 -#define DLC_REAR_MOTOR_TEMPS 4 +#define DLC_REAR_MOTOR_TEMPS 6 #define DLC_PRECHARGE_HB 2 #define DLC_REAR_WHEEL_SPEEDS 8 #define DLC_COOLANT_TEMPS 4 @@ -375,8 +375,10 @@ typedef union { struct { uint64_t left_mot_temp: 8; uint64_t right_mot_temp: 8; - uint64_t left_ctrl_temp: 8; - uint64_t right_ctrl_temp: 8; + uint64_t left_inv_temp: 8; + uint64_t right_inv_temp: 8; + uint64_t left_igbt_temp: 8; + uint64_t right_igbt_temp: 8; } rear_motor_temps; struct { uint64_t IMD: 8; @@ -556,8 +558,10 @@ typedef struct { struct { uint8_t left_mot_temp; uint8_t right_mot_temp; - uint8_t left_ctrl_temp; - uint8_t right_ctrl_temp; + uint8_t left_inv_temp; + uint8_t right_inv_temp; + uint8_t left_igbt_temp; + uint8_t right_igbt_temp; uint8_t stale; uint32_t last_rx; } rear_motor_temps; diff --git a/source/main_module/CMakeLists.txt b/source/main_module/CMakeLists.txt index 0622fdc8..6d4644d6 100644 --- a/source/main_module/CMakeLists.txt +++ b/source/main_module/CMakeLists.txt @@ -12,6 +12,6 @@ set_target_properties(${TARGET_NAME} PROPERTIES COMPONENT_NAME ${COMPONENT_NAME} COMPONENT_DIR ${CMAKE_CURRENT_LIST_DIR} LINKER_SCRIPT "STM32F407VGTx_FLASH" - COMMON_LIBS "CMSIS_F407;PSCHED_F407;QUEUE;DAQ_F407;CAN_PARSE_F407;PHAL_F407;FAULTS_F407;PLETTENBERG;BOOTLOADER_COMMON_F407" + COMMON_LIBS "CMSIS_F407;PSCHED_F407;QUEUE;DAQ_F407;CAN_PARSE_F407;PHAL_F407;FAULTS_F407;AMK;BOOTLOADER_COMMON_F407" ) COMMON_FIRMWARE_COMPONENT(${TARGET_NAME}) diff --git a/source/main_module/can/can_parse.h b/source/main_module/can/can_parse.h index 3517d539..969ac4d2 100644 --- a/source/main_module/can/can_parse.h +++ b/source/main_module/can/can_parse.h @@ -84,7 +84,7 @@ typedef union { #define DLC_REAR_MC_STATUS 6 #define DLC_REAR_MOTOR_CURRENTS_VOLTS 6 #define DLC_SDC_STATUS 2 -#define DLC_REAR_MOTOR_TEMPS 4 +#define DLC_REAR_MOTOR_TEMPS 6 #define DLC_REAR_WHEEL_SPEEDS 8 #define DLC_AMK_SETPOINTS 8 #define DLC_FAULT_SYNC_MAIN_MODULE 3 @@ -221,13 +221,15 @@ typedef union { data_a->sdc_status.pchg_out = pchg_out_;\ canTxSendToBack(&msg);\ } while(0) -#define SEND_REAR_MOTOR_TEMPS(left_mot_temp_, right_mot_temp_, left_ctrl_temp_, right_ctrl_temp_) do {\ +#define SEND_REAR_MOTOR_TEMPS(left_mot_temp_, right_mot_temp_, left_inv_temp_, right_inv_temp_, left_igbt_temp_, right_igbt_temp_) do {\ CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_REAR_MOTOR_TEMPS, .DLC=DLC_REAR_MOTOR_TEMPS, .IDE=1};\ CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ data_a->rear_motor_temps.left_mot_temp = left_mot_temp_;\ data_a->rear_motor_temps.right_mot_temp = right_mot_temp_;\ - data_a->rear_motor_temps.left_ctrl_temp = left_ctrl_temp_;\ - data_a->rear_motor_temps.right_ctrl_temp = right_ctrl_temp_;\ + data_a->rear_motor_temps.left_inv_temp = left_inv_temp_;\ + data_a->rear_motor_temps.right_inv_temp = right_inv_temp_;\ + data_a->rear_motor_temps.left_igbt_temp = left_igbt_temp_;\ + data_a->rear_motor_temps.right_igbt_temp = right_igbt_temp_;\ canTxSendToBack(&msg);\ } while(0) #define SEND_REAR_WHEEL_SPEEDS(left_speed_mc_, right_speed_mc_, left_speed_sensor_, right_speed_sensor_) do {\ @@ -421,8 +423,10 @@ typedef union { struct { uint64_t left_mot_temp: 8; uint64_t right_mot_temp: 8; - uint64_t left_ctrl_temp: 8; - uint64_t right_ctrl_temp: 8; + uint64_t left_inv_temp: 8; + uint64_t right_inv_temp: 8; + uint64_t left_igbt_temp: 8; + uint64_t right_igbt_temp: 8; } rear_motor_temps; struct { uint64_t left_speed_mc: 16; diff --git a/source/main_module/car/car.c b/source/main_module/car/car.c index b02ccfd8..bb95eabe 100644 --- a/source/main_module/car/car.c +++ b/source/main_module/car/car.c @@ -5,7 +5,7 @@ Car_t car; extern q_handle_t q_tx_can; extern q_handle_t q_tx_usart_l, q_tx_usart_r; -extern usart_rx_buf_t huart_l_rx_buf, huart_r_rx_buf; +// extern usart_rx_buf_t huart_l_rx_buf, huart_r_rx_buf; extern uint16_t num_failed_msgs_l, num_failed_msgs_r; extern WheelSpeeds_t wheel_speeds; // TODO: Just to remove errors for now @@ -48,9 +48,11 @@ bool carInit() const_tq_val = 0; hist_curr_idx = 0; /* Motor Controller Initialization */ - mcInit(&car.motor_l, MC_L_INVERT, &q_tx_usart_l, &huart_l_rx_buf, &car.pchg.pchg_complete); - mcInit(&car.motor_r, MC_R_INVERT, &q_tx_usart_r, &huart_r_rx_buf, &car.pchg.pchg_complete); + // mcInit(&car.motor_l, MC_L_INVERT, &q_tx_usart_l, &huart_l_rx_buf, &car.pchg.pchg_complete); + // mcInit(&car.motor_r, MC_R_INVERT, &q_tx_usart_r, &huart_r_rx_buf, &car.pchg.pchg_complete); + motorInit(&car.motor_r, &car.pchg.pchg_complete); + motorInit(&car.motor_l, &car.pchg.pchg_complete); PHAL_writeGPIO(SDC_MUX_S0_GPIO_Port, SDC_MUX_S0_Pin, 0); PHAL_writeGPIO(SDC_MUX_S1_GPIO_Port, SDC_MUX_S1_Pin, 0); @@ -62,10 +64,10 @@ bool carInit() void carHeartbeat() { SEND_MAIN_HB(car.state, car.pchg.pchg_complete); - SEND_REAR_MC_STATUS(car.motor_l.motor_state, - car.motor_l.link_state, car.motor_l.last_link_error, - car.motor_r.motor_state, car.motor_r.link_state, - car.motor_r.last_link_error); + // SEND_REAR_MC_STATUS(car.motor_l.motor_state, + // car.motor_l.link_state, car.motor_l.last_link_error, + // car.motor_r.motor_state, car.motor_r.link_state, + // car.motor_r.last_link_error); static uint8_t n; } @@ -427,8 +429,10 @@ void carPeriodic() PHAL_writeGPIO(SDC_CTRL_GPIO_Port, SDC_CTRL_Pin, car.sdc_close); PHAL_writeGPIO(BRK_LIGHT_GPIO_Port, BRK_LIGHT_Pin, car.brake_light | daq_brake); PHAL_writeGPIO(BUZZER_GPIO_Port, BUZZER_Pin, car.buzzer); - mcSetPower(car.torque_r.torque_left, &car.motor_l); - mcSetPower(car.torque_r.torque_right, &car.motor_r); + // mcSetPower(car.torque_r.torque_left, &car.motor_l); + // mcSetPower(car.torque_r.torque_right, &car.motor_r); + motorSetTorque(&car.motor_r, car.torque_r.torque_right); + motorSetTorque(&car.motor_l, car.torque_r.torque_left); } @@ -442,8 +446,11 @@ void parseMCDataPeriodic(void) uint16_t shock_l, shock_r; /* Update Motor Controller Data Structures */ - mcPeriodic(&car.motor_l); - mcPeriodic(&car.motor_r); + // mcPeriodic(&car.motor_l); + // mcPeriodic(&car.motor_r); + + motorPeriodic(&car.motor_l); + motorPeriodic(&car.motor_r); // setFault(ID_LEFT_MC_CONN_FAULT, car.pchg.pchg_complete && // car.motor_l.motor_state != MC_CONNECTED); @@ -467,18 +474,19 @@ void parseMCDataPeriodic(void) // uint16_t l_speed = (wheel_speeds.l->rad_s / (2*PI)); // uint16_t r_speed = (wheel_speeds.l->rad_s / (2*PI)); wheelSpeedsPeriodic(); - SEND_REAR_WHEEL_SPEEDS(car.motor_l.rpm, car.motor_r.rpm, - wheel_speeds.left_rad_s_x100, - wheel_speeds.right_rad_s_x100); + // 2025 TODO Setup wheel speed stuff: + // SEND_REAR_WHEEL_SPEEDS(car.motor_l.rpm, car.motor_r.rpm, + // wheel_speeds.left_rad_s_x100, + // wheel_speeds.right_rad_s_x100); static uint32_t last_curr_t; - if (sched.os_ticks - last_curr_t >= 100) - { - SEND_REAR_MOTOR_CURRENTS_VOLTS( - (uint16_t) car.motor_l.current_x10, - (uint16_t) car.motor_r.current_x10, - (uint16_t) car.motor_r.voltage_x10); - last_curr_t = sched.os_ticks; - } + // if (sched.os_ticks - last_curr_t >= 100) + // { + // SEND_REAR_MOTOR_CURRENTS_VOLTS( + // (uint16_t) car.motor_l.current_x10, + // (uint16_t) car.motor_r.current_x10, + // (uint16_t) car.motor_r.voltage_x10); + // last_curr_t = sched.os_ticks; + // } // TODO: possibly move into cooling static uint32_t last_tmp_t; if (sched.os_ticks - last_tmp_t >= 500) @@ -486,9 +494,11 @@ void parseMCDataPeriodic(void) SEND_REAR_MOTOR_TEMPS( (uint8_t) car.motor_l.motor_temp, (uint8_t) car.motor_r.motor_temp, - (uint8_t) car.motor_l.controller_temp, - (uint8_t) car.motor_r.controller_temp); - SEND_NUM_MC_SKIPS(num_failed_msgs_r, num_failed_msgs_l); + (uint8_t) car.motor_l.inverter_temp, + (uint8_t) car.motor_r.inverter_temp, + (uint8_t) car.motor_l.igbt_temp, + (uint8_t) car.motor_r.igbt_temp); + // SEND_NUM_MC_SKIPS(num_failed_msgs_r, num_failed_msgs_l); last_tmp_t = sched.os_ticks; } } @@ -861,4 +871,4 @@ void monitorSDCPeriodic() PHAL_writeGPIO(SDC_MUX_S1_GPIO_Port, SDC_MUX_S1_Pin, (index & 0x02)); PHAL_writeGPIO(SDC_MUX_S2_GPIO_Port, SDC_MUX_S2_Pin, (index & 0x04)); PHAL_writeGPIO(SDC_MUX_S3_GPIO_Port, SDC_MUX_S3_Pin, (index & 0x08)); -} \ No newline at end of file +} diff --git a/source/main_module/car/car.h b/source/main_module/car/car.h index a4a8348d..486b42de 100644 --- a/source/main_module/car/car.h +++ b/source/main_module/car/car.h @@ -14,10 +14,11 @@ #include "can_parse.h" #include "common/faults/faults.h" #include "common/phal_F4_F7/gpio/gpio.h" -#include "common/plettenberg/plettenberg.h" +// #include "common/plettenberg/plettenberg.h" #include "common/psched/psched.h" #include "cooling.h" #include "main.h" +#include "common/amk/amk.h" #include #define BUZZER_DURATION_MS 2500 // EV.10.5: 1-3s @@ -80,8 +81,10 @@ typedef struct typedef struct { car_state_t state; - motor_t motor_l; - motor_t motor_r; + // motor_t motor_l; + // motor_t motor_r; + amk_motor_t motor_l; + amk_motor_t motor_r; torqueRequest_t torque_r; torqueSource_t torque_src; @@ -145,4 +148,4 @@ typedef struct __attribute__((packed)) extern sdc_nodes_t sdc_mux; -#endif \ No newline at end of file +#endif diff --git a/source/torque_vector/can/can_parse.c b/source/torque_vector/can/can_parse.c index f507a807..643a9e24 100644 --- a/source/torque_vector/can/can_parse.c +++ b/source/torque_vector/can/can_parse.c @@ -101,8 +101,10 @@ void canRxUpdate() case ID_REAR_MOTOR_TEMPS: can_data.rear_motor_temps.left_mot_temp = msg_data_a->rear_motor_temps.left_mot_temp; can_data.rear_motor_temps.right_mot_temp = msg_data_a->rear_motor_temps.right_mot_temp; - can_data.rear_motor_temps.left_ctrl_temp = msg_data_a->rear_motor_temps.left_ctrl_temp; - can_data.rear_motor_temps.right_ctrl_temp = msg_data_a->rear_motor_temps.right_ctrl_temp; + can_data.rear_motor_temps.left_inv_temp = msg_data_a->rear_motor_temps.left_inv_temp; + can_data.rear_motor_temps.right_inv_temp = msg_data_a->rear_motor_temps.right_inv_temp; + can_data.rear_motor_temps.left_igbt_temp = msg_data_a->rear_motor_temps.left_igbt_temp; + can_data.rear_motor_temps.right_igbt_temp = msg_data_a->rear_motor_temps.right_igbt_temp; can_data.rear_motor_temps.stale = 0; can_data.rear_motor_temps.last_rx = sched.os_ticks; break; diff --git a/source/torque_vector/can/can_parse.h b/source/torque_vector/can/can_parse.h index 8083af62..dfb4ea07 100644 --- a/source/torque_vector/can/can_parse.h +++ b/source/torque_vector/can/can_parse.h @@ -78,7 +78,7 @@ #define DLC_DASHBOARD_TV_PARAMETERS 7 #define DLC_MAIN_HB 2 #define DLC_REAR_WHEEL_SPEEDS 8 -#define DLC_REAR_MOTOR_TEMPS 4 +#define DLC_REAR_MOTOR_TEMPS 6 #define DLC_MAX_CELL_TEMP 2 #define DLC_FAULT_SYNC_PDU 3 #define DLC_FAULT_SYNC_MAIN_MODULE 3 @@ -349,8 +349,10 @@ typedef union { struct { uint64_t left_mot_temp: 8; uint64_t right_mot_temp: 8; - uint64_t left_ctrl_temp: 8; - uint64_t right_ctrl_temp: 8; + uint64_t left_inv_temp: 8; + uint64_t right_inv_temp: 8; + uint64_t left_igbt_temp: 8; + uint64_t right_igbt_temp: 8; } rear_motor_temps; struct { uint64_t max_temp: 16; @@ -442,8 +444,10 @@ typedef struct { struct { uint8_t left_mot_temp; uint8_t right_mot_temp; - uint8_t left_ctrl_temp; - uint8_t right_ctrl_temp; + uint8_t left_inv_temp; + uint8_t right_inv_temp; + uint8_t left_igbt_temp; + uint8_t right_igbt_temp; uint8_t stale; uint32_t last_rx; } rear_motor_temps; From 099e108c62bfc1467724dc2c7ec2c9cde7745e25 Mon Sep 17 00:00:00 2001 From: Cole Date: Thu, 31 Oct 2024 20:29:28 -0400 Subject: [PATCH 23/36] Oops, forgot to commit cmakelists --- CMakeLists.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2436e264..014de838 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,8 @@ add_subdirectory(common/common_defs) add_subdirectory(common/log) add_subdirectory(common/faults) add_subdirectory(common/daq) -add_subdirectory(common/plettenberg) +# add_subdirectory(common/plettenberg) +add_subdirectory(common/amk) add_subdirectory(common/modules/wheel_speeds) add_subdirectory(common/modules/Wiznet) From 92755571ed9f212418ed526aab3ab356850338c4 Mon Sep 17 00:00:00 2001 From: Cole Date: Fri, 1 Nov 2024 13:38:25 -0400 Subject: [PATCH 24/36] I still have no idea what to do with these torque limits, maybe what I have here is good enough? Or can I just set them to max values and just set torque setpoint normally from there? --- common/amk/amk.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/common/amk/amk.c b/common/amk/amk.c index daa3583a..03ca46e1 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -87,6 +87,16 @@ void motorSetTorque(amk_motor_t* motor, int16_t torque_setpoint) torque_setpoint *= 10; motor->torque_setpoint = torque_setpoint; + + if (torque_setpoint < 0) { + motor->torque_limit_negative = torque_setpoint; + motor->torque_limit_positive = 0; + } + else { + motor->torque_limit_positive = torque_setpoint; + motor->torque_limit_negative = 0; + } + } static void motorGetData(amk_motor_t* motor) From 7e581a47966e5f749e2e9a79d2992deaff0890c3 Mon Sep 17 00:00:00 2001 From: Cole Date: Sun, 3 Nov 2024 12:27:13 -0500 Subject: [PATCH 25/36] pushing correct scaling, they can deal with it on TV and Dash, unless they want me to send with 1% scaling --- common/amk/amk.h | 4 ++++ common/daq/can_config.json | 12 ++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/common/amk/amk.h b/common/amk/amk.h index 02e5dcf8..c9cfd060 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -61,14 +61,18 @@ typedef struct { AMK_Status_t status; AMK_Control_t control; + /* Scaling: 0.1% */ int16_t torque_setpoint; int16_t torque_limit_positive; int16_t torque_limit_negative; + /* Scaling: 0.1% */ int16_t actual_torque; int16_t actual_speed; + uint32_t serial_num; // for sanity checking + /* Scaling: 0.1% */ int16_t motor_temp; int16_t inverter_temp; int16_t igbt_temp; diff --git a/common/daq/can_config.json b/common/daq/can_config.json index f5c69ee3..9fcbc36a 100644 --- a/common/daq/can_config.json +++ b/common/daq/can_config.json @@ -174,12 +174,12 @@ "msg_name": "rear_motor_temps", "msg_desc": "Temperature of motor controllers and motors", "signals": [ - {"sig_name": "left_mot_temp", "type":"uint8_t", "length": 8, "unit": "C"}, - {"sig_name": "right_mot_temp", "type":"uint8_t", "length": 8, "unit": "C"}, - {"sig_name": "left_inv_temp", "type":"uint8_t", "length":8, "unit": "C"}, - {"sig_name": "right_inv_temp", "type":"uint8_t", "length":8, "unit": "C"}, - {"sig_name": "left_igbt_temp", "type":"uint8_t", "length":8, "unit": "C"}, - {"sig_name": "right_igbt_temp", "type":"uint8_t", "length":8, "unit": "C"} + {"sig_name": "left_mot_temp", "type":"uint8_t", "length": 8, "unit": "C", "scale":0.1}, + {"sig_name": "right_mot_temp", "type":"uint8_t", "length": 8, "unit": "C", "scale":0.1}, + {"sig_name": "left_inv_temp", "type":"uint8_t", "length":8, "unit": "C", "scale":0.1}, + {"sig_name": "right_inv_temp", "type":"uint8_t", "length":8, "unit": "C", "scale":0.1}, + {"sig_name": "left_igbt_temp", "type":"uint8_t", "length":8, "unit": "C", "scale":0.1}, + {"sig_name": "right_igbt_temp", "type":"uint8_t", "length":8, "unit": "C", "scale":0.1} ], "msg_period": 1000, "msg_hlp": 4, From 08896c3efbe3a3d08be4ffa0d03097b68918da7e Mon Sep 17 00:00:00 2001 From: Cole Date: Mon, 4 Nov 2024 13:38:37 -0500 Subject: [PATCH 26/36] Starting error stuff --- common/amk/amk.c | 23 ++++++++++++++++++----- common/amk/amk.h | 5 +++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/common/amk/amk.c b/common/amk/amk.c index 03ca46e1..284543e5 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -125,11 +125,24 @@ static void motorGetData(amk_motor_t* motor) */ static void motorRunning(amk_motor_t* motor) { - /* Set setpoints as needed */ - SEND_AMK_SETPOINTS(motor->control.bits, - motor->torque_setpoint, - motor->torque_limit_positive, - motor->torque_limit_negative); + switch (motor->states.running_stage) { + case MOTOR_RUNNING_GOOD: + /* Set setpoints as needed */ + SEND_AMK_SETPOINTS(motor->control.bits, + motor->torque_setpoint, + motor->torque_limit_positive, + motor->torque_limit_negative); + + /* Check for errors */ + if (motor->status.fields.AMK_bError) + motor->states.running_stage = MOTOR_RUNNING_ERROR; + + break; + case MOTOR_RUNNING_ERROR: + /* 8.2.5 for error diagram */ + + break; + } } static void turnMotorOn(amk_motor_t* motor) diff --git a/common/amk/amk.h b/common/amk/amk.h index c9cfd060..f2ae56f1 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -111,6 +111,11 @@ typedef enum { MOTOR_DEINIT_DONE, } amk_motor_deinit_state_t; +typedef enum { + MOTOR_RUNNING_GOOD, + MOTOR_RUNNING_ERROR, +} amk_motor_running_state_t; + typedef enum { MOTOR_STAGE_OFF, MOTOR_STAGE_INIT, From c09aaf2c3761daf8456f1dd14030f84a81063346 Mon Sep 17 00:00:00 2001 From: Cole Date: Mon, 4 Nov 2024 13:40:32 -0500 Subject: [PATCH 27/36] Modified pinouts for Main MCU 25 --- source/main_module/main.h | 52 ++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 25 deletions(-) diff --git a/source/main_module/main.h b/source/main_module/main.h index 8192a3a6..87aae421 100644 --- a/source/main_module/main.h +++ b/source/main_module/main.h @@ -20,6 +20,18 @@ #define FAULT_NODE_NAME NODE_MAIN_MODULE +#define DIS_VOLT_DIAG_GPIO_Port (GPIOC) +#define DIS_VOLT_DIAG_GPIO_Pin (4) + +#define SAFE_STAT_DIAG_GPIO_Port (GPIOC) +#define SAFE_STAT_DIAG_GPIO_Pin (12) + +#define EX_OSC_GPIO_Port (GPIOC) +#define EX_OSC_GPIO_Pin (14) + +#define ABOX_VOLT_DIAG_GPIO_Port (GPIOE) +#define ABOX_VOLT_DIAG_GPIO_Pin (8) + // Internal Status Indicators #define ERR_LED_GPIO_Port (GPIOD) #define ERR_LED_Pin (4) @@ -38,8 +50,8 @@ #define BRK_BUZZER_STAT_GPIO_Port (GPIOB) #define BRK_BUZZER_STAT_Pin (15) -#define TSAL_LVAL_STAT_GPIO_Port (GPIOD) -#define TSAL_LVAL_STAT_Pin (10) +#define READY_TO_DRIVE_STAT_GPIO_Port (GPIOD) +#define READY_TO_DRIVE_STAT_GPIO_Pin (10) // CAN #define VCAN_RX_GPIO_Port (GPIOA) @@ -47,10 +59,10 @@ #define VCAN_TX_GPIO_Port (GPIOA) #define VCAN_TX_Pin (12) -#define EMCAN_RX_GPIO_Port (GPIOB) -#define EMCAN_RX_Pin (12) -#define EMCAN_TX_GPIO_Port (GPIOB) -#define EMCAN_TX_Pin (13) +#define AMK_RX_GPIO_Port (GPIOB) +#define AMK_RX_Pin (12) +#define AMK_TX_GPIO_Port (GPIOB) +#define AMK_TX_Pin (13) // SPI Peripherals #define SPI1_SCK_GPIO_Port (GPIOA) @@ -96,20 +108,10 @@ #define PRCHG_STAT_GPIO_Port (GPIOE) #define PRCHG_STAT_Pin (5) -// Motor Controllers -#define MC_L_INVERT (0) -#define MC_L_UART (USART1) -#define MC_L_UART_TX_GPIO_Port (GPIOA) -#define MC_L_UART_TX_GPIO_Pin (9) -#define MC_L_UART_RX_GPIO_Port (GPIOA) -#define MC_L_UART_RX_GPIO_Pin (10) - -#define MC_R_INVERT (0) -#define MC_R_UART (USART2) -#define MC_R_UART_TX_GPIO_Port (GPIOA) -#define MC_R_UART_TX_GPIO_Pin (2) -#define MC_R_UART_RX_GPIO_Port (GPIOA) -#define MC_R_UART_RX_GPIO_Pin (3) +#define SAFE_STAT_G_GPIO_Port (GPIOA) +#define SAFE_STAT_G__GPIO_Pin (2) +#define SAFE_STAT_R_GPIO_Port (GPIOA) +#define SAFE_STAT_R_GPIO_Pin (3) // Wheel Speed #define MOTOR_R_WS_PWM_TIM (TIM1) @@ -125,12 +127,12 @@ #define MOTOR_L_WS_AF (2) // Shock Pots -#define SHOCK_POT_L_GPIO_Port (GPIOC) -#define SHOCK_POT_L_Pin (3) +#define SHOCK_POT_R_GPIO_Port (GPIOC) +#define SHOCK_POT_R_Pin (3) #define SHOCK_POT_L_ADC_CHNL (13) -#define SHOCK_POT_R_GPIO_Port (GPIOC) -#define SHOCK_POT_R_Pin (2) +#define SHOCK_POT_L_GPIO_Port (GPIOC) +#define SHOCK_POT_L_Pin (2) #define SHOCK_POT_R_ADC_CHNL (12) // Load Sensors @@ -182,4 +184,4 @@ volatile extern ADCReadings_t adc_readings; void canTxSendToBack(CanMsgTypeDef_t *msg); -#endif \ No newline at end of file +#endif From 6143182afcfeba6e58ff274da2dcecae6153fed1 Mon Sep 17 00:00:00 2001 From: Cole Date: Thu, 14 Nov 2024 19:19:29 -0500 Subject: [PATCH 28/36] Mix of removing UART and some testing stuff --- common/amk/amk.c | 36 ++--- common/amk/amk.h | 8 +- common/daq/can_config.json | 26 ++- common/daq/per_dbc.dbc | 23 ++- source/f4_testing/can/can_parse.c | 12 ++ source/f4_testing/can/can_parse.h | 17 ++ source/main_module/can/can_parse.h | 17 ++ source/main_module/car/car.c | 6 +- source/main_module/main.c | 248 ++++++++++++++--------------- 9 files changed, 228 insertions(+), 165 deletions(-) diff --git a/common/amk/amk.c b/common/amk/amk.c index 284543e5..d3fa16fa 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -58,10 +58,18 @@ void motorInit(amk_motor_t* motor, bool* pchg_complete) * word needs to be sent every 50ms or the motors will shut off. Plettenberg did * every 15ms so maybe we will just do that? */ + +void amkCanTesting(amk_motor_t* motor) +{ + SEND_AMK_TESTING(motor->states.init_stage, motor->control.bits, motor->status.bits, *motor->pchg_complete); +} + void motorPeriodic(amk_motor_t* motor) { motorGetData(motor); + amkCanTesting(motor); + switch(motor->states.stage) { case MOTOR_STAGE_INIT: turnMotorOn(motor); @@ -161,14 +169,8 @@ 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; - - motor->status.bits = can_data.AMK_Actual_Values_1.AMK_Status; - if (motor->status.fields.AMK_bSystemReady) motor->states.init_stage = MOTOR_INIT_PRECHARGE; - break; case MOTOR_INIT_PRECHARGE: /* 2. Charge DC caps; QUE should be set (is this just DcOn?) */ @@ -197,11 +199,6 @@ static void turnMotorOn(amk_motor_t* motor) 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; - - 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 */ @@ -213,6 +210,7 @@ static void turnMotorOn(amk_motor_t* motor) break; case MOTOR_INIT_TORQUE_INIT: /* 4. Set AMK_TorqueLimitNegativ = 0 and AMK_TorqueLimitPositiv = 0 */ + /* Should already be done, just doing again to confirm */ motor->torque_limit_positive = 0; motor->torque_limit_negative = 0; @@ -249,11 +247,6 @@ static void turnMotorOn(amk_motor_t* motor) 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; - - 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 */ @@ -329,12 +322,6 @@ static void turnMotorOff(amk_motor_t* motor) break; case MOTOR_DEINIT_QUIT_INVERTER_CHECK: /* 4. Check AMK_bQuitInverterOn = 0 */ - - 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; } @@ -358,11 +345,6 @@ static void turnMotorOff(amk_motor_t* motor) case MOTOR_DEINIT_DC_OFF_CHECK: /* 6r. AMK_bDcOn is mirrored in AMK_Status, so should be on there */ /* 6r. Check AMK_bQuitDcOn = 0 */ - if (can_data.AMK_Actual_Values_1.stale) - break; - - 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 */ diff --git a/common/amk/amk.h b/common/amk/amk.h index f2ae56f1..79790d77 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -88,7 +88,7 @@ void motorPeriodic(amk_motor_t* motor); void motorSetTorque(amk_motor_t* motor, int16_t torque_setpoint); typedef enum { - MOTOR_INIT_POWER_ON, + MOTOR_INIT_POWER_ON = 0, MOTOR_INIT_PRECHARGE, MOTOR_INIT_DC_ON, MOTOR_INIT_DC_ON_CHECK, @@ -100,7 +100,7 @@ typedef enum { } amk_motor_init_state_t; typedef enum { - MOTOR_DEINIT_SETPOINTS_DEINIT, + MOTOR_DEINIT_SETPOINTS_DEINIT = 0, MOTOR_DEINIT_INVERTER_OFF, MOTOR_DEINIT_DISABLE, MOTOR_DEINIT_QUIT_INVERTER_CHECK, @@ -112,12 +112,12 @@ typedef enum { } amk_motor_deinit_state_t; typedef enum { - MOTOR_RUNNING_GOOD, + MOTOR_RUNNING_GOOD = 0, MOTOR_RUNNING_ERROR, } amk_motor_running_state_t; typedef enum { - MOTOR_STAGE_OFF, + MOTOR_STAGE_OFF = 0, MOTOR_STAGE_INIT, MOTOR_STAGE_RUNNING, MOTOR_STAGE_DEINIT diff --git a/common/daq/can_config.json b/common/daq/can_config.json index 9fcbc36a..670494b8 100644 --- a/common/daq/can_config.json +++ b/common/daq/can_config.json @@ -209,6 +209,18 @@ ], "msg_period": 5, "msg_id_override": "0x184" + }, + { + "msg_name": "AMK_Testing", + "msg_desc": "Contains control word and setpoints", + "signals": [ + {"sig_name": "AMK_InitStage", "sig_desc": "init stage", "type":"uint8_t"}, + {"sig_name": "AMK_Control", "sig_desc": "Control word", "type":"uint16_t"}, + {"sig_name": "AMK_Status_from_motor", "sig_desc": "Control word", "type":"uint16_t"}, + {"sig_name": "precharge", "sig_desc": "Control word", "type":"uint8_t"} + ], + "msg_period": 5, + "msg_id_override": "0x384" } ], "rx":[ @@ -1110,12 +1122,24 @@ "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":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" + }, + { + "msg_name": "AMK_Testing", + "msg_desc": "Contains control word and setpoints", + "signals": [ + {"sig_name": "AMK_InitStage", "sig_desc": "init stage", "type":"uint8_t", "choices":["power_on","percharge","dc_on","dc_on_check"]}, + {"sig_name": "AMK_Control", "sig_desc": "Control word", "type":"uint16_t"}, + {"sig_name": "AMK_Status_from_motor", "sig_desc": "Control word", "type":"uint16_t"}, + {"sig_name": "precharge", "sig_desc": "Control word", "type":"uint8_t"} + ], + "msg_period": 5, + "msg_id_override": "0x384" } ] }, diff --git a/common/daq/per_dbc.dbc b/common/daq/per_dbc.dbc index 1c0074de..8a9bb14b 100644 --- a/common/daq/per_dbc.dbc +++ b/common/daq/per_dbc.dbc @@ -108,12 +108,12 @@ BO_ 2348811137 sdc_status: 2 Main_Module SG_ IMD : 0|1@1+ (1,0) [0|0] "" Vector__XXX BO_ 2415919873 rear_motor_temps: 6 Main_Module - SG_ right_igbt_temp : 40|8@1+ (1,0) [0|0] "C" Vector__XXX - SG_ left_igbt_temp : 32|8@1+ (1,0) [0|0] "C" Vector__XXX - SG_ right_inv_temp : 24|8@1+ (1,0) [0|0] "C" Vector__XXX - SG_ left_inv_temp : 16|8@1+ (1,0) [0|0] "C" Vector__XXX - SG_ right_mot_temp : 8|8@1+ (1,0) [0|0] "C" Vector__XXX - SG_ left_mot_temp : 0|8@1+ (1,0) [0|0] "C" Vector__XXX + SG_ right_igbt_temp : 40|8@1+ (0.1,0) [0|0] "C" Vector__XXX + SG_ left_igbt_temp : 32|8@1+ (0.1,0) [0|0] "C" Vector__XXX + SG_ right_inv_temp : 24|8@1+ (0.1,0) [0|0] "C" Vector__XXX + SG_ left_inv_temp : 16|8@1+ (0.1,0) [0|0] "C" Vector__XXX + SG_ right_mot_temp : 8|8@1+ (0.1,0) [0|0] "C" Vector__XXX + SG_ left_mot_temp : 0|8@1+ (0.1,0) [0|0] "C" Vector__XXX BO_ 2214593409 rear_wheel_speeds: 8 Main_Module SG_ right_speed_sensor : 48|16@1+ (0.01,0) [0|0] "rad/s" Vector__XXX @@ -127,6 +127,12 @@ BO_ 2147484036 AMK_Setpoints: 8 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_ 2147484548 AMK_Testing: 6 Main_Module + SG_ precharge : 40|8@1+ (1,0) [0|0] "" Vector__XXX + SG_ AMK_Status_from_motor : 24|16@1+ (1,0) [0|0] "" Vector__XXX + SG_ AMK_Control : 8|16@1+ (1,0) [0|0] "" Vector__XXX + SG_ AMK_InitStage : 0|8@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 @@ -744,6 +750,11 @@ 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_ 2147484548 "Contains control word and setpoints"; +CM_ SG_ 2147484548 precharge "Control word"; +CM_ SG_ 2147484548 AMK_Status_from_motor "Control word"; +CM_ SG_ 2147484548 AMK_Control "Control word"; +CM_ SG_ 2147484548 AMK_InitStage "init stage"; CM_ BO_ 2148059649 "Fault status message"; CM_ SG_ 2148059649 latched ""; CM_ SG_ 2148059649 idx ""; diff --git a/source/f4_testing/can/can_parse.c b/source/f4_testing/can/can_parse.c index 109df992..c0383077 100644 --- a/source/f4_testing/can/can_parse.c +++ b/source/f4_testing/can/can_parse.c @@ -42,6 +42,14 @@ void canRxUpdate(void) can_data.AMK_Setpoints.stale = 0; can_data.AMK_Setpoints.last_rx = sched.os_ticks; break; + case ID_AMK_TESTING: + can_data.AMK_Testing.AMK_InitStage = msg_data_a->AMK_Testing.AMK_InitStage; + can_data.AMK_Testing.AMK_Control = msg_data_a->AMK_Testing.AMK_Control; + can_data.AMK_Testing.AMK_Status_from_motor = msg_data_a->AMK_Testing.AMK_Status_from_motor; + can_data.AMK_Testing.precharge = msg_data_a->AMK_Testing.precharge; + can_data.AMK_Testing.stale = 0; + can_data.AMK_Testing.last_rx = sched.os_ticks; + break; default: __asm__("nop"); } @@ -52,6 +60,9 @@ void canRxUpdate(void) CHECK_STALE(can_data.AMK_Setpoints.stale, sched.os_ticks, can_data.AMK_Setpoints.last_rx, UP_AMK_SETPOINTS); + CHECK_STALE(can_data.AMK_Testing.stale, + sched.os_ticks, can_data.AMK_Testing.last_rx, + UP_AMK_TESTING); /* END AUTO STALE CHECKS */ } @@ -71,6 +82,7 @@ bool initCANFilter() /* BEGIN AUTO FILTER */ CAN1->FA1R |= (1 << 0); // configure bank 0 CAN1->sFilterRegister[0].FR1 = (ID_AMK_SETPOINTS << 3) | 4; + CAN1->sFilterRegister[0].FR2 = (ID_AMK_TESTING << 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 ecf3787e..bc6252db 100644 --- a/source/f4_testing/can/can_parse.h +++ b/source/f4_testing/can/can_parse.h @@ -35,6 +35,7 @@ typedef union { #define ID_AMK_TEMPERATURES_1 0x285 #define ID_AMK_TEMPERATURES_2 0x286 #define ID_AMK_SETPOINTS 0x184 +#define ID_AMK_TESTING 0x384 /* END AUTO ID DEFS */ // Message DLC definitions @@ -44,6 +45,7 @@ typedef union { #define DLC_AMK_TEMPERATURES_1 6 #define DLC_AMK_TEMPERATURES_2 6 #define DLC_AMK_SETPOINTS 8 +#define DLC_AMK_TESTING 6 /* END AUTO DLC DEFS */ // Message sending macros @@ -86,6 +88,7 @@ typedef union { #define STALE_THRESH 30 / 2 // 5 / 2 would be 250% of period /* BEGIN AUTO UP DEFS (Update Period)*/ #define UP_AMK_SETPOINTS 5 +#define UP_AMK_TESTING 5 /* END AUTO UP DEFS */ #define CHECK_STALE(stale, curr, last, period) if(!stale && \ @@ -123,6 +126,12 @@ typedef union { uint64_t AMK_PositiveTorqueLimit: 16; uint64_t AMK_NegativeTorqueLimit: 16; } AMK_Setpoints; + struct { + uint64_t AMK_InitStage: 8; + uint64_t AMK_Control: 16; + uint64_t AMK_Status_from_motor: 16; + uint64_t precharge: 8; + } AMK_Testing; uint8_t raw_data[8]; } __attribute__((packed)) CanParsedData_t; /* END AUTO MESSAGE STRUCTURE */ @@ -139,6 +148,14 @@ typedef struct { uint8_t stale; uint32_t last_rx; } AMK_Setpoints; + struct { + uint8_t AMK_InitStage; + uint16_t AMK_Control; + uint16_t AMK_Status_from_motor; + uint8_t precharge; + uint8_t stale; + uint32_t last_rx; + } AMK_Testing; } can_data_t; /* END AUTO CAN DATA STRUCTURE */ diff --git a/source/main_module/can/can_parse.h b/source/main_module/can/can_parse.h index 969ac4d2..74ecb630 100644 --- a/source/main_module/can/can_parse.h +++ b/source/main_module/can/can_parse.h @@ -45,6 +45,7 @@ typedef union { #define ID_REAR_MOTOR_TEMPS 0x10000301 #define ID_REAR_WHEEL_SPEEDS 0x4000381 #define ID_AMK_SETPOINTS 0x184 +#define ID_AMK_TESTING 0x384 #define ID_FAULT_SYNC_MAIN_MODULE 0x8ca01 #define ID_DAQ_RESPONSE_MAIN_MODULE 0x17ffffc1 #define ID_RAW_THROTTLE_BRAKE 0x10000285 @@ -87,6 +88,7 @@ typedef union { #define DLC_REAR_MOTOR_TEMPS 6 #define DLC_REAR_WHEEL_SPEEDS 8 #define DLC_AMK_SETPOINTS 8 +#define DLC_AMK_TESTING 6 #define DLC_FAULT_SYNC_MAIN_MODULE 3 #define DLC_DAQ_RESPONSE_MAIN_MODULE 8 #define DLC_RAW_THROTTLE_BRAKE 8 @@ -250,6 +252,15 @@ typedef union { data_a->AMK_Setpoints.AMK_NegativeTorqueLimit = AMK_NegativeTorqueLimit_;\ canTxSendToBack(&msg);\ } while(0) +#define SEND_AMK_TESTING(AMK_InitStage_, AMK_Control_, AMK_Status_from_motor_, precharge_) do {\ + CanMsgTypeDef_t msg = {.Bus=CAN1, .ExtId=ID_AMK_TESTING, .DLC=DLC_AMK_TESTING, .IDE=1};\ + CanParsedData_t* data_a = (CanParsedData_t *) &msg.Data;\ + data_a->AMK_Testing.AMK_InitStage = AMK_InitStage_;\ + data_a->AMK_Testing.AMK_Control = AMK_Control_;\ + data_a->AMK_Testing.AMK_Status_from_motor = AMK_Status_from_motor_;\ + data_a->AMK_Testing.precharge = precharge_;\ + 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;\ @@ -440,6 +451,12 @@ typedef union { uint64_t AMK_PositiveTorqueLimit: 16; uint64_t AMK_NegativeTorqueLimit: 16; } AMK_Setpoints; + struct { + uint64_t AMK_InitStage: 8; + uint64_t AMK_Control: 16; + uint64_t AMK_Status_from_motor: 16; + uint64_t precharge: 8; + } AMK_Testing; struct { uint64_t idx: 16; uint64_t latched: 1; diff --git a/source/main_module/car/car.c b/source/main_module/car/car.c index bb95eabe..e957ccb3 100644 --- a/source/main_module/car/car.c +++ b/source/main_module/car/car.c @@ -51,7 +51,7 @@ bool carInit() // mcInit(&car.motor_l, MC_L_INVERT, &q_tx_usart_l, &huart_l_rx_buf, &car.pchg.pchg_complete); // mcInit(&car.motor_r, MC_R_INVERT, &q_tx_usart_r, &huart_r_rx_buf, &car.pchg.pchg_complete); - motorInit(&car.motor_r, &car.pchg.pchg_complete); + // motorInit(&car.motor_r, &car.pchg.pchg_complete); motorInit(&car.motor_l, &car.pchg.pchg_complete); PHAL_writeGPIO(SDC_MUX_S0_GPIO_Port, SDC_MUX_S0_Pin, 0); @@ -431,7 +431,7 @@ void carPeriodic() PHAL_writeGPIO(BUZZER_GPIO_Port, BUZZER_Pin, car.buzzer); // mcSetPower(car.torque_r.torque_left, &car.motor_l); // mcSetPower(car.torque_r.torque_right, &car.motor_r); - motorSetTorque(&car.motor_r, car.torque_r.torque_right); + // motorSetTorque(&car.motor_r, car.torque_r.torque_right); motorSetTorque(&car.motor_l, car.torque_r.torque_left); } @@ -450,7 +450,7 @@ void parseMCDataPeriodic(void) // mcPeriodic(&car.motor_r); motorPeriodic(&car.motor_l); - motorPeriodic(&car.motor_r); + // motorPeriodic(&car.motor_r); // setFault(ID_LEFT_MC_CONN_FAULT, car.pchg.pchg_complete && // car.motor_l.motor_state != MC_CONNECTED); diff --git a/source/main_module/main.c b/source/main_module/main.c index 22101a64..22bb7ed5 100644 --- a/source/main_module/main.c +++ b/source/main_module/main.c @@ -32,7 +32,7 @@ GPIOInitConfig_t gpio_config[] = { GPIO_INIT_OUTPUT(BRK_LIGHT_GPIO_Port, BRK_LIGHT_Pin, GPIO_OUTPUT_LOW_SPEED), GPIO_INIT_OUTPUT(BUZZER_GPIO_Port, BUZZER_Pin, GPIO_OUTPUT_LOW_SPEED), GPIO_INIT_INPUT(BRK_BUZZER_STAT_GPIO_Port, BRK_BUZZER_STAT_Pin, GPIO_INPUT_OPEN_DRAIN), - GPIO_INIT_INPUT(TSAL_LVAL_STAT_GPIO_Port, TSAL_LVAL_STAT_Pin, GPIO_INPUT_OPEN_DRAIN), + // GPIO_INIT_INPUT(TSAL_LVAL_STAT_GPIO_Port, TSAL_LVAL_STAT_Pin, GPIO_INPUT_OPEN_DRAIN), // CAN GPIO_INIT_CANRX_PA11, @@ -66,10 +66,10 @@ GPIOInitConfig_t gpio_config[] = { GPIO_INIT_INPUT(PRCHG_STAT_GPIO_Port, PRCHG_STAT_Pin, GPIO_INPUT_OPEN_DRAIN), // Motor Controllers - GPIO_INIT_USART2TX_PA2, - GPIO_INIT_USART2RX_PA3, - GPIO_INIT_USART1TX_PA9, - GPIO_INIT_USART1RX_PA10, + // GPIO_INIT_USART2TX_PA2, + // GPIO_INIT_USART2RX_PA3, + // GPIO_INIT_USART1TX_PA9, + // GPIO_INIT_USART1RX_PA10, // Wheel Speed GPIO_INIT_AF(MOTOR_R_WS_GPIO_Port, MOTOR_R_WS_Pin, MOTOR_R_WS_AF, GPIO_OUTPUT_HIGH_SPEED, GPIO_OUTPUT_OPEN_DRAIN, GPIO_INPUT_PULL_DOWN), @@ -92,52 +92,52 @@ GPIOInitConfig_t gpio_config[] = { /* USART Configuration */ // Left Motor Controller UART -dma_init_t usart_l_tx_dma_config = USART1_TXDMA_CONT_CONFIG(NULL, 1); -dma_init_t usart_l_rx_dma_config = USART1_RXDMA_CONT_CONFIG(NULL, 2); -char usart_l_rx_array[MC_MAX_RX_LENGTH] = {'\0'}; -volatile usart_rx_buf_t huart_l_rx_buf = { - .last_msg_time = 0, .msg_size = MC_MAX_TX_LENGTH, - .last_msg_loc = 0, .last_rx_time = 0, - .rx_buf_size = MC_MAX_RX_LENGTH, .rx_buf = usart_l_rx_array -}; -usart_init_t huart_l = { - .baud_rate = 115200, - .word_length = WORD_8, - .stop_bits = SB_ONE, - .parity = PT_NONE, - .hw_flow_ctl = HW_DISABLE, - .ovsample = OV_16, - .obsample = OB_DISABLE, - .periph = USART1, - .wake_addr = false, - .usart_active_num = USART1_ACTIVE_IDX, - .tx_dma_cfg = &usart_l_tx_dma_config, - .rx_dma_cfg = &usart_l_rx_dma_config -}; +// dma_init_t usart_l_tx_dma_config = USART1_TXDMA_CONT_CONFIG(NULL, 1); +// dma_init_t usart_l_rx_dma_config = USART1_RXDMA_CONT_CONFIG(NULL, 2); +// char usart_l_rx_array[MC_MAX_RX_LENGTH] = {'\0'}; +// volatile usart_rx_buf_t huart_l_rx_buf = { +// .last_msg_time = 0, .msg_size = MC_MAX_TX_LENGTH, +// .last_msg_loc = 0, .last_rx_time = 0, +// .rx_buf_size = MC_MAX_RX_LENGTH, .rx_buf = usart_l_rx_array +// }; +// usart_init_t huart_l = { +// .baud_rate = 115200, +// .word_length = WORD_8, +// .stop_bits = SB_ONE, +// .parity = PT_NONE, +// .hw_flow_ctl = HW_DISABLE, +// .ovsample = OV_16, +// .obsample = OB_DISABLE, +// .periph = USART1, +// .wake_addr = false, +// .usart_active_num = USART1_ACTIVE_IDX, +// .tx_dma_cfg = &usart_l_tx_dma_config, +// .rx_dma_cfg = &usart_l_rx_dma_config +// }; // Right Motor Controller UART -dma_init_t usart_r_tx_dma_config = USART2_TXDMA_CONT_CONFIG(NULL, 1); -dma_init_t usart_r_rx_dma_config = USART2_RXDMA_CONT_CONFIG(NULL, 2); -usart_init_t huart_r = { - .baud_rate = 115200, - .word_length = WORD_8, - .stop_bits = SB_ONE, - .parity = PT_NONE, - .hw_flow_ctl = HW_DISABLE, - .ovsample = OV_16, - .obsample = OB_DISABLE, - .periph = USART2, - .wake_addr = false, - .usart_active_num = USART2_ACTIVE_IDX, - .tx_dma_cfg = &usart_r_tx_dma_config, - .rx_dma_cfg = &usart_r_rx_dma_config -}; -char usart_r_rx_array[MC_MAX_RX_LENGTH] = {'\0'}; -volatile usart_rx_buf_t huart_r_rx_buf = { - .last_msg_time = 0, .msg_size = MC_MAX_TX_LENGTH, - .last_msg_loc = 0, .last_rx_time = 0, - .rx_buf_size = MC_MAX_RX_LENGTH, .rx_buf = usart_r_rx_array -}; +// dma_init_t usart_r_tx_dma_config = USART2_TXDMA_CONT_CONFIG(NULL, 1); +// dma_init_t usart_r_rx_dma_config = USART2_RXDMA_CONT_CONFIG(NULL, 2); +// usart_init_t huart_r = { +// .baud_rate = 115200, +// .word_length = WORD_8, +// .stop_bits = SB_ONE, +// .parity = PT_NONE, +// .hw_flow_ctl = HW_DISABLE, +// .ovsample = OV_16, +// .obsample = OB_DISABLE, +// .periph = USART2, +// .wake_addr = false, +// .usart_active_num = USART2_ACTIVE_IDX, +// .tx_dma_cfg = &usart_r_tx_dma_config, +// .rx_dma_cfg = &usart_r_rx_dma_config +// }; +// char usart_r_rx_array[MC_MAX_RX_LENGTH] = {'\0'}; +// volatile usart_rx_buf_t huart_r_rx_buf = { +// .last_msg_time = 0, .msg_size = MC_MAX_TX_LENGTH, +// .last_msg_loc = 0, .last_rx_time = 0, +// .rx_buf_size = MC_MAX_RX_LENGTH, .rx_buf = usart_r_rx_array +// }; /* ADC Configuration */ ADCInitConfig_t adc_config = { @@ -218,23 +218,23 @@ ClockRateConfig_t clock_config = { void preflightAnimation(void); void preflightChecks(void); void heartBeatLED(); -void usartTxUpdate(void); -void usartIdleIRQ(volatile usart_init_t *huart, volatile usart_rx_buf_t *rx_buf); +// void usartTxUpdate(void); +// void usartIdleIRQ(volatile usart_init_t *huart, volatile usart_rx_buf_t *rx_buf); void send_fault(uint16_t, bool); extern void HardFault_Handler(); void interpretLoadSensor(void); float voltToForce(uint16_t load_read); -q_handle_t q_tx_usart_l; -q_handle_t q_tx_usart_r; +// q_handle_t q_tx_usart_l; +// q_handle_t q_tx_usart_r; uint16_t num_failed_msgs_r; uint16_t num_failed_msgs_l; int main(void){ /* Data Struct Initialization */ - qConstruct(&q_tx_usart_l, MC_MAX_TX_LENGTH); - qConstruct(&q_tx_usart_r, MC_MAX_TX_LENGTH); + // qConstruct(&q_tx_usart_l, MC_MAX_TX_LENGTH); + // qConstruct(&q_tx_usart_r, MC_MAX_TX_LENGTH); /* HAL Initialization */ PHAL_trimHSI(HSI_TRIM_MAIN_MODULE); @@ -248,7 +248,6 @@ int main(void){ } PHAL_writeGPIO(SDC_CTRL_GPIO_Port, SDC_CTRL_Pin, 1); - /* Task Creation */ schedInit(APB1ClockRateHz); configureAnim(preflightAnimation, preflightChecks, 60, 750); @@ -267,7 +266,7 @@ int main(void){ // taskCreate(memFg, MEM_FG_TIME); taskCreateBackground(canTxUpdate); taskCreateBackground(canRxUpdate); - taskCreateBackground(usartTxUpdate); + // taskCreateBackground(usartTxUpdate); // taskCreateBackground(memBg); // uint8_t i = 0; // calibrateSteeringAngle(&i); @@ -285,17 +284,18 @@ void preflightChecks(void) { switch (state++) { + /* TODO: Change this to init AMK CAN */ case 0: - huart_l.rx_dma_cfg->circular = true; - if(!PHAL_initUSART(&huart_l, APB2ClockRateHz)) - { - HardFault_Handler(); - } - huart_r.rx_dma_cfg->circular = true; - if(!PHAL_initUSART(&huart_r, APB1ClockRateHz)) - { - HardFault_Handler(); - } + // huart_l.rx_dma_cfg->circular = true; + // if(!PHAL_initUSART(&huart_l, APB2ClockRateHz)) + // { + // HardFault_Handler(); + // } + // huart_r.rx_dma_cfg->circular = true; + // if(!PHAL_initUSART(&huart_r, APB1ClockRateHz)) + // { + // HardFault_Handler(); + // } break; case 1: if(!PHAL_initCAN(CAN1, false, VCAN_BPS)) @@ -324,12 +324,12 @@ void preflightChecks(void) { break; case 3: // initial rx request - PHAL_usartRxDma(&huart_r, - (uint16_t *) huart_r_rx_buf.rx_buf, - huart_r_rx_buf.rx_buf_size, 1); - PHAL_usartRxDma(&huart_l, - (uint16_t *) huart_l_rx_buf.rx_buf, - huart_l_rx_buf.rx_buf_size, 1); + // PHAL_usartRxDma(&huart_r, + // (uint16_t *) huart_r_rx_buf.rx_buf, + // huart_r_rx_buf.rx_buf_size, 1); + // PHAL_usartRxDma(&huart_l, + // (uint16_t *) huart_l_rx_buf.rx_buf, + // huart_l_rx_buf.rx_buf_size, 1); break; case 4: /* Module Initialization */ @@ -398,57 +398,57 @@ void heartBeatLED(void) /* USART Message Handling */ uint8_t tmp_left[MC_MAX_TX_LENGTH] = {'\0'}; uint8_t tmp_right[MC_MAX_TX_LENGTH] = {'\0'}; -void usartTxUpdate(void) -{ - if (!PHAL_usartTxBusy(&huart_l) && - qReceive(&q_tx_usart_l, tmp_left) == SUCCESS_G) - { - PHAL_usartTxDma(&huart_l, (uint16_t *) tmp_left, strlen(tmp_left)); - } - if (!PHAL_usartTxBusy(&huart_r) && - qReceive(&q_tx_usart_r, tmp_right) == SUCCESS_G) - { - PHAL_usartTxDma(&huart_r, (uint16_t *) tmp_right, strlen(tmp_right)); - } -} - -void usart_recieve_complete_callback(usart_init_t *handle) -{ - if (handle == &huart_r) - { - if (handle->rx_errors.noise_detected) - { - num_failed_msgs_r++; - return; - } - usartIdleIRQ(&huart_r, &huart_r_rx_buf); - } - else if (handle == &huart_l) - { - if (handle->rx_errors.noise_detected) - { - num_failed_msgs_l++; - return; - } - usartIdleIRQ(&huart_l, &huart_l_rx_buf); - } -} - -void usartIdleIRQ(volatile usart_init_t *huart, volatile usart_rx_buf_t *rx_buf) -{ - // TODO: check for overruns, framing errors, etc - uint16_t new_loc = 0; - rx_buf->last_rx_time = sched.os_ticks; - new_loc = rx_buf->rx_buf_size - huart->rx_dma_cfg->stream->NDTR; // extract last location from DMA - if (new_loc == rx_buf->rx_buf_size) new_loc = 0; // should never happen - else if (new_loc < rx_buf->last_rx_loc) new_loc += rx_buf->rx_buf_size; // wrap around - if (new_loc - rx_buf->last_rx_loc > rx_buf->msg_size) // status msg vs just an echo - { - rx_buf->last_msg_time = sched.os_ticks; - rx_buf->last_msg_loc = (rx_buf->last_rx_loc + 1) % rx_buf->rx_buf_size; - } - rx_buf->last_rx_loc = new_loc % rx_buf->rx_buf_size; -} +// void usartTxUpdate(void) +// { +// if (!PHAL_usartTxBusy(&huart_l) && +// qReceive(&q_tx_usart_l, tmp_left) == SUCCESS_G) +// { +// PHAL_usartTxDma(&huart_l, (uint16_t *) tmp_left, strlen(tmp_left)); +// } +// if (!PHAL_usartTxBusy(&huart_r) && +// qReceive(&q_tx_usart_r, tmp_right) == SUCCESS_G) +// { +// PHAL_usartTxDma(&huart_r, (uint16_t *) tmp_right, strlen(tmp_right)); +// } +// } + +// void usart_recieve_complete_callback(usart_init_t *handle) +// { +// if (handle == &huart_r) +// { +// if (handle->rx_errors.noise_detected) +// { +// num_failed_msgs_r++; +// return; +// } +// usartIdleIRQ(&huart_r, &huart_r_rx_buf); +// } +// else if (handle == &huart_l) +// { +// if (handle->rx_errors.noise_detected) +// { +// num_failed_msgs_l++; +// return; +// } +// usartIdleIRQ(&huart_l, &huart_l_rx_buf); +// } +// } + +// void usartIdleIRQ(volatile usart_init_t *huart, volatile usart_rx_buf_t *rx_buf) +// { +// // TODO: check for overruns, framing errors, etc +// uint16_t new_loc = 0; +// rx_buf->last_rx_time = sched.os_ticks; +// new_loc = rx_buf->rx_buf_size - huart->rx_dma_cfg->stream->NDTR; // extract last location from DMA +// if (new_loc == rx_buf->rx_buf_size) new_loc = 0; // should never happen +// else if (new_loc < rx_buf->last_rx_loc) new_loc += rx_buf->rx_buf_size; // wrap around +// if (new_loc - rx_buf->last_rx_loc > rx_buf->msg_size) // status msg vs just an echo +// { +// rx_buf->last_msg_time = sched.os_ticks; +// rx_buf->last_msg_loc = (rx_buf->last_rx_loc + 1) % rx_buf->rx_buf_size; +// } +// rx_buf->last_rx_loc = new_loc % rx_buf->rx_buf_size; +// } #define SCALE_F = (1 + (3.4/6.6)) From c2640349b76c95a8813c338dc922d6dadb65c915 Mon Sep 17 00:00:00 2001 From: Cole Date: Sat, 16 Nov 2024 20:57:19 -0500 Subject: [PATCH 29/36] not too much rn --- common/amk/amk.c | 10 +++++++--- common/amk/amk.h | 3 +++ common/daq/can_config.json | 16 ++++++++-------- source/main_module/main.c | 2 ++ 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/common/amk/amk.c b/common/amk/amk.c index d3fa16fa..5cf94a89 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -23,7 +23,7 @@ * default max velocity limit is ±5000 rpm */ -static amk_motor_t right = {0}; +amk_motor_t right = {0}; static void turnMotorOn(amk_motor_t* motor); static void motorRunning(amk_motor_t* motor); @@ -97,11 +97,13 @@ void motorSetTorque(amk_motor_t* motor, int16_t torque_setpoint) motor->torque_setpoint = torque_setpoint; if (torque_setpoint < 0) { - motor->torque_limit_negative = torque_setpoint; + // motor->torque_limit_negative = torque_setpoint; + motor->torque_limit_negative = 100; motor->torque_limit_positive = 0; } else { - motor->torque_limit_positive = torque_setpoint; + // motor->torque_limit_positive = torque_setpoint; + motor->torque_limit_positive = 100; motor->torque_limit_negative = 0; } @@ -148,6 +150,7 @@ static void motorRunning(amk_motor_t* motor) break; case MOTOR_RUNNING_ERROR: /* 8.2.5 for error diagram */ + /* FIXME: Just send a CAN message or something for now to test */ break; } @@ -238,6 +241,7 @@ static void turnMotorOn(amk_motor_t* motor) case MOTOR_INIT_INVERTER_ON: /* 8 Set AMK_bInverterOn = 1 */ motor->control.fields.AMK_bInverterOn = true; + SEND_AMK_SETPOINTS(motor->control.bits, motor->torque_setpoint, motor->torque_limit_positive, diff --git a/common/amk/amk.h b/common/amk/amk.h index 79790d77..900080ae 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -123,6 +123,9 @@ typedef enum { MOTOR_STAGE_DEINIT } amk_motor_stage_t; +extern amk_motor_t right; +extern amk_motor_t left; + #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 670494b8..ea5e2652 100644 --- a/common/daq/can_config.json +++ b/common/daq/can_config.json @@ -208,7 +208,7 @@ {"sig_name": "AMK_NegativeTorqueLimit", "sig_desc": "Negative Torque Limit", "type":"int16_t", "unit":"Nm", "scale":0.1} ], "msg_period": 5, - "msg_id_override": "0x184" + "msg_id_override": "0x182" }, { "msg_name": "AMK_Testing", @@ -242,7 +242,7 @@ {"sig_name": "AMK_MotorSerialNumber", "sig_desc": "Serial number of the motor", "type":"uint32_t"} ], "msg_period": 5, - "msg_id_override": "0x283" + "msg_id_override": "0x282" }, { "msg_name": "AMK_Actual_Values_2", @@ -264,7 +264,7 @@ {"sig_name": "AMK_IGBTTemp", "sig_desc": "IGBT temperature", "type":"int16_t", "unit":"C", "scale":0.1} ], "msg_period": 5, - "msg_id_override": "0x285" + "msg_id_override": "0x286" }, { "msg_name": "AMK_Temperatures_2", @@ -275,7 +275,7 @@ {"sig_name": "AMK_TempSensorMotor", "sig_desc": "???", "type":"int16_t", "unit":"C", "scale":0.1} ], "msg_period": 5, - "msg_id_override": "0x286" + "msg_id_override": "0x288" } ] }, @@ -1080,7 +1080,7 @@ {"sig_name": "AMK_MotorSerialNumber", "sig_desc": "Serial number of the motor", "type":"uint32_t"} ], "msg_period": 5, - "msg_id_override": "0x283" + "msg_id_override": "0x282" }, { "msg_name": "AMK_Actual_Values_2", @@ -1102,7 +1102,7 @@ {"sig_name": "AMK_IGBTTemp", "sig_desc": "IGBT temperature", "type":"int16_t", "unit":"C", "scale":0.1} ], "msg_period": 5, - "msg_id_override": "0x285" + "msg_id_override": "0x286" }, { "msg_name": "AMK_Temperatures_2", @@ -1113,7 +1113,7 @@ {"sig_name": "AMK_TempSensorMotor", "sig_desc": "???", "type":"int16_t", "unit":"C", "scale":0.1} ], "msg_period": 5, - "msg_id_override": "0x286" + "msg_id_override": "0x288" } ], "rx": [ @@ -1127,7 +1127,7 @@ {"sig_name": "AMK_NegativeTorqueLimit", "sig_desc": "Negative Torque Limit", "type":"int16_t", "unit":"Nm", "scale":0.1} ], "msg_period": 5, - "msg_id_override": "0x184" + "msg_id_override": "0x182" }, { "msg_name": "AMK_Testing", diff --git a/source/main_module/main.c b/source/main_module/main.c index 22bb7ed5..f3f966c7 100644 --- a/source/main_module/main.c +++ b/source/main_module/main.c @@ -14,6 +14,7 @@ #include "common/plettenberg/plettenberg.h" #include "common/psched/psched.h" #include "common/queue/queue.h" +#include "common/amk/amk.h" /* Module Includes */ #include "car.h" @@ -274,6 +275,7 @@ int main(void){ // SEND_LWS_CONFIG(0x05, 0, 0); // reset cal // SEND_LWS_CONFIG(0x03, 0, 0); // start new + motorSetTorque(&right, 100); schedStart(); return 0; From dea5733e126521d5051b590b04099af5c66b7980 Mon Sep 17 00:00:00 2001 From: Cole Date: Sat, 16 Nov 2024 21:40:11 -0500 Subject: [PATCH 30/36] Some additions based on the meeting we had with UIUC --- common/amk/amk.c | 51 ++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/common/amk/amk.c b/common/amk/amk.c index 5cf94a89..dcf6fa64 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -1,14 +1,6 @@ #include "amk.h" #include "source/main_module/can/can_parse.h" -/* 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 motor->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 think this is actually step 2) @@ -19,23 +11,17 @@ * Not sure if I need that */ -/* NOTE: Page 36 says max velocity is 6000 rpm. But page 37 says that the - * default max velocity limit is ±5000 rpm */ - - amk_motor_t right = {0}; static void turnMotorOn(amk_motor_t* motor); static void motorRunning(amk_motor_t* motor); static void turnMotorOff(amk_motor_t* motor); static void motorGetData(amk_motor_t* motor); +static void motorReset(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 * this may end up being deleted if everything just inits to 0 */ - -/* FIXME: Move motor->control word and status words into motor struct */ - void motorInit(amk_motor_t* motor, bool* pchg_complete) { *motor = (amk_motor_t){ @@ -43,7 +29,7 @@ void motorInit(amk_motor_t* motor, bool* pchg_complete) .states.stage = MOTOR_STAGE_INIT, .states.init_stage = MOTOR_INIT_POWER_ON, .states.deinit_stage = MOTOR_DEINIT_SETPOINTS_DEINIT, - .states.running_stage = 0, /* FIXME: FILL IN ONCE I MAKE ENUM */ + .states.running_stage = MOTOR_RUNNING_GOOD, /* Values */ .torque_setpoint = DEFAULT_TORQUE_SETPOINT, @@ -54,16 +40,15 @@ void motorInit(amk_motor_t* motor, bool* pchg_complete) }; } -/* TODO: Determine period of this. Should be pretty often of course. The control - * word needs to be sent every 50ms or the motors will shut off. Plettenberg did - * every 15ms so maybe we will just do that? - */ - void amkCanTesting(amk_motor_t* motor) { SEND_AMK_TESTING(motor->states.init_stage, motor->control.bits, motor->status.bits, *motor->pchg_complete); } +/* TODO: Determine period of this. Should be pretty often of course. The control + * word needs to be sent every 50ms or the motors will shut off. Plettenberg did + * every 15ms so maybe we will just do that? + */ void motorPeriodic(amk_motor_t* motor) { motorGetData(motor); @@ -97,14 +82,17 @@ void motorSetTorque(amk_motor_t* motor, int16_t torque_setpoint) motor->torque_setpoint = torque_setpoint; if (torque_setpoint < 0) { - // motor->torque_limit_negative = torque_setpoint; - motor->torque_limit_negative = 100; + motor->torque_limit_negative = -100; motor->torque_limit_positive = 0; } else { - // motor->torque_limit_positive = torque_setpoint; - motor->torque_limit_positive = 100; - motor->torque_limit_negative = 0; + /* FIXME: Was told 9.8Nm is nominal, and to set to limit to 17Nm for now, + * but in the mean time I am going to go less than 100% as I am unsure */ + motor->torque_limit_positive = 500; + + /* FIXME: Should this actually be negative? */ + /* NOTE: For some reason it cannot be 0, so do -0.1% (according to UIUC's team) */ + motor->torque_limit_negative = -1; } } @@ -130,6 +118,11 @@ static void motorGetData(amk_motor_t* motor) } } +static void motorReset(amk_motor_t* motor) +{ + /* State machine here based on 8.2.6 */ +} + /* TODO: Not really sure what needs to be done here. We just need to push * these values that are determined in car.c state machine (READY2DRIVE state) */ @@ -149,8 +142,10 @@ static void motorRunning(amk_motor_t* motor) break; case MOTOR_RUNNING_ERROR: - /* 8.2.5 for error diagram */ - /* FIXME: Just send a CAN message or something for now to test */ + /* FIXME: We should also send a message to dash, so we can see + * when this happens, or do we just latch an error in the fault + * library? */ + motorReset(motor); break; } From 7dbb3a2348bccbc36a52a815db516082831b3f71 Mon Sep 17 00:00:00 2001 From: Cole Date: Sun, 17 Nov 2024 11:55:14 -0500 Subject: [PATCH 31/36] Adding error handling stuff, no idea if its gonna work. Just like everything else --- common/amk/amk.c | 51 ++++++++++++++++++++++++++++-- common/amk/amk.h | 10 ++++++ common/daq/can_config.json | 6 ++-- common/daq/per_dbc.dbc | 44 ++++++++++++++------------ source/f4_testing/can/can_parse.h | 14 ++++---- source/main_module/can/can_parse.c | 1 + source/main_module/can/can_parse.h | 12 ++++--- 7 files changed, 102 insertions(+), 36 deletions(-) diff --git a/common/amk/amk.c b/common/amk/amk.c index dcf6fa64..a8c93629 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -30,6 +30,7 @@ void motorInit(amk_motor_t* motor, bool* pchg_complete) .states.init_stage = MOTOR_INIT_POWER_ON, .states.deinit_stage = MOTOR_DEINIT_SETPOINTS_DEINIT, .states.running_stage = MOTOR_RUNNING_GOOD, + .states.reset_state = MOTOR_RESET_INVERTER_OFF, /* Values */ .torque_setpoint = DEFAULT_TORQUE_SETPOINT, @@ -84,8 +85,7 @@ void motorSetTorque(amk_motor_t* motor, int16_t torque_setpoint) if (torque_setpoint < 0) { motor->torque_limit_negative = -100; motor->torque_limit_positive = 0; - } - else { + } else { /* FIXME: Was told 9.8Nm is nominal, and to set to limit to 17Nm for now, * but in the mean time I am going to go less than 100% as I am unsure */ motor->torque_limit_positive = 500; @@ -109,6 +109,8 @@ static void motorGetData(amk_motor_t* motor) motor->actual_speed = can_data.AMK_Actual_Values_2.AMK_ActualSpeed; motor->dc_bus_voltage = can_data.AMK_Actual_Values_2.AMK_DCBusVoltage; motor->system_reset = can_data.AMK_Actual_Values_2.AMK_SystemReset; + /* FIXME: Will this grab diagnostic number in time? It should? */ + motor->diagnostic_num = can_data.AMK_Actual_Values_2.AMK_DiagnosticNumber; } if (!can_data.AMK_Temperatures_1.stale) { @@ -121,6 +123,49 @@ static void motorGetData(amk_motor_t* motor) static void motorReset(amk_motor_t* motor) { /* State machine here based on 8.2.6 */ + switch (motor->states.reset_state) { + case MOTOR_RESET_INVERTER_OFF: + /* 1. Set AMK_bInverterOn = 0 */ + motor->control.fields.AMK_bInverterOn = false; + + SEND_AMK_SETPOINTS(motor->control.bits, + motor->torque_setpoint, + motor->torque_limit_positive, + motor->torque_limit_negative); + + motor->states.reset_state = MOTOR_RESET_ERROR_RESET_ON; + + break; + case MOTOR_RESET_ERROR_RESET_ON: + motor->control.fields.AMK_bErrorReset = true; + + SEND_AMK_SETPOINTS(motor->control.bits, + 0, + 0, + 0); + + motor->states.reset_state = MOTOR_RESET_ERROR_RESET_OFF; + + break; + case MOTOR_RESET_ERROR_RESET_OFF: + motor->control.fields.AMK_bErrorReset = false; + + SEND_AMK_SETPOINTS(motor->control.bits, + 0, + 0, + 0); + + motor->states.reset_state = MOTOR_RESET_CHECK_SYSTEM_READY; + + break; + case MOTOR_RESET_CHECK_SYSTEM_READY: + if (motor->status.fields.AMK_bSystemReady) { + motor->states.reset_state = MOTOR_RESET_INVERTER_OFF; + motor->states.running_stage = MOTOR_RUNNING_GOOD; + } + + break; + } } /* TODO: Not really sure what needs to be done here. We just need to push @@ -169,6 +214,7 @@ static void turnMotorOn(amk_motor_t* motor) /* 1r. Check AMK_bSystemReady = 1*/ if (motor->status.fields.AMK_bSystemReady) motor->states.init_stage = MOTOR_INIT_PRECHARGE; + break; case MOTOR_INIT_PRECHARGE: /* 2. Charge DC caps; QUE should be set (is this just DcOn?) */ @@ -243,6 +289,7 @@ static void turnMotorOn(amk_motor_t* motor) motor->torque_limit_negative); 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 */ diff --git a/common/amk/amk.h b/common/amk/amk.h index 900080ae..a2a8498a 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -54,6 +54,7 @@ typedef struct { uint8_t running_stage; uint8_t init_stage; uint8_t deinit_stage; + uint8_t reset_state; } amk_motor_states_t; typedef struct { @@ -80,6 +81,8 @@ typedef struct { uint16_t dc_bus_voltage; uint16_t system_reset; + uint16_t diagnostic_num; + bool* pchg_complete; } amk_motor_t; @@ -116,6 +119,13 @@ typedef enum { MOTOR_RUNNING_ERROR, } amk_motor_running_state_t; +typedef enum { + MOTOR_RESET_INVERTER_OFF = 0, + MOTOR_RESET_ERROR_RESET_ON, + MOTOR_RESET_ERROR_RESET_OFF, + MOTOR_RESET_CHECK_SYSTEM_READY, +} amk_motor_reset_state_t; + typedef enum { MOTOR_STAGE_OFF = 0, MOTOR_STAGE_INIT, diff --git a/common/daq/can_config.json b/common/daq/can_config.json index ea5e2652..8959f019 100644 --- a/common/daq/can_config.json +++ b/common/daq/can_config.json @@ -250,7 +250,8 @@ "signals": [ {"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"} + {"sig_name": "AMK_SystemReset", "sig_desc": "System reset", "type":"uint16_t"}, + {"sig_name": "AMK_DiagnosticNumber", "sig_desc": "Error number", "type":"uint16_t"} ], "msg_period": 5, "msg_id_override": "0x284" @@ -1088,7 +1089,8 @@ "signals": [ {"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"} + {"sig_name": "AMK_SystemReset", "sig_desc": "System reset", "type":"uint16_t"}, + {"sig_name": "AMK_DiagnosticNumber", "sig_desc": "Error number", "type":"uint16_t"} ], "msg_period": 5, "msg_id_override": "0x284" diff --git a/common/daq/per_dbc.dbc b/common/daq/per_dbc.dbc index 8a9bb14b..1a0b6f63 100644 --- a/common/daq/per_dbc.dbc +++ b/common/daq/per_dbc.dbc @@ -121,7 +121,7 @@ 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: 8 Main_Module +BO_ 2147484034 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 @@ -482,22 +482,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_ 2147484291 AMK_Actual_Values_1: 8 Inverter1 +BO_ 2147484290 AMK_Actual_Values_1: 8 Inverter1 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_ 2147484292 AMK_Actual_Values_2: 6 Inverter1 +BO_ 2147484292 AMK_Actual_Values_2: 8 Inverter1 + SG_ AMK_DiagnosticNumber : 48|16@1+ (1,0) [0|0] "" Vector__XXX 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_ 2147484293 AMK_Temperatures_1: 6 Inverter1 +BO_ 2147484294 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 +BO_ 2147484296 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 @@ -745,11 +746,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 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_ 2147484034 "Contains control word and setpoints"; +CM_ SG_ 2147484034 AMK_NegativeTorqueLimit "Negative Torque Limit"; +CM_ SG_ 2147484034 AMK_PositiveTorqueLimit "Positive Torque Limit"; +CM_ SG_ 2147484034 AMK_TorqueSetpoint "Torque setpoint"; +CM_ SG_ 2147484034 AMK_Control "Control word"; CM_ BO_ 2147484548 "Contains control word and setpoints"; CM_ SG_ 2147484548 precharge "Control word"; CM_ SG_ 2147484548 AMK_Status_from_motor "Control word"; @@ -1039,22 +1040,23 @@ CM_ SG_ 2217793020 cmd ""; 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_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_ 2147484290 "Contains the status word and actual values"; +CM_ SG_ 2147484290 AMK_MotorSerialNumber "Serial number of the motor"; +CM_ SG_ 2147484290 AMK_ActualTorque "Actual torque value"; +CM_ SG_ 2147484290 AMK_Status "Status word, bit field"; CM_ BO_ 2147484292 "Contains actual values"; +CM_ SG_ 2147484292 AMK_DiagnosticNumber "Error number"; 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_ SG_ 2147484294 AMK_IGBTTemp "IGBT temperature"; +CM_ SG_ 2147484294 AMK_InverterTemp "Inverter cold plate temperature"; +CM_ SG_ 2147484294 AMK_MotorTemp "Motor temperature"; +CM_ BO_ 2147484296 "Contains temperatures"; +CM_ SG_ 2147484296 AMK_TempSensorMotor "???"; +CM_ SG_ 2147484296 AMK_ExternalTemp "External temperature"; +CM_ SG_ 2147484296 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/source/f4_testing/can/can_parse.h b/source/f4_testing/can/can_parse.h index bc6252db..6aeb8623 100644 --- a/source/f4_testing/can/can_parse.h +++ b/source/f4_testing/can/can_parse.h @@ -30,18 +30,18 @@ typedef union { // Message ID definitions /* BEGIN AUTO ID DEFS */ -#define ID_AMK_ACTUAL_VALUES_1 0x283 +#define ID_AMK_ACTUAL_VALUES_1 0x282 #define ID_AMK_ACTUAL_VALUES_2 0x284 -#define ID_AMK_TEMPERATURES_1 0x285 -#define ID_AMK_TEMPERATURES_2 0x286 -#define ID_AMK_SETPOINTS 0x184 +#define ID_AMK_TEMPERATURES_1 0x286 +#define ID_AMK_TEMPERATURES_2 0x288 +#define ID_AMK_SETPOINTS 0x182 #define ID_AMK_TESTING 0x384 /* END AUTO ID DEFS */ // Message DLC definitions /* BEGIN AUTO DLC DEFS */ #define DLC_AMK_ACTUAL_VALUES_1 8 -#define DLC_AMK_ACTUAL_VALUES_2 6 +#define DLC_AMK_ACTUAL_VALUES_2 8 #define DLC_AMK_TEMPERATURES_1 6 #define DLC_AMK_TEMPERATURES_2 6 #define DLC_AMK_SETPOINTS 8 @@ -58,12 +58,13 @@ typedef union { 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 {\ +#define SEND_AMK_ACTUAL_VALUES_2(AMK_ActualSpeed_, AMK_DCBusVoltage_, AMK_SystemReset_, AMK_DiagnosticNumber_) 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_ActualSpeed = AMK_ActualSpeed_;\ data_a->AMK_Actual_Values_2.AMK_DCBusVoltage = AMK_DCBusVoltage_;\ data_a->AMK_Actual_Values_2.AMK_SystemReset = AMK_SystemReset_;\ + data_a->AMK_Actual_Values_2.AMK_DiagnosticNumber = AMK_DiagnosticNumber_;\ canTxSendToBack(&msg);\ } while(0) #define SEND_AMK_TEMPERATURES_1(AMK_MotorTemp_, AMK_InverterTemp_, AMK_IGBTTemp_) do {\ @@ -109,6 +110,7 @@ typedef union { uint64_t AMK_ActualSpeed: 16; uint64_t AMK_DCBusVoltage: 16; uint64_t AMK_SystemReset: 16; + uint64_t AMK_DiagnosticNumber: 16; } AMK_Actual_Values_2; struct { uint64_t AMK_MotorTemp: 16; diff --git a/source/main_module/can/can_parse.c b/source/main_module/can/can_parse.c index 939cce54..1e619b4e 100644 --- a/source/main_module/can/can_parse.c +++ b/source/main_module/can/can_parse.c @@ -102,6 +102,7 @@ void canRxUpdate(void) 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.AMK_DiagnosticNumber = msg_data_a->AMK_Actual_Values_2.AMK_DiagnosticNumber; can_data.AMK_Actual_Values_2.stale = 0; can_data.AMK_Actual_Values_2.last_rx = sched.os_ticks; break; diff --git a/source/main_module/can/can_parse.h b/source/main_module/can/can_parse.h index 74ecb630..215c41d8 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 0x184 +#define ID_AMK_SETPOINTS 0x182 #define ID_AMK_TESTING 0x384 #define ID_FAULT_SYNC_MAIN_MODULE 0x8ca01 #define ID_DAQ_RESPONSE_MAIN_MODULE 0x17ffffc1 @@ -57,10 +57,10 @@ 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_1 0x282 #define ID_AMK_ACTUAL_VALUES_2 0x284 -#define ID_AMK_TEMPERATURES_1 0x285 -#define ID_AMK_TEMPERATURES_2 0x286 +#define ID_AMK_TEMPERATURES_1 0x286 +#define ID_AMK_TEMPERATURES_2 0x288 #define ID_FAULT_SYNC_PDU 0x8cb1f #define ID_FAULT_SYNC_DASHBOARD 0x8cac5 #define ID_FAULT_SYNC_A_BOX 0x8ca44 @@ -101,7 +101,7 @@ 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 6 +#define DLC_AMK_ACTUAL_VALUES_2 8 #define DLC_AMK_TEMPERATURES_1 6 #define DLC_AMK_TEMPERATURES_2 6 #define DLC_FAULT_SYNC_PDU 3 @@ -515,6 +515,7 @@ typedef union { uint64_t AMK_ActualSpeed: 16; uint64_t AMK_DCBusVoltage: 16; uint64_t AMK_SystemReset: 16; + uint64_t AMK_DiagnosticNumber: 16; } AMK_Actual_Values_2; struct { uint64_t AMK_MotorTemp: 16; @@ -631,6 +632,7 @@ typedef struct { int16_t AMK_ActualSpeed; uint16_t AMK_DCBusVoltage; uint16_t AMK_SystemReset; + uint16_t AMK_DiagnosticNumber; uint8_t stale; uint32_t last_rx; } AMK_Actual_Values_2; From b82f602b7be49fa8c3c2720f5a3839b8d9cb633d Mon Sep 17 00:00:00 2001 From: Cole Date: Sun, 17 Nov 2024 12:18:21 -0500 Subject: [PATCH 32/36] Motors are in the car struct --- common/amk/amk.c | 2 -- common/amk/amk.h | 3 --- 2 files changed, 5 deletions(-) diff --git a/common/amk/amk.c b/common/amk/amk.c index a8c93629..7d09e14d 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -11,8 +11,6 @@ * Not sure if I need that */ -amk_motor_t right = {0}; - static void turnMotorOn(amk_motor_t* motor); static void motorRunning(amk_motor_t* motor); static void turnMotorOff(amk_motor_t* motor); diff --git a/common/amk/amk.h b/common/amk/amk.h index a2a8498a..b66e0a1b 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -133,9 +133,6 @@ typedef enum { MOTOR_STAGE_DEINIT } amk_motor_stage_t; -extern amk_motor_t right; -extern amk_motor_t left; - #define DEFAULT_TORQUE_SETPOINT 0 #define DEFAULT_POSITIVE_TORQUE_LIMIT 0 #define DEFAULT_NEGATIVE_TORQUE_LIMIT 0 From 3a8ad12e39acb3d9978d03899029c6de8e37613e Mon Sep 17 00:00:00 2001 From: Cole Date: Sun, 17 Nov 2024 12:21:27 -0500 Subject: [PATCH 33/36] Don't even know why that was there --- source/main_module/main.c | 1 - 1 file changed, 1 deletion(-) diff --git a/source/main_module/main.c b/source/main_module/main.c index f3f966c7..15a815c9 100644 --- a/source/main_module/main.c +++ b/source/main_module/main.c @@ -275,7 +275,6 @@ int main(void){ // SEND_LWS_CONFIG(0x05, 0, 0); // reset cal // SEND_LWS_CONFIG(0x03, 0, 0); // start new - motorSetTorque(&right, 100); schedStart(); return 0; From 6b379f70ee8632546c8f1d3dc73c381990a83298 Mon Sep 17 00:00:00 2001 From: Cole Date: Wed, 20 Nov 2024 21:22:08 -0500 Subject: [PATCH 34/36] Some review stuff --- CMakeLists.txt | 1 - common/amk/amk.c | 21 ++++++++++++++------- common/amk/amk.h | 15 +++++++-------- source/f4_testing/main.c | 3 +-- source/main_module/car/car.h | 2 -- 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 014de838..7e40e7a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -58,7 +58,6 @@ add_subdirectory(common/common_defs) add_subdirectory(common/log) add_subdirectory(common/faults) add_subdirectory(common/daq) -# add_subdirectory(common/plettenberg) add_subdirectory(common/amk) add_subdirectory(common/modules/wheel_speeds) add_subdirectory(common/modules/Wiznet) diff --git a/common/amk/amk.c b/common/amk/amk.c index 7d09e14d..ea7f5cef 100644 --- a/common/amk/amk.c +++ b/common/amk/amk.c @@ -72,8 +72,9 @@ void motorPeriodic(amk_motor_t* motor) void motorSetTorque(amk_motor_t* motor, int16_t torque_setpoint) { if (torque_setpoint > MAX_POSITIVE_TORQUE_SETPOINT - || torque_setpoint < MAX_NEGATIVE_TORQUE_SETPOINT) + || torque_setpoint < MAX_NEGATIVE_TORQUE_SETPOINT) { return; + } /* Scale up since unit is 0.1% of nominal torque */ torque_setpoint *= 10; @@ -180,8 +181,9 @@ static void motorRunning(amk_motor_t* motor) motor->torque_limit_negative); /* Check for errors */ - if (motor->status.fields.AMK_bError) + if (motor->status.fields.AMK_bError) { motor->states.running_stage = MOTOR_RUNNING_ERROR; + } break; case MOTOR_RUNNING_ERROR: @@ -210,8 +212,9 @@ 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 (motor->status.fields.AMK_bSystemReady) + if (motor->status.fields.AMK_bSystemReady) { motor->states.init_stage = MOTOR_INIT_PRECHARGE; + } break; case MOTOR_INIT_PRECHARGE: @@ -223,8 +226,9 @@ static void turnMotorOn(amk_motor_t* motor) /* if precharge complete pin is high */ /* 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 (*motor->pchg_complete) + if (*motor->pchg_complete) { motor->states.init_stage = MOTOR_INIT_DC_ON; + } break; case MOTOR_INIT_DC_ON: @@ -246,8 +250,9 @@ static void turnMotorOn(amk_motor_t* motor) /* 3r. (QUE & AMK_bDcOn) -> Check AMK_bQuitDcOn = 1 */ /* Does where do I check QUE??? */ - if (motor->status.fields.AMK_bQuitDcOn) + if (motor->status.fields.AMK_bQuitDcOn) { motor->states.init_stage = MOTOR_INIT_TORQUE_INIT; + } break; case MOTOR_INIT_TORQUE_INIT: @@ -394,8 +399,9 @@ static void turnMotorOff(amk_motor_t* motor) /* 3r. (QUE & AMK_bDcOn) -> Check AMK_bQuitDcOn = 1 */ /* Does where do I check QUE??? */ - if (!(motor->status.fields.AMK_bQuitDcOn)) + if (!(motor->status.fields.AMK_bQuitDcOn)) { motor->states.init_stage = MOTOR_INIT_TORQUE_INIT; + } motor->states.deinit_stage = MOTOR_DEINIT_PRECHARGE; @@ -404,8 +410,9 @@ static void turnMotorOff(amk_motor_t* motor) /* 7. Discharge DC caps; QUE should be reset (is this just DcOn?) */ /* FIXME: Will this work? Not sure if this goes low when discharged */ - if (!(*motor->pchg_complete)) + if (!(*motor->pchg_complete)) { motor->states.init_stage = MOTOR_DEINIT_POWER_OFF; + } /* If discharged, move on */ motor->states.deinit_stage = MOTOR_DEINIT_POWER_OFF; diff --git a/common/amk/amk.h b/common/amk/amk.h index b66e0a1b..bb1b7fd4 100644 --- a/common/amk/amk.h +++ b/common/amk/amk.h @@ -49,7 +49,6 @@ typedef union } AMK_Control_t; typedef struct { - // uint8_t state; uint8_t stage; uint8_t running_stage; uint8_t init_stage; @@ -133,13 +132,13 @@ typedef enum { MOTOR_STAGE_DEINIT } amk_motor_stage_t; -#define DEFAULT_TORQUE_SETPOINT 0 -#define DEFAULT_POSITIVE_TORQUE_LIMIT 0 -#define DEFAULT_NEGATIVE_TORQUE_LIMIT 0 +#define DEFAULT_TORQUE_SETPOINT (0) +#define DEFAULT_POSITIVE_TORQUE_LIMIT (0) +#define DEFAULT_NEGATIVE_TORQUE_LIMIT (0) -#define MAX_POSITIVE_TORQUE_SETPOINT 1000 -#define MAX_NEGATIVE_TORQUE_SETPOINT -1000 -#define MAX_POSITIVE_TORQUE_LIMIT 1000 -#define MAX_NEGATIVE_TORQUE_LIMIT -1000 +#define MAX_POSITIVE_TORQUE_SETPOINT (1000) +#define MAX_NEGATIVE_TORQUE_SETPOINT (-1000) +#define MAX_POSITIVE_TORQUE_LIMIT (1000) +#define MAX_NEGATIVE_TORQUE_LIMIT (-1000) #endif /* _AMK_H_ */ diff --git a/source/f4_testing/main.c b/source/f4_testing/main.c index 584060b6..a39b2e24 100644 --- a/source/f4_testing/main.c +++ b/source/f4_testing/main.c @@ -65,7 +65,6 @@ GPIOInitConfig_t gpio_config[] = { 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, @@ -215,4 +214,4 @@ void HardFault_Handler() { __asm__("nop"); } -} \ No newline at end of file +} diff --git a/source/main_module/car/car.h b/source/main_module/car/car.h index 486b42de..a6ef4fd5 100644 --- a/source/main_module/car/car.h +++ b/source/main_module/car/car.h @@ -81,8 +81,6 @@ typedef struct typedef struct { car_state_t state; - // motor_t motor_l; - // motor_t motor_r; amk_motor_t motor_l; amk_motor_t motor_r; From c41eb3a201ad77c255a2880c8918bb4dd5ebbe1e Mon Sep 17 00:00:00 2001 From: Cole Date: Fri, 6 Dec 2024 16:58:02 -0500 Subject: [PATCH 35/36] trying to do can2 but cannable isn't working? --- common/daq/can_parse_base.c | 41 +++++++++++++++++++++++++++++-------- common/daq/can_parse_base.h | 1 + source/main_module/main.c | 38 ++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+), 9 deletions(-) diff --git a/common/daq/can_parse_base.c b/common/daq/can_parse_base.c index 4bc682a0..749c1cf1 100644 --- a/common/daq/can_parse_base.c +++ b/common/daq/can_parse_base.c @@ -8,16 +8,21 @@ can_stats_t can_stats; // TODO: support CAN2 +// CAN2 cannot happen in here, move it over to MAIN stuff q_handle_t q_tx_can1_s[CAN_TX_MAILBOX_CNT]; +q_handle_t q_tx_can2_s[CAN_TX_MAILBOX_CNT]; q_handle_t q_rx_can; -uint32_t mbx_last_send_time[CAN_TX_MAILBOX_CNT]; +uint32_t can1_mbx_last_send_time[CAN_TX_MAILBOX_CNT]; +uint32_t can2_mbx_last_send_time[CAN_TX_MAILBOX_CNT]; void initCANParseBase() { for (uint8_t i = 0; i < CAN_TX_MAILBOX_CNT; ++i) { qConstruct(&q_tx_can1_s[i], sizeof(CanMsgTypeDef_t)); - mbx_last_send_time[i] = 0; + qConstruct(&q_tx_can2_s[i], sizeof(CanMsgTypeDef_t)); + can1_mbx_last_send_time[i] = 0; + can2_mbx_last_send_time[i] = 0; } qConstruct(&q_rx_can, sizeof(CanMsgTypeDef_t)); can_stats = (can_stats_t){0}; @@ -33,20 +38,38 @@ void canTxSendToBack(CanMsgTypeDef_t *msg) { case 0: case 1: - qh = &q_tx_can1_s[0]; + if (msg->Bus == CAN1) { + qh = &q_tx_can1_s[0]; + } else { + qh = &q_tx_can2_s[0]; + } break; case 2: case 3: - qh = &q_tx_can1_s[1]; + if (msg->Bus == CAN1) { + qh = &q_tx_can1_s[1]; + } else { + qh = &q_tx_can2_s[1]; + } break; default: - qh = &q_tx_can1_s[2]; + if (msg->Bus == CAN1) { + qh = &q_tx_can1_s[2]; + } else { + qh = &q_tx_can2_s[2]; + } break; } } else { - qh = &q_tx_can1_s[0]; // IDE = 0 doesn't have an HLP + // IDE = 0 doesn't have an HLP + if (msg->Bus == CAN1) { + qh = &q_tx_can1_s[0]; + } else { + qh = &q_tx_can2_s[0]; + } + // qh = &q_tx_can1_s[0]; // IDE = 0 doesn't have an HLP } if (qSendToBack(qh, msg) != SUCCESS_G) { @@ -66,10 +89,10 @@ void canTxUpdate(void) if (qReceive(&q_tx_can1_s[i], &tx_msg) == SUCCESS_G) // Check queue for items and take if there is one { PHAL_txCANMessage(&tx_msg, i); - mbx_last_send_time[i] = sched.os_ticks; + can1_mbx_last_send_time[i] = sched.os_ticks; } } - else if (sched.os_ticks - mbx_last_send_time[i] > CAN_TX_TIMEOUT_MS) + else if (sched.os_ticks - can1_mbx_last_send_time[i] > CAN_TX_TIMEOUT_MS) { PHAL_txCANAbort(CAN1, i); // aborts tx and empties the mailbox can_stats.tx_fail++; @@ -124,4 +147,4 @@ void canParseIRQHandler(CAN_TypeDef *can_h) can_stats.rx_of++; } } -} \ No newline at end of file +} diff --git a/common/daq/can_parse_base.h b/common/daq/can_parse_base.h index 76373e85..df7b3817 100644 --- a/common/daq/can_parse_base.h +++ b/common/daq/can_parse_base.h @@ -33,6 +33,7 @@ typedef struct { extern can_stats_t can_stats; extern q_handle_t q_tx_can1_s[CAN_TX_MAILBOX_CNT ]; +extern q_handle_t q_tx_can2_s[CAN_TX_MAILBOX_CNT ]; extern q_handle_t q_rx_can; void initCANParseBase(); diff --git a/source/main_module/main.c b/source/main_module/main.c index 15a815c9..a3ff8a31 100644 --- a/source/main_module/main.c +++ b/source/main_module/main.c @@ -16,6 +16,9 @@ #include "common/queue/queue.h" #include "common/amk/amk.h" +/* TODO: Move CAN2 stuff here since can parse base is dumb */ +#include "common/phal_F4_F7/can/can.h" + /* Module Includes */ #include "car.h" #include "can_parse.h" @@ -232,6 +235,30 @@ float voltToForce(uint16_t load_read); uint16_t num_failed_msgs_r; uint16_t num_failed_msgs_l; +extern q_handle_t q_tx_can2_s[CAN_TX_MAILBOX_CNT]; +extern uint32_t can2_mbx_last_send_time[CAN_TX_MAILBOX_CNT]; + +void can2TxUpdate(void) +{ + CanMsgTypeDef_t tx_msg; + for (uint8_t i = 0; i < CAN_TX_MAILBOX_CNT; ++i) + { + if(PHAL_txMailboxFree(CAN2, i)) + { + if (qReceive(&q_tx_can2_s[i], &tx_msg) == SUCCESS_G) // Check queue for items and take if there is one + { + PHAL_txCANMessage(&tx_msg, i); + can2_mbx_last_send_time[i] = sched.os_ticks; + } + } + else if (sched.os_ticks - can2_mbx_last_send_time[i] > CAN_TX_TIMEOUT_MS) + { + PHAL_txCANAbort(CAN2, i); // aborts tx and empties the mailbox + can_stats.tx_fail++; + } + } +} + int main(void){ /* Data Struct Initialization */ // qConstruct(&q_tx_usart_l, MC_MAX_TX_LENGTH); @@ -266,6 +293,7 @@ int main(void){ taskCreate(daqPeriodic, DAQ_UPDATE_PERIOD); // taskCreate(memFg, MEM_FG_TIME); taskCreateBackground(canTxUpdate); + // taskCreateBackground(can2TxUpdate); taskCreateBackground(canRxUpdate); // taskCreateBackground(usartTxUpdate); // taskCreateBackground(memBg); @@ -287,6 +315,11 @@ void preflightChecks(void) { { /* TODO: Change this to init AMK CAN */ case 0: + if(!PHAL_initCAN(CAN2, false, VCAN_BPS)) + { + HardFault_Handler(); + } + NVIC_EnableIRQ(CAN2_RX0_IRQn); // huart_l.rx_dma_cfg->circular = true; // if(!PHAL_initUSART(&huart_l, APB2ClockRateHz)) // { @@ -493,6 +526,11 @@ void CAN1_RX0_IRQHandler() canParseIRQHandler(CAN1); } +void CAN2_RX0_IRQHandler() +{ + canParseIRQHandler(CAN2); +} + void main_module_bl_cmd_CALLBACK(CanParsedData_t *msg_data_a) { if (can_data.main_module_bl_cmd.cmd == BLCMD_RST) From b29289ae2b51369680cedb04e886957db1e6f8b7 Mon Sep 17 00:00:00 2001 From: Cole Date: Tue, 10 Dec 2024 14:58:55 -0500 Subject: [PATCH 36/36] Why isn't this working?? --- source/main_module/main.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/main_module/main.c b/source/main_module/main.c index a3ff8a31..d691ba90 100644 --- a/source/main_module/main.c +++ b/source/main_module/main.c @@ -315,11 +315,11 @@ void preflightChecks(void) { { /* TODO: Change this to init AMK CAN */ case 0: - if(!PHAL_initCAN(CAN2, false, VCAN_BPS)) + if(!PHAL_initCAN(CAN1, false, VCAN_BPS)) { HardFault_Handler(); } - NVIC_EnableIRQ(CAN2_RX0_IRQn); + NVIC_EnableIRQ(CAN1_RX0_IRQn); // huart_l.rx_dma_cfg->circular = true; // if(!PHAL_initUSART(&huart_l, APB2ClockRateHz)) // { @@ -332,11 +332,11 @@ void preflightChecks(void) { // } break; case 1: - if(!PHAL_initCAN(CAN1, false, VCAN_BPS)) + if(!PHAL_initCAN(CAN2, false, VCAN_BPS)) { HardFault_Handler(); } - NVIC_EnableIRQ(CAN1_RX0_IRQn); + NVIC_EnableIRQ(CAN2_RX0_IRQn); // spi_config.data_rate = APB2ClockRateHz / 16; // 5 MHz // if (!PHAL_SPI_init(&spi_config)) // HardFault_Handler();