forked from Team4169/2022
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrobot.py
More file actions
166 lines (120 loc) · 5.37 KB
/
Copy pathrobot.py
File metadata and controls
166 lines (120 loc) · 5.37 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#!/usr/bin/env python3
import typing
import wpilib
import commands2
import ctre
from robotcontainer import RobotContainer
from deadzone import addDeadzone
class MyRobot(commands2.TimedCommandRobot):
"""
Our default robot class, pass it to wpilib.run
Command v2 robots are encouraged to inherit from TimedCommandRobot, which
has an implementation of robotPeriodic which runs the scheduler for you
"""
autonomousCommand: typing.Optional[commands2.Command] = None
def output(self, text, value):
print(text + ': ' + str(value))
self.container.drive.sd.putValue(text, str(value))
def robotInit(self) -> None:
"""
This function is run when the robot is first started up and should be used for any
initialization code.
"""
# Instantiate our RobotContainer. This will perform all our button bindings, and put our
# autonomous chooser on the dashboard.
self.container = RobotContainer()
self.driverController = self.container.driverController
self.operatorController = self.container.operatorController
self.leftTalon = self.container.leftTalon
self.leftVictor = self.container.leftVictor
self.rightTalon = self.container.rightTalon
self.rightVictor = self.container.rightVictor
self.liftArm = self.container.liftArm
self.rotateArm = self.container.rotateArm
self.rotateEncoder = self.container.rotateEncoder
self.liftEncoder = self.container.liftEncoder
self.liftArmUpLimitSwitch = self.container.liftArmUpLimitSwitch
self.liftArmDownLimitSwitch = self.container.liftArmDownLimitSwitch
self.rotateArmBackLimitSwitch = self.container.rotateArmBackLimitSwitch
self.rotateArmRobotLimitSwitch = self.container.rotateArmRobotLimitSwitch
self.intake = self.container.intake
self.outtake = self.container.outtake
self.snowveyor = self.container.snowveyor
self.drive = self.container.drive
def disabledInit(self) -> None:
"""This function is called once each time the robot enters Disabled mode."""
def disabledPeriodic(self) -> None:
"""This function is called periodically when disabled"""
def autonomousInit(self) -> None:
"""This autonomous runs the autonomous command selected by your RobotContainer class."""
self.autonomousCommand = self.container.getAutonomousCommand()
if self.autonomousCommand:
self.autonomousCommand.schedule()
def autonomousPeriodic(self) -> None:
"""This function is called periodically during autonomous"""
def teleopInit(self) -> None:
# This makes sure that the autonomous stops running when
# teleop starts running. If you want the autonomous to
# continue until interrupted by another command, remove
# this line or comment it out.
if self.autonomousCommand:
self.autonomousCommand.cancel()
print("Starting teleop...")
self.humancontrol = True
self.speed = 0
self.intake = 0
self.outtake = 0
self.climbMode = False
self.direction = 0
def teleopPeriodic(self):
self.output("newdriveencodervalueleft", self.container.drive.leftTalon.getSelectedSensorPosition())
self.output("newdriveencodervalueright", self.container.drive.rightTalon.getSelectedSensorPosition())
if self.driverController.getLeftBumperPressed():
self.direction = 0
else:
self.direction = self.driverController.getLeftX()
self.speed = addDeadzone(self.driverController.getLeftY())
if self.operatorController.getStartButtonPressed():
self.climbMode = not self.climbMode
if self.climbMode:
self.container.bindClimbMode()
else:
self.container.unbindClimbMode()
if self.climbMode:
dir = self.operatorController.getPOV()
self.speed = 0.2
if 225 < dir <= 315:
self.direction = -1
elif 135 < dir <= 225:
self.speed *= -1
self.direction = 0
elif 45 < dir <= 135:
self.direction = 1
elif dir <= 45:
self.direction = 0
else:
self.speed = 0
self.drive.arcadeDrive(self.speed, self.direction)
return
if self.driverController.getAButton():
self.speed *= 0.75
elif self.driverController.getBButton():
self.speed *= 0.5
elif self.driverController.getYButton():
self.speed *= 0.3
elif self.driverController.getXButton():
self.speed = 0
if self.operatorController.getLeftTriggerAxis() > 0.2:
self.snowveyor.tankDrive(1,0)
elif self.operatorController.getRightTriggerAxis() > 0.2:
self.snowveyor.tankDrive(1,-1)
elif self.operatorController.getLeftBumper():
self.snowveyor.tankDrive(-1,0)
elif self.operatorController.getRightBumper():
self.snowveyor.tankDrive(-1,-1)
self.drive.arcadeDrive(self.speed, self.direction)
def testInit(self) -> None:
# Cancels all running commands at the start of test mode
commands2.CommandScheduler.getInstance().cancelAll()
if __name__ == "__main__":
wpilib.run(MyRobot)