Skip to content

Commit af76d1b

Browse files
fletch3555virtuald
authored andcommitted
add arcade-drive-xbox-controller example and update arcade-drive
1 parent 7e38675 commit af76d1b

File tree

3 files changed

+56
-15
lines changed

3 files changed

+56
-15
lines changed

arcade-drive-xbox-controller/robot.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env python3
2+
"""
3+
This is a demo program showing the use of the DifferentialDrive class.
4+
Runs the motors with split arcade steering and an Xbox controller.
5+
"""
6+
7+
import wpilib
8+
import wpilib.drive
9+
10+
11+
class MyRobot(wpilib.TimedRobot):
12+
def robotInit(self):
13+
"""Robot initialization function"""
14+
15+
# create motor controller objects
16+
left = wpilib.PWMSparkMax(0)
17+
right = wpilib.PWMSparkMax(1)
18+
19+
# object that handles basic drive operations
20+
self.robotDrive = wpilib.drive.DifferentialDrive(left, right)
21+
22+
# xbox controller 0 on the driver station
23+
self.driverController = wpilib.XboxController(0)
24+
25+
# We need to invert one side of the drivetrain so that positive voltages
26+
# result in both sides moving forward. Depending on how your robot's
27+
# gearbox is constructed, you might have to invert the left side instead.
28+
right.setInverted(True)
29+
30+
def teleopPeriodic(self):
31+
# Drive with split arcade style
32+
# That means that the Y axis of the left stick moves forward
33+
# and backward, and the X of the right stick turns left and right.
34+
self.robotDrive.arcadeDrive(
35+
-self.driverController.getLeftY(), -self.driverController.getRightX()
36+
)
37+
38+
39+
if __name__ == "__main__":
40+
wpilib.run(MyRobot)

arcade-drive/robot.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#!/usr/bin/env python3
22
"""
3-
This is a demo program showing the use of the DifferentialDrive class,
4-
specifically it contains the code necessary to operate a robot with
5-
a single joystick
3+
This is a demo program showing the use of the DifferentialDrive class.
4+
Runs the motors with arcade steering.
65
"""
76

87
import wpilib
@@ -14,24 +13,25 @@ def robotInit(self):
1413
"""Robot initialization function"""
1514

1615
# create motor controller objects
17-
m_left = wpilib.Talon(0)
18-
m_right = wpilib.Talon(1)
16+
left = wpilib.PWMSparkMax(0)
17+
right = wpilib.PWMSparkMax(1)
18+
1919
# object that handles basic drive operations
20-
self.myRobot = wpilib.drive.DifferentialDrive(m_left, m_right)
21-
self.myRobot.setExpiration(0.1)
20+
self.robotDrive = wpilib.drive.DifferentialDrive(left, right)
2221

23-
# joystick #0
22+
# joystick 0 on the driver station
2423
self.stick = wpilib.Joystick(0)
2524

26-
def teleopInit(self):
27-
"""Executed at the start of teleop mode"""
28-
self.myRobot.setSafetyEnabled(True)
25+
# We need to invert one side of the drivetrain so that positive voltages
26+
# result in both sides moving forward. Depending on how your robot's
27+
# gearbox is constructed, you might have to invert the left side instead.
28+
right.setInverted(True)
2929

3030
def teleopPeriodic(self):
31-
"""Runs the motors with tank steering"""
32-
self.myRobot.arcadeDrive(
33-
self.stick.getRawAxis(0), self.stick.getRawAxis(1), True
34-
)
31+
# Drive with split arcade style
32+
# That means that the Y axis of the left stick moves forward
33+
# and backward, and the X of the right stick turns left and right.
34+
self.robotDrive.arcadeDrive(-self.stick.getY(), -self.stick.getX())
3535

3636

3737
if __name__ == "__main__":

run_tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ cd "$(dirname $0)"
66
BASE_TESTS="
77
addressableled
88
arcade-drive
9+
arcade-drive-xbox-controller
910
arm-simulation
1011
canpdp
1112
commands-v2/hatchbot

0 commit comments

Comments
 (0)