Skip to content
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

GM longitudinal pitch compensation #25469

Closed
wants to merge 5 commits into from

Conversation

twilsonco
Copy link
Contributor

@twilsonco twilsonco commented Aug 17, 2022

Part of PR stack, but I don't know how to submit a PR to commaai/openpilot that's comparing two branches in the opgm repo, so the layers of the PR stack will include the commits from the previous.

Description

Adds longitudinal pitch compensation to be used in cars that use gas/brake control, where the command specifies an amount of acceleration force rather than an amount of acceleration relative to the road. The implementation is contained in car controller, as a type of passive long feedforward, transparent to the controller.

To allow this to account for longitudinal actuator delay to allow for smoothing of the pitch signal, future model pitch is used to create a smoothed, predictive pitch.

Though not shown here, another benefit of this improvement is that if more than ACCEL_MAX acceleration is required to maintain speed up a steep hill, stock will not be able to maintain speed. With this improvement that is no longer the case.

actuators.accelPitchCompensated is used to determine the gas command, which specifies an acceleration force. The brake command on gm specifies acceleration relative to the ground, so the actuators.accel value is the correct value for friction brakes, even when going downhill.
To support this assertion, see that gas command does not match up with aEgo:
image
While brake command does match with aEgo
image
I also verified this extensively (though not with proper documentation) when developing "one pedal mode" in my openpilot fork, which involved artificially sending a constant brake command and observing the car's braking behavior. I found that the same brake command produces far more braking force on a decline, and far less (or none) on an incline.

However, when openpilot requests negative acceleration in order to stop behind a lead when going uphill, it would engage the friction brakes sooner (at the same time it would now, without this improvement), despite the negative gravitational acceleration, and resulting in more braking than in necessary, since it's being assisted by gravity.
So you'd like for openpilot to postpone friction brake use when decelerating uphill, but it can become a problem when stopping, as the pitch-compensated acceleration may remain positive even though openpilot would like to stop, resulting in late stopping behind leads.
The solution is to smoothly switch to non-pitch-compensated acceleration for determining brakes at low speed.
I've been using this method on my fork for about a month and it keeps the efficiency and brake-avoidance benefits of pitch-compensation without introducing possible problems when stopping behind leads.

(Any issues caused by the gas and brake signals having different physical meanings will also be minimized by using the correct gas/brake threshold acceleration value)

This should also be used on other makes that specify acceleration force with gas or brake commands

Verification

The result is a complete elimination of long error due to pitch changes. In the following image the plots on the left are without pitch compensation, and on the right with pitch compensation.

Screen Shot 2022-08-17 at 3 16 49 PM

See that as I climb up the stepped hill (pitch changing between 0 and ~12% grade), the pitchFutureLone (right side, second plot from top, orange line) predicts the liveParams pitch by ~0.4s, which is the value set for longitudinalActuatorDelayLowerBound (and upper bound), so it's predicting by the correct amount.

While there are large deviations between target and actual acceleration (fourth plot from top, left side) without pitch compensation, the pitch-induced error is completely removed on the right (error stays within ±0.05m/s^2 vs ±0.25m/s^2).
Also the with pitch compensation speed stays within 0±0.1m/s^2 compared to ±0.4m/s^2 (top plot).

Here's another image showing data where I descend down the same stepped hill. Again, with pitch compensation, the speed and acceleration oscillations due to changing pitch are completely removed.

Screen Shot 2022-08-17 at 3 12 35 PM

This PR includes three other PRs to 1) add liveParams pitch, 2) add liveParams future predicted pitch based on long actuator delay, and 3) to add calculation of pitch-compensated acceleration, saved to actuators.accelPitchCompensated.

Route: c11fcb510a549332|2022-08-17--13-58-51--0

missed pitch

cleanup
for compensating long actuator delay

cleanup revert Road Pitch string

missed pitch future

future pitch no kalman

future pitch reduce smoothing
was 0.01 in carstate at 100Hz,
now use 0.05 for 20Hz.

future_pitch not class member

slighlty less pitch smoothing

less pitch smoothing

add liveParams pitchFutureLong
bump cereal

bump cereal

bump cereal

add pitch accel deadzone
@twilsonco twilsonco marked this pull request as ready for review August 17, 2022 23:43
@twilsonco twilsonco force-pushed the pr-gm-long-pitch-compensation branch 2 times, most recently from af6f1fe to e88d676 Compare August 18, 2022 00:20
@twilsonco twilsonco marked this pull request as draft August 18, 2022 00:30
@twilsonco twilsonco changed the title Pr gm long pitch compensation GM long pitch compensation Aug 18, 2022
@twilsonco
Copy link
Contributor Author

Need to record routes on each PR in the stack. Will be ready for review after that

using smoothed, future pitch to account for long actuator delay

switch signs

use existing deadzone function

cc cleanup

log pitch-adjusted actuatorOutput.accel
and correct import

update submaster at 20Hz

gm use accelPitchCompensated

gm use accelPitchCompensated

bump cereal

only use pitch-compensation to determine gas

only use pitch to determine brakes on incline

only use pitch-comp accel for brakes at speed
@twilsonco twilsonco force-pushed the pr-gm-long-pitch-compensation branch from 872d420 to a01439e Compare August 18, 2022 01:29
@twilsonco
Copy link
Contributor Author

Routes recorded for other three PRs in the stack (not a real stack), so they're ready for review. Need to record a final route for this PR

@twilsonco twilsonco changed the title GM long pitch compensation GM longitudinal pitch compensation Aug 18, 2022
@sshane
Copy link
Contributor

sshane commented Aug 18, 2022

Generally when proposing a large change, it's best to open a single PR with all your changes so we can see what it would look like. Then if the PR is wanted and it could be split out into smaller PRs, we'd do that at that time.

@twilsonco
Copy link
Contributor Author

Route: c11fcb510a549332|2022-08-18--07-27-30--5

@twilsonco twilsonco marked this pull request as ready for review August 18, 2022 13:51
@twilsonco
Copy link
Contributor Author

twilsonco commented Aug 18, 2022

As I mention in the related pull requests. Future pitch is necessary in order to account for long actuator and other delays. Humans don't wait for the speed to drop before applying more gas when climbing a hill. They do it proactively, which avoids the error, avoids overcorrecting for the error, and improves efficiency and passenger comfort.

Surely if the model is reliable enough to plan a path to drive on, it's reliable enough to plan a tiny change in acceleration?

There are rate checks and caps in place to ensure predicted pitch values are safe and sane.

I've been driving on this logic for close to 1000 miles. It works great, consistently.

twilsonco added a commit to twilsonco/openpilot that referenced this pull request Aug 18, 2022
@twilsonco
Copy link
Contributor Author

I'll reimplement a standalone carcontroller version without using model pitch.

@twilsonco twilsonco closed this Aug 18, 2022
twilsonco added a commit to twilsonco/openpilot that referenced this pull request Aug 18, 2022
twilsonco added a commit to twilsonco/openpilot that referenced this pull request Aug 19, 2022
bounds check

use correct pitch bounds and rates
twilsonco added a commit to twilsonco/openpilot that referenced this pull request Aug 23, 2022
bounds check

use correct pitch bounds and rates
@nworb-cire nworb-cire deleted the pr-gm-long-pitch-compensation branch March 26, 2024 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants