|
1 | 1 | package org.usfirst.frc.team199.Robot2018.commands; |
2 | 2 |
|
| 3 | +import java.util.ArrayList; |
| 4 | +import java.util.Arrays; |
| 5 | +import java.util.Map; |
| 6 | + |
| 7 | +import org.usfirst.frc.team199.Robot2018.Robot; |
| 8 | + |
| 9 | +import edu.wpi.first.wpilibj.Timer; |
3 | 10 | import edu.wpi.first.wpilibj.command.CommandGroup; |
| 11 | +import edu.wpi.first.wpilibj.command.WaitCommand; |
4 | 12 |
|
5 | 13 | /** |
6 | 14 | * Gets the script name and runs the script. |
7 | 15 | */ |
8 | 16 | public class RunScript extends CommandGroup implements RunScriptInterface { |
9 | 17 |
|
10 | 18 | public RunScript(String scriptName) { |
11 | | - // TODO |
12 | | - |
13 | | - // Add Commands here: |
14 | | - // e.g. addSequential(new Command1()); |
15 | | - // addSequential(new Command2()); |
16 | | - // these will run in order. |
17 | | - |
18 | | - // To run multiple commands at the same time, |
19 | | - // use addParallel() |
20 | | - // e.g. addParallel(new Command1()); |
21 | | - // addSequential(new Command2()); |
22 | | - // Command1 and Command2 will run in parallel. |
23 | | - |
24 | | - // A command group will require all of the subsystems that each member |
25 | | - // would require. |
26 | | - // e.g. if Command1 requires chassis, and Command2 requires arm, |
27 | | - // a CommandGroup containing them would require both the chassis and the |
28 | | - // arm. |
| 19 | + ArrayList<String> script = Robot.autoScripts.getOrDefault(scriptName, new ArrayList<String>()); |
| 20 | + |
| 21 | + outerloop: |
| 22 | + for(String cmd : script) { |
| 23 | + String[] cmdParts = cmd.split(" "); |
| 24 | + String cmdName = cmdParts[0]; |
| 25 | + String[] cmdArgs = Arrays.copyOfRange(cmdParts, 1, cmdParts.length); |
| 26 | + |
| 27 | + switch (cmdParts[0]) { |
| 28 | + case "moveto": |
| 29 | + addSequential(new AutoMoveTo(cmdArgs)); |
| 30 | + break; |
| 31 | + case "turn": |
| 32 | + addSequential(new AutoTurn(cmdArgs[0])); |
| 33 | + break; |
| 34 | + case "move": |
| 35 | + addSequential(new AutoMove(cmdArgs[0])); |
| 36 | + break; |
| 37 | + case "switch": |
| 38 | + addSequential(new EjectToSwitch()); |
| 39 | + break; |
| 40 | + case "scale": |
| 41 | + addSequential(new EjectToScale()); |
| 42 | + break; |
| 43 | + case "exchange": |
| 44 | + addSequential(new EjectToExchange()); |
| 45 | + break; |
| 46 | + case "wait": |
| 47 | + addSequential(new WaitCommand(Double.parseDouble(cmdArgs[0]))); |
| 48 | + break; |
| 49 | + case "intake": |
| 50 | + addSequential(new IntakeCube()); |
| 51 | + break; |
| 52 | + case "jump": |
| 53 | + addSequential(new RunScript(cmdArgs[0])); |
| 54 | + break; |
| 55 | + case "end": |
| 56 | + break outerloop; |
| 57 | + default: |
| 58 | + throw new Exception(); |
| 59 | + } |
| 60 | + } |
29 | 61 | } |
30 | 62 | } |
0 commit comments