Skip to content

Commit

Permalink
feat: more elevator functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
mimizh2418 committed Jan 4, 2024
1 parent 6872dbf commit 2a08f6b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/main/java/org/team1540/advantagekitdemo/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ public static final class DrivetrainConstants {
public static final class ElevatorConstants {
public static final double GEAR_RATIO = 4.21;
public static final double DRUM_RADIUS_METERS = Units.inchesToMeters(0.75);
public static final double MAX_HEIGHT_METERS = Units.inchesToMeters(86);
public static final double MAX_HEIGHT_METERS = Units.inchesToMeters(70);
public static final double STAGE_1_HEIGHT_METERS = Units.inchesToMeters(38);
public static final double CARRIAGE_MASS_KG = 20;

public static final double KP = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import edu.wpi.first.math.controller.ElevatorFeedforward;
import edu.wpi.first.math.controller.ProfiledPIDController;
import edu.wpi.first.math.trajectory.TrapezoidProfile;
import edu.wpi.first.wpilibj.RobotState;
import edu.wpi.first.wpilibj2.command.ProfiledPIDSubsystem;
import org.littletonrobotics.junction.Logger;

Expand Down Expand Up @@ -40,6 +41,23 @@ public void setPosition(double positionMeters) {
setGoal(positionMeters);
}

public void stop() {
if (RobotState.isDisabled()) setVoltage(0);
else setPosition(getPositionMeters());
}

public double getPositionMeters() {
return getMeasurement();
}

public double getSetpoint() {
return getController().getGoal().position;
}

public double getProfilePosition() {
return getController().getSetpoint().position;
}

@Override
protected void useOutput(double output, TrapezoidProfile.State setpoint) {
setVoltage(output + feedforward.calculate(setpoint.velocity));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ class ElevatorIOInputs {
public double positionMeters = 0;
public double appliedVolts = 0;
public double currentAmps = 0;

public boolean upperLimit = false;
public boolean lowerLimit = false;
}

default void updateInputs(ElevatorIOInputs inputs) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class ElevatorIOSim implements ElevatorIO {
CARRIAGE_MASS_KG,
DRUM_RADIUS_METERS,
0,
MAX_HEIGHT_METERS/2, // divide by 2 due to cascade rigging
MAX_HEIGHT_METERS,
true,
0,
null
Expand All @@ -25,9 +25,11 @@ public class ElevatorIOSim implements ElevatorIO {
@Override
public void updateInputs(ElevatorIOInputs inputs) {
sim.update(0.02);
inputs.positionMeters = sim.getPositionMeters() * 2; // multiplied by 2 due to cascade rigging
inputs.positionMeters = sim.getPositionMeters();
inputs.appliedVolts = appliedVolts;
inputs.currentAmps = sim.getCurrentDrawAmps();
inputs.upperLimit = sim.hasHitUpperLimit();
inputs.lowerLimit = sim.hasHitLowerLimit();
}

@Override
Expand Down

0 comments on commit 2a08f6b

Please sign in to comment.