Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -413,20 +413,67 @@ public class FeederConstants {
}

public class ClimberConstants {
public static final DCMotor DCMOTOR = DCMotor.getKrakenX60(1);
public static final Mass CARRIAGE_MASS = Kilograms.of(2.5);
public static final String MOTOR_NAME = "Climber motor";
public static final Distance TOLERANCE = Inches.of(0.1);
public static final double GEARING = (5.0 / 1.0);
public static final Distance MIN_DISTANCE = Inches.of(0.0);
public static final Distance MAX_DISTANCE = Inches.of(10.0);
public static final Distance STARTING_DISTANCE = Inches.of(0.0);
public static final Distance DRUM_RADIUS = Inches.of(2.0);
public static final DistanceAngleConverter CONVERTER = new DistanceAngleConverter(DRUM_RADIUS);
public static final AngularVelocity CRUISE_VELOCITY =
RadiansPerSecond.of(2 * Math.PI).times(10.0);
public static final AngularAcceleration ACCELERATION = CRUISE_VELOCITY.div(0.1).per(Second);
public static final Velocity<AngularAccelerationUnit> JERK = ACCELERATION.per(Second);

public static final LinearMechCharacteristics CHARACTERISTICS =
new LinearMechCharacteristics(
new Translation3d(0.0, 0.0, 0.0),
MIN_DISTANCE,
MAX_DISTANCE,
STARTING_DISTANCE,
CONVERTER);

public static TalonFXConfiguration getFXConfig() {
TalonFXConfiguration config = new TalonFXConfiguration();

config.CurrentLimits.SupplyCurrentLimitEnable = Robot.isReal();
config.CurrentLimits.SupplyCurrentLimit = 40.0;
config.CurrentLimits.SupplyCurrentLowerLimit = 40.0;
config.CurrentLimits.SupplyCurrentLowerTime = 0.1;

config.CurrentLimits.StatorCurrentLimitEnable = Robot.isReal();
config.CurrentLimits.StatorCurrentLimit = 80.0;

config.Voltage.PeakForwardVoltage = 12.0;
config.Voltage.PeakReverseVoltage = -12.0;

config.MotorOutput.NeutralMode = NeutralModeValue.Brake;
config.MotorOutput.Inverted = InvertedValue.CounterClockwise_Positive;

config.SoftwareLimitSwitch.ForwardSoftLimitEnable = true;
config.SoftwareLimitSwitch.ForwardSoftLimitThreshold =
CONVERTER.toAngle(MAX_DISTANCE).in(Rotations);

config.SoftwareLimitSwitch.ReverseSoftLimitEnable = true;
config.SoftwareLimitSwitch.ReverseSoftLimitThreshold =
CONVERTER.toAngle(MIN_DISTANCE).in(Rotations);

config.Feedback.RotorToSensorRatio = 1.0;

config.Feedback.SensorToMechanismRatio = GEARING;

config.Slot0 = new Slot0Configs().withKP(0.75).withKI(0.0).withKD(0.0);

config.MotionMagic.MotionMagicCruiseVelocity = CRUISE_VELOCITY.in(RotationsPerSecond);
config.MotionMagic.MotionMagicAcceleration = ACCELERATION.in(RotationsPerSecondPerSecond);
config.MotionMagic.MotionMagicJerk = JERK.in(RotationsPerSecondPerSecond.per(Second));

return config;
} // End here

public static final Distance ELEVATOR_RADIUS = Inches.of(2.0);
public static final AngularVelocity ANGULAR_VELOCITY = RotationsPerSecond.of(1);
public static final AngularAcceleration ANGULAR_ACCELERATION =
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,19 @@
import frc.lib.W8.io.absoluteencoder.AbsoluteEncoderIOCANCoderSim;
import frc.lib.W8.io.motor.*;
import frc.lib.W8.mechanisms.flywheel.*;
import frc.lib.W8.mechanisms.linear.LinearMechanism;
import frc.lib.W8.mechanisms.linear.LinearMechanismReal;
import frc.lib.W8.mechanisms.linear.LinearMechanismSim;
import frc.lib.W8.mechanisms.rotary.RotaryMechanism;
import frc.lib.W8.mechanisms.rotary.RotaryMechanismReal;
import frc.lib.W8.mechanisms.rotary.RotaryMechanismSim;
import frc.robot.Constants.ClimberConstants;
import frc.robot.Constants.HopperConstants;
import frc.robot.Constants.IntakeConstants;
import frc.robot.Constants.Ports;
import frc.robot.commands.DriveCommands;
import frc.robot.generated.TunerConstants;
import frc.robot.subsystems.Climber;
import frc.robot.subsystems.Hopper;
import frc.robot.subsystems.Intake;
import frc.robot.subsystems.drive.Drive;
Expand All @@ -54,6 +59,7 @@ public class RobotContainer {
// Subsystems
private final Drive drive;
private final Hopper hopper;
private final Climber climber;
private final Intake intake;

// Controller
Expand Down Expand Up @@ -82,6 +88,14 @@ public RobotContainer() {
HopperConstants.MOTOR_NAME,
HopperConstants.getFXConfig(),
Ports.HopperRoller)));
climber =
new Climber(
new LinearMechanismReal(
new MotorIOTalonFX(
ClimberConstants.MOTOR_NAME,
ClimberConstants.getFXConfig(),
Ports.ClimberLinearMechanism),
ClimberConstants.CHARACTERISTICS));

intake =
new Intake(
Expand Down Expand Up @@ -123,6 +137,17 @@ public RobotContainer() {
HopperConstants.DCMOTOR,
HopperConstants.MOI,
HopperConstants.TOLERANCE));
climber =
new Climber(
new LinearMechanismSim(
new MotorIOTalonFXSim(
ClimberConstants.MOTOR_NAME,
ClimberConstants.getFXConfig(),
Ports.ClimberLinearMechanism),
ClimberConstants.DCMOTOR,
ClimberConstants.CARRIAGE_MASS,
ClimberConstants.CHARACTERISTICS,
true));

intake =
new Intake(
Expand Down Expand Up @@ -161,6 +186,10 @@ public RobotContainer() {
new ModuleIO() {});

hopper = new Hopper(new FlywheelMechanism() {});
climber =
new Climber(
new LinearMechanism(
ClimberConstants.MOTOR_NAME, ClimberConstants.CHARACTERISTICS) {});

intake =
new Intake(
Expand Down