      ret = car.CarState.new_message()
  
      ret.canValid = self.cp.can_valid
  
      # speeds
      ret.vEgo = self.CS.v_ego
      ret.vEgoRaw = self.CS.v_ego_raw
      ret.standstill = self.CS.standstill
      ret.wheelSpeeds.fl = self.CS.v_wheel_fl
      ret.wheelSpeeds.fr = self.CS.v_wheel_fr
      ret.wheelSpeeds.rl = self.CS.v_wheel_rl
      ret.wheelSpeeds.rr = self.CS.v_wheel_rr
  
      # steering wheel
      ret.steeringAngle = self.CS.angle_steers
      ret.steeringPressed = self.CS.steer_override
  
      # gas pedal
      ret.gas = self.CS.user_gas / 100.
      ret.gasPressed = self.CS.user_gas > 0.0001
      ret.brakePressed = self.CS.brake_pressed
      ret.brakeLights = self.CS.brake_lights
  
      ret.cruiseState.enabled = not (self.CS.pcm_acc_status in [0, 3])
      ret.cruiseState.speed = self.CS.v_cruise_pcm
      ret.cruiseState.available = self.CS.pcm_acc_status != 0
  
      ret.genericToggle = self.CS.generic_toggle
  
      # events
      events = []
  
      if self.CS.steer_error:
        events.append(create_event('steerUnavailable', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE, ET.PERMANENT]))
 
</s> remove     # update prevs, update must run once per loop
    self.prev_left_blinker_on = self.left_blinker_on
    self.prev_right_blinker_on = self.right_blinker_on

    # calc best v_ego estimate, by averaging two opposite corners
    self.v_wheel_fl = cp.vl["WheelSpeed_CG1"]['WhlRr_W_Meas'] * WHEEL_RADIUS
    self.v_wheel_fr = cp.vl["WheelSpeed_CG1"]['WhlRl_W_Meas'] * WHEEL_RADIUS
    self.v_wheel_rl = cp.vl["WheelSpeed_CG1"]['WhlFr_W_Meas'] * WHEEL_RADIUS
    self.v_wheel_rr = cp.vl["WheelSpeed_CG1"]['WhlFl_W_Meas'] * WHEEL_RADIUS
    self.v_ego_raw = mean([self.v_wheel_fl, self.v_wheel_fr, self.v_wheel_rl, self.v_wheel_rr])
    self.v_ego, self.a_ego = self.update_speed_kf(self.v_ego_raw)
    self.standstill = not self.v_ego_raw > 0.001

    self.angle_steers = cp.vl["Steering_Wheel_Data_CG1"]['SteWhlRelInit_An_Sns']
    self.v_cruise_pcm = cp.vl["Cruise_Status"]['Set_Speed'] * CV.MPH_TO_MS
    self.pcm_acc_status = cp.vl["Cruise_Status"]['Cruise_State']
    self.main_on = cp.vl["Cruise_Status"]['Cruise_State'] != 0
    self.lkas_state = cp.vl["Lane_Keep_Assist_Status"]['LaActAvail_D_Actl']
 </s> add     ret = car.CarState.new_message()
    ret.wheelSpeeds.rr = cp.vl["WheelSpeed_CG1"]['WhlRr_W_Meas'] * WHEEL_RADIUS
    ret.wheelSpeeds.rl = cp.vl["WheelSpeed_CG1"]['WhlRl_W_Meas'] * WHEEL_RADIUS
    ret.wheelSpeeds.fr = cp.vl["WheelSpeed_CG1"]['WhlFr_W_Meas'] * WHEEL_RADIUS
    ret.wheelSpeeds.fl = cp.vl["WheelSpeed_CG1"]['WhlFl_W_Meas'] * WHEEL_RADIUS
    ret.vEgoRaw = mean([ret.wheelSpeeds.rr, ret.wheelSpeeds.rl, ret.wheelSpeeds.fr, ret.wheelSpeeds.fl])
    ret.vEgo, ret.aEgo = self.update_speed_kf(ret.vEgoRaw)
    ret.standstill = not ret.vEgoRaw > 0.001
    ret.steeringAngle = cp.vl["Steering_Wheel_Data_CG1"]['SteWhlRelInit_An_Sns']
    ret.steeringPressed = not cp.vl["Lane_Keep_Assist_Status"]['LaHandsOff_B_Actl']
    ret.cruiseState.speed = cp.vl["Cruise_Status"]['Set_Speed'] * CV.MPH_TO_MS
    ret.cruiseState.enabled = not (cp.vl["Cruise_Status"]['Cruise_State'] in [0, 3])
    ret.cruiseState.available = cp.vl["Cruise_Status"]['Cruise_State'] != 0
    ret.gas = cp.vl["EngineData_14"]['ApedPosScal_Pc_Actl'] / 100.
    ret.gasPressed = ret.gas > 1e-6
    ret.brakePressed = bool(cp.vl["Cruise_Status"]["Brake_Drv_Appl"])
    ret.brakeLights = bool(cp.vl["BCM_to_HS_Body"]["Brake_Lights"])
    ret.genericToggle = bool(cp.vl["Steering_Buttons"]["Dist_Incr"]) </s> remove     self.CS.update(self.cp)

    # create message
    ret = car.CarState.new_message()
 </s> add     ret = self.CS.update(self.cp) </s> remove     return ret.as_reader()
 </s> add     self.CS.out = ret.as_reader()

    return self.CS.out </s> remove     self.steer_override = not cp.vl["Lane_Keep_Assist_Status"]['LaHandsOff_B_Actl']
 </s> add     self.lkas_state = cp.vl["Lane_Keep_Assist_Status"]['LaActAvail_D_Actl'] </s> remove     self.user_gas = cp.vl["EngineData_14"]['ApedPosScal_Pc_Actl']
    self.brake_pressed = bool(cp.vl["Cruise_Status"]["Brake_Drv_Appl"])
    self.brake_lights = bool(cp.vl["BCM_to_HS_Body"]["Brake_Lights"])
    self.generic_toggle = bool(cp.vl["Steering_Buttons"]["Dist_Incr"])
 </s> add     return ret
      ret = car.CarState.new_message()
  
      ret.canValid = self.cp.can_valid
  

























      # events
      events = []
  
      if self.CS.steer_error:
        events.append(create_event('steerUnavailable', [ET.NO_ENTRY, ET.IMMEDIATE_DISABLE, ET.PERMANENT]))
keep keep keep keep replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace replace keep keep keep keep keep
 Ford: have carstate update returning capnp struct directly (#1113)

* Before abstraction, adding speed init from VW as well

* strting to abstract carstate class

* fix bug and update lock?

* revert pipfile change

* another bug

* fix linter

* bug fix

* remove a bunch of diplicated kf code

* better to not have class vars. will abstract __init__ anyway later

* abstract common instance vars in carstate init and a generic gear parser static method

* abstract gear parser for chrysler

* abstract gm gear parser too

* remove unnecessary random vars

* Chrysler: carstate returns capnp struct directly

* revert ref commit

* test ref

* WIP

* more WIP

* ops, missed this conflict

* ford as well

* not sure why this got deleted

* no need to copy

* remove copy

* remove copy import

* remove unnecessary intermediate variable

* remove obsolete comments

Co-authored-by: Willem Melching <willem.melching@gmail.com> 
selfdrive/car/ford/interface.py