MCU
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
PedalsSystem Class Reference

#include <PedalsSystem.h>

Collaboration diagram for PedalsSystem:
Collaboration graph

Public Member Functions

 PedalsSystem (const PedalsParams &accelParams, const PedalsParams &brakeParams)
 pedals system class that evaluates pedals for both accel and brake percent as well as implausibilities More...
 
void setParams (const PedalsParams &accelParams, const PedalsParams &brakeParams)
 
const PedalsSystemData_sgetPedalsSystemData ()
 
PedalsSystemData_s getPedalsSystemDataCopy ()
 
float getMechBrakeActiveThreshold ()
 
void tick (const SysTick_s &tick, const AnalogConversion_s &accel1, const AnalogConversion_s &accel2, const AnalogConversion_s &brake)
 overloaded tick function that runs the evaluation of the pedals system. evaluates brake using only min and max params for sensor 1 (min_pedal_1 / max_pedal_1). More...
 
void tick (const SysTick_s &tick, const AnalogConversion_s &accel1, const AnalogConversion_s &accel2, const AnalogConversion_s &brake1, const AnalogConversion_s &brake2)
 
PedalsSystemData_s evaluate_pedals (const AnalogConversion_s &accel1, const AnalogConversion_s &accel2, const AnalogConversion_s &brake1, const AnalogConversion_s &brake2, unsigned long curr_time)
 
PedalsSystemData_s evaluate_pedals (const AnalogConversion_s &accel1, const AnalogConversion_s &accel2, const AnalogConversion_s &brake, unsigned long curr_time)
 

Private Member Functions

float remove_deadzone_ (float conversion_input, float deadzone)
 
bool max_duration_of_implausibility_exceeded_ (unsigned long curr_time)
 
bool evaluate_pedal_implausibilities_ (const AnalogConversion_s &pedalData1, const AnalogConversion_s &pedalData2, const PedalsParams &params, float max_percent_diff)
 Evaluate pedal implausibilities_ determines if there is a software implausibility in the pedals caused by them going out of range. Our max/min sensor ranges are calcuated from the pedal min/max values The pedal min/max values are defined in MCU_defs and are the real world raw values that we determine from the pedal output. The max/min sensor values are then a certain percent higher than these real world values as determined by the implausibility margin. This protects against physical damage to the sensor or pedal, but will not accidentally trip implausibility if pedal values fluctuate. More...
 
bool evaluate_pedal_implausibilities_ (const AnalogConversion_s &pedalData, const PedalsParams &params)
 overloaded pedal implaus check that doesnt need to check for percent diff between sensors since only one sensor More...
 
bool evaluate_brake_and_accel_pressed_ (const AnalogConversion_s &accelPedalData1, const AnalogConversion_s &accelPedalData2, const AnalogConversion_s &brakePedalData1, const AnalogConversion_s &brakePedalData2)
 function to determine if the pedals and the brakes are pressed at the same time. evaluates brake being pressed with mech brake activation threshold AFTER removing deadzones for both brake and accel More...
 
bool evaluate_brake_and_accel_pressed_ (const AnalogConversion_s &accelPedalData1, const AnalogConversion_s &accelPedalData2, const AnalogConversion_s &brakePedalData)
 overloaded version that evaluates with only one brake pedal value More...
 
bool evaluate_pedal_oor (const AnalogConversion_s &pedalData, int min, int max)
 This checks to see if any pedal sensor is out of range :(. More...
 
bool evaluate_min_max_pedal_implausibilities_ (const AnalogConversion_s &pedalData, int min, int max, float implaus_margin_scale)
 
bool pedal_is_active_ (float pedal1ConvertedData, float pedal2ConvertedData, const PedalsParams &params, bool check_mech_activation)
 check whether or not pedal is active according to input parameters. returns true if either pedal is over threshold. removes the deadzone before checking. More...
 

Private Attributes

PedalsSystemData_s data_ {}
 
PedalsParams accelParams_ {}
 
PedalsParams brakeParams_ {}
 
unsigned long implausibilityStartTime_
 

Detailed Description

Definition at line 41 of file PedalsSystem.h.

Constructor & Destructor Documentation

◆ PedalsSystem()

PedalsSystem::PedalsSystem ( const PedalsParams accelParams,
const PedalsParams brakeParams 
)
inline

pedals system class that evaluates pedals for both accel and brake percent as well as implausibilities

Parameters
accelParamsaccel pedal parameters. by rules, 2 sensors must be used for redundancy and evaluated w.r.t each other
brakeParamsbrake pedal params. when used with only one pedal sensor, the pedal parameter evaluation for brakes only looks at the min and max for min_pedal_1 / max_pedal_1

Definition at line 48 of file PedalsSystem.h.

50 {
51 setParams(accelParams, brakeParams);
53 }
unsigned long implausibilityStartTime_
Definition: PedalsSystem.h:127
void setParams(const PedalsParams &accelParams, const PedalsParams &brakeParams)
Definition: PedalsSystem.h:55

Member Function Documentation

◆ evaluate_brake_and_accel_pressed_() [1/2]

bool PedalsSystem::evaluate_brake_and_accel_pressed_ ( const AnalogConversion_s &  accelPedalData1,
const AnalogConversion_s &  accelPedalData2,
const AnalogConversion_s &  brakePedalData 
)
private

overloaded version that evaluates with only one brake pedal value

Parameters
accelPedalData1
accelPedalData2
brakePedalData
Returns

Definition at line 205 of file PedalsSystem.cpp.

208{
209
210
211
212 bool accel_pressed = pedal_is_active_(accelPedalData1.conversion, accelPedalData2.conversion, accelParams_, false); // .1
213 float brake_pedal_real = remove_deadzone_(brakePedalData.conversion, brakeParams_.deadzone_margin);
214 bool mech_brake_pressed = brake_pedal_real >= brakeParams_.mechanical_activation_percentage;
215 bool both_pedals_implausible = (accel_pressed && mech_brake_pressed);
216 return both_pedals_implausible;
217}
PedalsParams brakeParams_
Definition: PedalsSystem.h:126
PedalsParams accelParams_
Definition: PedalsSystem.h:125
bool pedal_is_active_(float pedal1ConvertedData, float pedal2ConvertedData, const PedalsParams &params, bool check_mech_activation)
check whether or not pedal is active according to input parameters. returns true if either pedal is o...
float remove_deadzone_(float conversion_input, float deadzone)
float deadzone_margin
Definition: PedalsSystem.h:36
float mechanical_activation_percentage
Definition: PedalsSystem.h:38

◆ evaluate_brake_and_accel_pressed_() [2/2]

bool PedalsSystem::evaluate_brake_and_accel_pressed_ ( const AnalogConversion_s &  accelPedalData1,
const AnalogConversion_s &  accelPedalData2,
const AnalogConversion_s &  brakePedalData1,
const AnalogConversion_s &  brakePedalData2 
)
private

function to determine if the pedals and the brakes are pressed at the same time. evaluates brake being pressed with mech brake activation threshold AFTER removing deadzones for both brake and accel

Parameters
accelPedalData1
accelPedalData2
brakePedalData1
brakePedalData2
Returns
true if accel and brake pressed at the same time, false otherwise

Definition at line 219 of file PedalsSystem.cpp.

223{
224
225
226 bool accel_pressed = pedal_is_active_(accelPedalData1.conversion, accelPedalData2.conversion, accelParams_, false); // .1
227 bool mech_brake_pressed = pedal_is_active_(brakePedalData1.conversion, brakePedalData2.conversion, brakeParams_, true); // 0.40
228
229
230 bool both_pedals_implausible = (accel_pressed && mech_brake_pressed);
231 return both_pedals_implausible;
232}

◆ evaluate_min_max_pedal_implausibilities_()

bool PedalsSystem::evaluate_min_max_pedal_implausibilities_ ( const AnalogConversion_s &  pedalData,
int  min,
int  max,
float  implaus_margin_scale 
)
private
Parameters
pedalData
min
max
implaus_margin_scale
Returns

Definition at line 151 of file PedalsSystem.cpp.

155{
156
157 bool pedal_swapped = false;
158
159 // get the pedal margin. The margin will be a percentage of the range of the measured max values
160 int pedal_margin = abs(max - min) * implaus_margin_scale;
161
162 if (min > max)
163 {
164 pedal_swapped = true;
165 // swap the logic: need to check and see if it is greater than min and less than max
166 }
167 // FSAE EV.5.5
168 // FSAE T.4.2.10
169 bool pedal_less_than_min = pedal_swapped ? (pedalData.raw > (min + pedal_margin))
170 : (pedalData.raw < (min - pedal_margin));
171
172 bool pedal_greater_than_max = pedal_swapped ? (pedalData.raw < (max - pedal_margin))
173 : (pedalData.raw > (max + pedal_margin));
174
175 if (pedal_less_than_min)
176 {
177 return true;
178 }
179 else if (pedal_greater_than_max)
180 {
181 return true;
182 }
183 else
184 {
185 return false;
186 }
187}

◆ evaluate_pedal_implausibilities_() [1/2]

bool PedalsSystem::evaluate_pedal_implausibilities_ ( const AnalogConversion_s &  pedalData,
const PedalsParams params 
)
private

overloaded pedal implaus check that doesnt need to check for percent diff between sensors since only one sensor

Parameters
pedalData
params
Returns

Definition at line 124 of file PedalsSystem.cpp.

125{
126 return evaluate_min_max_pedal_implausibilities_(pedalData, params.min_pedal_1, params.max_pedal_1, params.implausibility_margin);
127}
bool evaluate_min_max_pedal_implausibilities_(const AnalogConversion_s &pedalData, int min, int max, float implaus_margin_scale)
ParameterInterface params

◆ evaluate_pedal_implausibilities_() [2/2]

bool PedalsSystem::evaluate_pedal_implausibilities_ ( const AnalogConversion_s &  pedalData1,
const AnalogConversion_s &  pedalData2,
const PedalsParams params,
float  max_percent_diff 
)
private

Evaluate pedal implausibilities_ determines if there is a software implausibility in the pedals caused by them going out of range. Our max/min sensor ranges are calcuated from the pedal min/max values The pedal min/max values are defined in MCU_defs and are the real world raw values that we determine from the pedal output. The max/min sensor values are then a certain percent higher than these real world values as determined by the implausibility margin. This protects against physical damage to the sensor or pedal, but will not accidentally trip implausibility if pedal values fluctuate.

Parameters
pedalData1
pedalData2
params
max_percent_diff
Returns

Definition at line 129 of file PedalsSystem.cpp.

133{
134 bool pedal1_min_max_implaus = evaluate_min_max_pedal_implausibilities_(pedalData1, params.min_pedal_1, params.max_pedal_1, params.implausibility_margin);
135 bool pedal2_min_max_implaus = evaluate_min_max_pedal_implausibilities_(pedalData2, params.min_pedal_2, params.max_pedal_2, params.implausibility_margin);
136 bool sens_not_within_req_percent = (fabs(pedalData1.conversion - pedalData2.conversion) > max_percent_diff);
137 if (pedal1_min_max_implaus || pedal2_min_max_implaus)
138 {
139 return true;
140 }
141 else if (sens_not_within_req_percent)
142 {
143 return true;
144 }
145 else
146 {
147 return false;
148 }
149}

◆ evaluate_pedal_oor()

bool PedalsSystem::evaluate_pedal_oor ( const AnalogConversion_s &  pedalData,
int  min,
int  max 
)
private

This checks to see if any pedal sensor is out of range :(.

Parameters
PedalDataThe analog pedal Value
Returns

Definition at line 251 of file PedalsSystem.cpp.

254{
255 return (pedalData.raw >= max || pedalData.raw <= min);
256}

◆ evaluate_pedals() [1/2]

PedalsSystemData_s PedalsSystem::evaluate_pedals ( const AnalogConversion_s &  accel1,
const AnalogConversion_s &  accel2,
const AnalogConversion_s &  brake,
unsigned long  curr_time 
)
Parameters
accel1
accel2
brake
curr_time
Returns

Definition at line 21 of file PedalsSystem.cpp.

25{
27
28
29 out.accelPressed = pedal_is_active_(accel1.conversion, accel2.conversion, accelParams_, false);
31 out.accelPercent = (out.accelImplausible) ? accel1.conversion : (accel1.conversion + accel2.conversion) / 2.0;
33 out.accelPercent = std::max(out.accelPercent, 0.0f);
36 bool implausibility = (out.brakeAndAccelPressedImplausibility || out.brakeImplausible || out.accelImplausible);
37
38 if (implausibility && (implausibilityStartTime_ == 0))
39 {
40 implausibilityStartTime_ = curr_time;
41 }
42 else if ((!implausibility) && ((out.accelPercent <= 0.05)))
43 {
45 }
46
49 out.accelPercent = (oor) ? 0 : out.accelPercent;
50
51
52 out.brakePercent = brake.conversion;
54 out.brakePressed = brake.conversion >= brakeParams_.activation_percentage;
55
57 out.regenPercent = std::max(std::min(out.brakePercent / brakeParams_.mechanical_activation_percentage, 1.0f), 0.0f);
58
59
61 return out;
62}
bool max_duration_of_implausibility_exceeded_(unsigned long curr_time)
bool evaluate_pedal_oor(const AnalogConversion_s &pedalData, int min, int max)
This checks to see if any pedal sensor is out of range :(.
bool evaluate_pedal_implausibilities_(const AnalogConversion_s &pedalData1, const AnalogConversion_s &pedalData2, const PedalsParams &params, float max_percent_diff)
Evaluate pedal implausibilities_ determines if there is a software implausibility in the pedals cause...
bool evaluate_brake_and_accel_pressed_(const AnalogConversion_s &accelPedalData1, const AnalogConversion_s &accelPedalData2, const AnalogConversion_s &brakePedalData1, const AnalogConversion_s &brakePedalData2)
function to determine if the pedals and the brakes are pressed at the same time. evaluates brake bein...
int max_sensor_pedal_1
Definition: PedalsSystem.h:33
float activation_percentage
Definition: PedalsSystem.h:35
int min_sensor_pedal_1
Definition: PedalsSystem.h:31
int min_sensor_pedal_2
Definition: PedalsSystem.h:32
int max_sensor_pedal_2
Definition: PedalsSystem.h:34
bool brakeAndAccelPressedImplausibility
bool implausibilityExceededMaxDuration

◆ evaluate_pedals() [2/2]

PedalsSystemData_s PedalsSystem::evaluate_pedals ( const AnalogConversion_s &  accel1,
const AnalogConversion_s &  accel2,
const AnalogConversion_s &  brake1,
const AnalogConversion_s &  brake2,
unsigned long  curr_time 
)
Parameters
accel1
accel2
brake1
brake2
curr_time
Returns

Definition at line 64 of file PedalsSystem.cpp.

69{
70
72 out.accelPressed = pedal_is_active_(accel1.conversion, accel2.conversion, accelParams_, false);
74
75 auto percent = (out.accelImplausible) ? accel1.conversion : (accel1.conversion + accel2.conversion) / 2.0;
77 out.accelPercent = std::max(out.accelPercent, 0.0f);
78
79
82 bool implausibility = (out.brakeAndAccelPressedImplausibility || out.brakeImplausible || out.accelImplausible);
83
84 if (implausibility && (implausibilityStartTime_ == 0))
85 {
86 implausibilityStartTime_ = curr_time;
87 }
88 else if ((!implausibility) && (!(out.accelPercent > 0.05)))
89 {
91 }
92
95 out.accelPercent = (oor) ? 0 : out.accelPercent;
96
97 out.brakePercent = (brake1.conversion + brake2.conversion) / 2.0;
98
100
101 out.regenPercent = std::max(std::min(out.brakePercent / brakeParams_.mechanical_activation_percentage, 1.0f), 0.0f);
102
103 out.brakePressed = pedal_is_active_(brake1.conversion, brake2.conversion, brakeParams_, false);
104 out.mechBrakeActive = pedal_is_active_(brake1.conversion, brake2.conversion, brakeParams_, true);
106
107 return out;
108}

◆ getMechBrakeActiveThreshold()

float PedalsSystem::getMechBrakeActiveThreshold ( )
inline

Definition at line 72 of file PedalsSystem.h.

◆ getPedalsSystemData()

const PedalsSystemData_s & PedalsSystem::getPedalsSystemData ( )
inline

Definition at line 62 of file PedalsSystem.h.

63 {
64 return data_;
65 }
PedalsSystemData_s data_
Definition: PedalsSystem.h:124

◆ getPedalsSystemDataCopy()

PedalsSystemData_s PedalsSystem::getPedalsSystemDataCopy ( )
inline

Definition at line 67 of file PedalsSystem.h.

68 {
69 return data_;
70 }

◆ max_duration_of_implausibility_exceeded_()

bool PedalsSystem::max_duration_of_implausibility_exceeded_ ( unsigned long  curr_time)
private

Definition at line 111 of file PedalsSystem.cpp.

112{
114 {
115 return ((curr_time - implausibilityStartTime_) > 100);
116 }
117 else
118 {
119 return false;
120 }
121}

◆ pedal_is_active_()

bool PedalsSystem::pedal_is_active_ ( float  pedal1ConvertedData,
float  pedal2ConvertedData,
const PedalsParams params,
bool  check_mech_activation 
)
private

check whether or not pedal is active according to input parameters. returns true if either pedal is over threshold. removes the deadzone before checking.

Parameters
pedal1ConvertedDatathe value 0 to 1 of the first pedal without deadzone removed
pedal2ConvertedData... second pedal 0 to 1 val
paramsthe pedal parameters for this specific pedal
check_mech_activationif this is true, function will check percentages against the mechanical activation percentage
Returns
true or false accordingly

Definition at line 234 of file PedalsSystem.cpp.

235{
236 float val1_deadzone_removed = remove_deadzone_(pedal1ConvertedData, params.deadzone_margin);
237 float val2_deadzone_removed = remove_deadzone_(pedal2ConvertedData, params.deadzone_margin);
238 bool pedal_1_is_active;
239 bool pedal_2_is_active;
240 if(check_mech_activation)
241 {
242 pedal_1_is_active = val1_deadzone_removed >= params.mechanical_activation_percentage;
243 pedal_2_is_active = val2_deadzone_removed >= params.mechanical_activation_percentage;
244 } else {
245 pedal_1_is_active = val1_deadzone_removed >= params.activation_percentage;
246 pedal_2_is_active = val2_deadzone_removed >= params.activation_percentage;
247 }
248 return (pedal_1_is_active || pedal_2_is_active);
249}

◆ remove_deadzone_()

float PedalsSystem::remove_deadzone_ ( float  conversion_input,
float  deadzone 
)
private

Definition at line 189 of file PedalsSystem.cpp.

190{
191 float range = 1.0 - (deadzone * 2);
192 // e.g. vals from 0 to 1, deadzone is .05, range is .1
193 // subtract deadzone to be -.05 to .95 & clamp at 0
194 float out = std::max(conversion_input - deadzone, 0.0f);
195 // values now are 0 to .95
196 // divide by range of values to scale up (.9)
197 out /= range;
198 // values are now 0 to 1.0555...
199 // clamp at 0 to 1
200 out = std::min(out, 1.0f);
201
202 return out;
203}

◆ setParams()

void PedalsSystem::setParams ( const PedalsParams accelParams,
const PedalsParams brakeParams 
)
inline

Definition at line 55 of file PedalsSystem.h.

57 {
58 accelParams_ = accelParams;
59 brakeParams_ = brakeParams;
60 }

◆ tick() [1/2]

void PedalsSystem::tick ( const SysTick_s &  tick,
const AnalogConversion_s &  accel1,
const AnalogConversion_s &  accel2,
const AnalogConversion_s &  brake 
)

overloaded tick function that runs the evaluation of the pedals system. evaluates brake using only min and max params for sensor 1 (min_pedal_1 / max_pedal_1).

Parameters
tickcurrent system time tick
accel1accel 1 sensor reading with scaled and offset value from 0 to 1
accel2accel 2 sensor reading with scaled and offset value from 0 to 1
brakebrake sensor reading with scaled and offset value from 0 to 1

Definition at line 12 of file PedalsSystem.cpp.

13{
14 data_ = evaluate_pedals(accel1, accel2, brake, tick.millis);
15}
PedalsSystemData_s evaluate_pedals(const AnalogConversion_s &accel1, const AnalogConversion_s &accel2, const AnalogConversion_s &brake1, const AnalogConversion_s &brake2, unsigned long curr_time)
void tick(const SysTick_s &tick, const AnalogConversion_s &accel1, const AnalogConversion_s &accel2, const AnalogConversion_s &brake)
overloaded tick function that runs the evaluation of the pedals system. evaluates brake using only mi...

◆ tick() [2/2]

void PedalsSystem::tick ( const SysTick_s &  tick,
const AnalogConversion_s &  accel1,
const AnalogConversion_s &  accel2,
const AnalogConversion_s &  brake1,
const AnalogConversion_s &  brake2 
)
Parameters
tick
accel1
accel2
brake1
brake2

Definition at line 7 of file PedalsSystem.cpp.

8{
9 data_ = evaluate_pedals(accel1, accel2, brake1, brake2, tick.millis);
10}

Member Data Documentation

◆ accelParams_

PedalsParams PedalsSystem::accelParams_ {}
private

Definition at line 125 of file PedalsSystem.h.

◆ brakeParams_

PedalsParams PedalsSystem::brakeParams_ {}
private

Definition at line 126 of file PedalsSystem.h.

◆ data_

PedalsSystemData_s PedalsSystem::data_ {}
private

Definition at line 124 of file PedalsSystem.h.

◆ implausibilityStartTime_

unsigned long PedalsSystem::implausibilityStartTime_
private

Definition at line 127 of file PedalsSystem.h.


The documentation for this class was generated from the following files: