Create RobotMap to decouple Subsystems from their hardware.

With the hardware objects decoupled from the subsystems, we can then pass mock hardware into these subsystems to run simulations/tests on.
This commit is contained in:
Keenan D. Buckley
2020-03-28 21:27:15 -06:00
parent 2e0330cab5
commit 850f503889
4 changed files with 131 additions and 75 deletions
@@ -7,10 +7,7 @@
package frc4388.robot.subsystems;
import com.ctre.phoenix.motorcontrol.InvertType;
import com.ctre.phoenix.motorcontrol.NeutralMode;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
import com.ctre.phoenix.sensors.PigeonIMU;
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
@@ -27,38 +24,25 @@ public class Drive extends SubsystemBase {
// Put methods for controlling this subsystem
// here. Call these from Commands.
private WPI_TalonSRX m_leftFrontMotor = new WPI_TalonSRX(DriveConstants.DRIVE_LEFT_FRONT_CAN_ID);
private WPI_TalonSRX m_rightFrontMotor = new WPI_TalonSRX(DriveConstants.DRIVE_RIGHT_FRONT_CAN_ID);
private WPI_TalonSRX m_leftBackMotor = new WPI_TalonSRX(DriveConstants.DRIVE_LEFT_BACK_CAN_ID);
private WPI_TalonSRX m_rightBackMotor = new WPI_TalonSRX(DriveConstants.DRIVE_RIGHT_BACK_CAN_ID);
private DifferentialDrive m_driveTrain = new DifferentialDrive(m_leftFrontMotor, m_rightFrontMotor);
private RobotGyro m_gyro = new RobotGyro(new PigeonIMU(DriveConstants.DRIVE_PIGEON_ID));
private WPI_TalonSRX m_leftFrontMotor;
private WPI_TalonSRX m_rightFrontMotor;
private WPI_TalonSRX m_leftBackMotor;
private WPI_TalonSRX m_rightBackMotor;
private DifferentialDrive m_driveTrain;
private RobotGyro m_gyro;
/**
* Add your docs here.
*/
public Drive(){
/* factory default values */
m_leftFrontMotor.configFactoryDefault();
m_rightFrontMotor.configFactoryDefault();
m_leftBackMotor.configFactoryDefault();
m_rightBackMotor.configFactoryDefault();
public Drive(WPI_TalonSRX leftFrontMotor, WPI_TalonSRX rightFrontMotor, WPI_TalonSRX leftBackMotor,
WPI_TalonSRX rightBackMotor, RobotGyro gyro) {
/* set back motors as followers */
m_leftBackMotor.follow(m_leftFrontMotor);
m_rightBackMotor.follow(m_rightFrontMotor);
/* set neutral mode */
m_leftFrontMotor.setNeutralMode(NeutralMode.Brake);
m_rightFrontMotor.setNeutralMode(NeutralMode.Brake);
m_leftFrontMotor.setNeutralMode(NeutralMode.Brake);
m_rightFrontMotor.setNeutralMode(NeutralMode.Brake);
/* flip input so forward becomes back, etc */
m_leftFrontMotor.setInverted(false);
m_rightFrontMotor.setInverted(false);
m_leftBackMotor.setInverted(InvertType.FollowMaster);
m_rightBackMotor.setInverted(InvertType.FollowMaster);
m_leftFrontMotor = leftFrontMotor;
m_rightFrontMotor = rightFrontMotor;
m_leftBackMotor = leftBackMotor;
m_rightBackMotor = rightBackMotor;
m_driveTrain = new DifferentialDrive(m_leftFrontMotor, m_rightFrontMotor);
m_gyro = gyro;
}
@Override
@@ -73,20 +57,19 @@ public class Drive extends SubsystemBase {
/**
* Add your docs here.
*/
public void driveWithInput(double move, double steer){
public void driveWithInput(double move, double steer) {
m_driveTrain.arcadeDrive(move, steer);
}
public RobotGyro getRobotGyro(){
return m_gyro;
}
/**
* Add your docs here.
*/
private void updateSmartDashboard() {
// Examples of the functionality of RobotGyro
SmartDashboard.putBoolean("Is Gyro a Pigeon?", getRobotGyro().m_isGyroAPigeon);
SmartDashboard.putNumber("Turn Rate", getRobotGyro().getRate());
SmartDashboard.putNumber("Gyro Pitch", getRobotGyro().getPitch());
SmartDashboard.putData(getRobotGyro());
SmartDashboard.putBoolean("Is Gyro a Pigeon?", m_gyro.m_isGyroAPigeon);
SmartDashboard.putNumber("Turn Rate", m_gyro.getRate());
SmartDashboard.putNumber("Gyro Pitch", m_gyro.getPitch());
SmartDashboard.putData(m_gyro);
}
}
+13 -13
View File
@@ -20,36 +20,36 @@ import frc4388.utility.LEDPatterns;
*/
public class LED extends SubsystemBase {
private float currentLED;
private Spark LEDController;
private float m_currentLED;
private Spark m_LEDController;
/**
* Add your docs here.
*/
public LED(){
LEDController = new Spark(LEDConstants.LED_SPARK_ID);
public LED(Spark LEDController){
m_LEDController = LEDController;
setPattern(LEDConstants.DEFAULT_PATTERN);
LEDController.set(currentLED);
m_LEDController.set(m_currentLED);
System.err.println("In the Beginning, there was Joe.\nAnd he said, 'Let there be LEDs.'\nAnd it was good.");
}
@Override
public void periodic(){
SmartDashboard.putNumber("LED", m_currentLED);
}
/**
* Add your docs here.
*/
public void updateLED(){
LEDController.set(currentLED);
m_LEDController.set(m_currentLED);
}
/**
* Add your docs here.
*/
public void setPattern(LEDPatterns pattern){
currentLED = pattern.getValue();
LEDController.set(currentLED);
}
@Override
public void periodic(){
SmartDashboard.putNumber("LED", currentLED);
m_currentLED = pattern.getValue();
m_LEDController.set(m_currentLED);
}
}