From bb36a1c8b2136ef556613abddaca308a05d54295 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Fri, 25 Mar 2022 14:17:45 -0700 Subject: [PATCH] sim: add ignition toggling (#24043) --- tools/sim/bridge.py | 9 ++++++--- tools/sim/lib/keyboard_ctrl.py | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tools/sim/bridge.py b/tools/sim/bridge.py index 70bc5f4e9..13f10af9c 100755 --- a/tools/sim/bridge.py +++ b/tools/sim/bridge.py @@ -48,6 +48,7 @@ class VehicleState: self.vel = carla.Vector3D() self.cruise_button = 0 self.is_engaged = False + self.ignition = True def steer_rate_limit(old, new): @@ -126,13 +127,13 @@ def imu_callback(imu, vehicle_state): pm.send('sensorEvents', dat) -def panda_state_function(exit_event: threading.Event): +def panda_state_function(vs: VehicleState, exit_event: threading.Event): pm = messaging.PubMaster(['pandaStates']) while not exit_event.is_set(): dat = messaging.new_message('pandaStates', 1) dat.valid = True dat.pandaStates[0] = { - 'ignitionLine': True, + 'ignitionLine': vs.ignition, 'pandaType': "blackPanda", 'controlsAllowed': True, 'safetyModel': 'hondaNidec' @@ -283,7 +284,7 @@ def bridge(q): # launch fake car threads threads = [] exit_event = threading.Event() - threads.append(threading.Thread(target=panda_state_function, args=(exit_event,))) + threads.append(threading.Thread(target=panda_state_function, args=(vehicle_state, exit_event,))) threads.append(threading.Thread(target=peripheral_state_function, args=(exit_event,))) threads.append(threading.Thread(target=fake_driver_monitoring, args=(exit_event,))) threads.append(threading.Thread(target=can_function_runner, args=(vehicle_state, exit_event,))) @@ -346,6 +347,8 @@ def bridge(q): elif m[1] == "cancel": cruise_button = CruiseButtons.CANCEL is_openpilot_engaged = False + elif m[0] == "ignition": + vehicle_state.ignition = not vehicle_state.ignition elif m[0] == "quit": break diff --git a/tools/sim/lib/keyboard_ctrl.py b/tools/sim/lib/keyboard_ctrl.py index 08d120d61..1c50b9b89 100644 --- a/tools/sim/lib/keyboard_ctrl.py +++ b/tools/sim/lib/keyboard_ctrl.py @@ -53,6 +53,8 @@ def keyboard_poll_thread(q: 'Queue[str]'): q.put("brake_%f" % 1.0) elif c == 'd': q.put("steer_%f" % -0.15) + elif c == 'i': + q.put("ignition") elif c == 'q': q.put("quit") break