forked from Team708/2015-Banshee
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRobot.java
148 lines (123 loc) · 4.98 KB
/
Robot.java
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
package org.team708.robot;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.Preferences;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.command.Scheduler;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import org.team708.robot.commands.autonomous.OneContainerOneTote;
import org.team708.robot.commands.visionProcessor.FollowYellowTote;
import org.team708.robot.subsystems.Drivetrain;
import org.team708.robot.subsystems.VisionProcessor;
import org.team708.robot.subsystems.Claw;
import org.team708.robot.subsystems.ClawElevator;
import org.team708.robot.subsystems.HockeyStick;
import org.team708.robot.subsystems.Intake;
import org.team708.robot.subsystems.ToteElevator;
/**
* The VM is configured to automatically run this class, and to call the
* functions corresponding to each mode, as described in the IterativeRobot
* documentation. If you change the name of this class or the package after
* creating this project, you must also update the manifest file in the resource
* directory.
*/
public class Robot extends IterativeRobot {
public static Drivetrain drivetrain;
public static VisionProcessor visionProcessor;
public static OI oi;
//SmartDashboard
Preferences robotPreferences;
//creates timer for the SmartDashboard stat sending
Timer statsTimer; // Timer used for Smart Dash statistics
private final double sendStatsIntervalSec = .5; // Interval between statistic reporting
public static final Intake intake = new Intake();
public static final HockeyStick hockeyStick = new HockeyStick();
public static final ToteElevator toteElevator = new ToteElevator();
public static final Claw claw = new Claw();
public static final ClawElevator clawElevator = new ClawElevator();
Command autonomousCommand;
SendableChooser autonomousMode;
/**
* This function is run when the robot is first started up and should be
* used for any initialization code.
*/
public void robotInit() {
//initialize timer periodic debug messages
statsTimer = new Timer();
statsTimer.start();
drivetrain = new Drivetrain();
oi = new OI();
visionProcessor = new VisionProcessor();
SmartDashboard.putData(drivetrain);
LiveWindow.addActuator("PID", "PID", drivetrain.getPIDController());
// instantiate the command used for the autonomous period
autonomousMode = new SendableChooser();
queueAutonomousModes();
setPIDPreferences();
}
public void disabledPeriodic() {
Scheduler.getInstance().run();
sendStatistics();
}
public void autonomousInit() {
// schedule the autonomous command (example)
autonomousCommand = (Command)autonomousMode.getSelected();
if (autonomousCommand != null) autonomousCommand.start();
}
/**
* This function is called periodically during autonomous
*/
public void autonomousPeriodic() {
Scheduler.getInstance().run();
sendStatistics();
}
public void teleopInit() {
// 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 (autonomousCommand != null) autonomousCommand.cancel();
}
/**
* This function is called when the disabled button is hit.
* You can use it to reset subsystems before shutting down.
*/
public void disabledInit() {
}
/**
* This function is called periodically during operator control
*/
public void teleopPeriodic() {
Scheduler.getInstance().run();
sendStatistics();
}
/**
* This function is called periodically during test mode
*/
public void testPeriodic() {
LiveWindow.run();
sendStatistics();
}
private void sendStatistics() {
if (statsTimer.get() >= sendStatsIntervalSec) {
statsTimer.reset();
// Various debug information
drivetrain.sendToDashboard();
visionProcessor.sendToDashboard();
intake.sendToDashboard();
}
}
private void queueAutonomousModes() {
// autonomousMode.addDefault("Drive in Square", new DriveInSquare());
autonomousMode.addObject("Follow Tote", new FollowYellowTote());
autonomousMode.addDefault("One Container", new OneContainerOneTote());
SmartDashboard.putData("Autonomous Selection", autonomousMode);
}
private void setPIDPreferences() {
drivetrain.setPIDGain('p', robotPreferences.getDouble("P", drivetrain.getPIDGain('p')));
drivetrain.setPIDGain('i', robotPreferences.getDouble("I", drivetrain.getPIDGain('i')));
drivetrain.setPIDGain('d', robotPreferences.getDouble("D", drivetrain.getPIDGain('d')));
}
}