11
22package org .usfirst .frc .team199 .Robot2018 ;
33
4+ import java .util .ArrayList ;
5+ import java .util .HashMap ;
6+ import java .util .Map ;
7+
8+ import org .usfirst .frc .team199 .Robot2018 .autonomous .AutoUtils ;
9+ import org .usfirst .frc .team199 .Robot2018 .commands .Autonomous ;
10+ import org .usfirst .frc .team199 .Robot2018 .commands .Autonomous .Position ;
11+ import org .usfirst .frc .team199 .Robot2018 .commands .Autonomous .Strategy ;
412import org .usfirst .frc .team199 .Robot2018 .subsystems .Climber ;
513import org .usfirst .frc .team199 .Robot2018 .subsystems .ClimberAssist ;
614import org .usfirst .frc .team199 .Robot2018 .subsystems .Drivetrain ;
715import org .usfirst .frc .team199 .Robot2018 .subsystems .IntakeEject ;
8- import org .usfirst .frc .team199 .Robot2018 .subsystems .LeftDrive ;
916import org .usfirst .frc .team199 .Robot2018 .subsystems .Lift ;
10- import org .usfirst .frc .team199 .Robot2018 .subsystems .RightDrive ;
1117
18+ import edu .wpi .first .wpilibj .DriverStation ;
19+ import edu .wpi .first .wpilibj .Preferences ;
1220import edu .wpi .first .wpilibj .TimedRobot ;
1321import edu .wpi .first .wpilibj .command .Command ;
1422import edu .wpi .first .wpilibj .command .Scheduler ;
@@ -30,14 +38,16 @@ public class Robot extends TimedRobot {
3038 public static Lift lift ;
3139 public static RobotMap rmap ;
3240 public static Drivetrain dt ;
33- public static LeftDrive ld ;
34- public static RightDrive rd ;
3541 public static Listener listen ;
3642
3743 public static OI oi ;
44+
45+ public static Map <String , ArrayList <String []>> autoScripts ;
3846
3947 Command autonomousCommand ;
40- SendableChooser <Command > chooser = new SendableChooser <>();
48+ SendableChooser <Position > posChooser = new SendableChooser <Position >();
49+ Map <String , SendableChooser <Strategy >> stratChoosers = new HashMap <String , SendableChooser <Strategy >>();
50+ String [] fmsPossibilities = {"LL" , "LR" , "RL" , "RR" };
4151
4252 public static double getConst (String key , double def ) {
4353 if (!SmartDashboard .containsKey ("Const/" + key )) {
@@ -65,13 +75,31 @@ public void robotInit() {
6575 intakeEject = new IntakeEject ();
6676 lift = new Lift ();
6777 dt = new Drivetrain ();
68- ld = new LeftDrive ();
69- rd = new RightDrive ();
70- rmap .initPIDControllers ();
7178 oi = new OI ();
79+
80+ // auto position chooser
81+ for (Position p : Position .values ()) {
82+ posChooser .addObject (p .getSDName (), p );
83+ }
84+ SmartDashboard .putData ("Starting Position" , posChooser );
85+
86+ // auto strategy choosers
87+ for (String input : fmsPossibilities ) {
88+ SendableChooser <Strategy > chooser = new SendableChooser <Strategy >();
89+ for (Strategy s : Strategy .values ()) {
90+ chooser .addObject (s .getSDName (), s );
91+ }
92+ SmartDashboard .putData (input , chooser );
93+ stratChoosers .put (input , chooser );
94+ }
95+
96+ // auto delay chooser
97+ SmartDashboard .putNumber ("Auto Delay" , 0 );
98+
99+ // parse scripts from Preferences, which maintains values throughout reboots
100+ autoScripts = AutoUtils .parseScriptFile (Preferences .getInstance ().getString ("autoscripts" , "" ));
101+
72102 listen = new Listener ();
73- // chooser.addObject("My Auto", new MyAutoCommand());
74- SmartDashboard .putData ("Auto mode" , chooser );
75103 }
76104
77105 /**
@@ -90,30 +118,25 @@ public void disabledPeriodic() {
90118 }
91119
92120 /**
93- * This autonomous (along with the chooser code above) shows how to select
94- * between different autonomous modes using the dashboard. The sendable chooser
95- * code works with the Java SmartDashboard. If you prefer the LabVIEW Dashboard,
96- * remove all of the chooser code and uncomment the getString code to get the
97- * auto name from the text box below the Gyro
98- *
99- * You can add additional auto modes by adding additional commands to the
100- * chooser code above (like the commented example) or additional comparisons to
101- * the switch structure below with additional strings & commands.
121+ * This function is called once during the start of autonomous in order to
122+ * grab values from SmartDashboard and the FMS and call the Autonomous
123+ * command with those values.
102124 */
103125 @ Override
104126 public void autonomousInit () {
105- autonomousCommand = chooser .getSelected ();
106-
107- /*
108- * String autoSelected = SmartDashboard.getString("Auto Selector", "Default");
109- * switch(autoSelected) { case "My Auto": autonomousCommand = new
110- * MyAutoCommand(); break; case "Default Auto": default: autonomousCommand = new
111- * ExampleCommand(); break; }
112- */
113-
114- // schedule the autonomous command (example)
115- if (autonomousCommand != null )
116- autonomousCommand .start ();
127+ String fmsInput = DriverStation .getInstance ().getGameSpecificMessage ();
128+ Position startPos = posChooser .getSelected ();
129+ double autoDelay = SmartDashboard .getNumber ("Auto Delay" , 0 );
130+
131+ Map <String , Strategy > strategies = new HashMap <String , Strategy >();
132+ for (Map .Entry <String , SendableChooser <Strategy >> entry : stratChoosers .entrySet ()) {
133+ String key = entry .getKey ();
134+ SendableChooser <Strategy > chooser = entry .getValue ();
135+ strategies .put (key , chooser .getSelected ());
136+ }
137+
138+ Autonomous auto = new Autonomous (startPos , strategies , autoDelay , fmsInput , false );
139+ auto .start ();
117140 }
118141
119142 /**
@@ -147,5 +170,7 @@ public void teleopPeriodic() {
147170 */
148171 @ Override
149172 public void testPeriodic () {
173+ // Robot.dt.setLeft(0.2);
174+ Robot .dt .setRight (0.2 );
150175 }
151176}
0 commit comments