Skip to content

Quality of life tweaks: Enhance motor temp handling in ESC, chill range#90

Merged
zjwhitehead merged 10 commits intomasterfrom
7.4-Tweaks
Feb 13, 2026
Merged

Quality of life tweaks: Enhance motor temp handling in ESC, chill range#90
zjwhitehead merged 10 commits intomasterfrom
7.4-Tweaks

Conversation

@zjwhitehead
Copy link
Member

@zjwhitehead zjwhitehead commented Feb 11, 2026

This PR improves telemetry reliability, simplifies alert behavior, and removes dead code.

  • Motor temperature validity is now handled explicitly with NaN for disconnected/invalid readings, and downstream logic (monitoring, UI, BLE payloads) treats NaN as “no valid sensor value” instead of generating bad alerts or fake values.
  • Sensor monitor behavior was tightened so NaN readings are skipped and alert state is reset cleanly to OK.
  • Throttle mapping/control was improved to be mode-aware across the full physical throttle range, with smoother behavior when switching modes and cleaner cruise interaction.
  • Critical alert vibration was simplified to a single active path (UI timer + pulse vibration), and the older unused “critical vibration service/task” path was removed.
  • Unused helpers and redundant code were removed (including old temp helpers/utilities and unused locals/params), reducing maintenance overhead.
  • Altimeter setup API was simplified by removing an unused parameter.

Flown with by Zach, full testing by Paul

PaulDWhite and others added 4 commits January 31, 2026 11:47
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.
@zjwhitehead zjwhitehead marked this pull request as ready for review February 12, 2026 04:17
PaulDWhite and others added 3 commits February 12, 2026 12:11
…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.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

@zjwhitehead zjwhitehead changed the title Enhance motor temperature handling in ESC Quality of life tweaks: Enhance motor temp handling in ESC, chill range Feb 13, 2026
@zjwhitehead zjwhitehead merged commit d3a7997 into master Feb 13, 2026
7 checks passed
@zjwhitehead zjwhitehead deleted the 7.4-Tweaks branch February 13, 2026 15:49
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.

2 participants