-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobot.py
More file actions
96 lines (73 loc) · 3.41 KB
/
Copy pathrobot.py
File metadata and controls
96 lines (73 loc) · 3.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from extras.debugmsgs import * # Formatted messages used for debugging
from components.drivetrain import Drivetrain
from components.controller import XboxController
from pathplannerlib.auto import NamedCommands
from autonomous.autonomous import PPL
from wpilib import TimedRobot
# Load constants from the json file
import json
with open('constants.json') as jsonf:
constants = json.load(jsonf)
jsonf.close()
# Create the robot class (his name is terrance)
class terrance(TimedRobot):
def robotInit(self):
# Robot initialization
self.drivetrain = Drivetrain()
successMsg('Drivetrain initialized')
try:
self.controller = XboxController(self) # Link the xbox controller to the terrance class
successMsg('Xbox controller initialized')
except Exception as e:
errorMsg('Issue in initializing xbox controller:', e, __file__)
self.PPL = PPL(self)
'''
THIS IS TEMPORARY DONT HARASS ME ABOUT IT :3
try:
# Register Named Commands
for command in constants["PATHPLANNER_CONSTANTS"]["AUTONOMOUS_COMMANDS"].keys():
# Register's a command that runs an auton command based on the given string name of the function
NamedCommands.registerCommand(str(command), autonCommand(str(command)))
except Exception as e:
errorMsg('Could not register commands to PPL:',e,__file__)
'''
def robotPeriodic(self):
# TODO: Add proccesses that should always be running at all times here
pass
def disabledPeriodic(self):
# TODO: Add functionality
pass
def autonomousInit(self): # Called at the begining of autonomous mode
debugMsg('Entering autonomous mode') # Called only at the beginning of autonomous mode.
self.controller.rumble(0.5) # Vibrate xbox controller to let driver know they are in auton mode
self.PPL.followPath('Example Path') # Run the autonomous command
def autonomousPeriodic(self): # Called every 20ms in autonomous mode.
self.driveWithJoystick(False) # Disable joystick controll in autonomous mode
self.drivetrain.updateOdometry()
def autonomousExit(self): # Called when exiting autonomous mode
debugMsg('Exiting autonomous mode')
def teleopInit(self): # Called only at the begining of teleop mode
debugMsg('Entering tele-operated mode')
self.controller.rumble(0.0) # Stop vibrating xbox controller to let driver know they are in teleop mode
def teleopPeriodic(self): # Called every 20 milliseconds in teleop mode
self.driveWithJoystick(True) # Enable drive mode with joystick
def teleopExit(self): # Called when exiting teleop mode
debugMsg('Exiting tele-operated mode')
def driveWithJoystick(self, state: bool): # Custom method to drive with joystick
self.controller.getSwerveValues()
self.drivetrain.drive(self.controller.xSpeed,
self.controller.ySpeed,
self.controller.rot,
state,
self.getPeriod())
'''
MACROS:
Below, add functions that can be linked to specific buttons
on a compatible peripherial device
'''
def zeroGyro(self):
self.drivetrain.zeroGyro()
def slowDownSwerve(self):
pass
def resetSwerveSpeed(self):
pass