1
1
#!/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
+ #
5
7
6
8
import wpilib
7
9
import wpilib .drive
@@ -13,34 +15,47 @@ def robotInit(self):
13
15
This function is called upon program startup and
14
16
should be used for any initialization code.
15
17
"""
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 )
20
24
self .timer = wpilib .Timer ()
21
25
22
26
# We need to invert one side of the drivetrain so that positive voltages
23
27
# result in both sides moving forward. Depending on how your robot's
24
28
# gearbox is constructed, you might have to invert the left side instead.
25
- self .right_motor .setInverted (True )
29
+ self .rightDrive .setInverted (True )
26
30
27
31
def autonomousInit (self ):
28
32
"""This function is run once each time the robot enters autonomous mode."""
29
- self .timer .reset ()
30
- self .timer .start ()
33
+ self .timer .restart ()
31
34
32
35
def autonomousPeriodic (self ):
33
36
"""This function is called periodically during autonomous."""
34
37
35
38
# Drive for two seconds
36
39
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 )
38
42
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."""
40
47
41
48
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."""
44
59
45
60
46
61
if __name__ == "__main__" :
0 commit comments