-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobot.py
77 lines (58 loc) · 2.06 KB
/
robot.py
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
#!/usr/bin/env python3
"""
This is a program showing the use of the RobotDrive class,
specifically it contains the code necessary to operate a robot with
a single joystick
"""
import wpilib
import wpilib.drive
import wpilib.cameraserver as cameraserver
from wpilib.DoubleSolenoid.Value import kOff, kForward, kReverse
# from cscore import CameraServer
import rev
class Robot(wpilib.IterativeRobot):
"""2020 robot code"""
# stick 1
AXIS_THROTTLE = 1 # l stick
AXIS_STEER = 0 # l stick
BUTTON_SHIFT = 6 # r bumper
def robotInit(self):
"""Robot initialization function"""
self.motors = {
"left": [rev.CANSparkMax(3), rev.CANSparkMax(4)],
"right": [rev.CANSparkMax(1), rev.CANSparkMax(2)],
}
self.drive = wpilib.drive.DifferentialDrive(
wpilib.SpeedControllerGroup(*self.motors["left"]),
wpilib.SpeedControllerGroup(*self.motors["right"]),
)
# self.drive.setExpiration(0.5)
self.shifter = wpilib.DoubleSolenoid(0, 1)
self.compressor = wpilib.Compressor(0)
# wpilib.CameraServer.launch()
# camera_alpha = cameraserver.getInstance().startAutomaticCapture(0)
# camera_beta = cameraserver.getInstance().startAutomaticCapture(1)
# cameraserver.CameraServer.launch()
cameraserver.CameraServer.launch("camera.py:main")
# camera.setResolution(426, 240)
# camera.setFPS(15)
def autonomousInit(self):
self.teleopInit()
def autonomousPeriodic(self):
self.teleopPeriodic()
def teleopInit(self):
"""Executed at the start of teleop mode"""
# self.drive.setSafetyEnabled(True)
self.compressor.start()
def teleopPeriodic(self):
"""Does stuff"""
x = self.stick_drive.getRawAxis(self.AXIS_THROTTLE)
y = self.stick_drive.getRawAxis(self.AXIS_STEER)
a = self.stick_drive.getRawButton(self.BUTTON_A)
self.drive.arcadeDrive(-x, y)
self.shifter.set(kForward if a else kReverse)
def testInit(self):
self.compressor.stop() # disable compressor for testing use in quiet environments
testPeriodic = teleopPeriodic
if __name__ == "__main__":
wpilib.run(Robot)