      raise NotImplementedError('This longitudinal tune does not exist')
  
  
  ###### LAT ######
  def set_lat_tune(tune, name):
    if name == LatTunes.INDI_PRIUS:
      tune.init('indi')
      tune.indi.innerLoopGainBP = [0.]
      tune.indi.innerLoopGainV = [4.0]
      tune.indi.outerLoopGainBP = [0.]
      tune.indi.outerLoopGainV = [3.0]
 
</s> remove 
  elif name == LatTunes.LQR_RAV4:
    tune.init('lqr')
    tune.lqr.scale = 1500.0
    tune.lqr.ki = 0.05
    tune.lqr.a = [0., 1., -0.22619643, 1.21822268]
    tune.lqr.b = [-1.92006585e-04, 3.95603032e-05]
    tune.lqr.c = [1., 0.]
    tune.lqr.k = [-110.73572306, 451.22718255]
    tune.lqr.l = [0.3233671, 0.3185757]
    tune.lqr.dcGain = 0.002237852961363602

 </s> add  </s> remove       elif tuning == 'lqr':
        self.assertTrue(len(self.CP.lateralTuning.lqr.a))
 </s> add       elif tuning == 'torque':
        self.assertTrue(self.CP.lateralTuning.torque.kf > 0) </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, MAX_TORQUE=2.5, FRICTION=0.06)
def set_lat_tune(tune, name, MAX_TORQUE=2.5, FRICTION=.1):
  if name == LatTunes.TORQUE:
    tune.init('torque')
    tune.torque.useSteeringAngle = True
    tune.torque.kp = 2.0 / MAX_TORQUE
    tune.torque.kf = 1.0 / MAX_TORQUE
    tune.torque.ki = 0.5 / MAX_TORQUE
    tune.torque.friction = FRICTION
  elif name == LatTunes.INDI_PRIUS:
      raise NotImplementedError('This longitudinal tune does not exist')
  
  
  ###### LAT ######
def set_lat_tune(tune, name, MAX_TORQUE=2.5, FRICTION=.1):
  if name == LatTunes.TORQUE:
    tune.init('torque')
    tune.torque.useSteeringAngle = True
    tune.torque.kp = 2.0 / MAX_TORQUE
    tune.torque.kf = 1.0 / MAX_TORQUE
    tune.torque.ki = 0.5 / MAX_TORQUE
    tune.torque.friction = FRICTION
  elif name == LatTunes.INDI_PRIUS:
def set_lat_tune(tune, name, MAX_TORQUE=2.5, FRICTION=.1):
  if name == LatTunes.TORQUE:
    tune.init('torque')
    tune.torque.useSteeringAngle = True
    tune.torque.kp = 2.0 / MAX_TORQUE
    tune.torque.kf = 1.0 / MAX_TORQUE
    tune.torque.ki = 0.5 / MAX_TORQUE
    tune.torque.friction = FRICTION
  elif name == LatTunes.INDI_PRIUS:
      tune.init('indi')
      tune.indi.innerLoopGainBP = [0.]
      tune.indi.innerLoopGainV = [4.0]
      tune.indi.outerLoopGainBP = [0.]
      tune.indi.outerLoopGainV = [3.0]
keep keep keep keep replace replace 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/tunes.py