Skip to content
This repository was archived by the owner on Sep 14, 2019. It is now read-only.

Commit 2ac79eb

Browse files
authored
Merge pull request #11 from kevinzwang/master
add RunScript command
2 parents b5aeb14 + 0270364 commit 2ac79eb

1 file changed

Lines changed: 50 additions & 18 deletions

File tree

  • Robot2018/src/org/usfirst/frc/team199/Robot2018/commands
Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,62 @@
11
package org.usfirst.frc.team199.Robot2018.commands;
22

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;
310
import edu.wpi.first.wpilibj.command.CommandGroup;
11+
import edu.wpi.first.wpilibj.command.WaitCommand;
412

513
/**
614
* Gets the script name and runs the script.
715
*/
816
public class RunScript extends CommandGroup implements RunScriptInterface {
917

1018
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+
}
2961
}
3062
}

0 commit comments

Comments
 (0)