-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e68414a
commit 2133d58
Showing
5 changed files
with
49 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/main/java/org/team1540/robot2024/subsystems/elevator/ElevatorIOSim.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package org.team1540.robot2024.subsystems.elevator; | ||
|
||
import edu.wpi.first.math.MathUtil; | ||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.wpilibj.simulation.ElevatorSim; | ||
import static org.team1540.robot2024.Constants.Elevator.*; | ||
import static org.team1540.robot2024.Constants.LOOP_PERIOD_SECS; | ||
|
||
public class ElevatorIOSim implements ElevatorIO{ | ||
// fields | ||
private final ElevatorSim elevatorSim = new ElevatorSim(DCMotor.getFalcon500Foc(2), ELEVATOR_GEAR_RATIO, SIM_CARRIAGE_MASS_KG, SIM_DRUM_RADIUS_METERS, ELEVATOR_MINIMUM_HEIGHT, ELEVATOR_MAX_HEIGHT, true, ELEVATOR_MINIMUM_HEIGHT); | ||
private double elevatorAppliedVolts = 0.0; | ||
|
||
@Override | ||
public void updateInputs(ElevatorIOInputs inputs){ | ||
elevatorSim.update(LOOP_PERIOD_SECS); | ||
|
||
inputs.positionMeters = elevatorSim.getPositionMeters(); | ||
inputs.velocityRPM = elevatorSim.getVelocityMetersPerSecond(); | ||
inputs.voltage = elevatorAppliedVolts; | ||
inputs.current = new double[]{elevatorSim.getCurrentDrawAmps()}; | ||
inputs.upperLimit = elevatorSim.hasHitUpperLimit(); | ||
inputs.lowerLimit = elevatorSim.hasHitLowerLimit(); | ||
} | ||
|
||
public void setElevatorAppliedVolts(double volts){ | ||
elevatorAppliedVolts = MathUtil.clamp(volts, -12.0, 12.0); //TODO: check this range | ||
elevatorSim.setInputVoltage(elevatorAppliedVolts); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters