@@ -44,9 +44,9 @@ In this section we will be going over
44
44
!!! summary ""
45
45
** 4)** Inside type:
46
46
47
- ''' java
48
- distance = inches;
49
- '''
47
+ ``` java
48
+ distance = inches;
49
+ ```
50
50
51
51
!!! summary ""
52
52
** 5)** In ** initialize** add our ** resetDriveEncoder** method
@@ -61,74 +61,74 @@ In this section we will be going over
61
61
!!! summary ""
62
62
** 7)** In ** isFinished** type:
63
63
64
- ''' java
65
- return Robot.m_drivetrain.getDriveEncoderDistance() == distance;
66
- '''
64
+ ``` java
65
+ return Robot.m_drivetrain.getDriveEncoderDistance() == distance;
66
+ ```
67
67
!!! summary ""
68
68
** 8)** In ** end** stop the ** Drivetrain** and call ** end** in ** interrupted**
69
69
70
70
??? Example
71
71
72
- Your full ** DriveDistance.java** should look like this
73
-
74
- '''java
75
- package frc.robot.commands;
76
-
77
- import edu.wpi.first.wpilibj.command.Command;
78
- import frc.robot.Robot;
79
- import frc.robot.RobotPreferences;
80
-
81
- public class DriveDistance extends Command {
82
-
83
- private double distance;
84
-
85
- public DriveDistance(double inches) {
86
- // Use requires() here to declare subsystem dependencies
87
- // eg. requires(chassis);
88
- requires(Robot.m_drivetrain);
89
- distance = inches;
90
- }
91
-
92
- // Called just before this Command runs the first time
93
- @Override
94
- protected void initialize() {
95
- Robot.m_drivetrain.resetDriveEncoder();
96
- }
97
-
98
- // Called repeatedly when this Command is scheduled to run
99
- @Override
100
- protected void execute() {
101
- Robot.m_drivetrain.arcadeDrive(RobotPreferences.driveDistanceSpeed(), 0.0);
102
- }
103
-
104
- // Make this return true when this Command no longer needs to run execute()
105
- @Override
106
- protected boolean isFinished() {
107
- return Robot.m_drivetrain.getDriveEncoderDistance() == distance;
108
- }
109
-
110
- // Called once after isFinished returns true
111
- @Override
112
- protected void end() {
113
- Robot.m_drivetrain.arcadeDrive(0.0, 0.0);
114
- }
115
-
116
- // Called when another command which requires one or more of the same
117
- // subsystems is scheduled to run
118
- @Override
119
- protected void interrupted() {
120
- end();
121
- }
72
+ Your full ** DriveDistance.java** should look like this
73
+
74
+ ```java
75
+ package frc.robot.commands;
76
+
77
+ import edu.wpi.first.wpilibj.command.Command;
78
+ import frc.robot.Robot;
79
+ import frc.robot.RobotPreferences;
80
+
81
+ public class DriveDistance extends Command {
82
+
83
+ private double distance;
84
+
85
+ public DriveDistance(double inches) {
86
+ // Use requires() here to declare subsystem dependencies
87
+ // eg. requires(chassis);
88
+ requires(Robot.m_drivetrain);
89
+ distance = inches;
90
+ }
91
+
92
+ // Called just before this Command runs the first time
93
+ @Override
94
+ protected void initialize() {
95
+ Robot.m_drivetrain.resetDriveEncoder();
96
+ }
97
+
98
+ // Called repeatedly when this Command is scheduled to run
99
+ @Override
100
+ protected void execute() {
101
+ Robot.m_drivetrain.arcadeDrive(RobotPreferences.driveDistanceSpeed(), 0.0);
102
+ }
103
+
104
+ // Make this return true when this Command no longer needs to run execute()
105
+ @Override
106
+ protected boolean isFinished() {
107
+ return Robot.m_drivetrain.getDriveEncoderDistance() == distance;
122
108
}
123
- '''
109
+
110
+ // Called once after isFinished returns true
111
+ @Override
112
+ protected void end() {
113
+ Robot.m_drivetrain.arcadeDrive(0.0, 0.0);
114
+ }
115
+
116
+ // Called when another command which requires one or more of the same
117
+ // subsystems is scheduled to run
118
+ @Override
119
+ protected void interrupted() {
120
+ end();
121
+ }
122
+ }
123
+ ```
124
124
125
- The code you typed in ** RobotPreferences.java** should be this
126
-
127
- ''' java
128
- public static final double driveDistanceSpeed() {
129
- return Preferences.getInstance().getDouble("driveDistanceSpeed", 0.5);
130
- }
131
- '''
125
+ The code you typed in **RobotPreferences.java** should be this
126
+
127
+ ``` java
128
+ public static final double driveDistanceSpeed() {
129
+ return Preferences.getInstance().getDouble("driveDistanceSpeed", 0.5);
130
+ }
131
+ ```
132
132
133
133
## Creating The Autonomous Command
134
134
@@ -140,10 +140,10 @@ In this section we will be going over
140
140
!!! summary ""
141
141
** 2)** In the constructor type
142
142
143
- ''' java
144
- addSequential(new DriveDistance(RobotPreferences.autoDriveDistance()));
145
- addSequential(new ShooterUp());
146
- '''
143
+ ``` java
144
+ addSequential(new DriveDistance(RobotPreferences.autoDriveDistance()));
145
+ addSequential(new ShooterUp());
146
+ ```
147
147
148
148
- To add a ** command** to run in a ** command group** use ** addSequential** to execute commands in order
149
149
@@ -182,55 +182,55 @@ In this section we will be going over
182
182
183
183
Your full **DoDelay.java** should look like this
184
184
185
- '''java
186
- package frc.robot.commands;
187
-
188
- import edu.wpi.first.wpilibj.command.Command;
189
-
190
- public class DoDelay extends Command {
191
-
192
- private double expireTime;
193
- private double timeout;
194
-
195
- public DoDelay(double seconds) {
196
- // Use requires() here to declare subsystem dependencies
197
- // eg. requires(chassis);
198
- timeout = seconds;
199
- }
200
-
201
- protected void startTimer() {
202
- expireTime = timeSinceInitialized() + timeout;
203
- }
204
-
205
- // Called just before this Command runs the first time
206
- @Override
207
- protected void initialize() {
208
- startTimer();
209
- }
210
-
211
- // Called repeatedly when this Command is scheduled to run
212
- @Override
213
- protected void execute() {
214
- }
215
-
216
- // Make this return true when this Command no longer needs to run execute()
217
- @Override
218
- protected boolean isFinished() {
219
- return (timeSinceInitialized() >= expireTime);
220
- }
221
-
222
- // Called once after isFinished returns true
223
- @Override
224
- protected void end() {
225
- }
226
-
227
- // Called when another command which requires one or more of the same
228
- // subsystems is scheduled to run
229
- @Override
230
- protected void interrupted() {
231
- }
185
+ ```java
186
+ package frc.robot.commands;
187
+
188
+ import edu.wpi.first.wpilibj.command.Command;
189
+
190
+ public class DoDelay extends Command {
191
+
192
+ private double expireTime;
193
+ private double timeout;
194
+
195
+ public DoDelay(double seconds) {
196
+ // Use requires() here to declare subsystem dependencies
197
+ // eg. requires(chassis);
198
+ timeout = seconds;
199
+ }
200
+
201
+ protected void startTimer() {
202
+ expireTime = timeSinceInitialized() + timeout;
203
+ }
204
+
205
+ // Called just before this Command runs the first time
206
+ @Override
207
+ protected void initialize() {
208
+ startTimer();
209
+ }
210
+
211
+ // Called repeatedly when this Command is scheduled to run
212
+ @Override
213
+ protected void execute() {
214
+ }
215
+
216
+ // Make this return true when this Command no longer needs to run execute()
217
+ @Override
218
+ protected boolean isFinished() {
219
+ return (timeSinceInitialized() >= expireTime);
232
220
}
233
- '''
221
+
222
+ // Called once after isFinished returns true
223
+ @Override
224
+ protected void end() {
225
+ }
226
+
227
+ // Called when another command which requires one or more of the same
228
+ // subsystems is scheduled to run
229
+ @Override
230
+ protected void interrupted() {
231
+ }
232
+ }
233
+ ```
234
234
235
235
## Adding the DoDelay Command to Autonomous.java
236
236
@@ -239,51 +239,51 @@ In this section we will be going over
239
239
240
240
??? Example
241
241
242
- Your full **Autonomous.java** should look like this
243
-
244
- '''java
245
- package frc.robot.commands;
246
-
247
- import edu.wpi.first.wpilibj.command.CommandGroup;
248
- import frc.robot.RobotPreferences;
249
-
250
- public class Autonomous extends CommandGroup {
251
- /**
252
- * Add your docs here.
253
- * /
254
- public Autonomous() {
255
- addSequential(new DriveDistance(RobotPreferences.autoDriveDistance()));
256
- addSequential(new DoDelay(RobotPreferences.autoDelay()));
257
- addSequential(new ShooterUp());
258
- }
242
+ Your full **Autonomous.java** should look like this
243
+
244
+ ```java
245
+ package frc.robot.commands;
246
+
247
+ import edu.wpi.first.wpilibj.command.CommandGroup;
248
+ import frc.robot.RobotPreferences;
249
+
250
+ public class Autonomous extends CommandGroup {
251
+ /**
252
+ * Add your docs here.
253
+ */
254
+ public Autonomous() {
255
+ addSequential(new DriveDistance(RobotPreferences.autoDriveDistance()));
256
+ addSequential(new DoDelay(RobotPreferences.autoDelay()));
257
+ addSequential(new ShooterUp());
259
258
}
260
- '''
261
-
262
- The code you typed in ** RobotPreferences.java** should look like this
259
+ }
260
+ ```
263
261
264
- '''java
265
- public static double autoDelay() {
266
- return Preferences.getInstance().getDouble("autoDelay", 5.0);
267
- }
262
+ The code you typed in **RobotPreferences.java** should look like this
263
+
264
+ ```java
265
+ public static double autoDelay() {
266
+ return Preferences.getInstance().getDouble("autoDelay", 5.0);
267
+ }
268
268
269
- public static double autoDriveDistance() {
270
- return Preferences.getInstance().getDouble("autoDriveDistance", 12.0);
271
- }
272
- '''
269
+ public static double autoDriveDistance() {
270
+ return Preferences.getInstance().getDouble("autoDriveDistance", 12.0);
271
+ }
272
+ ```
273
273
274
274
## Adding Our Autonomous Command to Robot.java
275
275
276
276
- In order to run our ** Autonomous** command in autonomous we will have to put it in ** Robot.java** so that it will run as soon as the robot enters the autonomous mode
277
277
278
278
- In ** Robot.java** under ** autonomousInit** find ** m_autonomousCommand = m_chooser.getSelected();** and change it to
279
279
280
- <!-- TODO: Explain why we don't use chooser? -->
281
-
282
- ''' java
283
- public void autonomousInit() {
284
- m_autonomousCommand = new Autonomous();
285
- ...
286
- '''
280
+ <!-- TODO: Explain why we don't use chooser? -->
281
+
282
+ ``` java
283
+ public void autonomousInit() {
284
+ m_autonomousCommand = new Autonomous();
285
+ ...
286
+ ```
287
287
288
288
## Testing Our Autonomous Command
289
289
0 commit comments