-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrobot.py
78 lines (59 loc) · 2.47 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
#!/usr/bin/env python3
import wpilib
from wpilib.command import Scheduler
from networktables import NetworkTable
import logging
from oi import OI
from subsystems.drivetrain import DriveTrain
from subsystems.pneumatics_comp import Pneumatics
from subsystems.intake import Intake
from subsystems.lift import LiftMech
class Bob(wpilib.IterativeRobot):
#: update every 0.005 seconds/5 milliseconds (200Hz)
kUpdatePeriod = 0.005
def robotInit(self):
"""
This function is called upon program startup and
should be used for any initialization code.
"""
self.drivetrain = DriveTrain(self)
self.pneumatics_comp = Pneumatics(self)
self.intake = Intake(self)
self.lift = LiftMech(self)
self.oi = OI(self)
self.sd = NetworkTable.getTable("SmartDashboard")
self.drivetrain.drive.setExpiration(0.1)
self.drivetrain.drive2.setExpiration(0.1)
self.drivetrain.drive.setSafetyEnabled(True)
self.drivetrain.drive2.setSafetyEnabled(True)
def autonomousInit(self): #has nothing so far probably wont who knows
self.auto_loop_counter = 0 #teaches the roboto how to count
def autonomousPeriodic(self):
"""This function is called periodically during autonomous."""
self.drivetrain.drive.setSafetyEnabled(False)
self.drivetrain.drive2.setSafetyEnabled(False)
if self.auto_loop_counter < 100:
self.drivetrain.drive.tankDrive(-0.5, -0.5) #drive forward
self.drivetrain.drive2.tankDrive(-0.5, -0.5)
self.auto_loop_counter += 1
else:
self.drivetrain.drive.tankDrive(0,0)
self.drivetrain.drive2.tankDrive(0,0)
self.drivetrain.drive.setSafetyEnabled(True)
self.drivetrain.drive2.setSafetyEnabled(True)
def teleopPeriodic(self):
"""This function is called periodically during operator control."""
#cancel out autonomous
while self.isOperatorControl() and self.isEnabled():
Scheduler.getInstance().run()
self.log()
def testPeriodic(self):
"""This function is called periodically during test mode."""
wpilib.LiveWindow.run()
def log(self):
self.drivetrain.log()
self.lift.log()
self.sd.putNumber('someNumber', 1234) #checks to see if dashboard is working
#self.sd.getBoolean('Right trigger?',self.r_trig.get())
if __name__ == "__main__":
wpilib.run(Bob)