generated from TitaniumTigers4829/4829-BaseRobotCode
-
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
Showing
6 changed files
with
34 additions
and
145 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
25 changes: 0 additions & 25 deletions
25
src/main/java/frc/robot/subsystems/elevator/ElevatorConstants.java
This file was deleted.
Oops, something went wrong.
23 changes: 8 additions & 15 deletions
23
src/main/java/frc/robot/subsystems/elevator/ElevatorInterface.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
66 changes: 9 additions & 57 deletions
66
src/main/java/frc/robot/subsystems/elevator/PhysicalElevator.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 |
---|---|---|
@@ -1,61 +1,13 @@ | ||
package frc.robot.subsystems.elevator; | ||
|
||
import com.ctre.phoenix6.StatusSignal; | ||
import com.ctre.phoenix6.configs.TalonFXConfiguration; | ||
import com.ctre.phoenix6.hardware.TalonFX; | ||
import edu.wpi.first.units.measure.Angle; | ||
import edu.wpi.first.units.measure.Voltage; | ||
import frc.robot.subsystems.elevator.ElevatorInterface.ElevatorInputs; | ||
|
||
/** Add your docs here. */ | ||
public class PhysicalElevator { | ||
private TalonFX leaderMotor = new TalonFX(ElevatorConstants.ELEVATOR_LEADER_MOTOR_ID); | ||
private TalonFX followerMotor = new TalonFX(ElevatorConstants.ELEVATOR_FOLLOWER_MOTOR_ID); | ||
|
||
StatusSignal<Angle> leaderPosition; | ||
StatusSignal<Angle> followerPosition; | ||
|
||
StatusSignal<Voltage> leaderAppliedVoltage; | ||
StatusSignal<Voltage> followerAppliedVoltage; | ||
|
||
public PhysicalElevator() { | ||
leaderPosition = leaderMotor.getRotorPosition(); | ||
followerPosition = followerMotor.getRotorPosition(); | ||
|
||
leaderAppliedVoltage = leaderMotor.getMotorVoltage(); | ||
followerAppliedVoltage = followerMotor.getMotorVoltage(); | ||
// 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. | ||
|
||
TalonFXConfiguration elevatorConfig = new TalonFXConfiguration(); | ||
|
||
elevatorConfig.Slot0.kP = ElevatorConstants.ELEVATOR_P; | ||
elevatorConfig.Slot0.kI = ElevatorConstants.ELEVATOR_I; | ||
elevatorConfig.Slot0.kD = ElevatorConstants.ELEVATOR_D; | ||
|
||
leaderMotor.getConfigurator().apply(elevatorConfig); | ||
followerMotor.getConfigurator().apply(elevatorConfig); | ||
} | ||
|
||
public void updateInputs(ElevatorInputs inputs) { | ||
inputs.leaderMotorPosition = leaderPosition.getValueAsDouble(); | ||
inputs.followerMotorPosition = followerPosition.getValueAsDouble(); | ||
} | ||
|
||
public double getElevatorPosition() { | ||
return leaderPosition.getValueAsDouble(); | ||
} | ||
|
||
public void setElevatorPosition(double position) { | ||
leaderMotor.setPosition(position); | ||
followerMotor.setPosition(position); | ||
} | ||
package frc.robot.subsystems.elevator; | ||
|
||
public void setVolts(double volts) { | ||
leaderMotor.setVoltage(volts); | ||
followerMotor.setVoltage(volts); | ||
; | ||
} | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
|
||
public double getVolts() { | ||
return leaderMotor.getMotorVoltage().getValueAsDouble(); | ||
} | ||
public class PhysicalElevator implements ElevatorInterface { | ||
/** Creates a new ElevatorHardware. */ | ||
public PhysicalElevator() {} | ||
|
||
} |
56 changes: 11 additions & 45 deletions
56
src/main/java/frc/robot/subsystems/elevator/SimulatedElevator.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 |
---|---|---|
@@ -1,51 +1,17 @@ | ||
package frc.robot.subsystems.elevator; | ||
|
||
import edu.wpi.first.math.controller.PIDController; | ||
import edu.wpi.first.math.system.plant.DCMotor; | ||
import edu.wpi.first.wpilibj.simulation.ElevatorSim; | ||
|
||
/** Add your docs here. */ | ||
public class SimulatedElevator implements ElevatorInterface { | ||
private ElevatorSim elevatorSim = | ||
new ElevatorSim( | ||
DCMotor.getFalcon500(2), | ||
ElevatorConstants.ELEVATOR_GEAR_RATIO, | ||
ElevatorConstants.ELEVATOR_CARRIAGE_MASS, | ||
ElevatorConstants.DRUM_RADIUS, | ||
ElevatorConstants.MIN_HEIGHT, | ||
ElevatorConstants.MAX_HEIGHT, | ||
true, | ||
0.0); | ||
private PIDController simPID; | ||
private double currentVolts; | ||
// 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. | ||
|
||
public SimulatedElevator() { | ||
simPID = | ||
new PIDController( | ||
ElevatorConstants.ELEVATOR_P, | ||
ElevatorConstants.ELEVATOR_I, | ||
ElevatorConstants.ELEVATOR_D); | ||
} | ||
|
||
public void updateInputs(ElevatorInputs inputs) { | ||
inputs.leaderMotorPosition = getElevatorPosition(); | ||
inputs.followerMotorPosition = getElevatorPosition(); | ||
} | ||
package frc.robot.subsystems.elevator; | ||
|
||
public void setElevatorPosition(double position) { | ||
setVolts(simPID.calculate(getElevatorPosition(), position)); | ||
} | ||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
|
||
public double getElevatorPosition() { | ||
return elevatorSim.getPositionMeters(); | ||
} | ||
|
||
public void setVolts(double volts) { | ||
currentVolts = simPID.calculate(volts); | ||
elevatorSim.setInputVoltage(currentVolts); | ||
} | ||
public class SimulatedElevator extends SubsystemBase { | ||
/** Creates a new ElevatorSimulation. */ | ||
public SimulatedElevator() {} | ||
|
||
public double getVolts() { | ||
return currentVolts; | ||
@Override | ||
public void periodic() { | ||
// This method will be called once per scheduler run | ||
} | ||
} |