Skip to content

Commit

Permalink
Updating to match cpp examples verbatim and adding to run_tests.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
fletch3555 committed Dec 3, 2023
1 parent 731dab1 commit d7add5c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 32 deletions.
30 changes: 13 additions & 17 deletions arcade-drive-xbox-controller/robot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,27 @@ def robotInit(self):
"""Robot initialization function"""

# create motor controller objects
m_left = wpilib.Talon(0)
m_right = wpilib.Talon(1)
left = wpilib.PWMSparkMax(0)
right = wpilib.PWMSparkMax(1)

# object that handles basic drive operations
self.myRobot = wpilib.drive.DifferentialDrive(m_left, m_right)
self.myRobot.setExpiration(0.1)
self.robotDrive = wpilib.drive.DifferentialDrive(left, right)

# xbox controller #0
self.stick = wpilib.XboxController(0)
# xbox controller 0 on the driver station
self.driverController = wpilib.XboxController(0)

# We need to invert one side of the drivetrain so that positive voltages
# result in both sides moving forward. Depending on how your robot's
# gearbox is constructed, you might have to invert the left side instead.
m_right.setInverted(True)

def teleopInit(self):
"""Executed at the start of teleop mode"""
self.myRobot.setSafetyEnabled(True)
right.setInverted(True)

def teleopPeriodic(self):
"""Runs the motors with tank steering"""

# Drive with split arcade style
# That means that the Y axis of the left stick moves forward
# and backward, and the X of the right stick turns left and right.
self.myRobot.arcadeDrive(-self.stick.getLeftY(), -self.stick.getRightX())
"""
Drive with split arcade style
That means that the Y axis of the left stick moves forward
and backward, and the X of the right stick turns left and right.
"""
self.robotDrive.arcadeDrive(-self.driverController.getLeftY(), -self.driverController.getRightX())


if __name__ == "__main__":
Expand Down
28 changes: 13 additions & 15 deletions arcade-drive/robot.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#!/usr/bin/env python3
"""
This is a demo program showing the use of the DifferentialDrive class,
specifically it contains the code necessary to operate a robot with
a single joystick
This is a demo program showing the use of the DifferentialDrive class.
Runs the motors with arcade steering.
"""

import wpilib
Expand All @@ -14,24 +13,23 @@ def robotInit(self):
"""Robot initialization function"""

# create motor controller objects
m_left = wpilib.Talon(0)
m_right = wpilib.Talon(1)
left = wpilib.PWMSparkMax(0)
right = wpilib.PWMSparkMax(1)

# object that handles basic drive operations
self.myRobot = wpilib.drive.DifferentialDrive(m_left, m_right)
self.myRobot.setExpiration(0.1)
self.robotDrive = wpilib.drive.DifferentialDrive(left, right)

# joystick #0
# joystick 0 on the driver station
self.stick = wpilib.Joystick(0)

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

def teleopPeriodic(self):
"""Runs the motors with tank steering"""
self.myRobot.arcadeDrive(
self.stick.getRawAxis(0), self.stick.getRawAxis(1), True
)
"""Drive with arcade style"""
self.robotDrive.arcadeDrive(-self.stick.getY(), -self.stick.getX())


if __name__ == "__main__":
Expand Down
1 change: 1 addition & 0 deletions run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ cd "$(dirname $0)"
BASE_TESTS="
addressableled
arcade-drive
arcade-drive-xbox-controller
arm-simulation
commands-v2/hatchbot
commands-v2/hatchbot-inlined
Expand Down

0 comments on commit d7add5c

Please sign in to comment.