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

Commit 84c01b3

Browse files
committed
integrate Autonomous command with SmartDashboard
in robotInit() and autoInit() of Robot.java, puts and gets values in SmartDashboard into the Auto command
1 parent 859d1e1 commit 84c01b3

1 file changed

Lines changed: 39 additions & 15 deletions

File tree

  • Robot2018/src/org/usfirst/frc/team199/Robot2018

Robot2018/src/org/usfirst/frc/team199/Robot2018/Robot.java

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,19 @@
22
package org.usfirst.frc.team199.Robot2018;
33

44
import java.util.ArrayList;
5+
import java.util.HashMap;
56
import java.util.Map;
67

78
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;
812
import org.usfirst.frc.team199.Robot2018.subsystems.Climber;
913
import org.usfirst.frc.team199.Robot2018.subsystems.ClimberAssist;
1014
import org.usfirst.frc.team199.Robot2018.subsystems.IntakeEject;
1115
import org.usfirst.frc.team199.Robot2018.subsystems.Lift;
1216

17+
import edu.wpi.first.wpilibj.DriverStation;
1318
import edu.wpi.first.wpilibj.Preferences;
1419
import edu.wpi.first.wpilibj.TimedRobot;
1520
import edu.wpi.first.wpilibj.command.Command;
@@ -35,7 +40,9 @@ public class Robot extends TimedRobot {
3540
public static Map<String, ArrayList<String[]>> autoScripts;
3641

3742
Command autonomousCommand;
38-
SendableChooser<Command> chooser = new SendableChooser<>();
43+
SendableChooser<Position> posChooser = new SendableChooser<Position>();
44+
Map<String, SendableChooser<Strategy>> stratChoosers = new HashMap<String, SendableChooser<Strategy>>();
45+
String[] fmsPossibilities = {"LL", "LR", "RL", "RR"};
3946

4047
/**
4148
* This function is run when the robot is first started up and should be
@@ -44,8 +51,24 @@ public class Robot extends TimedRobot {
4451
@Override
4552
public void robotInit() {
4653
oi = new OI();
47-
// chooser.addObject("My Auto", new MyAutoCommand());
48-
SmartDashboard.putData("Auto mode", chooser);
54+
55+
// put in position chooer
56+
for (Position p : Position.values()) {
57+
posChooser.addObject(p.getSDName(), p);
58+
}
59+
SmartDashboard.putData("Starting Position", posChooser);
60+
61+
// put in strategy choosers
62+
for (String input : fmsPossibilities) {
63+
SendableChooser<Strategy> chooser = new SendableChooser<Strategy>();
64+
for (Strategy s : Strategy.values()) {
65+
chooser.addObject(s.getSDName(), s);
66+
}
67+
SmartDashboard.putData(input, chooser);
68+
stratChoosers.put(input, chooser);
69+
}
70+
71+
SmartDashboard.putNumber("Auto Delay", 0);
4972

5073
autoScripts = AutoUtils.parseScriptFile(Preferences.getInstance().getString("autoscripts", ""));
5174
}
@@ -78,18 +101,19 @@ public void disabledPeriodic() {
78101
*/
79102
@Override
80103
public void autonomousInit() {
81-
autonomousCommand = chooser.getSelected();
82-
83-
/*
84-
* String autoSelected = SmartDashboard.getString("Auto Selector",
85-
* "Default"); switch(autoSelected) { case "My Auto": autonomousCommand
86-
* = new MyAutoCommand(); break; case "Default Auto": default:
87-
* autonomousCommand = new ExampleCommand(); break; }
88-
*/
89-
90-
// schedule the autonomous command (example)
91-
if (autonomousCommand != null)
92-
autonomousCommand.start();
104+
String fmsInput = DriverStation.getInstance().getGameSpecificMessage();
105+
Position startPos = posChooser.getSelected();
106+
double autoDelay = SmartDashboard.getNumber("Auto Delay", 0);
107+
108+
Map<String, Strategy> strategies = new HashMap<String, Strategy>();
109+
for (Map.Entry<String, SendableChooser<Strategy>> entry : stratChoosers.entrySet()) {
110+
String key = entry.getKey();
111+
SendableChooser<Strategy> chooser = entry.getValue();
112+
strategies.put(key, chooser.getSelected());
113+
}
114+
115+
Autonomous auto = new Autonomous(startPos, strategies, autoDelay, fmsInput);
116+
auto.start();
93117
}
94118

95119
/**

0 commit comments

Comments
 (0)