Files
2018-Robot/src/org/usfirst/frc4388/robot/Robot.java
T

262 lines
8.2 KiB
Java
Raw Normal View History

2018-03-05 18:50:01 -07:00
package org.usfirst.frc4388.robot;
import edu.wpi.first.wpilibj.IterativeRobot;
import edu.wpi.first.wpilibj.CameraServer;
import edu.wpi.first.wpilibj.DriverStation;
//import edu.wpi.first.wpilibj.PowerDistributionPanel;
import edu.wpi.first.wpilibj.DriverStation.Alliance;
import edu.wpi.first.wpilibj.command.Command;
import edu.wpi.first.wpilibj.command.Scheduler;
import edu.wpi.first.wpilibj.command.Subsystem;
import edu.wpi.first.wpilibj.livewindow.LiveWindow;
import edu.wpi.first.wpilibj.smartdashboard.SendableChooser;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
//import org.usfirst.frc4388.controller.Robot.OperationMode;
import org.usfirst.frc4388.robot.commands.*;
import org.usfirst.frc4388.robot.commands.auton.*;
import org.usfirst.frc4388.robot.OI;
import org.usfirst.frc4388.robot.subsystems.*;
import org.usfirst.frc4388.utility.ControlLooper;
import org.usfirst.frc4388.robot.subsystems.Drive;
import org.usfirst.frc4388.robot.subsystems.Carriage;
2018-03-05 18:57:23 -07:00
import org.usfirst.frc4388.robot.subsystems.LED;
import org.usfirst.frc4388.robot.subsystems.Drive.DriveControlMode;;
2018-09-22 20:13:56 -06:00
2018-03-05 18:50:01 -07:00
public class Robot extends IterativeRobot
{
public static OI oi;
public static final Drive drive = new Drive();
2018-09-22 20:13:56 -06:00
2018-03-05 18:50:01 -07:00
public static final Carriage carriage = new Carriage();
public static final Elevator elevator = new Elevator();
public static final LED led = new LED();
public static final Climber climber = new Climber();
public static final Pnumatics pnumatics = new Pnumatics();
public static final long periodMS = 10;
public static final ControlLooper controlLoop = new ControlLooper("Main control loop", periodMS);
public static enum OperationMode { TEST, COMPETITION };
public static OperationMode operationMode = OperationMode.TEST;
private SendableChooser<OperationMode> operationModeChooser;
2018-03-05 18:57:23 -07:00
private SendableChooser<Command> RRautonTaskChooser;
private SendableChooser<Command> RLautonTaskChooser;
private SendableChooser<Command> LRautonTaskChooser;
private SendableChooser<Command> LLautonTaskChooser;
2018-03-05 18:50:01 -07:00
2018-03-05 18:57:23 -07:00
private Command RRautonomousCommand;
private Command RLautonomousCommand;
private Command LRautonomousCommand;
private Command LLautonomousCommand;
2018-03-05 18:50:01 -07:00
public void robotInit()
{
//Printing game data to riolog
String gameData = DriverStation.getInstance().getGameSpecificMessage();
System.out.println(gameData);
CameraServer.getInstance().startAutomaticCapture();
2018-09-22 20:13:56 -06:00
CameraServer.getInstance().putVideo("res", 300, 220);
2018-03-05 18:50:01 -07:00
try {
oi = OI.getInstance();
controlLoop.addLoopable(drive);
controlLoop.addLoopable(elevator);
2018-09-22 20:13:56 -06:00
2018-03-05 18:50:01 -07:00
operationModeChooser = new SendableChooser<OperationMode>();
operationModeChooser.addDefault("Test", OperationMode.TEST);
operationModeChooser.addObject("Competition", OperationMode.COMPETITION);
SmartDashboard.putData("Operation Mode", operationModeChooser);
2018-03-05 18:57:23 -07:00
RRautonTaskChooser = new SendableChooser<Command>();
2018-03-05 21:17:54 -07:00
RRautonTaskChooser.addDefault("Choose RR Program", new CrossTheBaseLine());
2018-03-23 23:36:51 -06:00
RRautonTaskChooser.addObject("Right too 2 Cube Scale", new Cube2Right());
RRautonTaskChooser.addObject("Center too right 2 Cube", new CenterRight2Cube());
RRautonTaskChooser.addObject("Left to Right Switch", new LeftStartRightScore());
2018-03-05 22:27:44 -07:00
RRautonTaskChooser.addObject("Center to Right Switch", new CenterRight());
2018-03-05 21:17:54 -07:00
RRautonTaskChooser.addObject("Right to Right Switch", new RightSwitchAuton());
2018-03-23 23:36:51 -06:00
RRautonTaskChooser.addObject("Right to Right tall boi", new ScaleFrom3());
2018-03-05 18:57:23 -07:00
SmartDashboard.putData("RRAuton Task", RRautonTaskChooser);
RLautonTaskChooser = new SendableChooser<Command>();
2018-03-05 21:17:54 -07:00
RLautonTaskChooser.addDefault("Choose RL Program", new CrossTheBaseLine());
2018-03-06 18:46:18 -07:00
2018-03-05 21:17:54 -07:00
RLautonTaskChooser.addObject("Left to Right Switch", new LeftStartRightScore());
2018-03-23 23:36:51 -06:00
RLautonTaskChooser.addObject("Left to Left tall boi", new ScaleFrom1());
RLautonTaskChooser.addObject("Center too right 2 Cube", new CenterRight2Cube());
2018-03-05 22:27:44 -07:00
RLautonTaskChooser.addObject("Center to Right Switch", new CenterRight());
2018-03-05 21:17:54 -07:00
RLautonTaskChooser.addObject("Right to Right Switch", new RightSwitchAuton());
2018-03-23 23:36:51 -06:00
RLautonTaskChooser.addObject("Left to left 2 Cube Scale", new Cube2Left());
2018-03-05 18:57:23 -07:00
SmartDashboard.putData("RLAuton Task", RLautonTaskChooser);
LLautonTaskChooser = new SendableChooser<Command>();
2018-03-05 21:17:54 -07:00
LLautonTaskChooser.addDefault("Choose LL Program", new CrossTheBaseLine());
2018-03-06 18:46:18 -07:00
2018-03-23 23:36:51 -06:00
LLautonTaskChooser.addObject("Left to Left tall boi", new ScaleFrom1());
2018-03-09 00:01:29 -06:00
LLautonTaskChooser.addObject("Left to Left Switch", new LeftSwitchAuton());
2018-03-23 23:36:51 -06:00
LLautonTaskChooser.addObject("Center too 2 left cube", new CenterLeft2Cube());
2018-03-05 21:17:54 -07:00
LLautonTaskChooser.addObject("Center to Left Switch", new CenterLeft());
LLautonTaskChooser.addObject("Right to Left Switch", new RightStartLeftScore());
2018-03-23 23:36:51 -06:00
LLautonTaskChooser.addObject("Left to left 2 Cube Scale", new Cube2Left ());
2018-03-05 18:50:01 -07:00
2018-03-05 18:57:23 -07:00
SmartDashboard.putData("LLAuton Task", LLautonTaskChooser);
LRautonTaskChooser = new SendableChooser<Command>();
2018-03-05 21:17:54 -07:00
LRautonTaskChooser.addDefault("Choose LR Program", new CrossTheBaseLine());
2018-03-06 18:46:18 -07:00
2018-03-09 00:01:29 -06:00
LRautonTaskChooser.addObject("Left to Left Switch", new LeftSwitchAuton());
2018-03-23 23:36:51 -06:00
LRautonTaskChooser.addObject("Right to 2 Cube Scale", new Cube2Right());
2018-03-05 22:27:44 -07:00
LRautonTaskChooser.addObject("Center to Left Switch", new CenterLeft());
2018-03-23 23:36:51 -06:00
LRautonTaskChooser.addObject("Center too left 2 cube", new CenterLeft2Cube());
2018-03-05 21:17:54 -07:00
LRautonTaskChooser.addObject("Right to Left Switch", new RightStartLeftScore());
2018-03-23 23:36:51 -06:00
LRautonTaskChooser.addObject("Right To Right tall boi", new ScaleFrom3());
2018-03-05 18:57:23 -07:00
SmartDashboard.putData("LRAuton Task", LRautonTaskChooser);
2018-03-05 18:50:01 -07:00
//ledLights.setAllLightsOn(false);
} catch (Exception e) {
System.err.println("An error occurred in robotInit()");
}
}
public void disabledInit(){
}
public void disabledPeriodic() {
Scheduler.getInstance().run();
updateStatus();
}
public void autonomousInit() {
updateChoosers();
controlLoop.start();
drive.endGyroCalibration();
drive.resetEncoders();
drive.resetGyro();
drive.setIsRed(getAlliance().equals(Alliance.Red));
2018-03-05 18:57:23 -07:00
String gameData;
gameData = DriverStation.getInstance().getGameSpecificMessage();
2018-03-06 18:46:18 -07:00
if (gameData.length() > 0) {
if (gameData.charAt(0) == 'L') {
if (gameData.charAt(1) == 'L') {
if (LLautonomousCommand != null) {
LLautonomousCommand.start();
}
} else {
if (LRautonomousCommand != null) {
LRautonomousCommand.start();
}
}
} else {
if (gameData.charAt(1) == 'L') {
if (RLautonomousCommand != null) {
RLautonomousCommand.start();
}
} else {
if (RRautonomousCommand != null) {
RRautonomousCommand.start();
}
}
}
}
}
2018-03-05 18:57:23 -07:00
2018-03-05 18:50:01 -07:00
public void autonomousPeriodic() {
Scheduler.getInstance().run();
updateStatus();
}
public void teleopInit() {
2018-03-05 18:57:23 -07:00
if (RRautonomousCommand != null) RRautonomousCommand.cancel();
if (RLautonomousCommand != null) RLautonomousCommand.cancel();
if (LRautonomousCommand != null) LRautonomousCommand.cancel();
if (LLautonomousCommand != null) LLautonomousCommand.cancel();
2018-09-22 20:13:56 -06:00
drive.setToBrakeOnNeutral(false);
2018-03-05 18:50:01 -07:00
updateChoosers();
controlLoop.start();
drive.resetEncoders();
drive.endGyroCalibration();
2018-09-22 20:13:56 -06:00
2018-03-05 18:50:01 -07:00
updateStatus();
}
2018-09-22 20:13:56 -06:00
2018-03-05 18:50:01 -07:00
public void teleopPeriodic()
{
Scheduler.getInstance().run();
updateStatus();
}
public void testPeriodic() {
LiveWindow.run();
updateStatus();
}
private void updateChoosers() {
operationMode = (OperationMode)operationModeChooser.getSelected();
2018-03-05 18:57:23 -07:00
RRautonomousCommand = (Command)RRautonTaskChooser.getSelected();
RLautonomousCommand = (Command)RLautonTaskChooser.getSelected();
LRautonomousCommand = (Command)LRautonTaskChooser.getSelected();
LLautonomousCommand = (Command)LLautonTaskChooser.getSelected();
2018-03-05 18:50:01 -07:00
}
public Alliance getAlliance() {
return m_ds.getAlliance();
}
public void updateStatus() {
drive.updateStatus(operationMode);
2018-03-05 18:57:23 -07:00
elevator.updateStatus(operationMode);
2018-09-22 20:13:56 -06:00
2018-03-05 18:50:01 -07:00
}
}