-
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.
* maybe it will work * Added more intake stuff and made it finally build! * intake commands * Cool elevator stuff * more elevator stuff * Hopefully i finish this soon * idk how that got in there * Fun arm things * format * Remove unnecessary blank line in MathUtil.java * nerf intake to not use position for otb intake. delete arm example bc it is redundant with elevator existing * format i think? * update beta version --------- Co-authored-by: Ishan1522 <[email protected]>
- Loading branch information
Showing
16 changed files
with
475 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// This command ejects the note from the intake by reversing the rollors | ||
|
||
package frc.robot.commands.intake; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.subsystems.intake.Intake; | ||
|
||
public class Outtake extends Command { | ||
private final Intake intakeSubsystem; | ||
|
||
public Outtake(Intake intake) { | ||
this.intakeSubsystem = intake; | ||
addRequirements(this.intakeSubsystem); | ||
} | ||
|
||
// Called when the command is initially scheduled. | ||
@Override | ||
public void initialize() {} | ||
|
||
// Called every time the scheduler runs while the command is scheduled. | ||
@Override | ||
public void execute() { | ||
intakeSubsystem.setIntakeSpeed(-1); | ||
} | ||
|
||
// Called once the command ends or is interrupted. | ||
@Override | ||
public void end(boolean interrupted) {} | ||
|
||
// Returns true when the command should end. | ||
@Override | ||
public boolean isFinished() { | ||
return false; | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/frc/robot/commands/intake/RegularIntake.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,35 @@ | ||
// This command runs the rollers from the intake and grabs the note from the floor | ||
|
||
package frc.robot.commands.intake; | ||
|
||
import edu.wpi.first.wpilibj2.command.Command; | ||
import frc.robot.subsystems.intake.Intake; | ||
|
||
public class RegularIntake extends Command { | ||
private final Intake intakeSubsystem; | ||
|
||
public RegularIntake(Intake intake) { | ||
this.intakeSubsystem = intake; | ||
addRequirements(this.intakeSubsystem); | ||
} | ||
|
||
// Called when the command is initially scheduled. | ||
@Override | ||
public void initialize() {} | ||
|
||
// Called every time the scheduler runs while the command is scheduled. | ||
@Override | ||
public void execute() { | ||
intakeSubsystem.setIntakeSpeed(1); | ||
} | ||
|
||
// Called once the command ends or is interrupted. | ||
@Override | ||
public void end(boolean interrupted) {} | ||
|
||
// Returns true when the command should end. | ||
@Override | ||
public boolean isFinished() { | ||
return false; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** This subsystem is an elevator that uses PID for its position. */ | ||
package frc.robot.subsystems.elevator; | ||
|
||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
public class Elevator extends SubsystemBase { | ||
/** Creates a new Elevator. */ | ||
private ElevatorInterface elevatorInterface; | ||
|
||
private ElevatorInputsAutoLogged inputs = new ElevatorInputsAutoLogged(); | ||
|
||
public Elevator(ElevatorInterface elevatorInterface) { | ||
this.elevatorInterface = elevatorInterface; | ||
} | ||
|
||
public double getElevatorPosition() { | ||
return elevatorInterface.getElevatorPosition(); | ||
} | ||
|
||
public double getVolts() { | ||
return elevatorInterface.getVolts(); | ||
} | ||
|
||
public void setElevatorPosition(double position) { | ||
elevatorInterface.setElevatorPosition(position); | ||
} | ||
|
||
public void setVolts(double volts) { | ||
elevatorInterface.setVolts(volts); | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
// This method will be called once per scheduler run | ||
elevatorInterface.updateInputs(inputs); | ||
Logger.processInputs("Elevator/", inputs); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/frc/robot/subsystems/elevator/ElevatorConstants.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,25 @@ | ||
package frc.robot.subsystems.elevator; | ||
|
||
public class ElevatorConstants { | ||
public static final int ELEVATOR_LEADER_MOTOR_ID = 0 - 9; | ||
public static final int ELEVATOR_FOLLOWER_MOTOR_ID = 0 - 9; | ||
|
||
public static final double ELEVATOR_P = 0 - 9; | ||
public static final double ELEVATOR_I = 0 - 9; | ||
public static final double ELEVATOR_D = 0 - 9; | ||
|
||
public static final double DRUM_RADIUS = 0 - 9; | ||
public static final double ELEVATOR_GEAR_RATIO = 2; | ||
public static final double ELEVATOR_CARRIAGE_MASS = 0 - 9; | ||
public static final double ENCODER_CONVERSION_FACTOR = 71.81; | ||
public static final double MIN_HEIGHT = 0; | ||
public static final double MAX_HEIGHT = 0 - 9; | ||
|
||
public static final double INTAKE_POSITION = MIN_HEIGHT; | ||
public static final double SHOOT_AMP_POSITION = 0 - 9; | ||
public static final double SHOOT_SPEAKER_POSITION = 0 - 9; | ||
public static final double SHOOT_PASS_POSITION = 0 - 9; | ||
public static final double ELEVATOR_OVER_DEFENSE = MAX_HEIGHT; | ||
|
||
public static final double VELOCITY_METERS_PER_SECOND = 0 - 9; | ||
} |
37 changes: 37 additions & 0 deletions
37
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package frc.robot.subsystems.elevator; | ||
|
||
import org.littletonrobotics.junction.AutoLog; | ||
|
||
public interface ElevatorInterface { | ||
|
||
@AutoLog | ||
public static class ElevatorInputs { | ||
public double leaderMotorPosition = 0.0; | ||
|
||
public double followerMotorPosition = 0.0; | ||
} | ||
|
||
/** | ||
* Updates inputs for elevator for AdvantageKit to log | ||
* | ||
* @param inputs values related to the elevator | ||
*/ | ||
public default void updateInputs(ElevatorInputs inputs) {} | ||
|
||
/** | ||
* Gets the current position of the elevator | ||
* | ||
* @return | ||
*/ | ||
public default double getElevatorPosition() { | ||
return 0.0; | ||
} | ||
|
||
public default void setElevatorPosition(double position) {} | ||
|
||
public default void setVolts(double volts) {} | ||
|
||
public default double getVolts() { | ||
return 0.0; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
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(); | ||
|
||
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); | ||
} | ||
|
||
public void setVolts(double volts) { | ||
leaderMotor.setVoltage(volts); | ||
followerMotor.setVoltage(volts); | ||
; | ||
} | ||
|
||
public double getVolts() { | ||
return leaderMotor.getMotorVoltage().getValueAsDouble(); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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; | ||
|
||
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(); | ||
} | ||
|
||
public void setElevatorPosition(double position) { | ||
setVolts(simPID.calculate(getElevatorPosition(), position)); | ||
} | ||
|
||
public double getElevatorPosition() { | ||
return elevatorSim.getPositionMeters(); | ||
} | ||
|
||
public void setVolts(double volts) { | ||
currentVolts = simPID.calculate(volts); | ||
elevatorSim.setInputVoltage(currentVolts); | ||
} | ||
|
||
public double getVolts() { | ||
return currentVolts; | ||
} | ||
} |
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,29 @@ | ||
package frc.robot.subsystems.intake; | ||
|
||
import edu.wpi.first.wpilibj2.command.SubsystemBase; | ||
import org.littletonrobotics.junction.Logger; | ||
|
||
public class Intake extends SubsystemBase { | ||
private IntakeInterface intakeInterface; | ||
private IntakeInputsAutoLogged inputs = new IntakeInputsAutoLogged(); | ||
|
||
public Intake(IntakeInterface intakeInterface) { | ||
this.intakeInterface = intakeInterface; | ||
} | ||
|
||
/** | ||
* Sets the speed of the intake rollers | ||
* | ||
* @param speed intake roller speed (-1.0 to 1.0) | ||
*/ | ||
public void setIntakeSpeed(double speed) { | ||
intakeInterface.setIntakeSpeed(speed); | ||
Logger.recordOutput("OTBIntake/IntakeSpeed", speed); | ||
} | ||
|
||
@Override | ||
public void periodic() { | ||
intakeInterface.updateInputs(inputs); | ||
Logger.processInputs("OTBIntake/", inputs); | ||
} | ||
} |
Oops, something went wrong.