Skip to content

Commit

Permalink
ctrl: limit sends by config
Browse files Browse the repository at this point in the history
  • Loading branch information
JMPZ11 committed Jun 20, 2022
1 parent acac4ce commit e0a1093
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions selfdrive/car/gm/carcontroller.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from selfdrive.car.gm.values import DBC, CanBus, CarControllerParams

VisualAlert = car.CarControl.HUDControl.VisualAlert
NetworkLocation = car.CarParams.NetworkLocation


class CarController:
Expand Down Expand Up @@ -61,7 +62,7 @@ def update(self, CC, CS):
can_sends.append(gmcan.create_steering_control(self.packer_pt, CanBus.POWERTRAIN, apply_steer, idx, lkas_enabled))

# Gas/regen and brakes - all at 25Hz
if (self.frame % 4) == 0:
if CS.CP.openpilotLongitudinalControl and ((self.frame % 4) == 0):
if not CC.longActive:
# Stock ECU sends max regen when not enabled
self.apply_gas = self.params.MAX_ACC_REGEN
Expand All @@ -79,7 +80,7 @@ def update(self, CC, CS):
can_sends.append(gmcan.create_friction_brake_command(self.packer_ch, CanBus.CHASSIS, self.apply_brake, idx, near_stop, at_full_stop))

# Send dashboard UI commands (ACC status), 25hz
if (self.frame % 4) == 0:
if CS.CP.openpilotLongitudinalControl and ((self.frame % 4) == 0):
send_fcw = hud_alert == VisualAlert.fcw
can_sends.append(gmcan.create_acc_dashboard_command(self.packer_pt, CanBus.POWERTRAIN, CC.enabled,
hud_v_cruise * CV.MS_TO_KPH, hud_control.leadVisible, send_fcw))
Expand All @@ -89,18 +90,18 @@ def update(self, CC, CS):
time_and_headlights_step = 10
tt = self.frame * DT_CTRL

if self.frame % time_and_headlights_step == 0:
if CS.CP.openpilotLongitudinalControl and (not CS.CP.radarOffCan) and ((self.frame % time_and_headlights_step) == 0):
idx = (self.frame // time_and_headlights_step) % 4
can_sends.append(gmcan.create_adas_time_status(CanBus.OBSTACLE, int((tt - self.start_time) * 60), idx))
can_sends.append(gmcan.create_adas_headlights_status(self.packer_obj, CanBus.OBSTACLE))

speed_and_accelerometer_step = 2
if self.frame % speed_and_accelerometer_step == 0:
if CS.CP.openpilotLongitudinalControl and (not CS.CP.radarOffCan) and ((self.frame % speed_and_accelerometer_step) == 0):
idx = (self.frame // speed_and_accelerometer_step) % 4
can_sends.append(gmcan.create_adas_steering_status(CanBus.OBSTACLE, idx))
can_sends.append(gmcan.create_adas_accelerometer_speed_status(CanBus.OBSTACLE, CS.out.vEgo, idx))

if self.frame % self.params.ADAS_KEEPALIVE_STEP == 0:
if CS.CP.openpilotLongitudinalControl and CS.CP.networkLocation == NetworkLocation.gateway and ((self.frame % self.params.ADAS_KEEPALIVE_STEP) == 0):
can_sends += gmcan.create_adas_keepalive(CanBus.POWERTRAIN)

# Show green icon when LKA torque is applied, and
Expand All @@ -110,7 +111,7 @@ def update(self, CC, CS):
lka_active = CS.lkas_status == 1
lka_critical = lka_active and abs(actuators.steer) > 0.9
lka_icon_status = (lka_active, lka_critical)
if self.frame % self.params.CAMERA_KEEPALIVE_STEP == 0 or lka_icon_status != self.lka_icon_status_last:
if CS.CP.networkLocation != NetworkLocation.fwdCamera and ((self.frame % self.params.CAMERA_KEEPALIVE_STEP) == 0 or lka_icon_status != self.lka_icon_status_last):
steer_alert = hud_alert in (VisualAlert.steerRequired, VisualAlert.ldw)
can_sends.append(gmcan.create_lka_icon_command(CanBus.SW_GMLAN, lka_active, lka_critical, steer_alert))
self.lka_icon_status_last = lka_icon_status
Expand Down

0 comments on commit e0a1093

Please sign in to comment.