Skip to content

Conversation

sshane
Copy link
Contributor

@sshane sshane commented Jul 22, 2025

Idea thanks to Harald. Moves everything to be in accel space until the very end. Instead of: #35780

This works because error is added onto feedforward, which is then converted at the right place on the non-linear curve for Bolt at the end.

Changes behavior slightly for Bolt, checking for linear cars...

opendbc: commaai/opendbc#2528

@@ -26,6 +27,7 @@
class LatControlTorque(LatControl):
def __init__(self, CP, CI):
super().__init__(CP, CI)
self.steer_max = ISO_LATERAL_ACCEL
Copy link
Contributor

Choose a reason for hiding this comment

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

This may limit max torque in ways we don't want

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Isn't it the same effect? We were limiting from -1 to 1, which was after gravity_adjusted_lateral_accel was converted to torque. Now we limit to the torque that can achieve 3 m/s^2?

Copy link
Contributor Author

@sshane sshane Jul 27, 2025

Choose a reason for hiding this comment

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

Assuming a perfectly linear torque car, I see that it could be a saturation problem if the car's lat accel factor is less than 3 m/s^2. Output could be 3 m/s^2 and torque_from_lateral_accel would convert it to 1.5x of the max torque which would be clipped to 1, and integral would windup outside the range. Is that what you mean?

Copy link
Contributor Author

@sshane sshane Jul 27, 2025

Choose a reason for hiding this comment

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

We need an inverse of all torque_from_lateral_accel functions I think, but that's impossible for the neural function without binary search which is ugly. It's simple for linear

Maybe this is why the PID controller was in torque space

Copy link
Contributor Author

@sshane sshane Jul 27, 2025

Choose a reason for hiding this comment

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

Actually we can revert #33970 to fix this.

Copy link
Contributor

@Copilot 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 PR refactors the torque controller to perform all calculations in lateral acceleration space rather than converting to torque space early in the process. This approach allows for more accurate handling of non-linear torque responses, particularly for vehicles like the Bolt that have non-linear torque curves.

Key changes:

  • Moves PID calculations to lateral acceleration space and converts to torque only at the final output step
  • Simplifies error calculation by working directly with lateral acceleration values
  • Updates saturation checking to use acceleration limits instead of torque limits

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
selfdrive/controls/lib/latcontrol_torque.py Refactors torque controller calculations to work in acceleration space, simplifying PID error computation and deferring torque conversion
opendbc_repo Updates subproject commit to support new ISO_LATERAL_ACCEL constant
Comments suppressed due to low confidence (2)

selfdrive/controls/lib/latcontrol_torque.py:30

  • The variable name steer_max is misleading since it now represents a lateral acceleration limit rather than a steering/torque limit. Consider renaming to lateral_accel_max or accel_limit to reflect the actual units and purpose.
    self.steer_max = ISO_LATERAL_ACCEL

selfdrive/controls/lib/latcontrol_torque.py:69

  • [nitpick] The variable name output_accel is more descriptive than the original output_torque, but consider using pid_output_accel or lateral_accel_output to be more explicit about what this represents in the control flow.
      output_accel = self.pid.update(pid_log.error,

Copy link
Contributor

github-actions bot commented Aug 7, 2025

This PR has had no activity for 9 days. It will be automatically closed in 2 days if there is no activity.

@github-actions github-actions bot added the stale label Aug 7, 2025
@sshane sshane added this to the 0.10.1 milestone Aug 7, 2025
@haraschax haraschax force-pushed the refactor-torque branch 2 times, most recently from 5db20f5 to 1d192f3 Compare August 14, 2025 17:47
@haraschax haraschax merged commit ab44c9a into master Aug 15, 2025
10 of 11 checks passed
@haraschax haraschax deleted the refactor-torque branch August 15, 2025 18:39
wtogami added a commit to wtogami/openpilot that referenced this pull request Aug 25, 2025
wtogami added a commit to wtogami/openpilot that referenced this pull request Aug 25, 2025
wtogami added a commit to wtogami/openpilot that referenced this pull request Aug 26, 2025
wtogami added a commit to wtogami/openpilot that referenced this pull request Aug 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants