-
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
Calculate average desired curvature using planned distance instead of vego #28118
Conversation
Just made another observation from the graphs. Despite hitting the curve 10 mph faster there was still less roll than when I hit the curve without the change. This lines up with my impression of how it feels in the curves. |
Not sure if this helps, but I tested the code out, and it feels better in many turns with speeds above 40kph, but there is one short, low speed turn on the way to my house that it's not making anymore when I apply these changes, like it didn't have enough torque - but there's also no torque limit warning. Here's a clip and route before applying: and after applying these changes, with me taking over to not hit the curb: I'm driving through that curve very often, I did multiple tests with and without the patch with the same results each time. I'm running a fork of the latest sunnypilot dev branch, with some changes on top but I think none that would affect lateral. |
Interesting, i'll take a look over the data in plotjuggler here in a bit. there's a chance that the model struggles with that curve and the way that get_lag_adjusted_curvature worked before caused it to request to turn more than the model actually desired, but i wouldn't think it would be that severe at those speed. I know there's still some amount of error in the calculations even with this change because it actually ends up requesting the curvature up to a point just before where we would expect to be distance wise. There's some things that could be done to deal with that last bit of error but my assumption was it was low enough of an error to not be worth the increase in complexity to fix it. I'll have to take a look at the data though to see if it seems to be caused by the error in the distance we're requesting. |
One other thought is that it could be related to the STEERING_RATE_COST in the lateral planner. It would stand to reason that the amount of extra curvature that get_lag_adjusted_curvature was requesting overcame the high steering rate cost that's set in the lateral planner currently, but that once it starts requesting a more accurate curvature the steering rate cost overcomes the curvature the model is requesting and causes that feeling of not having enough torque at low speeds |
Ok, let me know if I can help in any way or if you could use more routes. |
why is the |
it's a rough approximation of the average velocity between now and the point we're calculating the curvature at. average velocity * delay would be the distance the model thinks you're going to be at for the psi value. If we use only the velocity at the delay then we would have a similar issue as using v_ego, the final velocity * delay will either overshoot or undershoot based off of if the starting velocity was higher or lower than the final velocity. |
another thought i had since i made this PR was potentially exposing the x solution from the longitudinal mpc in the longitudinalPlan. Grabbing the x solution position at the delay would likely be more accurate than this rough average. |
That makes more sense. Or you can integrate the speeds up to t=delay using np.cumsum if you want to quickly experiment without changing the messages. |
Switched over to mpc distance. Initial impression is good, but i'll be getting in more driving today. |
Pretty happy with how it's performing. I've made a route public to use as an example: https://connect.comma.ai/6cc716ffa2eb1f32/1684276696320/1684277240226 |
@YassineYousfi any thoughts on this in its current state? Or anything you'd like me to do for validation? |
This single-handedly removes crossing the yellow line on every other corner for me. Without this modification op is almost unusable on the winding side roads where I live. I have tried it on master. I have tried it on other forks, no matter where I place this commit the effects are immediate. 22 sonata limited |
No stock ff at low speed NNFF Toyota: kf + 20%; rav4 torque by default ioniq 5 '22: raise torque kf 20% nnff: toyota lower kf 5% use speed-predictive curvature lag per commaai#28118
No stock ff at low speed NNFF Toyota: kf + 20%; rav4 torque by default ioniq 5 '22: raise torque kf 20% nnff: toyota lower kf 5% use speed-predictive curvature lag per commaai#28118 fix ordinal
No stock ff at low speed NNFF Toyota: kf + 20%; rav4 torque by default ioniq 5 '22: raise torque kf 20% nnff: toyota lower kf 5% use speed-predictive curvature lag per commaai#28118 fix ordinal merge fix logged wrong value
My issue is also resolved, it was model based - no longer a problem on Nicky, and after driving with this change for a longer while I can attest that it does mostly solve corner cutting on tighter turns. |
without this I still experienced cutting corner, with both new models, including the newest, hot coffee. |
Do you mean with this change? Rchybicki is saying that with this change most of his cutting is gone |
On stock Nicki me too, with this PR and Nicki nearly no more corner cutting. My issue, the one that was resolved, was about not having enough torque on one specific turn - that one is resolved and was only model related. |
No stock ff at low speed NNFF Toyota: kf + 20%; rav4 torque by default ioniq 5 '22: raise torque kf 20% nnff: toyota lower kf 5% use speed-predictive curvature lag per commaai#28118 fix ordinal merge fix logged wrong value
We are looking into this. Some turn cutting comes from higher in the planner stack which we are also looking into. |
No stock ff at low speed NNFF Toyota: kf + 20%; rav4 torque by default ioniq 5 '22: raise torque kf 20% nnff: toyota lower kf 5% use speed-predictive curvature lag per commaai#28118 fix ordinal merge fix logged wrong value torque: more jerk lookahead, no filtering use pfeiferj's lateral planner costs fix ordinal
No stock ff at low speed NNFF Toyota: kf + 20%; rav4 torque by default ioniq 5 '22: raise torque kf 20% nnff: toyota lower kf 5% use speed-predictive curvature lag per commaai#28118 fix ordinal merge fix logged wrong value torque: more jerk lookahead, no filtering use pfeiferj's lateral planner costs fix ordinal
hmm, not sure how but i managed to have my cereal and panda out of sync with master. updated to pull in latest master |
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
Added toggle to calculate average desired curvature using planned distance instead of vego. Credit goes to Pfeiferj! https://github.com/pfeiferj commaai#28118
The problem:
The psis used when calculating the average desired curvature in get_lag_adjusted_curvature appear to be the psi based on the planned acceleration. In get_lag_adjusted_curvature we try to remove the distance from the psi to get the curvature. To determine the distance the function takes the current velocity times the lag. However, when the model is planning on having a positive or negative acceleration in the curve there will be a difference in distance the model plans on traveling vs the distance that would be traveled at the current velocity. This results in poor planner performance in the curve because the planner is using a falsely high or low curvature depending on negative or positive acceleration in the model.
Solution:
This change gets a simple average of the first planned velocity and the velocity interpolated at the lag time to then use in the distance calculation. This results in more accurate curve planning by the planner.
Graphs:
Without change:
Notice how the planner curvature (green second row) flattens out at the apex of the curve whenever we begin accelerating.
With change:
In this screenshot note how much smoother the planner curvature lowers and rises. Also note that this was even hitting the curve 10 mph faster than in the previous graph without the change, which traditionally would have caused poorer performance.
Personal Observation:
Control throughout curves feels noticeably smoother and more planted. Fewer odd jerks of the steering wheel. Seems not to cut the corner as bad either.