Skip to content

Commit

Permalink
panda_runner: fixup safety mode setting
Browse files Browse the repository at this point in the history
  • Loading branch information
adeebshihadeh committed Sep 1, 2024
1 parent b4d39b9 commit 48ab55f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
12 changes: 4 additions & 8 deletions examples/joystick.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions opendbc/car/panda_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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

Expand Down

0 comments on commit 48ab55f

Please sign in to comment.