-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrobot.py
executable file
·80 lines (56 loc) · 2.13 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
78
79
80
#!/usr/bin/env python3
import wpilib
from magicbot import MagicRobot, tunable
from components.drivetrain import DriveTrain
from components.rotator import Rotator
class MyRobot(MagicRobot):
#
# Define components here
#
rotator = Rotator
drivetrain = DriveTrain
twitchy = tunable(0.9)
def createObjects(self):
"""Initialize all wpilib motors & sensors"""
# camera
# utrasoni sensors
# motors
self.robot = self
self.left_motor = wpilib.Spark(0)
self.right_motor = wpilib.Spark(1)
self.left_motor.setInverted(True)
self.right_motor.setInverted(True)
self.lifter_motor = wpilib.Talon(2)
self.ultrasonic = wpilib.AnalogInput(0)
self.light_relay = wpilib.Relay(0)
self.light_relay.set(wpilib.Relay.Value.kOn)
self.myRobot = wpilib.RobotDrive(self.left_motor, self.right_motor)
self.myRobot.setSafetyEnabled(False)
#2Joysticks
self.leftStick = wpilib.Joystick(0)
#self.rightStick = wpilib.Joystick(1)
# 5 motor controlors: 1colocter, 2 for weels, 1 for shooter
#light
#lifter: 1 motor
#
self.gyro = wpilib.ADXRS450_Gyro()
wpilib.CameraServer.launch('vision.py:main')
def teleopPeriodic(self):
"""Place code here that does things as a result of operator
actions. This code gets called over and over again, do not
put a loop in"""
self.drivetrain.move(self.leftStick.getY(), self.twitchy*self.leftStick.getX())
#if not self.rightStick.getTrigger():
if self.leftStick.getRawButton(7):
self.drivetrain.move(-self.leftStick.getY(), self.twitchy*self.leftStick.getX())
self.lifter_motor.set(1)
else:
self.lifter_motor.set(0)
#if self.rightStick.getTrigger():
# self.lifter_motor.set(self.rightStick.getY())
if self.leftStick.getTrigger():
self.rotator.rotateTotarget()
if self.leftStick.getRawButton(10):
self.drivetrain.driveToWall()
if __name__ == '__main__':
wpilib.run(MyRobot)