Skip to content

Commit 86ba0fb

Browse files
committed
fix: maybe make elevator work?
1 parent 86f747e commit 86ba0fb

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

src/main/java/org/team1540/robot2024/commands/elevator/ElevatorManualCommand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void execute() {
2525
} else {
2626
val -= DEADZONE;
2727
}
28-
elevator.setVoltage(-val * 12 * 0.18);
28+
elevator.setVoltage(-val * 12);
2929
} else {
3030
elevator.holdPosition();
3131
}

src/main/java/org/team1540/robot2024/subsystems/elevator/ElevatorIO.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ public interface ElevatorIO {
77
class ElevatorIOInputs {
88
public double positionMeters = 0.0;
99
public double velocityMPS = 0.0;
10-
public double voltage = 0.0;
10+
public double[] voltage = new double[]{};
1111
public double[] currentAmps = new double[]{};
1212
public double[] tempCelsius = new double[]{};
1313
public boolean atUpperLimit = false;

src/main/java/org/team1540/robot2024/subsystems/elevator/ElevatorIOSim.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void updateInputs(ElevatorIOInputs inputs) {
4747

4848
inputs.positionMeters = elevatorSim.getPositionMeters();
4949
inputs.velocityMPS = elevatorSim.getVelocityMetersPerSecond();
50-
inputs.voltage = elevatorAppliedVolts;
50+
inputs.voltage = new double[]{elevatorAppliedVolts};
5151
inputs.currentAmps = new double[]{elevatorSim.getCurrentDrawAmps()};
5252
inputs.atUpperLimit = elevatorSim.hasHitUpperLimit();
5353
inputs.atLowerLimit = elevatorSim.hasHitLowerLimit();

src/main/java/org/team1540/robot2024/subsystems/elevator/ElevatorIOTalonFX.java

+20-9
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,34 @@
77
import com.ctre.phoenix6.configs.TalonFXConfiguration;
88
import com.ctre.phoenix6.controls.Follower;
99
import com.ctre.phoenix6.controls.MotionMagicVoltage;
10+
import com.ctre.phoenix6.controls.VoltageOut;
1011
import com.ctre.phoenix6.hardware.TalonFX;
1112
import com.ctre.phoenix6.signals.*;
1213
import edu.wpi.first.wpilibj.Servo;
1314
import org.team1540.robot2024.Constants;
1415

1516
public class ElevatorIOTalonFX implements ElevatorIO {
16-
17-
private final MotionMagicVoltage motionMagicOut = new MotionMagicVoltage(0).withEnableFOC(true);
1817
private final TalonFX leader = new TalonFX(Constants.Elevator.LEADER_ID);
1918
private final TalonFX follower = new TalonFX(Constants.Elevator.FOLLOWER_ID);
19+
20+
private final MotionMagicVoltage motionMagicOut = new MotionMagicVoltage(0).withEnableFOC(true);
21+
private final VoltageOut voltageOut = new VoltageOut(0).withEnableFOC(true);
22+
private final Follower followerReq = new Follower(leader.getDeviceID(), false);
23+
2024
private final Servo leftFlipper = new Servo(Constants.Elevator.LEFT_FLIPPER_ID);
2125
private final Servo rightFlipper = new Servo(Constants.Elevator.RIGHT_FLIPPER_ID);
26+
2227
private final StatusSignal<Double> leaderPosition = leader.getPosition();
2328
private final StatusSignal<Double> leaderVelocity = leader.getVelocity();
2429
private final StatusSignal<Double> leaderAppliedVolts = leader.getMotorVoltage();
30+
private final StatusSignal<Double> followerAppliedVolts = follower.getMotorVoltage();
2531
private final StatusSignal<Double> leaderCurrent = leader.getStatorCurrent();
2632
private final StatusSignal<Double> followerCurrent = follower.getStatorCurrent();
2733
private final StatusSignal<Double> leaderTemp = leader.getDeviceTemp();
2834
private final StatusSignal<Double> followerTemp = follower.getDeviceTemp();
2935
private final StatusSignal<ForwardLimitValue> topLimitStatus = leader.getForwardLimit();
3036
private final StatusSignal<ReverseLimitValue> bottomLimitStatus = leader.getReverseLimit();
31-
TalonFXConfiguration config;
37+
private final TalonFXConfiguration config;
3238

3339

3440
public ElevatorIOTalonFX() {
@@ -45,6 +51,7 @@ public ElevatorIOTalonFX() {
4551
leaderPosition,
4652
leaderVelocity,
4753
leaderAppliedVolts,
54+
followerAppliedVolts,
4855
leaderCurrent,
4956
followerCurrent,
5057
leaderTemp,
@@ -55,7 +62,7 @@ public ElevatorIOTalonFX() {
5562
follower.optimizeBusUtilization();
5663

5764
// setting slot 0 gains
58-
Slot0Configs slot0Configs = config.Slot0;
65+
Slot0Configs slot0Configs = new Slot0Configs();
5966
slot0Configs.kS = Constants.Elevator.KS;
6067
slot0Configs.kV = Constants.Elevator.KV;
6168
slot0Configs.kA = Constants.Elevator.KA;
@@ -64,21 +71,22 @@ public ElevatorIOTalonFX() {
6471
slot0Configs.kD = Constants.Elevator.KD;
6572
slot0Configs.kG = Constants.Elevator.KG;
6673
slot0Configs.GravityType = GravityTypeValue.Elevator_Static;
74+
config.Slot0 = slot0Configs;
6775

6876
// setting Motion Magic Settings
69-
MotionMagicConfigs motionMagicConfigs = config.MotionMagic;
77+
MotionMagicConfigs motionMagicConfigs = new MotionMagicConfigs();
7078
motionMagicConfigs.MotionMagicCruiseVelocity = Constants.Elevator.CRUISE_VELOCITY_MPS;
7179
motionMagicConfigs.MotionMagicAcceleration = Constants.Elevator.MAXIMUM_ACCELERATION_MPS2;
7280
motionMagicConfigs.MotionMagicJerk = Constants.Elevator.JERK_MPS3;
81+
config.MotionMagic = motionMagicConfigs;
7382

7483
config.HardwareLimitSwitch.ForwardLimitEnable = true;
7584
config.HardwareLimitSwitch.ReverseLimitEnable = true;
7685
config.HardwareLimitSwitch.ReverseLimitAutosetPositionEnable = true;
7786
config.HardwareLimitSwitch.ReverseLimitAutosetPositionValue = 0;
7887
leader.getConfigurator().apply(config);
79-
config.MotorOutput.Inverted = InvertedValue.CounterClockwise_Positive;
8088
follower.getConfigurator().apply(config);
81-
follower.setControl(new Follower(leader.getDeviceID(), false));
89+
follower.setControl(followerReq);
8290
}
8391

8492
@Override
@@ -87,6 +95,7 @@ public void updateInputs(ElevatorIOInputs inputs) {
8795
leaderPosition,
8896
leaderVelocity,
8997
leaderAppliedVolts,
98+
followerAppliedVolts,
9099
leaderCurrent,
91100
followerCurrent,
92101
leaderTemp,
@@ -96,7 +105,7 @@ public void updateInputs(ElevatorIOInputs inputs) {
96105

97106
inputs.positionMeters = leaderPosition.getValueAsDouble();
98107
inputs.velocityMPS = leaderVelocity.getValueAsDouble();
99-
inputs.voltage = leaderAppliedVolts.getValueAsDouble();
108+
inputs.voltage = new double[]{leaderAppliedVolts.getValueAsDouble(), followerAppliedVolts.getValueAsDouble()};
100109
inputs.currentAmps = new double[]{leaderCurrent.getValueAsDouble(), followerCurrent.getValueAsDouble()};
101110
inputs.tempCelsius = new double[]{leaderTemp.getValueAsDouble(), followerTemp.getValueAsDouble()};
102111
inputs.atUpperLimit = topLimitStatus.getValue() == ForwardLimitValue.ClosedToGround;
@@ -111,13 +120,14 @@ public void setSetpointMeters(double positionMeters) {
111120

112121
@Override
113122
public void setVoltage(double voltage) {
114-
leader.set(voltage);
123+
leader.setControl(voltageOut.withOutput(voltage));
115124
}
116125

117126
@Override
118127
public void setBrakeMode(boolean isBrakeMode) {
119128
leader.setNeutralMode(isBrakeMode ? NeutralModeValue.Brake : NeutralModeValue.Coast);
120129
follower.setNeutralMode(isBrakeMode ? NeutralModeValue.Brake : NeutralModeValue.Coast);
130+
follower.setControl(followerReq);
121131
}
122132

123133
@Override
@@ -134,5 +144,6 @@ public void configPID(double kP, double kI, double kD) {
134144
configs.kI = kI;
135145
configs.kD = kD;
136146
leader.getConfigurator().apply(configs);
147+
follower.setControl(followerReq);
137148
}
138149
}

0 commit comments

Comments
 (0)