  class CarController:
    def __init__(self, dbc_name, CP, VM):
      self.CP = CP
      self.frame = 0
      self.last_steer = 0
      self.alert_active = False
      self.last_standstill = False
      self.standstill_req = False
 
</s> remove     elif self.CP.lateralTuning.which() == 'lqr':
      self.LaC = LatControlLQR(self.CP, self.CI)
 </s> add     elif self.CP.lateralTuning.which() == 'torque':
      self.LaC = LatControlTorque(self.CP, self.CI) </s> remove   def update(self, active, CS, CP, VM, params, last_actuators, desired_curvature, desired_curvature_rate):
 </s> add   def update(self, active, CS, CP, VM, params, last_actuators, desired_curvature, desired_curvature_rate, llk): </s> remove       set_lat_tune(ret.lateralTuning, LatTunes.LQR_RAV4)
 </s> add       set_lat_tune(ret.lateralTuning, LatTunes.TORQUE) </s> remove     apply_steer = apply_toyota_steer_torque_limits(new_steer, self.last_steer, CS.out.steeringTorqueEps, CarControllerParams)
 </s> add     apply_steer = apply_toyota_steer_torque_limits(new_steer, self.last_steer, CS.out.steeringTorqueEps, self.torque_rate_limits) </s> remove   @parameterized.expand([(HONDA.CIVIC, LatControlPID), (TOYOTA.RAV4, LatControlLQR), (TOYOTA.PRIUS, LatControlINDI), (NISSAN.LEAF, LatControlAngle)])
 </s> add   @parameterized.expand([(HONDA.CIVIC, LatControlPID), (TOYOTA.RAV4, LatControlTorque), (TOYOTA.PRIUS, LatControlINDI), (NISSAN.LEAF, LatControlAngle)])
    self.torque_rate_limits = CarControllerParams(self.CP)
  class CarController:
    def __init__(self, dbc_name, CP, VM):
      self.CP = CP
    self.torque_rate_limits = CarControllerParams(self.CP)
      self.frame = 0
      self.last_steer = 0
      self.alert_active = False
      self.last_standstill = False
      self.standstill_req = False
keep keep add keep keep keep keep keep
 Lateral torque-based control with roll on TSS2 corolla and TSSP rav4 (#24260)

* Initial commit

* Fix bugs

* Need more torque rate

* Cleanup cray cray control

* Write nicely

* Chiiil

* Not relevant for cray cray control

* Do some logging

* Seems like it has more torque than I thought

* Bit more feedforward

* Tune change

* Retune

* Retune

* Little more chill

* Add coroll

* Add corolla

* Give craycray a good name

* Update to proper logging

* D to the PI

* Should be in radians

* Add d

* Start oscillations

* Add D term

* Only change torque rate limits for new tune

* Add d logging

* Should be enough

* Wrong sign in D

* Downtune a little

* Needed to prevent faults

* Add lqr rav4 to tune

* Try derivative again

* Data based retune

* Data based retune

* add friction compensation

* Doesnt need too much P with friction comp

* remove lqr

* Remove kd

* Fix tests

* fix tests

* Too much error

* Get roll induced error under 1cm/deg

* Too much jitter

* Do roll comp

* Add ki

* Final update

* Update refs

* Cleanup latcontrol_torque a little more 
selfdrive/car/toyota/carcontroller.py