Skip to content

Commit

Permalink
Added Dpad controls to move the robot for non-analogue control
Browse files Browse the repository at this point in the history
and also rumble too
  • Loading branch information
Tsunami014 committed Jan 12, 2024
1 parent 1cadeac commit ea3c25f
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,53 @@ def teleopInit(self) -> None:
def teleopPeriodic(self) -> None:
# Driving
spin_rate = 4
drive_x = -rescale_js(self.gamepad.getLeftY(), 0.1) * self.max_speed
drive_y = -rescale_js(self.gamepad.getLeftX(), 0.1) * self.max_speed
drive_z = -rescale_js(self.gamepad.getRightX(), 0.1, exponential=2) * spin_rate

joysticks = [
self.gamepad.getLeftY(),
self.gamepad.getLeftX(),
self.gamepad.getRightX(),
]

pov = self.gamepad.getPOV()
# print(pov)
if pov != -1:
joysticks[0] = 0
joysticks[1] = 0
match pov:
case 0:
joysticks[0] = 1
case 45:
joysticks[0] = 1
joysticks[1] = 1
case 90:
joysticks[1] = 1
case 135:
joysticks[0] = -1
joysticks[1] = 1
case 180:
joysticks[0] = -1
case 225:
joysticks[0] = -1
joysticks[1] = -1
case 270:
joysticks[1] = -1
case 315:
joysticks[0] = 1
joysticks[1] = -1

drive_x = -rescale_js(joysticks[0], 0.1) * self.max_speed
drive_y = -rescale_js(joysticks[1], 0.1) * self.max_speed
drive_z = -rescale_js(joysticks[2], 0.1, exponential=2) * spin_rate
local_driving = self.gamepad.getBButton()
driver_inputs = (drive_x, drive_y, drive_z)
if local_driving:
self.chassis.drive_local(*driver_inputs)
else:
self.chassis.drive_field(*driver_inputs)

if self.gamepad.getYButton():
self.rumble_for(self.gamepad.getLeftTriggerAxis(), 0.1)

# stop rumble after time
if self.rumble_timer.hasElapsed(self.rumble_duration):
self.gamepad.setRumble(wpilib.XboxController.RumbleType.kBothRumble, 0)
Expand Down

0 comments on commit ea3c25f

Please sign in to comment.