-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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 long: add pitch-compensation #25485
GM long: add pitch-compensation #25485
Conversation
Route: c11fcb510a549332|2022-08-19--09-03-54--0 VerificationHere we compare master (no pitch) with present and future pitch compensation on a couple steep steps of a hill, going up and down the steps. "Present pitch" is from the above route. Pitch compensation cuts speed error in half, and lowers acceleration error by 13%. (In the future, when Comma has sufficiently verified the model predicted pitch, I'd like to include future pitch in order to compensate for long actuator delay, which, as you can see here, decreases speed and acceleration error by an additional 46% compared to when using instantaneous pitch, and is tunable depending on the value of long actuator delay. Compared to master, future pitch compensation reduces speed and acceleration error by 74% and 53% respectively, resulting in greater passenger comfort and improved vehicle efficiency.) |
comment don't initialize filter log and use new_actuators.accel calculate accel_g for all frames record smoothed pitch to pitchDEPRECATED do initialize filter indentation no save deprecatedPitch comment
704b6a6
to
f26c961
Compare
It's possible we need something similar to this for Toyotas to undo the accel compensation the PCM does, so we should try to make this as generic as possible. |
So something in between this and the previous implementation that was unnecessarily couched inside of liveParams? |
This isn't that large; blocking this on abstracting it out seems like premature optimization. |
The additional calculation of accel_g in the |
pitch = clip(CC.orientationNED[1], self.pitch.x - PITCH_MAX_DELTA, self.pitch.x + PITCH_MAX_DELTA) | ||
pitch = clip(pitch, PITCH_MIN, PITCH_MAX) | ||
self.pitch.update(pitch) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feels like the delta clip and the filter do similar things, any reason for both?
|
||
self.packer_pt = CANPacker(DBC[self.CP.carFingerprint]['pt']) | ||
self.packer_obj = CANPacker(DBC[self.CP.carFingerprint]['radar']) | ||
self.packer_ch = CANPacker(DBC[self.CP.carFingerprint]['chassis']) | ||
|
||
def update(self, CC, CS): | ||
actuators = CC.actuators | ||
accel = actuators.accel |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use class variable so you don't need to set it when not an active control frame. check toyota/carcontroller
@@ -25,13 +34,15 @@ def __init__(self, dbc_name, CP, VM): | |||
self.lka_icon_status_last = (False, False) | |||
|
|||
self.params = CarControllerParams() | |||
self.pitch = FirstOrderFilter(0., 0.09 * 4, DT_CTRL * 4) # runs at 25 Hz |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we only use the filter, ensure that going from min to max pitch doesn't violate your selected rate limit above
if not CC.longActive: | ||
# Stock ECU sends max regen when not enabled | ||
self.apply_gas = self.params.MAX_ACC_REGEN | ||
self.apply_brake = 0 | ||
else: | ||
brake_accel = actuators.accel + accel_g * interp(CS.out.vEgo, BRAKE_PITCH_FACTOR_BP, BRAKE_PITCH_FACTOR_V) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if we change brake like this we probably should change gas
else: | ||
accel_g = ACCELERATION_DUE_TO_GRAVITY * apply_deadzone(self.pitch.x, PITCH_DEADZONE) # driving uphill is positive pitch | ||
accel += accel_g |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use class variable
With a view towards #30341, second-order effects would change the calculation from |
Thanks @simontheflutist. Oops forgot to close this. This too will be superseded by #29659. |
Closed this in favor of #29659 which is now closed. Reopening |
This PR has had no activity for 30 days. It will be automatically closed in 7 days if there is no activity. |
I'll get Shanes's proposed changes done and a new test route so that this can be merged |
This PR has had no activity for 30 days. It will be automatically closed in 7 days if there is no activity. |
This PR has been automatically closed due to inactivity. Feel free to re-open once activity resumes. |
It looks like you didn't use one of the Pull Request templates. Please check the contributing docs. Also make sure that you didn't modify any of the checkboxes or headings within the template. |
This PR has had no activity for 30 days. It will be automatically closed in 7 days if there is no activity. |
We've moved the car interfacing code to our PR_NUMBER=33045
curl -L https://github.com/commaai/openpilot/pull/$PR_NUMBER.patch | sed -e 's/selfdrive\/car/opendbc_repo\/opendbc\/car/g' | git apply -v --reject Simply replace the PR number with your own. Once done, add the files, fix any conflicts, and open a new PR. Alternatively, you may start a new PR from scratch if that is easier for you. |
If you would like to re-open, you can run our new maneuver tool and share the before and after reports. Here are some examples of the report showing a clear and obvious improvement, enabling us to merge a new tune faster and easier: |
(This, but without model-predicted pitch, and this is entirely contained in gm/carcontroller)
Description/justification
This PR adds pitch compensation to longitudinal control for GM cars, resulting in a large decrease in longitudinal error (versus the long plan) when pitch changes or when on an incline/decline.
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 theactuators.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:
While brake command does match with aEgo
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
Route: c11fcb510a549332|2022-08-19--09-03-54--0