Skip to content

Commit

Permalink
GM: clean up safety classes (#1143)
Browse files Browse the repository at this point in the history
* add PCM_CRUISE flag to GM safety tests (like safety code)

* pcm_status_msg

* rm 2
  • Loading branch information
sshane authored Nov 9, 2022
1 parent a01513d commit 8f7befa
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions tests/safety/test_gm.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ class Buttons:


class GmLongitudinalBase(common.PandaSafetyTest):
PCM_CRUISE = False # openpilot can control the PCM state if longitudinal

# pylint: disable=no-member,abstract-method
def test_set_resume_buttons(self):
"""
Expand Down Expand Up @@ -70,6 +72,8 @@ class TestGmSafetyBase(common.PandaSafetyTest, common.DriverTorqueSteeringSafety
INACTIVE_REGEN = 0
MAX_BRAKE = 0

PCM_CRUISE = True # openpilot is tied to the PCM state if not longitudinal

@classmethod
def setUpClass(cls):
if cls.__name__ == "TestGmSafetyBase":
Expand All @@ -85,7 +89,11 @@ def setUp(self):
self.safety.init_tests()

def _pcm_status_msg(self, enable):
raise NotImplementedError
if self.PCM_CRUISE:
values = {"CruiseState": enable}
return self.packer.make_can_msg_panda("AcceleratorPedal2", 0, values)
else:
raise NotImplementedError

def _speed_msg(self, speed):
values = {"%sWheelSpd" % s: speed for s in ["RL", "RR"]}
Expand All @@ -102,6 +110,9 @@ def _user_regen_msg(self, regen):

def _user_gas_msg(self, gas):
values = {"AcceleratorPedal2": 1 if gas else 0}
if self.PCM_CRUISE:
# Fill CruiseState with expected value if the safety mode reads cruise state from gas msg
values["CruiseState"] = self.safety.get_controls_allowed()
return self.packer.make_can_msg_panda("AcceleratorPedal2", 0, values)

def _send_brake_msg(self, brake):
Expand Down Expand Up @@ -179,15 +190,6 @@ def setUp(self):
self.safety.set_safety_hooks(Panda.SAFETY_GM, Panda.FLAG_GM_HW_CAM)
self.safety.init_tests()

def _user_gas_msg(self, gas):
cruise_active = self.safety.get_controls_allowed()
values = {"AcceleratorPedal2": 1 if gas else 0, "CruiseState": cruise_active}
return self.packer.make_can_msg_panda("AcceleratorPedal2", 0, values)

def _pcm_status_msg(self, enable):
values = {"CruiseState": enable}
return self.packer.make_can_msg_panda("AcceleratorPedal2", 0, values)

def test_buttons(self):
# Only CANCEL button is allowed while cruise is enabled
self.safety.set_controls_allowed(0)
Expand Down

0 comments on commit 8f7befa

Please sign in to comment.