From 73a1a25193c7c7a3929e63fb57dabc39c15c7794 Mon Sep 17 00:00:00 2001 From: stebb1976 Date: Sat, 6 Mar 2021 11:51:46 -0500 Subject: [PATCH] Made work with general purpose code --- src/main/java/frc/robot/Constants.java | 7 +- src/main/java/frc/robot/Main.java | 29 --------- src/main/java/frc/robot/RobotContainer.java | 1 - src/main/java/frc/robot/Utility/Motor.java | 8 ++- .../java/frc/robot/subsystems/Feeder.java | 6 +- .../java/frc/robot/subsystems/Kicker.java | 4 +- .../java/frc/robot/subsystems/Shooter.java | 65 ++----------------- 7 files changed, 20 insertions(+), 100 deletions(-) diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index 92dbdf5..b42c1fe 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -20,10 +20,9 @@ public class Constants { //Shooter public static final int SHOOTER_LEFT_MASTER_ID = 1; public static final int SHOOTER_RIGHT_SLAVE_ID = 1; - public static final int SHOOTER_KP = 0; - public static final int SHOOTER_KI = 0; - public static final int SHOOTER_KFF = 0; - public static final int SHOOTER_KD = 0; + public static final double SHOOTER_KS = 0; + public static final double SHOOTER_KV = 0; + public static final double SHOOTER_KA = 0; public static final int SPIN_UP_RPM = 0; diff --git a/src/main/java/frc/robot/Main.java b/src/main/java/frc/robot/Main.java index b9b6c7f..fd5672b 100644 --- a/src/main/java/frc/robot/Main.java +++ b/src/main/java/frc/robot/Main.java @@ -12,35 +12,6 @@ Any new differential drive subsystems should implement this feature (view TalonS New differential drive subsystems will need new code for motor creation, motor configuration, motor output, and PID configuration. */ -/** - * TODO - * - * Make a shuffle board interface - * - * Make more differential drivetrain commands - * -arcade drive- done - * - * Make manipulator Subsystem - * - * Make a recording mode for the manipulator mover - * -test - * - * - * Add support for max velocity and acceleration for TalonSRX_Drivetrain - * - * Make a unity testing branch for github - * - * Make unity testing tools - * -make a dedicated utility class - * - * Make tests to ensure the code actually works on a robot - * - * Ramsete might spin because setting the voltage might be affected by the motor controller inversion setting - * - * test drivetrain commands to ensure everything is inverted properly - * - */ - package frc.robot; import edu.wpi.first.wpilibj.RobotBase; diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index a9c2238..cae18c5 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -24,7 +24,6 @@ import edu.wpi.first.wpilibj.GenericHID; import edu.wpi.first.wpilibj.XboxController; -import edu.wpi.first.wpilibj2.command.Command; import frc.robot.commands.Shoot; import frc.robot.subsystems.Kicker; import frc.robot.subsystems.Shooter; diff --git a/src/main/java/frc/robot/Utility/Motor.java b/src/main/java/frc/robot/Utility/Motor.java index de27ed1..8b95311 100644 --- a/src/main/java/frc/robot/Utility/Motor.java +++ b/src/main/java/frc/robot/Utility/Motor.java @@ -230,6 +230,11 @@ public void follow(Motor master){ follow(master, false); } + /** + * If motor is a follower, then this does nothing. + * Set follower inversion from master when setting master. + * @param isInverted + */ public void setInverted(boolean isInverted){ if (m_motorType == MotorType.TalonSRX) { if(m_talonSRX.getControlMode() != com.ctre.phoenix.motorcontrol.ControlMode.Follower) @@ -247,7 +252,8 @@ public void setInverted(boolean isInverted){ } if (m_motorType == MotorType.CANSparkMax) { - m_canSparkMax.setInverted(isInverted); + if(!m_canSparkMax.isFollower()) + m_canSparkMax.setInverted(isInverted); } } diff --git a/src/main/java/frc/robot/subsystems/Feeder.java b/src/main/java/frc/robot/subsystems/Feeder.java index 388aa67..d6d9160 100644 --- a/src/main/java/frc/robot/subsystems/Feeder.java +++ b/src/main/java/frc/robot/subsystems/Feeder.java @@ -7,15 +7,13 @@ package frc.robot.subsystems; -import com.revrobotics.CANSparkMaxLowLevel.MotorType; - import edu.wpi.first.wpilibj2.command.SubsystemBase; import frc.robot.Constants; import frc.robot.Utility.Motor; public class Feeder extends SubsystemBase { - Motor m_feederMotor = new Motor(Constants.FEEDER_MOTOR_ID, "CANSparkMax"); - Motor m_serializerMotor = new Motor(Constants.SERIALIZER_MOTOR_ID, "CANSparkMax"); + Motor m_feederMotor = new Motor(Constants.FEEDER_MOTOR_ID, Motor.MotorType.CANSparkMax); + Motor m_serializerMotor = new Motor(Constants.SERIALIZER_MOTOR_ID, Motor.MotorType.CANSparkMax); /** * Creates a new Feeder. */ diff --git a/src/main/java/frc/robot/subsystems/Kicker.java b/src/main/java/frc/robot/subsystems/Kicker.java index 9cfb4b5..33856f5 100644 --- a/src/main/java/frc/robot/subsystems/Kicker.java +++ b/src/main/java/frc/robot/subsystems/Kicker.java @@ -7,15 +7,13 @@ package frc.robot.subsystems; -//import com.ctre.phoenix.motorcontrol.InvertType; -import com.revrobotics.CANSparkMaxLowLevel.MotorType; import edu.wpi.first.wpilibj2.command.SubsystemBase; import frc.robot.Constants; import frc.robot.Utility.Motor; public class Kicker extends SubsystemBase { - Motor m_kickerMotor = new Motor(Constants.KICKER_MOTOR_ID, "CANSparkMax"); + Motor m_kickerMotor = new Motor(Constants.KICKER_MOTOR_ID, Motor.MotorType.CANSparkMax); diff --git a/src/main/java/frc/robot/subsystems/Shooter.java b/src/main/java/frc/robot/subsystems/Shooter.java index 7e90cd7..866914e 100644 --- a/src/main/java/frc/robot/subsystems/Shooter.java +++ b/src/main/java/frc/robot/subsystems/Shooter.java @@ -7,76 +7,25 @@ package frc.robot.subsystems; -import com.ctre.phoenix.motorcontrol.NeutralMode; - import edu.wpi.first.wpilibj2.command.SubsystemBase; import frc.robot.Constants; import frc.robot.Utility.Motor; public class Shooter extends SubsystemBase { - Motor m_leftMaster = new Motor(Constants.SHOOTER_LEFT_MASTER_ID, "TalonFX"); - Motor m_rightSlave = new Motor(Constants.SHOOTER_RIGHT_SLAVE_ID, "TalonFX"); + Motor m_leftMaster = new Motor(Constants.SHOOTER_LEFT_MASTER_ID, Motor.MotorType.TalonFX); + Motor m_rightSlave = new Motor(Constants.SHOOTER_RIGHT_SLAVE_ID, Motor.MotorType.TalonFX); /** * Creates a new Shooter. */ public Shooter() { - /* - m_leftMaster.SetP_velocity(Constants.SHOOTER_KP); - m_leftMaster.SetFF_velocity(Constants.SHOOTER_KFF); - m_leftMaster.SetI_velocity(Constants.SHOOTER_KI); - m_leftMaster.SetD_velocity(Constants.SHOOTER_KD); - - m_rightSlave.SetP_velocity(Constants.SHOOTER_KP); - m_rightSlave.SetFF_velocity(Constants.SHOOTER_KFF); - m_rightSlave.SetI_velocity(Constants.SHOOTER_KI); - m_rightSlave.SetD_velocity(Constants.SHOOTER_KD); - */ - - //TODO configure shooter feedforward + m_leftMaster.configFeedforward(Constants.SHOOTER_KS, Constants.SHOOTER_KV, Constants.SHOOTER_KA); - // m_leftMaster.ConfigFactoryDefault(); - // m_rightSlave.ConfigFactoryDefault(); - - m_rightSlave.follow(m_leftMaster, false); + m_rightSlave.follow(m_leftMaster, true); m_leftMaster.setInverted(false); - m_rightSlave.setInverted(true); - - /* - m_leftMaster.setNeutralMode(NeutralMode.Coast); - m_rightSlave.setNeutralMode(NeutralMode.Coast); - */ - - // motorcontrol::SupplyCurrentLimitConfiguration supply_config_ { - // true, constants::shooter::kMaxCurrentDraw.to(), - // constants::shooter::kMaxCurrentDraw.to(), - // constants::shooter::kCurrentLimitingTriggerTime.to() - // }; - - // m_leftMaster.ConfigIntegratedSensorInitializationStrategy(ctre::phoenix::sensors::SensorInitializationStrategy::BootToZero); - // m_leftMaster.ConfigSupplyCurrentLimit(supply_config_); - // m_rightSlave.ConfigIntegratedSensorInitializationStrategy(ctre::phoenix::sensors::SensorInitializationStrategy::BootToZero); - // m_rightSlave.ConfigSupplyCurrentLimit(supply_config_); - - // m_leftMaster.ConfigOpenloopRamp(1.8); - // m_rightSlave.ConfigOpenloopRamp(1.8); - - // m_leftMaster.ConfigClosedloopRamp(1.8); - // m_rightSlave.ConfigClosedloopRamp(1.8); - - // m_leftMaster.Config_kP(0, constants::shooter::kP); - // m_leftMaster.Config_kI(0, 0); - // m_leftMaster.Config_kD(0, constants::shooter::kD); - // m_leftMaster.Config_kF(0, constants::shooter::kFF); - // m_leftMaster.Config_kF(0, 0.05); - - // m_rightSlave.Config_kP(0, constants::shooter::kP); - // m_rightSlave.Config_kI(0, 0); - // m_rightSlave.Config_kD(0, constants::shooter::kD); - // m_rightSlave.Config_kF(0, constants::shooter::kFF); - // m_rightSlave.Config_kF(0, 0.05); - // m_leftMaster.ConfigSelectedFeedbackSensor(FeedbackDevice::IntegratedSensor, 0, 0); - // m_rightSlave.ConfigSelectedFeedbackSensor(FeedbackDevice::IntegratedSensor, 0, 0); + + m_leftMaster.enableBrakeMode(false); + m_rightSlave.enableBrakeMode(false); } @Override