Skip to content

Commit c616f00

Browse files
Update getting-started (#72)
Update getting-started to be inline with upstream examples. as per #49.
1 parent 7746b1b commit c616f00

File tree

2 files changed

+29
-16
lines changed

2 files changed

+29
-16
lines changed

arm-simulation/physics.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ def __init__(self, physics_controller: PhysicsInterface, robot: "MyRobot"):
5353
0.762,
5454
math.radians(-75),
5555
math.radians(255),
56-
5,
5756
True,
58-
[robot.kArmEncoderDistPerPulse],
5957
)
6058
self.encoderSim = wpilib.simulation.EncoderSim(robot.encoder)
6159
self.motorSim = wpilib.simulation.PWMSim(robot.motor.getChannel())

getting-started/robot.py

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env python3
2-
"""
3-
This is a good foundation to build your robot code on
4-
"""
2+
#
3+
# Copyright (c) FIRST and other WPILib contributors.
4+
# Open Source Software; you can modify and/or share it under the terms of
5+
# the WPILib BSD license file in the root directory of this project.
6+
#
57

68
import wpilib
79
import wpilib.drive
@@ -13,34 +15,47 @@ def robotInit(self):
1315
This function is called upon program startup and
1416
should be used for any initialization code.
1517
"""
16-
self.left_motor = wpilib.Spark(0)
17-
self.right_motor = wpilib.Spark(1)
18-
self.drive = wpilib.drive.DifferentialDrive(self.left_motor, self.right_motor)
19-
self.stick = wpilib.Joystick(0)
18+
self.leftDrive = wpilib.PWMSparkMax(0)
19+
self.rightDrive = wpilib.PWMSparkMax(1)
20+
self.robotDrive = wpilib.drive.DifferentialDrive(
21+
self.leftDrive, self.rightDrive
22+
)
23+
self.controller = wpilib.XboxController(0)
2024
self.timer = wpilib.Timer()
2125

2226
# We need to invert one side of the drivetrain so that positive voltages
2327
# result in both sides moving forward. Depending on how your robot's
2428
# gearbox is constructed, you might have to invert the left side instead.
25-
self.right_motor.setInverted(True)
29+
self.rightDrive.setInverted(True)
2630

2731
def autonomousInit(self):
2832
"""This function is run once each time the robot enters autonomous mode."""
29-
self.timer.reset()
30-
self.timer.start()
33+
self.timer.restart()
3134

3235
def autonomousPeriodic(self):
3336
"""This function is called periodically during autonomous."""
3437

3538
# Drive for two seconds
3639
if self.timer.get() < 2.0:
37-
self.drive.arcadeDrive(-0.5, 0) # Drive forwards at half speed
40+
# Drive forwards half speed, make sure to turn input squaring off
41+
self.robotDrive.arcadeDrive(0.5, 0, squareInputs=False)
3842
else:
39-
self.drive.arcadeDrive(0, 0) # Stop robot
43+
self.robotDrive.stopMotor() # Stop robot
44+
45+
def teleopInit(self):
46+
"""This function is called once each time the robot enters teleoperated mode."""
4047

4148
def teleopPeriodic(self):
42-
"""This function is called periodically during operator control."""
43-
self.drive.arcadeDrive(self.stick.getY(), self.stick.getX())
49+
"""This function is called periodically during teleoperated mode."""
50+
self.robotDrive.arcadeDrive(
51+
-self.controller.getLeftY(), -self.controller.getRightX()
52+
)
53+
54+
def testInit(self):
55+
"""This function is called once each time the robot enters test mode."""
56+
57+
def testPeriodic(self):
58+
"""This function is called periodically during test mode."""
4459

4560

4661
if __name__ == "__main__":

0 commit comments

Comments
 (0)