2021-11-15 16:26:16 -07:00
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
/* Copyright (c) 2018-2019 FIRST. All Rights Reserved. */
|
|
|
|
|
/* Open Source Software - may be modified and shared by FRC teams. The code */
|
|
|
|
|
/* must be accompanied by the FIRST BSD license file in the root directory of */
|
|
|
|
|
/* the project. */
|
|
|
|
|
/*----------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
package frc4388.robot;
|
|
|
|
|
|
|
|
|
|
import com.ctre.phoenix.motorcontrol.InvertType;
|
|
|
|
|
import com.ctre.phoenix.motorcontrol.NeutralMode;
|
2021-12-06 17:53:15 -07:00
|
|
|
import com.ctre.phoenix.motorcontrol.RemoteSensorSource;
|
2021-11-15 16:26:16 -07:00
|
|
|
import com.ctre.phoenix.motorcontrol.can.WPI_TalonFX;
|
|
|
|
|
import com.ctre.phoenix.sensors.PigeonIMU;
|
2021-12-06 16:41:28 -07:00
|
|
|
import com.ctre.phoenix.sensors.AbsoluteSensorRange;
|
2021-12-02 17:24:41 -07:00
|
|
|
import com.ctre.phoenix.sensors.CANCoder;
|
2021-11-15 16:26:16 -07:00
|
|
|
|
|
|
|
|
import edu.wpi.first.wpilibj.Spark;
|
|
|
|
|
import edu.wpi.first.wpilibj.drive.DifferentialDrive;
|
2021-11-15 17:52:28 -07:00
|
|
|
import frc4388.robot.Constants.ArcadeDriveConstants;
|
2021-11-15 16:26:16 -07:00
|
|
|
import frc4388.robot.Constants.LEDConstants;
|
2021-11-29 17:18:31 -07:00
|
|
|
import frc4388.robot.Constants.SwerveDriveConstants;
|
2021-11-15 16:26:16 -07:00
|
|
|
import frc4388.utility.RobotGyro;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Defines and holds all I/O objects on the Roborio. This is useful for unit
|
|
|
|
|
* testing and modularization.
|
|
|
|
|
*/
|
|
|
|
|
public class RobotMap {
|
|
|
|
|
|
|
|
|
|
public RobotMap() {
|
|
|
|
|
configureLEDMotorControllers();
|
2021-12-16 16:22:36 -07:00
|
|
|
//configureArcadeDriveMotorControllers();
|
2021-12-06 16:41:28 -07:00
|
|
|
configureSwerveMotorControllers();
|
2021-11-15 16:26:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* LED Subsystem */
|
|
|
|
|
public final Spark LEDController = new Spark(LEDConstants.LED_SPARK_ID);
|
|
|
|
|
|
|
|
|
|
void configureLEDMotorControllers() {
|
|
|
|
|
|
|
|
|
|
}
|
2021-12-16 16:22:36 -07:00
|
|
|
|
2021-11-15 17:52:28 -07:00
|
|
|
/* ArcadeDrive Subsystem */
|
2021-12-16 16:22:36 -07:00
|
|
|
//public final WPI_TalonFX leftFrontMotor = new WPI_TalonFX(ArcadeDriveConstants.DRIVE_LEFT_FRONT_CAN_ID);
|
|
|
|
|
//public final WPI_TalonFX rightFrontMotor = new WPI_TalonFX(ArcadeDriveConstants.DRIVE_RIGHT_FRONT_CAN_ID);
|
|
|
|
|
//public final WPI_TalonFX leftBackMotor = new WPI_TalonFX(ArcadeDriveConstants.DRIVE_LEFT_BACK_CAN_ID);
|
|
|
|
|
//public final WPI_TalonFX rightBackMotor = new WPI_TalonFX(ArcadeDriveConstants.DRIVE_RIGHT_BACK_CAN_ID);
|
|
|
|
|
//public final DifferentialDrive driveTrain = new DifferentialDrive(leftFrontMotor, rightFrontMotor);
|
|
|
|
|
//public final RobotGyro gyroDrive = new RobotGyro(new PigeonIMU(ArcadeDriveConstants.DRIVE_PIGEON_ID));
|
2021-11-15 16:26:16 -07:00
|
|
|
|
2021-12-16 16:22:36 -07:00
|
|
|
/*void configureArcadeDriveMotorControllers() {
|
2021-11-15 16:26:16 -07:00
|
|
|
|
2021-12-16 16:22:36 -07:00
|
|
|
// factory default values
|
2021-11-15 16:26:16 -07:00
|
|
|
leftFrontMotor.configFactoryDefault();
|
|
|
|
|
rightFrontMotor.configFactoryDefault();
|
|
|
|
|
leftBackMotor.configFactoryDefault();
|
|
|
|
|
rightBackMotor.configFactoryDefault();
|
|
|
|
|
|
2021-12-16 16:22:36 -07:00
|
|
|
// set back motors as followers
|
2021-11-15 16:26:16 -07:00
|
|
|
leftBackMotor.follow(leftFrontMotor);
|
|
|
|
|
rightBackMotor.follow(rightFrontMotor);
|
|
|
|
|
|
2021-12-16 16:22:36 -07:00
|
|
|
// set neutral mode
|
2021-11-15 16:26:16 -07:00
|
|
|
leftFrontMotor.setNeutralMode(NeutralMode.Brake);
|
|
|
|
|
rightFrontMotor.setNeutralMode(NeutralMode.Brake);
|
|
|
|
|
leftFrontMotor.setNeutralMode(NeutralMode.Brake);
|
|
|
|
|
rightFrontMotor.setNeutralMode(NeutralMode.Brake);
|
|
|
|
|
|
2021-12-16 16:22:36 -07:00
|
|
|
// flip input so forward becomes back, etc
|
2021-11-15 16:26:16 -07:00
|
|
|
leftFrontMotor.setInverted(false);
|
|
|
|
|
rightFrontMotor.setInverted(false);
|
|
|
|
|
leftBackMotor.setInverted(InvertType.FollowMaster);
|
|
|
|
|
rightBackMotor.setInverted(InvertType.FollowMaster);
|
2021-12-16 16:22:36 -07:00
|
|
|
}*/
|
2021-11-29 17:18:31 -07:00
|
|
|
/* Swerve Subsystem */
|
|
|
|
|
public final WPI_TalonFX leftFrontSteerMotor = new WPI_TalonFX(SwerveDriveConstants.LEFT_FRONT_STEER_CAN_ID);
|
|
|
|
|
public final WPI_TalonFX leftFrontWheelMotor = new WPI_TalonFX(SwerveDriveConstants.LEFT_FRONT_WHEEL_CAN_ID);
|
|
|
|
|
public final WPI_TalonFX rightFrontSteerMotor = new WPI_TalonFX(SwerveDriveConstants.RIGHT_FRONT_STEER_CAN_ID);
|
|
|
|
|
public final WPI_TalonFX rightFrontWheelMotor = new WPI_TalonFX(SwerveDriveConstants.RIGHT_FRONT_WHEEL_CAN_ID);
|
|
|
|
|
public final WPI_TalonFX leftBackSteerMotor = new WPI_TalonFX(SwerveDriveConstants.LEFT_BACK_STEER_CAN_ID);
|
|
|
|
|
public final WPI_TalonFX leftBackWheelMotor = new WPI_TalonFX(SwerveDriveConstants.LEFT_BACK_WHEEL_CAN_ID);
|
|
|
|
|
public final WPI_TalonFX rightBackSteerMotor = new WPI_TalonFX(SwerveDriveConstants.RIGHT_BACK_STEER_CAN_ID);
|
|
|
|
|
public final WPI_TalonFX rightBackWheelMotor = new WPI_TalonFX(SwerveDriveConstants.RIGHT_BACK_WHEEL_CAN_ID);
|
2021-12-02 17:24:41 -07:00
|
|
|
public final CANCoder leftFrontEncoder = new CANCoder(SwerveDriveConstants.LEFT_FRONT_STEER_CAN_ENCODER_ID);
|
|
|
|
|
public final CANCoder rightFrontEncoder = new CANCoder(SwerveDriveConstants.RIGHT_FRONT_STEER_CAN_ENCODER_ID);
|
|
|
|
|
public final CANCoder leftBackEncoder = new CANCoder(SwerveDriveConstants.LEFT_BACK_STEER_CAN_ENCODER_ID);
|
|
|
|
|
public final CANCoder rightBackEncoder = new CANCoder(SwerveDriveConstants.RIGHT_BACK_STEER_CAN_ENCODER_ID);
|
2021-12-06 16:41:28 -07:00
|
|
|
|
|
|
|
|
void configureSwerveMotorControllers() {
|
|
|
|
|
leftFrontEncoder.configMagnetOffset(SwerveDriveConstants.LEFT_BACK_ENCODER_OFFSET);
|
|
|
|
|
rightFrontEncoder.configMagnetOffset(SwerveDriveConstants.RIGHT_FRONT_ENCODER_OFFSET);
|
|
|
|
|
leftBackEncoder.configMagnetOffset(SwerveDriveConstants.LEFT_BACK_ENCODER_OFFSET);
|
|
|
|
|
rightBackEncoder.configMagnetOffset(SwerveDriveConstants.RIGHT_BACK_ENCODER_OFFSET);
|
2021-12-06 17:45:45 -07:00
|
|
|
|
|
|
|
|
leftFrontSteerMotor.configFactoryDefault();
|
|
|
|
|
leftFrontWheelMotor.configFactoryDefault();
|
|
|
|
|
rightFrontSteerMotor.configFactoryDefault();
|
|
|
|
|
rightFrontWheelMotor.configFactoryDefault();
|
|
|
|
|
leftBackSteerMotor.configFactoryDefault();
|
|
|
|
|
leftBackWheelMotor.configFactoryDefault();
|
|
|
|
|
rightBackSteerMotor.configFactoryDefault();
|
|
|
|
|
rightBackWheelMotor.configFactoryDefault();
|
|
|
|
|
|
|
|
|
|
leftFrontSteerMotor.configOpenloopRamp(SwerveDriveConstants.OPEN_LOOP_RAMP_RATE, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
leftFrontWheelMotor.configOpenloopRamp(SwerveDriveConstants.OPEN_LOOP_RAMP_RATE, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
rightFrontSteerMotor.configOpenloopRamp(SwerveDriveConstants.OPEN_LOOP_RAMP_RATE, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
rightFrontWheelMotor.configOpenloopRamp(SwerveDriveConstants.OPEN_LOOP_RAMP_RATE, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
leftBackSteerMotor.configOpenloopRamp(SwerveDriveConstants.OPEN_LOOP_RAMP_RATE, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
leftBackWheelMotor.configOpenloopRamp(SwerveDriveConstants.OPEN_LOOP_RAMP_RATE, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
rightBackSteerMotor.configOpenloopRamp(SwerveDriveConstants.OPEN_LOOP_RAMP_RATE, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
rightBackWheelMotor.configOpenloopRamp(SwerveDriveConstants.OPEN_LOOP_RAMP_RATE, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
|
|
|
|
|
leftFrontWheelMotor.configClosedloopRamp(SwerveDriveConstants.OPEN_LOOP_RAMP_RATE, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
leftFrontSteerMotor.configClosedloopRamp(SwerveDriveConstants.OPEN_LOOP_RAMP_RATE, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
rightFrontSteerMotor.configClosedloopRamp(SwerveDriveConstants.OPEN_LOOP_RAMP_RATE, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
rightFrontWheelMotor.configClosedloopRamp(SwerveDriveConstants.OPEN_LOOP_RAMP_RATE, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
leftBackSteerMotor.configClosedloopRamp(SwerveDriveConstants.OPEN_LOOP_RAMP_RATE, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
leftBackWheelMotor.configClosedloopRamp(SwerveDriveConstants.OPEN_LOOP_RAMP_RATE, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
rightBackSteerMotor.configClosedloopRamp(SwerveDriveConstants.OPEN_LOOP_RAMP_RATE, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
rightBackWheelMotor.configClosedloopRamp(SwerveDriveConstants.OPEN_LOOP_RAMP_RATE, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
|
|
|
|
|
leftFrontWheelMotor.configNeutralDeadband(SwerveDriveConstants.NEUTRAL_DEADBAND, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
leftFrontSteerMotor.configNeutralDeadband(SwerveDriveConstants.NEUTRAL_DEADBAND, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
rightFrontSteerMotor.configNeutralDeadband(SwerveDriveConstants.NEUTRAL_DEADBAND, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
rightFrontWheelMotor.configNeutralDeadband(SwerveDriveConstants.NEUTRAL_DEADBAND, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
leftBackSteerMotor.configNeutralDeadband(SwerveDriveConstants.NEUTRAL_DEADBAND, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
leftBackWheelMotor.configNeutralDeadband(SwerveDriveConstants.NEUTRAL_DEADBAND, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
rightBackSteerMotor.configNeutralDeadband(SwerveDriveConstants.NEUTRAL_DEADBAND, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
rightBackWheelMotor.configNeutralDeadband(SwerveDriveConstants.NEUTRAL_DEADBAND, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
2021-12-06 17:53:15 -07:00
|
|
|
|
|
|
|
|
// config cancoder as remote encoder for swerve steer motors
|
|
|
|
|
leftFrontSteerMotor.configRemoteFeedbackFilter(leftFrontEncoder.getDeviceID(), RemoteSensorSource.CANCoder, SwerveDriveConstants.REMOTE_0, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
leftBackSteerMotor.configRemoteFeedbackFilter(leftBackEncoder.getDeviceID(), RemoteSensorSource.CANCoder, SwerveDriveConstants.REMOTE_0, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
rightFrontSteerMotor.configRemoteFeedbackFilter(rightFrontEncoder.getDeviceID(), RemoteSensorSource.CANCoder, SwerveDriveConstants.REMOTE_0, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
|
|
|
|
rightBackSteerMotor.configRemoteFeedbackFilter(rightBackEncoder.getDeviceID(), RemoteSensorSource.CANCoder, SwerveDriveConstants.REMOTE_0, SwerveDriveConstants.SWERVE_TIMEOUT_MS);
|
2021-12-02 17:24:41 -07:00
|
|
|
}
|
2021-12-06 17:45:45 -07:00
|
|
|
|
2021-11-15 16:26:16 -07:00
|
|
|
}
|