-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathRobot.java
More file actions
272 lines (238 loc) · 10.3 KB
/
Robot.java
File metadata and controls
272 lines (238 loc) · 10.3 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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package frc.robot;
import com.pathplanner.lib.path.PathConstraints;
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.util.Units;
import edu.wpi.first.wpilibj.DataLogManager;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.CommandScheduler;
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
import frc.robot.Constants.ReefScorePositions;
import frc.robot.subsystems.FlexAutoSubsystem;
import frc.robot.subsystems.UltrasonicSensor;
import java.util.List;
/**
* The VM is configured to automatically run this class, and to call the functions corresponding to
* each mode, as described in the TimedRobot documentation. If you change the name of this class or
* the package after creating this project, you must also update the build.gradle file in the
* project.
*/
public class Robot extends TimedRobot {
private static Robot instance;
public static SequentialCommandGroup autonomousCommand;
private RobotContainer m_robotContainer;
public static UltrasonicSensor globalUltraSensors;
public static FlexAutoSubsystem flexAutoSubsystem;
private Timer disabledTimer;
private Command centerModules = RobotContainer.drivebase.centerModulesCommand();
private String m_autoSelected;
private final SendableChooser<String> m_chooser = new SendableChooser<>();
private final SendableChooser<String> m_CoralStationChooser = new SendableChooser<>();
public static final SendableChooser<ReefScorePositions> desiredScoreSendableChooser =
new SendableChooser<>();
public Robot() {
SmartDashboard.putBoolean("FlexAuto", false);
SmartDashboard.putBoolean("", false);
SmartDashboard.putBoolean("", false);
SmartDashboard.putNumber("AssistMinDistance", 40);
SmartDashboard.putNumber("AutoMoveSpeed", 5);
SmartDashboard.putNumber("AutoScanSpeed", 5);
SmartDashboard.putNumber("Elevator-P", 0);
SmartDashboard.putNumber("Elevator-I", 0);
SmartDashboard.putNumber("Elevator-D", 0);
SmartDashboard.putNumber("Elevator-F", 0);
instance = this;
m_chooser.setDefaultOption("Our Cage 1", "Default Drop C");
m_chooser.addOption("Our Cage 2", "Default Drop M");
m_chooser.addOption("Our Cage 3", "Default Drop F");
m_chooser.addOption("Their Cage 1", "Other Drop C");
m_chooser.addOption("Their Cage 2", "Other Drop M");
m_chooser.addOption("Their Cage 3", "Other Drop F");
m_chooser.addOption("Box-9", "Box-9");
m_chooser.addOption("FWD 10 feet", "FWD10");
m_chooser.addOption("FWD 5 feet", "FWD5");
m_chooser.addOption("Wait", "wait");
SmartDashboard.putData(m_chooser);
m_CoralStationChooser.setDefaultOption("LeftCoralStation", "left");
m_CoralStationChooser.addOption("RightCoralStation", "right");
m_CoralStationChooser.addOption("Stop", "stop");
SmartDashboard.putData(m_CoralStationChooser);
DataLogManager.start();
}
public static Robot getInstance() {
return instance;
}
/**
* This function is run when the robot is first started up and should be used for any
* initialization code.
*/
@Override
public void robotInit() {
// Instantiate our RobotContainer. This will perform all our button bindings, and put our
// autonomous chooser on the dashboard.
m_robotContainer = new RobotContainer();
flexAutoSubsystem = new FlexAutoSubsystem();
// Create a timer to disable motor brake a few seconds after disable. This will let the robot
// stop
// immediately when disabled, but then also let it be pushed more
disabledTimer = new Timer();
if (isSimulation()) {
DriverStation.silenceJoystickConnectionWarning(true);
}
}
/**
* This function is called every 20 ms, no matter the mode. Use this for items like diagnostics
* that you want ran during disabled, autonomous, teleoperated and test.
*
* <p>This runs after the mode specific periodic functions, but before LiveWindow and
* SmartDashboard integrated updating.
*/
@Override
public void robotPeriodic() {
// Runs the Scheduler. This is responsible for polling buttons, adding newly-scheduled
// commands, running already-scheduled commands, removing finished or interrupted commands,
// and running subsystem periodic() methods. This must be called from the robot's periodic
// block in order for anything in the Command-based framework to work.
CommandScheduler.getInstance().run();
if (!DriverStation.isDisabled()) {
m_robotContainer.Periodic();
}
frc.robot.RobotContainer.elevatorSubsystem.Periodic();
// to set the levels
// SmartDashboard.putNumber("ElevEncoder:",
// RobotContainer.elevatorSubsystem.getPositionEncoder());
/*
SmartDashboard.putNumber("getAutoAlignOffsetX", 0);
desiredScoreSendableChooser.setDefaultOption("FRONTLEFT", ReefScorePositions.FRONTLEFT);
desiredScoreSendableChooser.addOption("FRONT", ReefScorePositions.FRONT);
desiredScoreSendableChooser.addOption("FRONTRIGHT", ReefScorePositions.FRONTRIGHT);
desiredScoreSendableChooser.addOption("BACKRIGHT", ReefScorePositions.BACKRIGHT);
desiredScoreSendableChooser.addOption("BACK", ReefScorePositions.BACK);
desiredScoreSendableChooser.addOption("BACKLEFT", ReefScorePositions.BACKLEFT);
desiredScoreSendableChooser.addOption("PROCESSER", ReefScorePositions.PROCESSER);
SmartDashboard.putData(desiredScoreSendableChooser);
*/
}
/** This function is called once each time the robot enters Disabled mode. */
@Override
public void disabledInit() {
m_robotContainer.setMotorBrake(true);
disabledTimer.reset();
disabledTimer.start();
RobotContainer.elevatorSubsystem.stop();
RobotContainer.coralHoldAngleSubsystem.stopTilt();
// RobotContainer.climberSubsystem.stop();
// centerModules.ignoringDisable(true);
}
@Override
public void disabledPeriodic() {
if (disabledTimer.hasElapsed(Constants.DrivebaseConstants.WHEEL_LOCK_TIME)) {
m_robotContainer.setMotorBrake(false);
disabledTimer.stop();
}
// centerModules.schedule();
}
/** This autonomous runs the autonomous command selected by your {@link RobotContainer} class. */
@Override
public void autonomousInit() {
// centerModules.end(true);
// RobotContainer.drivebase.zeroGyro();
m_robotContainer.init();
m_autoSelected = m_chooser.getSelected();
System.out.println("Auto selected: " + m_autoSelected);
if (!m_autoSelected.equals("wait")) {
autonomousCommand =
new SequentialCommandGroup(m_robotContainer.getAutonomousCommand(m_autoSelected));
}
// if (m_autoSelected.contains("Drop")) {
// autonomousCommand.andThen(
// new CoralShootCommand(RobotContainer.coralHoldSubsystem), new WaitCommand(1));
// }
// schedule the autonomous command
if (!m_CoralStationChooser.getSelected().equals("stop")) {
if (m_autoSelected.equals("wait")) {
autonomousCommand =
new SequentialCommandGroup(
m_robotContainer.getCoralPathCommand(m_CoralStationChooser.getSelected()));
} else {
autonomousCommand.addCommands(
m_robotContainer.getCoralPathCommand(m_CoralStationChooser.getSelected()));
}
}
// autonomousCommand.addCommands((Commands.runOnce(RobotContainer.drivebase::zeroGyro)));
if (autonomousCommand != null
&& !(m_CoralStationChooser.getSelected().equals("stop") && m_autoSelected.equals("wait"))) {
autonomousCommand.schedule();
}
}
List<Pose2d> points;
/** This function is called periodically during autonomous. */
@Override
public void autonomousPeriodic() {
// if flex auto enabled and we are not moving (flex checks this using .isnewpathavailable() )
SmartDashboard.putBoolean("AutoDone", autonomousCommand.isFinished());
if (SmartDashboard.getBoolean("FlexAuto", false) && flexAutoSubsystem.isNewPathAvailable()) {
// create robots constraints
PathConstraints constraints =
new PathConstraints(
RobotContainer.drivebase.getMaximumChassisVelocity(),
4.0,
RobotContainer.drivebase.getMaximumChassisAngularVelocity(),
Units.degreesToRadians(720));
// have flex create points to follow
flexAutoSubsystem.CreatePath(constraints, m_CoralStationChooser.getSelected());
}
// Will constantly get the position of the elevator,
// so that when we go into tele, we have an offset to
// adjust to
RobotContainer.getStart();
}
@Override
public void teleopInit() {
centerModules.end(true);
// RobotContainer.drivebase.zeroGyro();
// 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.
m_robotContainer.init();
if (autonomousCommand != null) {
autonomousCommand.cancel();
RobotContainer.drivebase.drive(new Translation2d(0, 0), 0, true);
} else {
CommandScheduler.getInstance().cancelAll();
}
// This is for testing- if we already have an offset,
// this will do nothing
if (!RobotContainer.gottenStart()) {
RobotContainer.getStart();
}
}
/** This function is called periodically during operator control. */
@Override
public void teleopPeriodic() {}
@Override
public void testInit() {
centerModules.end(true);
m_robotContainer.init();
// Cancels all running commands at the start of test mode.
CommandScheduler.getInstance().cancelAll();
}
/** This function is called periodically during test mode. */
@Override
public void testPeriodic() {}
/** This function is called once when the robot is first started up. */
@Override
public void simulationInit() {}
/** This function is called periodically whilst in simulation. */
@Override
public void simulationPeriodic() {}
}