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

Commit bb7201b

Browse files
authored
Merge pull request #4 from kevinzwang/master
Add autonomous interfaces to implement
2 parents ae2b64f + 67a4a46 commit bb7201b

7 files changed

Lines changed: 281 additions & 0 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package org.usfirst.frc.team199.Robot2018;
2+
3+
import edu.wpi.first.wpilibj.Sendable;
4+
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
5+
6+
/**
7+
* Directly copied from Robot2017 - @kevinzwang
8+
*/
9+
10+
public interface DashboardInterface {
11+
12+
/**
13+
* Puts all desired data on SmartDashboard
14+
*/
15+
public default void displayData() {
16+
17+
}
18+
19+
/*
20+
* Methods for displaying values with modified keys
21+
*/
22+
default void putNumber(String key, double value) {
23+
SmartDashboard.putNumber(getKey(key), value);
24+
}
25+
26+
default void putBoolean(String key, boolean value) {
27+
SmartDashboard.putBoolean(getKey(key), value);
28+
}
29+
30+
default void putString(String key, String value) {
31+
SmartDashboard.putString(getKey(key), value);
32+
}
33+
34+
default void putSendable(String key, Sendable value) {
35+
SmartDashboard.putData(getKey(key), value);
36+
}
37+
38+
/*
39+
* Methods for reading numbers, without specifying the modified key
40+
*/
41+
default double getNumber(String key, double defaultValue) {
42+
return SmartDashboard.getNumber(getKey(key), defaultValue);
43+
}
44+
45+
default boolean getBoolean(String key, boolean defaultValue) {
46+
return SmartDashboard.getBoolean(getKey(key), defaultValue);
47+
}
48+
49+
default String getString(String key, String defaultValue) {
50+
return SmartDashboard.getString(getKey(key), defaultValue);
51+
}
52+
53+
default double[] getNumArray(String key, double[] defaultValue) {
54+
return SmartDashboard.getNumberArray(getKey(key), defaultValue);
55+
}
56+
57+
/**
58+
* Converts the specified display key into one with its subsystem name appended
59+
* as a prefix, to be compatible with the Subsystem widget on SmartDashboard for
60+
* organizational purposes
61+
*
62+
* @param key The name of the original key
63+
* @return A modified key with prefix subsystem name
64+
*/
65+
default String getKey(String key) {
66+
return getClass().getSimpleName() + "/" + key;
67+
}
68+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package org.usfirst.frc.team199.Robot2018.commands;
2+
3+
import edu.wpi.first.wpilibj.command.CommandGroup;
4+
5+
/**
6+
* Initially run during Auto. Responsible for getting input from SmartDashboard
7+
* and the FMS, and then calling RunAuto with the specified script.
8+
*/
9+
public class Autonomous extends CommandGroup implements AutonomousInterface {
10+
11+
public Autonomous() {
12+
// TODO
13+
14+
// Add Commands here:
15+
// e.g. addSequential(new Command1());
16+
// addSequential(new Command2());
17+
// these will run in order.
18+
19+
// To run multiple commands at the same time,
20+
// use addParallel()
21+
// e.g. addParallel(new Command1());
22+
// addSequential(new Command2());
23+
// Command1 and Command2 will run in parallel.
24+
25+
// A command group will require all of the subsystems that each member
26+
// would require.
27+
// e.g. if Command1 requires chassis, and Command2 requires arm,
28+
// a CommandGroup containing them would require both the chassis and the
29+
// arm.
30+
}
31+
32+
/**
33+
* {@inheritDoc}
34+
*/
35+
@Override
36+
public Position getStartingPos() {
37+
// TODO
38+
return null;
39+
}
40+
41+
/**
42+
* {@inheritDoc}
43+
*/
44+
@Override
45+
public Strategy[] getStrategies() {
46+
// TODO
47+
return null;
48+
}
49+
50+
/**
51+
* {@inheritDoc}
52+
*/
53+
@Override
54+
public double getDelay() {
55+
// TODO
56+
return 0;
57+
}
58+
59+
/**
60+
* {@inheritDoc}
61+
*/
62+
@Override
63+
public String pickScript() {
64+
// TODO
65+
return null;
66+
}
67+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package org.usfirst.frc.team199.Robot2018.commands;
2+
3+
import org.usfirst.frc.team199.Robot2018.DashboardInterface;
4+
5+
import edu.wpi.first.wpilibj.DriverStation;
6+
7+
public interface AutonomousInterface extends DashboardInterface{
8+
public enum Position {
9+
LEFT,
10+
CENTER,
11+
RIGHT
12+
}
13+
14+
public enum Strategy {
15+
AUTO_LINE,
16+
SWITCH,
17+
SCALE,
18+
EXCHANGE,
19+
SWITCH_SCALE,
20+
SWITCH_EXCHANGE,
21+
NOTHING
22+
}
23+
24+
/**
25+
* Gets the starting position set in SmartDashboard
26+
*
27+
* @return an enum for the starting position
28+
*/
29+
public Position getStartingPos();
30+
31+
/**
32+
* Gets the four strategies set in SmartDashboard
33+
*
34+
* @return 4 strategies, in the order of (Switch + Scale ): LL, LR, RR, RL
35+
*/
36+
public Strategy[] getStrategies();
37+
38+
/**
39+
* Gets delay before running the specified script set in SmartDashboard
40+
*
41+
* @return delay in seconds
42+
*/
43+
public double getDelay();
44+
45+
/**
46+
* Directly gets the string from FMS
47+
*
48+
* @return FMS data
49+
*/
50+
default String getFMS() {
51+
return DriverStation.getInstance().getGameSpecificMessage();
52+
}
53+
54+
/**
55+
* Pick the script to run for Autonomous
56+
*
57+
* @return A String representing the name of the script
58+
*/
59+
public String pickScript();
60+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package org.usfirst.frc.team199.Robot2018.commands;
2+
3+
import edu.wpi.first.wpilibj.command.CommandGroup;
4+
5+
/**
6+
* Gets the script name and runs the script.
7+
*/
8+
public class RunScript extends CommandGroup implements RunScriptInterface {
9+
10+
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.
29+
}
30+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package org.usfirst.frc.team199.Robot2018.commands;
2+
3+
public interface RunScriptInterface {
4+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package org.usfirst.frc.team199.Robot2018.commands;
2+
3+
import edu.wpi.first.wpilibj.command.CommandGroup;
4+
5+
/**
6+
* Used for testing the autonomous interfaces. Runs the script specified in
7+
* SmartDashboard
8+
*/
9+
public class TestAuto extends CommandGroup implements TestAutoInterface {
10+
11+
public TestAuto() {
12+
// TODO
13+
14+
// Add Commands here:
15+
// e.g. addSequential(new Command1());
16+
// addSequential(new Command2());
17+
// these will run in order.
18+
19+
// To run multiple commands at the same time,
20+
// use addParallel()
21+
// e.g. addParallel(new Command1());
22+
// addSequential(new Command2());
23+
// Command1 and Command2 will run in parallel.
24+
25+
// A command group will require all of the subsystems that each member
26+
// would require.
27+
// e.g. if Command1 requires chassis, and Command2 requires arm,
28+
// a CommandGroup containing them would require both the chassis and the
29+
// arm.
30+
}
31+
32+
/**
33+
* {@inheritDoc}
34+
*/
35+
@Override
36+
public String getScriptToTest() {
37+
// TODO
38+
return null;
39+
}
40+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.usfirst.frc.team199.Robot2018.commands;
2+
3+
import org.usfirst.frc.team199.Robot2018.DashboardInterface;
4+
5+
public interface TestAutoInterface extends DashboardInterface {
6+
/**
7+
* gets the script name that we want to run from SmartDashboard
8+
*
9+
* @return the script name
10+
*/
11+
public String getScriptToTest();
12+
}

0 commit comments

Comments
 (0)