|
1 | 1 | package org.usfirst.frc.team69.util; |
2 | 2 |
|
| 3 | +import java.util.Collections; |
3 | 4 | import java.util.function.BooleanSupplier; |
4 | 5 |
|
5 | 6 | import edu.wpi.first.wpilibj.command.Command; |
6 | 7 | import edu.wpi.first.wpilibj.command.CommandGroup; |
7 | 8 | import edu.wpi.first.wpilibj.command.ConditionalCommand; |
| 9 | +import edu.wpi.first.wpilibj.command.GetRequirements; |
8 | 10 | import edu.wpi.first.wpilibj.command.InstantCommand; |
| 11 | +import edu.wpi.first.wpilibj.command.Subsystem; |
9 | 12 | import edu.wpi.first.wpilibj.command.WaitCommand; |
10 | 13 | import edu.wpi.first.wpilibj.command.WaitUntilCommand; |
11 | 14 |
|
@@ -165,6 +168,39 @@ public CommandBuilder ifThenElse(BooleanSupplier condition, Command ifTrue, Comm |
165 | 168 | return this; |
166 | 169 | } |
167 | 170 |
|
| 171 | + /** |
| 172 | + * End any command currently running on the subsystem. This is accomplished |
| 173 | + * by running a command which ends instantly, which requires the given |
| 174 | + * subsystem. Afterwards, the default command will run, if there is one. |
| 175 | + * |
| 176 | + * @param subsystem The subsystem to release |
| 177 | + * @return This CommandBuilder object |
| 178 | + */ |
| 179 | + public CommandBuilder release(Subsystem subsystem) { |
| 180 | + m_cmdGroup.addSequential(QuickCommand.release(subsystem)); |
| 181 | + return this; |
| 182 | + } |
| 183 | + |
| 184 | + /** |
| 185 | + * End all commands currently running in parallel. This is accomplished by |
| 186 | + * starting an command which requires all the subsystems used so far, |
| 187 | + * which ends instantly. This will have the effect of starting the default |
| 188 | + * commands for all these subsystems, if they have any. |
| 189 | + * |
| 190 | + * @return This CommandBuilder object |
| 191 | + */ |
| 192 | + @SuppressWarnings("unchecked") |
| 193 | + public CommandBuilder releaseAll() { |
| 194 | + m_cmdGroup.addSequential(new InstantCommand() { |
| 195 | + { |
| 196 | + for (Object req : Collections.list(GetRequirements.getRequirements(m_cmdGroup))) { |
| 197 | + requires((Subsystem) req); |
| 198 | + } |
| 199 | + } |
| 200 | + }); |
| 201 | + return this; |
| 202 | + } |
| 203 | + |
168 | 204 | /** |
169 | 205 | * Build a command. Note that for simplicity, calling this method |
170 | 206 | * multiple times will return the same {@link Command} object. This |
|
0 commit comments