@@ -44,9 +44,9 @@ In this section we will be going over
4444!!! summary ""
4545 ** 4)** Inside type:
4646
47- ''' java
48- distance = inches;
49- '''
47+ ``` java
48+ distance = inches;
49+ ```
5050
5151!!! summary ""
5252 ** 5)** In ** initialize** add our ** resetDriveEncoder** method
@@ -61,74 +61,74 @@ In this section we will be going over
6161!!! summary ""
6262 ** 7)** In ** isFinished** type:
6363
64- ''' java
65- return Robot.m_drivetrain.getDriveEncoderDistance() == distance;
66- '''
64+ ``` java
65+ return Robot.m_drivetrain.getDriveEncoderDistance() == distance;
66+ ```
6767!!! summary ""
6868 ** 8)** In ** end** stop the ** Drivetrain** and call ** end** in ** interrupted**
6969
7070??? Example
7171
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;
122108 }
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+ ```
124124
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+ ```
132132
133133## Creating The Autonomous Command
134134
@@ -140,10 +140,10 @@ In this section we will be going over
140140!!! summary ""
141141 ** 2)** In the constructor type
142142
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+ ```
147147
148148 - To add a ** command** to run in a ** command group** use ** addSequential** to execute commands in order
149149
@@ -182,55 +182,55 @@ In this section we will be going over
182182
183183 Your full **DoDelay.java** should look like this
184184
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);
232220 }
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+ ```
234234
235235## Adding the DoDelay Command to Autonomous.java
236236
@@ -239,51 +239,51 @@ In this section we will be going over
239239
240240??? Example
241241
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());
259258 }
260- '''
261-
262- The code you typed in ** RobotPreferences.java** should look like this
259+ }
260+ ```
263261
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+ }
268268
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+ ```
273273
274274## Adding Our Autonomous Command to Robot.java
275275
276276- 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
277277
278278- In ** Robot.java** under ** autonomousInit** find ** m_autonomousCommand = m_chooser.getSelected();** and change it to
279279
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+ ```
287287
288288## Testing Our Autonomous Command
289289
0 commit comments