Repository navigation
feat(throttle): unify cruise max at 70% and raise chill max to 80% - #128
Merged
Merged
Conversation
Chill max goes from 1600us (61% ESC output) to 1770us (80%). Cruise max is now a single output level, CRUISE_MAX_PWM = 1680us (70%), shared by chill and sport. Percentages are of the stock ESC throttle window, 1050-1950us. Cruise holds exactly the output being flown when it engages. Above the cruise max, activation is refused (icon flashes) instead of clamped, which removes the sport-mode drop when engaging at 60-70% lever. The old 60% clamp and 70% lever gate are gone, and BLE cruise updates now respect the same cap (previously they accepted up to 1950us). Fix a cruise-engage race: the state flipped to ARMED_CRUISING before the cruise PWM, start time and pot reference were set, so a throttle tick in that gap could command a stale setpoint (idle on the first cruise after boot) or cancel cruise immediately. The references are now recorded before the state change and the throttle task latches its own last output on entry.
Resolve the conflict with #127 (ESP-IDF time shim): keep this branch's removal of afterCruiseStart(), whose work moved to toggleCruise() and the throttle task, and use timeMillis() for the cruise start time that toggleCruise() now records.
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.
For 8.1: gives chill mode more top-end thrust, and makes cruise work the same way in both modes. Cruise now has one maximum shared by chill and sport, and it always holds exactly the throttle you were flying at when you set it.
All percentages below are of the stock ESC throttle window (
normal_pwm_start1050 µs tonormal_pwm_end1950 µs, curve set to "Linear Thrust"), so output % = (µs − 1050) / 900. The oldCHILL_MODE_MAX_PWMcomment said "70%", but 1600 µs was actually 61%.What changes
CRUISE_MAX_PWM(1680 µs) replacesCRUISE_MAX_PERCENTAGE(the 60% clamp) andCRUISE_ACTIVATION_MAX_POT_PERCENTAGE(the 70% lever gate). The limit is on output, so sport reaches it at about 70% lever and chill at about 88%.ThrottleValueCallbacks) respects the same cap. Before, it accepted anything up to 1950 µs, which bypassed the cruise limit entirely.Race fix: engaging cruise
changeDeviceState()setARMED_CRUISINGand released the mutex beforeafterCruiseStart()recordedcruisedPotValandcruisedAtMillisand queued the cruise PWM. If the 50 Hz throttle task ran in that gap, one of two things happened:currentCruiseThrottlePWMfor a tick. On the first cruise after boot that'sESC_MIN_PWM, i.e. idle.cruisedPotVal = 0and an oldcruisedAtMillis, which cancels cruise immediately.Now
toggleCruise()records the cruise references before the state changes. The throttle task latches its own last commanded output when it seesARMED_CRUISINGfor the first time, so no other task has to hand it a value. The throttle task also readscurrentStateonce per tick, so the latch and theswitchalways see the same state.afterCruiseStart()has been removed.Relation to
pot-travel-cruiseThis covers the same area as the unmerged
pot-travel-cruisebranch (chill 75%, 70% lever gate, "+20 points past" cancel). It differs in three ways: the limit is on output rather than lever position so both modes share one cruise max, chill goes to 80%, and the existing cancel rule is kept. It includes that branch's fix for reading the lever once when cruise engages.Validation
pio test -e native-test: 56 passed.calculateCruisePwmandisPotInCruiseActivationRangewere retired along with their 7 tests. 3 new tests cover the 80%/70% values, refusing just above the cruise max, and the exact lever position where cruise stops engaging in each mode (sport 2891/4095, chill 3599/4095).pio run -e OpenPPG-CESP32S3-CAN-SP140: target build succeeded, no new warnings; RAM and flash unchanged (36.8% / 36.3%).Before merging: bench test (prop off, watching ESC input µs)