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