From c463dc78f8ddb207719e2b1b9daeb54fcab728a9 Mon Sep 17 00:00:00 2001 From: Steel Ridge Robotics Date: Mon, 4 Jul 2022 16:06:53 -0700 Subject: [PATCH] Fixed Joystick issue Happy Independence day! --- Larry/conversions.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Larry/conversions.py b/Larry/conversions.py index 8ae7286..7799604 100644 --- a/Larry/conversions.py +++ b/Larry/conversions.py @@ -17,7 +17,13 @@ def sign(num) -> int: return 0 def convertJoystickInputToDegrees(x: float, y: float): # this allows us to use the x and y values on the joystick and convert it into degrees - return float(math.degrees(math.atan2(y, x))) + if sign(x) == -1: + return float(math.degrees(math.atan2(x, -y)) + 360.0) # this will make sure that it gives us a number between 0 and 360 + else: + if float(math.degrees(math.atan2(x, -y))) == 360.0: #This makes sure that if we get 360.0 degrees, it will be zero + return 0.0 + else: + return float(math.degrees(math.atan2(x, -y))) # the degrees, the joystick up is zero and the values increase clock-wise def deadband(value: float, band: float): # this makes sure that joystick drifting is not an issue.