Quality of life tweaks: Enhance motor temp handling in ESC, chill range#90
Merged
zjwhitehead merged 10 commits intomasterfrom Feb 13, 2026
Merged
Quality of life tweaks: Enhance motor temp handling in ESC, chill range#90zjwhitehead merged 10 commits intomasterfrom
zjwhitehead merged 10 commits intomasterfrom
Conversation
Introduced a constant for disconnected motor temperature and updated telemetry processing to set motor temperature to MOTOR_TEMP_DISCONNECTED (-40.0) when the sensor is invalid. Adjusted related code in telemetry updates and monitoring to ensure proper handling of disconnected sensors, improving robustness and clarity in BLE telemetry reporting.
Include <math.h> and add isnan checks in SensorMonitor and HysteresisSensorMonitor so NaN readings are treated as OK (log/reset state and skip alert logic). Change motor temperature supplier to return NAN for out-of-range/disconnected values instead of a nominal 50. This prevents spurious alerts when sensors are disconnected or invalid.
Replace the previous sentinel value for a disconnected motor temp with NaN and centralize the validity check. Added MOTOR_TEMP_VALID_MIN_C / MAX_C and inline isMotorTempValidC() in esc.h, updated the telemetry struct comment to indicate motor_temp may be NaN, and changed readESCTelemetry() to store NAN for invalid readings. BLE and LVGL code were updated to treat NaN as an invalid/missing reading (and math.h was included). The monitor callback now returns the stored motor_temp directly. This makes handling of disconnected/invalid motor temperature readings explicit and consistent across components.
…hysical throttle range in chill mode) Added new function potRawToModePwm for converting raw pot readings to PWM values based on performance mode (CHILL or SPORT). Updated getSmoothedThrottlePwm and afterCruiseEnd to utilize this new mapping. Adjusted comments for clarity and consistency. Enhanced unit tests to verify mode-specific behavior in throttle calculations, ensuring correct PWM output across different performance modes.
Fix off-by-one expected PWM in CalculateCruisePwmChillModeFullRange test: potRawToModePwm(3276, 0) returns 1487, so update the comment and EXPECT_EQ from 1486 to 1487.
Expose a test hook for analogRead in native Arduino stubs (g_testAnalogReadValue + setTestAnalogReadValue) so tests can control ADC input. Add unit tests to exercise throttle behavior: deceleration clamping to ESC minimum (ApplyModeRampClampDecelToFloor), throttle filter ring buffer rollover and averages (ThrottleFilterRollover), and mode-aware mapping plus smoothing for getSmoothedThrottlePwm (GetSmoothedThrottlePwmModeAwareAndSmoothing). These additions increase coverage for boundary cases and smoothing logic.
There was a problem hiding this comment.
Pull request overview
This pull request enhances motor temperature handling in the ESC telemetry system and refactors throttle mapping to provide mode-aware behavior. The PR addresses issues from testing by @PaulDWhite.
Changes:
- Introduces NaN representation for invalid/disconnected motor temperature sensors instead of range checks
- Implements mode-aware throttle mapping where CHILL mode maps the full physical throttle range to a reduced PWM range (1035-1600) instead of hard clamping
- Adds comprehensive test coverage for new throttle mapping behavior and edge cases
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/sp140/esc.cpp | Updates motor temperature filtering to store NaN for invalid readings instead of keeping previous values |
| inc/sp140/esc.h | Adds constants and validation function for motor temperature range checking |
| src/sp140/lvgl/lvgl_updates.cpp | Updates UI to check for NaN motor temperature values instead of range validation |
| inc/sp140/simple_monitor.h | Enhances sensor monitors to skip NaN values and treat them as OK status |
| src/sp140/throttle.cpp | Implements potRawToModePwm for mode-aware throttle mapping and updates cruise control to use same mapping |
| inc/sp140/throttle.h | Documents new mode-aware throttle mapping function |
| src/sp140/sp140.ino | Updates throttle calls to pass performance mode parameter |
| src/sp140/ble/esc_service.cpp | Adds comments documenting NaN motor temperature behavior in BLE telemetry |
| inc/sp140/structs.h | Documents motor_temp field as potentially containing NaN |
| test/test_throttle/test_throttle.cpp | Adds comprehensive tests for mode-aware throttle mapping, cruise control consistency, and edge cases |
| test/native_stubs/Arduino.h | Adds test infrastructure for controlling analogRead return values |
| src/sp140/esc_monitors.cpp | Updates comment to document NaN handling for motor temperature monitor |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR improves telemetry reliability, simplifies alert behavior, and removes dead code.
NaNfor disconnected/invalid readings, and downstream logic (monitoring, UI, BLE payloads) treatsNaNas “no valid sensor value” instead of generating bad alerts or fake values.NaNreadings are skipped and alert state is reset cleanly toOK.Flown with by Zach, full testing by Paul