deepcopy -> copy: we can technically make a reference, but copy is almost free and less error-prone

saves ~1% CPU
pull/33208/head
Shane Smiskol 1 year ago
parent 1a61723c2c
commit 6f307cf19f
  1. 2
      selfdrive/car/body/carcontroller.py
  2. 2
      selfdrive/car/chrysler/carcontroller.py
  3. 2
      selfdrive/car/ford/carcontroller.py
  4. 2
      selfdrive/car/gm/carcontroller.py
  5. 2
      selfdrive/car/honda/carcontroller.py
  6. 2
      selfdrive/car/hyundai/carcontroller.py
  7. 2
      selfdrive/car/mazda/carcontroller.py
  8. 4
      selfdrive/car/mock/carcontroller.py
  9. 2
      selfdrive/car/nissan/carcontroller.py
  10. 2
      selfdrive/car/subaru/carcontroller.py
  11. 2
      selfdrive/car/toyota/carcontroller.py
  12. 2
      selfdrive/car/volkswagen/carcontroller.py

@ -133,7 +133,7 @@ class CarController(CarControllerBase):
can_sends = []
can_sends.append(bodycan.create_control(self.packer, torque_l, torque_r))
new_actuators = copy.deepcopy(CC.actuators)
new_actuators = copy.copy(CC.actuators)
new_actuators.accel = torque_l
new_actuators.steer = torque_r
new_actuators.steerOutputCan = torque_r

@ -77,7 +77,7 @@ class CarController(CarControllerBase):
self.frame += 1
new_actuators = copy.deepcopy(CC.actuators)
new_actuators = copy.copy(CC.actuators)
new_actuators.steer = self.apply_steer_last / self.params.STEER_MAX
new_actuators.steerOutputCan = self.apply_steer_last

@ -111,7 +111,7 @@ class CarController(CarControllerBase):
self.steer_alert_last = steer_alert
self.lead_distance_bars_last = hud_control.leadDistanceBars
new_actuators = copy.deepcopy(actuators)
new_actuators = copy.copy(actuators)
new_actuators.curvature = self.apply_curvature_last
self.frame += 1

@ -153,7 +153,7 @@ class CarController(CarControllerBase):
if self.frame % 10 == 0:
can_sends.append(gmcan.create_pscm_status(self.packer_pt, CanBus.CAMERA, CS.pscm_status))
new_actuators = copy.deepcopy(actuators)
new_actuators = copy.copy(actuators)
new_actuators.steer = self.apply_steer_last / self.params.STEER_MAX
new_actuators.steerOutputCan = self.apply_steer_last
new_actuators.gas = self.apply_gas

@ -242,7 +242,7 @@ class CarController(CarControllerBase):
self.speed = pcm_speed
self.gas = pcm_accel / self.params.NIDEC_GAS_MAX
new_actuators = copy.deepcopy(actuators)
new_actuators = copy.copy(actuators)
new_actuators.speed = self.speed
new_actuators.accel = self.accel
new_actuators.gas = self.gas

@ -162,7 +162,7 @@ class CarController(CarControllerBase):
if self.frame % 50 == 0 and self.CP.openpilotLongitudinalControl:
can_sends.append(hyundaican.create_frt_radar_opt(self.packer))
new_actuators = copy.deepcopy(actuators)
new_actuators = copy.copy(actuators)
new_actuators.steer = apply_steer / self.params.STEER_MAX
new_actuators.steerOutputCan = apply_steer
new_actuators.accel = accel

@ -57,7 +57,7 @@ class CarController(CarControllerBase):
can_sends.append(mazdacan.create_steering_control(self.packer, self.CP,
self.frame, apply_steer, CS.cam_lkas))
new_actuators = copy.deepcopy(CC.actuators)
new_actuators = copy.copy(CC.actuators)
new_actuators.steer = apply_steer / CarControllerParams.STEER_MAX
new_actuators.steerOutputCan = apply_steer

@ -1,6 +1,6 @@
import copy
from openpilot.selfdrive.car.interfaces import CarControllerBase
class CarController(CarControllerBase):
def update(self, CC, CS, now_nanos):
return copy.deepcopy(CC.actuators), []
return CC.actuators, []

@ -74,7 +74,7 @@ class CarController(CarControllerBase):
self.packer, CS.lkas_hud_info_msg, steer_hud_alert
))
new_actuators = copy.deepcopy(actuators)
new_actuators = copy.copy(actuators)
new_actuators.steeringAngleDeg = apply_angle
self.frame += 1

@ -136,7 +136,7 @@ class CarController(CarControllerBase):
if self.frame % 2 == 0:
can_sends.append(subarucan.create_es_static_2(self.packer))
new_actuators = copy.deepcopy(actuators)
new_actuators = copy.copy(actuators)
new_actuators.steer = self.apply_steer_last / self.p.STEER_MAX
new_actuators.steerOutputCan = self.apply_steer_last

@ -168,7 +168,7 @@ class CarController(CarControllerBase):
if self.frame % 20 == 0 and self.CP.flags & ToyotaFlags.DISABLE_RADAR.value:
can_sends.append(make_tester_present_msg(0x750, 0, 0xF))
new_actuators = copy.deepcopy(actuators)
new_actuators = copy.copy(actuators)
new_actuators.steer = apply_steer / self.params.STEER_MAX
new_actuators.steerOutputCan = apply_steer
new_actuators.steeringAngleDeg = self.last_angle

@ -110,7 +110,7 @@ class CarController(CarControllerBase):
can_sends.append(self.CCS.create_acc_buttons_control(self.packer_pt, self.ext_bus, CS.gra_stock_values,
cancel=CC.cruiseControl.cancel, resume=CC.cruiseControl.resume))
new_actuators = copy.deepcopy(actuators)
new_actuators = copy.copy(actuators)
new_actuators.steer = self.apply_steer_last / self.CCP.STEER_MAX
new_actuators.steerOutputCan = self.apply_steer_last

Loading…
Cancel
Save