@@ -39,10 +39,12 @@ public class ElevatorIOSparkMax {
3939 public ElevatorIOSparkMax() {
4040 leftMotor = new SparkMax(ElevatorConstants.LEFT_MOTOR_ID, MotorType.kBrushless);
4141 rightMotor = new SparkMax(ElevatorConstants.RIGHT_MOTOR_ID, MotorType.kBrushless);
42-
42+ // encoders have the same height, since elevator moves up and down
4343 leftEncoder = leftMotor.getEncoder();
4444 leftEncoder.setPosition(0);
4545
46+
47+ // Configs were borrowed from previous code :)
4648 SparkMaxConfig leftConfig = new SparkMaxConfig();
4749 leftConfig
4850 .smartCurrentLimit(Constants.NEO_CURRENT_LIMIT)
@@ -57,12 +59,6 @@ public class ElevatorIOSparkMax {
5759 SparkMaxConfig rightConfig = new SparkMaxConfig();
5860 rightConfig.apply(leftConfig);
5961 rightConfig.follow(leftMotor, true);
60-
61- // reset safe kResetSafeParameters switches the motor to default paramaters, then adds the
62- // changes from the config object
63- // persist paramaters saves these changes to the motor memory so it doesn't get cooked during
64- // brownouts
65- // only use persist in the BEGINNING, not later
6662 leftMotor.configure(leftConfig, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters);
6763 rightMotor.configure(
6864 rightConfig, ResetMode.kResetSafeParameters, PersistMode.kPersistParameters);
@@ -74,11 +70,64 @@ public class ElevatorIOSparkMax {
7470 }
7571
7672 private void updateMotorConfig(SparkMaxConfig config) {
77- // DO NOT RESET paramaters becasue we only want to change some paramaters, not all
78- // DO NOT PERSIST because this is a temporary change that we don't want to save to memory
7973 leftMotor.configure(config, ResetMode.kNoResetSafeParameters, PersistMode.kNoPersistParameters);
8074 rightMotor.configure(
8175 config, ResetMode.kNoResetSafeParameters, PersistMode.kNoPersistParameters);
8276 }
77+
78+ @Override
79+ public void updateInputs(ElevatorIOInputs inputs) {
80+ inputs.setpointMeters = getSetpoint();
81+ inputs.positionMeters = getPosition();
82+ inputs.velocityMetersPerSec = getVelocity();
83+ inputs.appliedVoltage = getAppliedVoltage();
84+ inputs.isLimitSwitchPressed = isLimitSwitchPressed();
85+
86+ }
87+
88+ @Override
89+ public double getSetpoint() {
90+ return pidController.getSetpoint().position;
91+ }
92+
93+ @Override
94+ public double getPosition {
95+ return leftEncoder.getPosition();
96+ }
97+
98+ @Override
99+ public double getVelocity {
100+ return leftEncoder.getVelocity();
101+ }
102+
103+ @Override
104+ public double getAppliedVoltage {
105+ return leftMotor.getAppliedOutput() * leftMotor.getBusVoltage();
106+ }
107+
108+ @Override
109+ public boolean isLimitSwitchPressed() {
110+ return !limitSwitch.get();
111+ }
112+
113+
114+ @Override
115+ public void setSetpoint(double setpoint) {
116+ pidController.setGoal(MathUtil.clamp(setpoint, ElevatorConstants.MIN_HEIGHT, ElevatorConstants.MAX_HEIGHT));
117+ }
118+
119+ @Override
120+ public void goToSetpoint() {
121+ double pidOutput = pid.Controller.calculate(getPosition());
122+
123+ double ffOutput = feedforward.calculate(pidController.getSetpoint().velocity, pidController.getSetpoint().acceleration);
124+
125+ double acceleration = pidController.getSetpoint().acceleration;
126+
127+ setVoltage(math.util.clamp(pidOutput, -ElevatorConstants.MAX_VOLTAGE, ElevatorConstants.MAX_VOLTAGE));
128+ }
129+
130+
131+
83132}
84133}
0 commit comments