MCU
Loading...
Searching...
No Matches
LoadCellVectoringController.cpp
Go to the documentation of this file.
2
3
5 const SysTick_s &tick,
6 const PedalsSystemData_s &pedalsData,
7 const LoadCellInterfaceOutput_s &loadCellData
8)
9{
10 // Calculate torque commands at 100hz
11 if (tick.triggers.trigger100)
12 {
13 // Apply FIR filter to load cell data
18
19 for (int i = 0; i < 4; i++)
20 {
22 for (int FIROffset = 0; FIROffset < numFIRTaps_; FIROffset++)
23 {
24 int index = (FIRCircBufferHead + FIROffset) % numFIRTaps_;
25 loadCellForcesFiltered_[i] += loadCellForcesRaw_[i][index] * FIRTaps_[FIROffset];
26 }
27 }
30 FIRSaturated_ = true;
31
32 // Do sanity checks on raw data
33 loadCellsErrorCounter_[0] = loadCellData.loadCellConversions.FL.raw != 4095 && loadCellData.loadCellConversions.FL.status != AnalogSensorStatus_e::ANALOG_SENSOR_CLAMPED ? 0 : loadCellsErrorCounter_[0] + 1;
34 loadCellsErrorCounter_[1] = loadCellData.loadCellConversions.FR.raw != 4095 && loadCellData.loadCellConversions.FR.status != AnalogSensorStatus_e::ANALOG_SENSOR_CLAMPED ? 0 : loadCellsErrorCounter_[1] + 1;
35 loadCellsErrorCounter_[2] = loadCellData.loadCellConversions.RL.raw != 4095 && loadCellData.loadCellConversions.RL.status != AnalogSensorStatus_e::ANALOG_SENSOR_CLAMPED ? 0 : loadCellsErrorCounter_[2] + 1;
36 loadCellsErrorCounter_[3] = loadCellData.loadCellConversions.RR.raw != 4095 && loadCellData.loadCellConversions.RR.status != AnalogSensorStatus_e::ANALOG_SENSOR_CLAMPED ? 0 : loadCellsErrorCounter_[3] + 1;
38
40
41 if (ready_)
42 {
43 // Calculate total normal force
44 float sumNormalForce = 0.0f;
45 for (int i = 0; i < 4; i++)
46 {
47 sumNormalForce += loadCellForcesFiltered_[i];
48 }
49
50 // Both pedals are not pressed and no implausibility has been detected
51 // accelRequest goes between 1.0 and -1.0
52 float accelRequest = pedalsData.accelPercent - pedalsData.regenPercent;
53 float torquePool;
54 float torqueRequest;
55
56 if (accelRequest >= 0.0)
57 {
58 // Positive torque request
59 // NOTE: using "torquePool" here instead of torqueRequest for legibility
60 torquePool = accelRequest * PhysicalParameters::AMK_MAX_TORQUE * 4;
61
66
71 }
72 else
73 {
74 // Negative torque request
75 // No load cell vectoring on regen
76 torqueRequest = PhysicalParameters::MAX_REGEN_TORQUE * accelRequest * -1.0;
77
82
87 }
88 }
89 else
90 {
92 }
93 }
94}
95
97{
98 tick(state.systick, state.pedals_data, state.loadcell_data);
99 return writeout_;
100}
const int RR
Definition: Utility.h:9
const int FL
Definition: Utility.h:6
const int FR
Definition: Utility.h:7
const int RL
Definition: Utility.h:8
void tick(const SysTick_s &tick, const PedalsSystemData_s &pedalsData, const LoadCellInterfaceOutput_s &loadCellData)
Calculates speed set point based on normal force applied to wheels individually.
TorqueControllerOutput_s evaluate(const SharedCarState_s &state) override
const DrivetrainCommand_s TC_COMMAND_NO_TORQUE
Definition: BaseController.h:9
const float AMK_MAX_TORQUE
const float MAX_REGEN_TORQUE
float inverter_torque_limit[NUM_MOTORS]
float speeds_rpm[NUM_MOTORS]
veh_vec< float > loadCellForcesFiltered
veh_vec< AnalogConversion_s > loadCellConversions
car state struct that contains state of everything about the car including
LoadCellInterfaceOutput_s loadcell_data
PedalsSystemData_s pedals_data
Packages drivetrain command with ready boolean to give feedback on controller successfully evaluating...
DrivetrainCommand_s command
T FL
Definition: Utility.h:19
T RL
Definition: Utility.h:21
T RR
Definition: Utility.h:22
T FR
Definition: Utility.h:20