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

Commit 91e34ed

Browse files
Merge branch 'working' of
https://github.com/DriverStationComputer/RobotCode2018 Conflicts: Robot2018/src/org/usfirst/frc/team199/Robot2018/Robot.java Robot2018/src/org/usfirst/frc/team199/Robot2018/RobotMap.java
2 parents dad76f7 + dfd6217 commit 91e34ed

32 files changed

Lines changed: 1568 additions & 855 deletions

.gitignore

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@ bin/
22
build/
33
dist/
44
.DS_Store
5-
*auto*
6-
*Auto*

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

Lines changed: 21 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,16 @@
2424
* interface to the commands and command groups that allow control of the robot.
2525
*/
2626
public class OI {
27-
//// CREATING BUTTONS
28-
// One type of button is a joystick button which is any button on a
29-
//// joystick.
30-
// You create one by telling it which joystick it's on and which button
31-
// number it is.
32-
// Joystick stick = new Joystick(port);
33-
// Button button = new JoystickButton(stick, buttonNumber);
34-
35-
// There are a few additional built in buttons you can use. Additionally,
36-
// by subclassing Button you can create custom triggers and bind those to
37-
// commands the same as any other Button.
38-
39-
//// TRIGGERING COMMANDS WITH BUTTONS
40-
// Once you have a button, it's trivial to bind it to a button in one of
41-
// three ways:
42-
43-
// Start the command when the button is pressed and let it run the command
44-
// until it is finished as determined by it's isFinished method.
45-
// button.whenPressed(new ExampleCommand());
46-
47-
// Run the command while the button is being held down and interrupt it once
48-
// the button is released.
49-
// button.whileHeld(new ExampleCommand());
50-
51-
// Start the command when the button is released and let it run the command
52-
// until it is finished as determined by it's isFinished method.
53-
// button.whenReleased(new ExampleCommand());
5427

5528
public Joystick leftJoy;
56-
private JoystickButton shiftLowGear;
57-
private JoystickButton shiftHighGear;
58-
private JoystickButton shiftDriveType;
59-
private JoystickButton PIDMove;
60-
private JoystickButton PIDTurn;
29+
private JoystickButton shiftLowGearButton;
30+
private JoystickButton shiftHighGearButton;
31+
private JoystickButton shiftDriveTypeButton;
32+
private JoystickButton PIDMoveButton;
33+
private JoystickButton PIDTurnButton;
6134
public Joystick rightJoy;
62-
private JoystickButton updatePidConstants;
63-
private JoystickButton updateEncoderDPP;
35+
private JoystickButton updatePIDConstantsButton;
36+
private JoystickButton updateEncoderDPPButton;
6437
public Joystick manipulator;
6538

6639
public int getButton(String key, int def) {
@@ -72,22 +45,22 @@ public int getButton(String key, int def) {
7245

7346
public OI() {
7447
leftJoy = new Joystick(0);
75-
shiftLowGear = new JoystickButton(leftJoy, getButton("Shift Low Gear", 3));
76-
shiftLowGear.whenPressed(new ShiftLowGear());
77-
shiftHighGear = new JoystickButton(leftJoy, getButton("Shift High Gear", 5));
78-
shiftHighGear.whenPressed(new ShiftHighGear());
79-
shiftDriveType = new JoystickButton(leftJoy, getButton("Shift Drive Type", 2));
80-
shiftDriveType.whenPressed(new ShiftDriveType());
81-
PIDMove = new JoystickButton(leftJoy, getButton("PID Move", 7));
82-
PIDMove.whenPressed(new PIDMove(40, Robot.dt));
83-
PIDTurn = new JoystickButton(leftJoy, getButton("PID Turn", 8));
84-
PIDTurn.whenPressed(new PIDTurn(30, Robot.dt));
48+
shiftLowGearButton = new JoystickButton(leftJoy, getButton("Shift Low Gear", 3));
49+
shiftLowGearButton.whenPressed(new ShiftLowGear());
50+
shiftHighGearButton = new JoystickButton(leftJoy, getButton("Shift High Gear", 5));
51+
shiftHighGearButton.whenPressed(new ShiftHighGear());
52+
shiftDriveTypeButton = new JoystickButton(leftJoy, getButton("Shift Drive Type", 2));
53+
shiftDriveTypeButton.whenPressed(new ShiftDriveType());
54+
PIDMoveButton = new JoystickButton(leftJoy, getButton("PID Move", 7));
55+
PIDMoveButton.whenPressed(new PIDMove(40, Robot.dt, RobotMap.distEncAvg));
56+
PIDTurnButton = new JoystickButton(leftJoy, getButton("PID Turn", 8));
57+
PIDTurnButton.whenPressed(new PIDTurn(30, Robot.dt, RobotMap.fancyGyro));
8558

8659
rightJoy = new Joystick(1);
87-
updatePidConstants = new JoystickButton(rightJoy, getButton("Get PID Constants", 8));
88-
updatePidConstants.whenPressed(new UpdatePIDConstants());
89-
updateEncoderDPP = new JoystickButton(rightJoy, getButton("Get Encoder Dist Per Pulse", 9));
90-
updateEncoderDPP.whenPressed(new SetDistancePerPulse());
60+
updatePIDConstantsButton = new JoystickButton(rightJoy, getButton("Get PID Constants", 8));
61+
updatePIDConstantsButton.whenPressed(new UpdatePIDConstants());
62+
updateEncoderDPPButton = new JoystickButton(rightJoy, getButton("Get Encoder Dist Per Pulse", 9));
63+
updateEncoderDPPButton.whenPressed(new SetDistancePerPulse());
9164

9265
manipulator = new Joystick(2);
9366
}

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

Lines changed: 56 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
11

22
package 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;
412
import org.usfirst.frc.team199.Robot2018.subsystems.Climber;
513
import org.usfirst.frc.team199.Robot2018.subsystems.ClimberAssist;
614
import org.usfirst.frc.team199.Robot2018.subsystems.Drivetrain;
715
import org.usfirst.frc.team199.Robot2018.subsystems.IntakeEject;
8-
import org.usfirst.frc.team199.Robot2018.subsystems.LeftDrive;
916
import 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;
1220
import edu.wpi.first.wpilibj.TimedRobot;
1321
import edu.wpi.first.wpilibj.command.Command;
1422
import 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

Comments
 (0)