From 7bd8c5425bfe91c2811827e87452aa5a2fb105e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20R=C4=85czy?= Date: Tue, 7 Nov 2023 15:48:13 -0800 Subject: [PATCH] controlsd: reset axes in joystick mode if message is old (#30409) Reset joystick if it wasnt received after 0.2 sec old-commit-hash: c419376bbde634801d0bdf247d564a5b8ecff795 --- selfdrive/controls/controlsd.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/selfdrive/controls/controlsd.py b/selfdrive/controls/controlsd.py index d800d895d3..437cf2d7ce 100755 --- a/selfdrive/controls/controlsd.py +++ b/selfdrive/controls/controlsd.py @@ -619,11 +619,18 @@ class Controls: else: lac_log = log.ControlsState.LateralDebugState.new_message() if self.sm.rcv_frame['testJoystick'] > 0: + # reset joystick if it hasn't been received in a while + should_reset_joystick = (self.sm.frame - self.sm.rcv_frame['testJoystick'])*DT_CTRL > 0.2 + if not should_reset_joystick: + joystick_axes = self.sm['testJoystick'].axes + else: + joystick_axes = [0.0, 0.0] + if CC.longActive: - actuators.accel = 4.0*clip(self.sm['testJoystick'].axes[0], -1, 1) + actuators.accel = 4.0*clip(joystick_axes[0], -1, 1) if CC.latActive: - steer = clip(self.sm['testJoystick'].axes[1], -1, 1) + steer = clip(joystick_axes[1], -1, 1) # max angle is 45 for angle-based cars, max curvature is 0.02 actuators.steer, actuators.steeringAngleDeg, actuators.curvature = steer, steer * 45., steer * -0.02