Skip to content
This repository has been archived by the owner on Apr 20, 2024. It is now read-only.

Commit

Permalink
fix elevator subsystem units
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanjcoderman committed Feb 11, 2024
1 parent 1228ed2 commit 1439e95
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 81 deletions.
35 changes: 11 additions & 24 deletions src/main/java/frc/robot/config/CompConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
import com.ctre.phoenix6.signals.NeutralModeValue;
import edu.wpi.first.math.geometry.Rotation2d;
import frc.robot.config.RobotConfig.ClimberConfig;
import frc.robot.config.RobotConfig.ElevatorConfig;
import frc.robot.config.RobotConfig.IMUConfig;
import frc.robot.config.RobotConfig.IntakeConfig;
import frc.robot.config.RobotConfig.LightsConfig;
import frc.robot.config.RobotConfig.ShooterConfig;
import frc.robot.config.RobotConfig.ShoulderConfig;
import frc.robot.config.RobotConfig.SwerveConfig;
import frc.robot.config.RobotConfig.ElevatorConfig;

class CompConfig {
public static final RobotConfig competitionBot =
Expand Down Expand Up @@ -127,7 +127,7 @@ class CompConfig {
floorSpotDistanceToAngle.put(4.8, 20.0);
floorSpotDistanceToAngle.put(15.0, 10.0);
}),
new ElevatorConfig(
new ElevatorConfig(
0,
new TalonFXConfiguration()
.withSlot0(
Expand All @@ -142,35 +142,22 @@ class CompConfig {
.withKP(0.0))
.withMotionMagic(
new MotionMagicConfigs()
.withMotionMagicAcceleration(0.0)
.withMotionMagicCruiseVelocity(0.0)
.withMotionMagicAcceleration(2.0)
.withMotionMagicCruiseVelocity(1.5)
.withMotionMagicJerk(0))
.withFeedback(
new FeedbackConfigs()
.withSensorToMechanismRatio(
0.0))
.withCurrentLimits(new CurrentLimitsConfigs().withSupplyCurrentLimit(0))
.withFeedback(new FeedbackConfigs().withSensorToMechanismRatio(0))
.withCurrentLimits(new CurrentLimitsConfigs().withSupplyCurrentLimit(40))
.withMotorOutput(
new MotorOutputConfigs()
.withInverted(InvertedValue.Clockwise_Positive)
.withNeutralMode(NeutralModeValue.Brake)),
new CurrentLimitsConfigs().withSupplyCurrentLimit(0),
0.0,
new CurrentLimitsConfigs().withSupplyCurrentLimit(40),
-0.05,
0,
0,
Rotation2d.fromDegrees(0),
4,
Rotation2d.fromDegrees(0),
Rotation2d.fromDegrees(0),
distanceToAngleTolerance -> {
distanceToAngleTolerance.put(0.0, 0.0);
distanceToAngleTolerance.put(0.0, 0.0);
},
speakerDistanceToAngle -> {
speakerDistanceToAngle.put(0.0, 0.0);
},
floorSpotDistanceToAngle -> {
floorSpotDistanceToAngle.put(0.0, 0.0);
}),
0.0,
0.0),
new IntakeConfig(
16,
22,
Expand Down
35 changes: 7 additions & 28 deletions src/main/java/frc/robot/config/PracticeConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
import com.ctre.phoenix6.signals.NeutralModeValue;
import edu.wpi.first.math.geometry.Rotation2d;
import frc.robot.config.RobotConfig.ClimberConfig;
import frc.robot.config.RobotConfig.ElevatorConfig;
import frc.robot.config.RobotConfig.IMUConfig;
import frc.robot.config.RobotConfig.IntakeConfig;
import frc.robot.config.RobotConfig.LightsConfig;
import frc.robot.config.RobotConfig.ShooterConfig;
import frc.robot.config.RobotConfig.ShoulderConfig;
import frc.robot.config.RobotConfig.SwerveConfig;
import frc.robot.config.RobotConfig.ElevatorConfig;


class PracticeConfig {
public static final RobotConfig config =
Expand Down Expand Up @@ -117,7 +116,7 @@ class PracticeConfig {
floorSpotDistanceToAngle.put(3.4, 60.0);
floorSpotDistanceToAngle.put(4.8, 50.0);
}),
new ElevatorConfig(
new ElevatorConfig(
0,
new TalonFXConfiguration()
.withSlot0(
Expand All @@ -135,10 +134,7 @@ class PracticeConfig {
.withMotionMagicAcceleration(2.0)
.withMotionMagicCruiseVelocity(1.5)
.withMotionMagicJerk(0))
.withFeedback(
new FeedbackConfigs()
.withSensorToMechanismRatio(
0))
.withFeedback(new FeedbackConfigs().withSensorToMechanismRatio(0))
.withCurrentLimits(new CurrentLimitsConfigs().withSupplyCurrentLimit(40))
.withMotorOutput(
new MotorOutputConfigs()
Expand All @@ -147,22 +143,10 @@ class PracticeConfig {
new CurrentLimitsConfigs().withSupplyCurrentLimit(40),
-0.05,
0,
Rotation2d.fromDegrees(0),
0,
4,
Rotation2d.fromDegrees(0),
Rotation2d.fromDegrees(0),
distanceToAngleTolerance -> {
distanceToAngleTolerance.put(0.0, 0.0);
distanceToAngleTolerance.put(0.0, 0.0);
},
speakerDistanceToAngle -> {
speakerDistanceToAngle.put(0.0, 0.0);

},
floorSpotDistanceToAngle -> {
floorSpotDistanceToAngle.put(0.0, 0.0);

}),
0.0,
0.0),
new IntakeConfig(
16,
22,
Expand Down Expand Up @@ -192,10 +176,5 @@ class PracticeConfig {
distanceToAngleTolerance.put(1.0, 2.5);
distanceToAngleTolerance.put(1.0, 2.5);
}),



new LightsConfig(23));


new LightsConfig(23));
}
16 changes: 5 additions & 11 deletions src/main/java/frc/robot/config/RobotConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ public record RobotConfig(
IntakeConfig intake,
SwerveConfig swerve,
IMUConfig imu,
LightsConfig lights

) {

LightsConfig lights) {

public record ShooterConfig(
int bottomMotorID,
Expand Down Expand Up @@ -59,19 +56,16 @@ public record ShoulderConfig(
Consumer<InterpolatingDoubleTreeMap> speakerShotAngles,
Consumer<InterpolatingDoubleTreeMap> floorShotAngles) {}

public record ElevatorConfig(
int rightMotorID,
public record ElevatorConfig(
int motorID,
TalonFXConfiguration motorConfig,
CurrentLimitsConfigs strictCurrentLimits,
double homingVoltage,
double homingCurrentThreshold,
double homingEndPosition,
int currentTaps,
Rotation2d minAngle,
Rotation2d maxAngle,
Consumer<InterpolatingDoubleTreeMap> distanceToAngleTolerance,
Consumer<InterpolatingDoubleTreeMap> speakerShotAngles,
Consumer<InterpolatingDoubleTreeMap> floorShotAngles) {}
double minHeight,
double maxHeight) {}

public record IMUConfig(
int deviceID, Consumer<InterpolatingDoubleTreeMap> distanceToAngleTolerance) {}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/frc/robot/elevator/ElevatorPositions.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

package frc.robot.elevator;

public class ElevatorPositions {
Expand Down
39 changes: 22 additions & 17 deletions src/main/java/frc/robot/elevator/ElevatorSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

import com.ctre.phoenix6.controls.CoastOut;
import com.ctre.phoenix6.controls.MotionMagicTorqueCurrentFOC;
import com.ctre.phoenix6.controls.MotionMagicVoltage;
import com.ctre.phoenix6.controls.StaticBrake;
import com.ctre.phoenix6.hardware.TalonFX;
import edu.wpi.first.math.filter.LinearFilter;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj.DriverStation;
import frc.robot.config.RobotConfig;
import frc.robot.util.HomingState;
Expand Down Expand Up @@ -50,11 +48,11 @@ public class ElevatorSubsystem extends LifecycleSubsystem {
private int slot = 0;

public ElevatorSubsystem(TalonFX motor) {

super(SubsystemPriority.ELEVATOR);
this.motor = motor;

motor.getConfigurator().apply(RobotConfig.get().elevator().motorConfig());

this.motor = motor;
}

@Override
Expand Down Expand Up @@ -85,7 +83,7 @@ public void robotPeriodic() {
// homingEndPosition + (currentAngle - minAngle)
double homingEndPosition = RobotConfig.get().elevator().homingEndPosition();
double homedPosition = homingEndPosition + (getHeight() - lowestSeenHeight);
motor.setPosition(homedPosition);
motor.setPosition(inchesToRotations(homedPosition));

preMatchHomingOccured = true;
homingState = HomingState.HOMED;
Expand All @@ -99,16 +97,18 @@ public void robotPeriodic() {
homingState = HomingState.HOMED;
goalHeight = ElevatorPositions.STOWED;

motor.setPosition(RobotConfig.get().elevator().homingEndPosition());
motor.setPosition(inchesToRotations(RobotConfig.get().elevator().homingEndPosition()));
}
break;
case HOMED:
double usedGoalPosition = ntposition.get() == -1 ? clampHeight(goalHeight) : ntposition.get();
double usedGoalPosition =
ntposition.get() == -1 ? clampHeight(goalHeight) : ntposition.get();

slot = goalHeight == minHeight ? 1 : 0;
Logger.recordOutput("Elevator/UsedGoalAngle", usedGoalPosition);
Logger.recordOutput("Elevator/UsedGoalPosition", usedGoalPosition);

motor.setControl(positionRequest.withSlot(slot).withPosition(usedGoalPosition));
motor.setControl(
positionRequest.withSlot(slot).withPosition(inchesToRotations(usedGoalPosition)));

break;
}
Expand All @@ -118,10 +118,9 @@ public boolean rangeOfMotionSeen() {
return highestSeenHeight - lowestSeenHeight >= PRE_MATCH_HOMING_MIN_MOVEMENT;
}

public void setHeight(double newHeight) {
goalHeight = clampHeight(newHeight);
}

public void setGoalHeight(double newHeight) {
goalHeight = clampHeight(newHeight);
}

public double getHeight() {
return rotationsToInches(motor.getPosition().getValueAsDouble());
Expand All @@ -131,19 +130,25 @@ public boolean atGoal() {
return Math.abs(getHeight() - goalHeight) < TOLERANCE;
}

// Tune later
public boolean atGoal(double inches) {
return Math.abs(getHeight() - inches) < TOLERANCE;
}

// Tune the radius in inches later
private double rotationsToInches(double rotations) {
return rotations * 0;
return rotations * (2 * Math.PI * 0);
}

private double inchesToRotations(double inches) {
return inches / (2 * Math.PI * 0);
}

private static double clampHeight(double height) {
if (height < minHeight) {
height = minHeight;

} else if (height > maxHeight) {
height = maxHeight;
}

return height;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public enum SubsystemPriority {
IMU(10),
SHOOTER(10),
SHOULDER(10),
ELEVATOR(10),//Maybe needs to be different priority
ELEVATOR(10), // Maybe needs to be different priority
VISION(10),
LOCALIZATION(10),
LIGHTS(10),
Expand Down

0 comments on commit 1439e95

Please sign in to comment.