diff --git a/examples/joystick.py b/examples/joystick.py index 9a2e1c08be..26bfa24e12 100755 --- a/examples/joystick.py +++ b/examples/joystick.py @@ -3,6 +3,7 @@ import threading import argparse import numpy as np +from pprint import pprint from inputs import get_gamepad from kbhit import KBHit @@ -78,20 +79,15 @@ def joystick_thread(joystick): def main(joystick): threading.Thread(target=joystick_thread, args=(joystick,), daemon=True).start() - with PandaRunner() as (p, CI): + with PandaRunner() as p: CC = CarControl(enabled=False) while True: - cd = [CanData(addr, dat, bus) for addr, dat, bus in p.can_recv()] - CI.update([0, cd]) - CC.actuators.accel = float(4.0*np.clip(joystick.axes_values['gb'], -1, 1)) CC.actuators.steer = float(np.clip(joystick.axes_values['steer'], -1, 1)) - - from pprint import pprint pprint(CC) - _, can_sends = CI.apply(CC) - p.can_send_many(can_sends, timeout=1000) + p.read() + p.write(CC) # 100Hz time.sleep(0.01) diff --git a/opendbc/car/panda_runner.py b/opendbc/car/panda_runner.py index 2e6221decb..598ff51e4a 100644 --- a/opendbc/car/panda_runner.py +++ b/opendbc/car/panda_runner.py @@ -4,7 +4,7 @@ from panda import Panda from opendbc.car.car_helpers import get_car from opendbc.car.can_definitions import CanData -from opendbc.car.structs import CarControl +from opendbc.car.structs import CarParams, CarControl class PandaRunner(AbstractContextManager): def __enter__(self): @@ -14,12 +14,12 @@ def __enter__(self): # setup + fingerprinting self.p.set_safety_mode(Panda.SAFETY_ELM327, 1) self.CI = get_car(self._can_recv, self.p.can_send_many, self.p.set_obd, True) - print("fingerprinted", self.CI.CP.carName) - assert self.CI.CP.carFingerprint != "mock", "Unable to identify car. Check connections and ensure car is supported." + assert self.CI.CP.carFingerprint.lower() != "mock", "Unable to identify car. Check connections and ensure car is supported." + safety_model = list(CarParams.SafetyModel).index(self.CI.CP.safetyConfigs[0].safetyModel) self.p.set_safety_mode(Panda.SAFETY_ELM327, 1) self.CI.init(self.CI.CP, self._can_recv, self.p.can_send_many) - self.p.set_safety_mode(Panda.SAFETY_TOYOTA, self.CI.CP.safetyConfigs[0].safetyParam) + self.p.set_safety_mode(safety_model, self.CI.CP.safetyConfigs[0].safetyParam) return self