Skip to content

bugfix/header-errors#11

Open
louisbrennan wants to merge 4 commits into
mainfrom
bugfix/header-errors
Open

bugfix/header-errors#11
louisbrennan wants to merge 4 commits into
mainfrom
bugfix/header-errors

Conversation

@louisbrennan

Copy link
Copy Markdown
Contributor

Put missing #pragma once to some headers and added serial log option and also put logs dir in gitignore

@louisbrennan louisbrennan requested a review from swhelan123 April 14, 2026 22:56
@louisbrennan louisbrennan deleted the bugfix/header-errors branch April 14, 2026 22:57
@louisbrennan louisbrennan restored the bugfix/header-errors branch April 14, 2026 22:58
@louisbrennan louisbrennan reopened this Apr 14, 2026

@swhelan123 swhelan123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

went on a tangent re optimisation, otherwise lgtm

Comment thread include/config.h Outdated
#define MAX_BUF 16
#define MAX_LOG_LEN 128
extern FsFile logFile;
#define SERIAL_DEBUG true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in earlier iterations of code i wrote for the teensy, i defined serial debug not as a boolean true or false, but as a number 0 through 4 or 5, so i could have varying levels of verbosity
That means you could still have statements like this

if(SERIAL_DEBUG) {
    Serial.print("Value:");
    Serial.println(some_value)
}

But also like level-specific guards:

if(SERIAL_DEBUG >= 2) {
    Serial.print("Detailed value: ");
    Serial.println(some_value);
}

This way SERIAL_DEBUG 0 is silent, 1 gives high-level status messages, and higher levels progressively expose more granular internals. The boolean check still works at level 1+ since any non-zero value is truthy in cpp
During drive SERIAL_DEBUG should be set to 0 before compilation. Compiler should treat the if blocks as dead code and omit them from the compiled binary, but worth looking into the default optimisation values for teensy
platformio.ini supports build_flags so may be worth explicitly setting build_flags = -02 for speed optimisation

Comment thread src/main.cpp
@louisbrennan louisbrennan requested a review from swhelan123 May 4, 2026 19:53
@louisbrennan

Copy link
Copy Markdown
Contributor Author

@swhelan123 not letting me merge, adding new changes to this pr

@swhelan123 swhelan123 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

small changes requested. see comments. maybe i'm being stupid about the LogLevel gripes, pls explain if i am

Comment thread include/Logger.h Outdated
Comment on lines +16 to +20
static LogLevel serialDebug;

public:
static CircularBuffer<LogEntry, MAX_BUF> _logBuffer;
static bool begin();
static bool begin(LogLevel debugLevel);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

having "debug" in the variable name for LogLevel types could get confusing since DEBUG is a level itself. Also serialDebug implies pertinence to the serial channel even though LogLevel only concerns SD card datalogging
SERIAL_DEBUG_LEVEL or something along those lines could be used as a compile time macro and accessed globally to increase or decrease verbosity of output to serial monitor but that is out of the scope of the logger class

Comment thread src/Logger.cpp Outdated
Comment on lines +29 to +30
bool Logger::begin(LogLevel serialDebugLevel) {
serialDebug = serialDebugLevel;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same comment as above. serial has nothing to do with SD card data logging in this context

Comment thread src/main.cpp Outdated

LogLevel serialDebug = LogLevel::NONE;
Logger::begin(serialDebug);
if (serialDebug != LogLevel::NONE) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok now i'm confused if logger has to do with sd card data logging or live serial output or both. if the latter, consider splitting up responsibility of the logger class to an SD logger and a live debug logger?

Comment thread src/Pedal.cpp
Comment thread src/Pedal.cpp
Comment on lines +17 to +24
// 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;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.
❌ T11.8.8 - if an implausibility persists for more than 100ms, power to the motor(s) must be immediately shut down completely. Shutting down via the motor controller is sufficient - you don't have to open the SDC, but the inverter must cut power.

11.8.9 is implemented fine with the macro, 11.8.8 should be implemented to comply completely with rules

Comment thread src/Pedal.cpp

Copy link
Copy Markdown
Member

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.

Comment thread src/Pedal.cpp

float pct = (pct1 + pct2) * 0.5f;

if (pct < PEDAL_DEADBAND_PERCENT) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you do what you did below doing pct = std::max(0, PEDAL_DEADBAND_PERCENT?

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants