-
Notifications
You must be signed in to change notification settings - Fork 0
bugfix/header-errors #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,3 +3,4 @@ | |
| .vscode/c_cpp_properties.json | ||
| .vscode/launch.json | ||
| .vscode/ipch | ||
| /logs | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| #pragma once | ||
| #include "config.h" | ||
| #include "Logger.h" | ||
| #include "Nextion.h" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #pragma once | ||
| #include "config.h" | ||
|
|
||
| class Pedal { | ||
| private: | ||
| float appsPercent(int raw, int rest, int full); | ||
| bool fault = false; | ||
| uint8_t plausibilityCount = 0; | ||
| public: | ||
| Pedal(); | ||
| int16_t apps1Raw = 0; | ||
| int16_t apps2Raw = 0; | ||
| int16_t read(); | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| #include "pedal.h" | ||
|
|
||
| float Pedal::appsPercent(int raw, int rest, int full) { | ||
| float pct = (float)(rest - raw) * 100.0f / (float)(rest - full); | ||
| pct = std::clamp(pct, 0.0f, 100.0f); | ||
| return pct; | ||
| } | ||
|
swhelan123 marked this conversation as resolved.
|
||
|
|
||
| int16_t Pedal::read() { | ||
| apps1Raw = analogRead(APPS1_PIN); | ||
| apps2Raw = analogRead(APPS2_PIN); | ||
|
|
||
| float pct1 = appsPercent(apps1Raw, APPS1_REST, APPS1_FULL); | ||
| float pct2 = appsPercent(apps2Raw, APPS2_REST, APPS2_FULL); | ||
|
|
||
| // Plausibility: sensors must agree within PEDAL_PLAUSIBILITY_PERCENT. | ||
| // Fault only latches after 3 consecutive bad readings (~60ms) to reject | ||
| // single noisy samples. Zero torque immediately on any bad reading. | ||
| if (fabsf(pct1 - pct2) > PEDAL_PLAUSIBILITY_PERCENT) { | ||
| plausibilityCount++; | ||
| if (plausibilityCount >= 3) fault = true; | ||
| return 0; | ||
| } | ||
|
Comment on lines
+16
to
+23
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ✅ T11.8.9 - implausibility is defined as >10 percentage points deviation between any two APPS sensors. 11.8.9 is implemented fine with the macro, 11.8.8 should be implemented to comply completely with rules |
||
|
|
||
| plausibilityCount = 0; | ||
|
|
||
| // reset fault when pedal is released | ||
| if (fault) { | ||
| if (pct1 < PEDAL_DEADBAND_PERCENT && pct2 < PEDAL_DEADBAND_PERCENT) { | ||
| fault = false; | ||
| } else { | ||
| return 0; | ||
| } | ||
| } | ||
| // TODO: cut power if fault persistent for 100ms | ||
|
|
||
| float pct = (pct1 + pct2) * 0.5f; | ||
| if (pct < PEDAL_DEADBAND_PERCENT) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could you do what you did below doing i suppose that would mirror the same logic as what you've got here, but does that mean as you increase pedal it goes 0...0...3 all of a sudden?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the reason for the deadband in the old code is that when you configure rest to say 2000 and full to 1000, a bit of noise may make rest go to like 1956 or 2083 or something so rather than throwing errors if raw reading goes outside set range (drops to 1956) or send a small percentage torque request (goes to 2083) a small deadband is set around rest so this noise can be dealt with. would still obviously like to preserve a full 0-100 operational window though |
||
| pct = 0.0f; | ||
| } | ||
| pct = std::min(pct, (float)MAX_ACCEL_PERCENT); | ||
|
|
||
| return (int16_t)(TORQUE_MAX * (pct / 100.0f)); | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this where brake pedal pressure sensor inputs will be handled in the future too? if yes, add placeholders to ensure we do not forget to implement the following
EV2.3.1 — if brakes are mechanically actuated AND APPS signals >25% pedal travel (or >5kW, whichever is lower) simultaneously for more than 500ms, commanded torque must be 0 Nm.
EV2.3.2 — once that condition triggers, torque must stay at 0 Nm until APPS drops below 5% and 0 Nm is commanded — regardless of whether brakes are still on.