Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elevator #23

Merged
merged 65 commits into from
Feb 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
fb30625
started elevator
txrnqt Jan 18, 2025
4cf1f55
changed imports
txrnqt Jan 18, 2025
d278cad
left config and home
txrnqt Jan 18, 2025
1645527
pid constants
txrnqt Jan 19, 2025
399b585
package names fixed
txrnqt Jan 21, 2025
444e61d
java docs added
txrnqt Jan 21, 2025
acb15db
spell check
txrnqt Jan 21, 2025
a377575
added binds
txrnqt Jan 22, 2025
7d41e3c
elevator commands
txrnqt Jan 23, 2025
c09c088
unit conversions
txrnqt Jan 23, 2025
29b8c53
unit conversions continued
txrnqt Jan 23, 2025
1e1ba79
comments
txrnqt Jan 23, 2025
7242b1d
Merge branch 'main' into Elevator
txrnqt Jan 24, 2025
6e7b47f
lint
txrnqt Jan 25, 2025
bcc2e25
linting part 2
txrnqt Jan 25, 2025
8c347ea
linting part 3
txrnqt Jan 25, 2025
759ea1b
linting? part 4
txrnqt Jan 25, 2025
0f44573
linting part 5
txrnqt Jan 25, 2025
7b55a80
linting part 7
txrnqt Jan 25, 2025
26d647d
spell check
txrnqt Jan 25, 2025
c096c8a
spell check like 3
txrnqt Jan 25, 2025
8177e3b
update
txrnqt Jan 25, 2025
9d6b29f
Merge branch 'main' into Elevator
txrnqt Jan 25, 2025
571ff07
updadte
txrnqt Jan 25, 2025
ec028e7
Merge branch 'main' into Elevator
txrnqt Jan 27, 2025
68e67b7
set positon
txrnqt Jan 30, 2025
db6e30d
Merge branch 'Elevator' of https://github.com/Frc5572/FRC2025 into El…
txrnqt Jan 30, 2025
7f48c0d
linting part 1
txrnqt Jan 30, 2025
caec7ef
linting part 2
txrnqt Jan 30, 2025
ee97e3a
linting part 4
txrnqt Jan 30, 2025
7bea311
Merge branch 'main' into Elevator
txrnqt Jan 30, 2025
4c11c3e
pid tuning
txrnqt Jan 31, 2025
cf4ff89
heights
txrnqt Jan 31, 2025
fa27f10
home command
txrnqt Jan 31, 2025
903f662
Merge branch 'main' into Elevator
txrnqt Jan 31, 2025
5404662
linting
txrnqt Jan 31, 2025
dbe2272
robot container fixes
txrnqt Jan 31, 2025
1cbca10
command name changes
txrnqt Jan 31, 2025
52ebddd
unused stuff removed
txrnqt Jan 31, 2025
512fdf3
swerve commnet?
txrnqt Jan 31, 2025
85aeba3
home fixes
txrnqt Jan 31, 2025
dc2ada9
time home
txrnqt Feb 1, 2025
c7d500a
linting
txrnqt Feb 1, 2025
376bbb5
linting
txrnqt Feb 1, 2025
508d42f
Merge branch 'main' into Elevator
txrnqt Feb 1, 2025
88092a2
comment finxes
txrnqt Feb 1, 2025
1bb91dd
un used methods
txrnqt Feb 1, 2025
f7fc567
updates
txrnqt Feb 1, 2025
0708836
motor updates
txrnqt Feb 1, 2025
977a305
removed simgui ds
txrnqt Feb 2, 2025
5aa199b
linting
txrnqt Feb 2, 2025
1883fb2
Merge branch 'main' into Elevator
txrnqt Feb 2, 2025
ac7dd54
fix names
wilsonwatson Feb 4, 2025
3d9d645
height changes
txrnqt Feb 4, 2025
1f3e794
Merge branch 'Elevator' of https://github.com/Frc5572/FRC2025 into El…
txrnqt Feb 4, 2025
c551689
conversion and command fixes
txrnqt Feb 4, 2025
5bb9392
removed random vendor rep
txrnqt Feb 6, 2025
1f8ca2a
constatnts changes
txrnqt Feb 6, 2025
0983751
Merge branch 'Elevator' of https://github.com/Frc5572/FRC2025 into El…
txrnqt Feb 6, 2025
9203df3
constants changes pt2
txrnqt Feb 6, 2025
aaddd92
Merge branch 'main' into Elevator
txrnqt Feb 6, 2025
de80115
testing setup
txrnqt Feb 8, 2025
1c38ee2
Merge branch 'main' into Elevator
txrnqt Feb 8, 2025
76a89a4
removed unused
txrnqt Feb 8, 2025
6008f60
robot heights
txrnqt Feb 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion src/main/java/frc/robot/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import static edu.wpi.first.units.Units.MetersPerSecondPerSecond;
import static edu.wpi.first.units.Units.Pounds;
import static edu.wpi.first.units.Units.Radians;
import static edu.wpi.first.units.Units.Rotations;
import static edu.wpi.first.units.Units.RotationsPerSecond;
import static edu.wpi.first.units.Units.Seconds;
import static edu.wpi.first.units.Units.Volts;
Expand Down Expand Up @@ -296,6 +297,46 @@ private enum Mk4iReductions {
}
}


/**
* Elevator Constants
*/

public static final class Elevator {
public static final int RIGHT_ID = 7;
public static final int LEFT_ID = 4;
public static final int LIMIT_ID = 1;

public static final NeutralModeValue BREAK = NeutralModeValue.Brake;

// PID and feedforward
public static final double KP = 7.0;
public static final double KI = 2.0;
public static final double KD = 0.0;
public static final double KS = 0.1675;
public static final double KV = 0.0;
public static final double KA = 0.0;
public static final double KG = 0.3375;
public static final AngularVelocity MAX_VELOCITY = RotationsPerSecond.of(0.0);

// positions
public static final Distance HOME = Inches.of(2);
public static final Distance P0 = Inches.of(26); // Coral L2
public static final Distance P1 = Inches.of(16.5); // Algae L2-L3
public static final Distance P2 = Inches.of(43); // Coral L3
public static final Distance P3 = Inches.of(33); // Algae L3-L4
public static final Distance P4 = Inches.of(67); // Coral L4


public static final double gearRatio = 1.0;
public static final Distance INCHES_AT_TOP = Inches.of(72.0);
public static final Angle ROTATIONS_AT_TOP = Radians.of(220);
public static final double SensorToMechanismRatio =
Constants.Elevator.ROTATIONS_AT_TOP.in(Rotations)
/ Constants.Elevator.INCHES_AT_TOP.in(Meters);
}


/** Vision Constants */
public static class Vision {

Expand All @@ -320,6 +361,7 @@ public double centerPixelYawRads() {
public static final double fieldBorderMargin = 0.5;
}


/** State Estimator Constants */
public static class StateEstimator {
public static final boolean keepInField = true;
Expand All @@ -336,5 +378,6 @@ public static final class CoralScoringConstants {
public static final int Coral_Touch_Sensor_DIO_Port = 3;
public static final int Random_Touch_Sensor = 1;
}

}


2 changes: 1 addition & 1 deletion src/main/java/frc/robot/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ private Main() {}

/**
* Main initialization function. Do not perform any initialization here.
*
*
* <p>
* If you change your main robot class, change the parameter type.
*
Expand Down
79 changes: 31 additions & 48 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import edu.wpi.first.math.geometry.Pose2d;
import edu.wpi.first.math.geometry.Rotation2d;
import edu.wpi.first.wpilibj.GenericHID;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.XboxController;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.util.Color;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.InstantCommand;
Expand All @@ -24,6 +24,9 @@
import frc.robot.subsystems.coral.CoralScoring;
import frc.robot.subsystems.coral.CoralScoringIO;
import frc.robot.subsystems.coral.CoralScoringReal;
import frc.robot.subsystems.elevator.Elevator;
import frc.robot.subsystems.elevator.ElevatorIO;
import frc.robot.subsystems.elevator.ElevatorReal;
import frc.robot.subsystems.elevator_algae.ElevatorAlgae;
import frc.robot.subsystems.elevator_algae.ElevatorAlgaeReal;
import frc.robot.subsystems.swerve.Swerve;
Expand Down Expand Up @@ -62,9 +65,11 @@ public class RobotContainer {
/** State */
private final RobotState state;


/* Subsystems */
private ElevatorAlgae s_ElevatorAlgae;
private LEDs leds = new LEDs();
private Elevator elevator;
private final Swerve s_Swerve;
private final Vision s_Vision;
private CoralScoring coralScoring;
Expand All @@ -83,6 +88,7 @@ public RobotContainer(RobotRunType runtimeType) {
state = new RobotState(vis);
switch (runtimeType) {
case kReal:
elevator = new Elevator(new ElevatorReal());
s_Swerve = new Swerve(state, new SwerveReal());
s_Vision = new Vision(state, VisionReal::new);
coralScoring = new CoralScoring(new CoralScoringReal());
Expand All @@ -95,20 +101,24 @@ public RobotContainer(RobotRunType runtimeType) {
SimulatedArena.getInstance().addDriveTrainSimulation(driveSimulation);
s_Swerve = new Swerve(state, new SwerveSim(driveSimulation));
s_Vision = new Vision(state, VisionSimPhoton.partial(driveSimulation));
txrnqt marked this conversation as resolved.
Show resolved Hide resolved
elevator = new Elevator(new ElevatorIO() {});
coralScoring = new CoralScoring(new CoralScoringIO() {});
climb = new Climber(new ClimberIO.Empty());
break;
default:
elevator = new Elevator(new ElevatorIO() {});
s_Swerve = new Swerve(state, new SwerveIO.Empty() {});
s_Vision = new Vision(state, VisionIO::empty);
coralScoring = new CoralScoring(new CoralScoringIO() {});
climb = new Climber(new ClimberIO.Empty());
}

/* Default Commands */
s_Swerve.setDefaultCommand(s_Swerve.teleOpDrive(driver, Constants.Swerve.isFieldRelative,
Constants.Swerve.isOpenLoop));
leds.setDefaultCommand(leds.setLEDsBreathe(Color.kRed).ignoringDisable(true));
/* Button and Trigger Bindings */

configureButtonBindings(runtimeType);
configureTriggerBindings();
}
Expand All @@ -117,60 +127,32 @@ public RobotContainer(RobotRunType runtimeType) {
* Use this method to vol your button->command mappings. Buttons can be created by instantiating
* a {@link GenericHID} or one of its subclasses ({@link edu.wpi.first.wpilibj.Joystick} or
* {@link XboxController}), and then passing it to a
* {@link edu.wpi.first.wpilibj2.command.button.JoystickButton}.
* {@link edu1.wpi.first.wpilibj2.command.button.JoystickButton}.
txrnqt marked this conversation as resolved.
Show resolved Hide resolved
*/
private void configureButtonBindings(RobotRunType runtimeType) {
algaeInIntake.onTrue(leds.blinkLEDs(Color.kCyan));
operator.rightTrigger()
driver.rightTrigger()
.whileTrue(s_ElevatorAlgae.setMotorVoltageCommand(Constants.Algae.VOLTAGE));
operator.leftTrigger()
driver.leftTrigger()
.whileTrue(s_ElevatorAlgae.setMotorVoltageCommand(Constants.Algae.NEGATIVE_VOLTAGE));


driver.y().onTrue(new InstantCommand(() -> s_Swerve.resetFieldRelativeOffset()));
driver.a().onTrue(new Command() {
Timer timer = new Timer();

@Override
public void initialize() {
timer.reset();
timer.start();
}

@Override
public void execute() {
vis.setElevatorHeight(Inches.of(timer.get() * 30.0));
}

@Override
public boolean isFinished() {
return timer.hasElapsed(3.0);
}
});
driver.b().onTrue(new Command() {
Timer timer = new Timer();

@Override
public void initialize() {
timer.reset();
timer.start();
}

@Override
public void execute() {
vis.setElevatorHeight(Inches.of(Math.max(72.0 - timer.get() * 30.0, 0)));
}

@Override
public boolean isFinished() {
return timer.hasElapsed(3.0);
}
});

driver.x().onTrue(new InstantCommand(() -> {
s_Swerve.resetOdometry(new Pose2d(7.24, 4.05, Rotation2d.kZero));
}));
operator.x().whileTrue(coralScoring.runScoringMotor(2));

driver.povDown().onTrue(elevator.home());
driver.povLeft().onTrue(elevator.p0());
SmartDashboard.putNumber("elevatorVoltage", 1.0);
txrnqt marked this conversation as resolved.
Show resolved Hide resolved
SmartDashboard.putNumber("elevatorTargetHeight", 20);
driver.a().whileTrue(
elevator.moveTo(() -> Inches.of(SmartDashboard.getNumber("elevatorTargetHeight", 20))));
driver.povUp().whileTrue(elevator.moveUp());
driver.povRight().whileTrue(elevator.moveDown());


// driver.x().onTrue(new InstantCommand(() -> {
// s_Swerve.resetOdometry(new Pose2d(7.24, 4.05, Rotation2d.kZero));
// }));
driver.x().whileTrue(coralScoring.runScoringMotor(2));
driver.rightStick().whileTrue(climb.runClimberMotorCommand());
controllerThree.y().whileTrue(climb.resetClimberCommand());

Expand Down Expand Up @@ -226,5 +208,6 @@ public void updateSimulation() {

}
}

}


4 changes: 0 additions & 4 deletions src/main/java/frc/robot/subsystems/coral/CoralScoring.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ public boolean getGrabingRightBeamBrakeStatus() {
return coralScoringAutoLogged.grabingBeamBrakeRight;
}

public boolean getRandomStatus() {
return coralScoringAutoLogged.randomTouchSensor;
}

@Override
public void periodic() {
io.updateInputs(coralScoringAutoLogged);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public static class CoralScoringInputs {
public double scoringRPM;
public boolean scoringBeamBrake;
public boolean grabingBeamBrakeRight;
public boolean randomTouchSensor;
}

public default void updateInputs(CoralScoringInputs inputs) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public class CoralScoringReal implements CoralScoringIO {
private final DigitalInput coralTouchSensor =
new DigitalInput(Constants.CoralScoringConstants.Coral_Touch_Sensor_DIO_Port);
SparkMaxConfig motorConfig = new SparkMaxConfig();
private final DigitalInput randomTouchSensor =
new DigitalInput(Constants.CoralScoringConstants.Random_Touch_Sensor);

/**
* Coral Scoring Real
Expand All @@ -40,7 +38,6 @@ public CoralScoringReal() {
*/

public void updateInputs(CoralScoringInputs inputs) {
inputs.randomTouchSensor = randomTouchSensor.get();
inputs.scoringBeamBrake = !scoringBeamBrake.get();
inputs.grabingBeamBrakeRight = coralTouchSensor.get();
}
Expand Down
110 changes: 110 additions & 0 deletions src/main/java/frc/robot/subsystems/elevator/Elevator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
package frc.robot.subsystems.elevator;

import static edu.wpi.first.units.Units.Inches;
import static edu.wpi.first.units.Units.Meters;
import java.util.function.Supplier;
import org.littletonrobotics.junction.Logger;
import edu.wpi.first.units.measure.Distance;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants;

/**
* Elevator Subsystem
*/
public class Elevator extends SubsystemBase {
ElevatorIO io;
Timer time = new Timer();
private ElevatorInputsAutoLogged inputs = new ElevatorInputsAutoLogged();

public Elevator(ElevatorIO io) {
this.io = io;
io.updateInputs(inputs);
}

@Override
public void periodic() {
io.updateInputs(inputs);
Logger.processInputs("Elevator", inputs);
Logger.recordOutput("Elevator/position_in", inputs.position.in(Inches));
if (inputs.limitSwitch) {
io.resetHome();
}
}

/**
* moves elevator to home with time out
*
* @return home position
*/
public Command homeTimer() {
Command slowLower = Commands.run(() -> io.setVoltage(-0.1)).withTimeout(1);
return moveTo(() -> Constants.Elevator.HOME).until(() -> inputs.position.in(Inches) < 5.0)
.andThen(slowLower);
}

/**
* moves elevator to home
*
* @return elevator at home
*
*/
public Command home() {

Command slowLower = Commands.runEnd(() -> io.setVoltage(-0.7), () -> io.setVoltage(0.0));
return moveTo(() -> Constants.Elevator.HOME).until(() -> inputs.position.in(Inches) < 5.0)
.andThen(slowLower).until(() -> (inputs.limitSwitch == true));
}

/**
* moves elevator to l2
*
* @return elevator at l2
*
*/
public Command p0() {
return moveTo(() -> Constants.Elevator.P0);
}

public Command p1() {
return moveTo(() -> Constants.Elevator.P1);
}

public Command p2() {
return moveTo(() -> Constants.Elevator.P2);
}

public Command p3() {
return moveTo(() -> Constants.Elevator.P3);
}

public Command p4() {
return moveTo(() -> Constants.Elevator.P4);
}

/**
* sets height of elevator
*
* @param height desired height of elevator
* @return elevator height change
*
*/
public Command moveTo(Supplier<Distance> height) {
return run(() -> {
Logger.recordOutput("targetHeight", height.get().in(Meters));
io.setPositon(height.get().in(Meters));
}).until(() -> Math.abs(inputs.position.in(Inches) - height.get().in(Inches)) < 1);
}

public Command moveUp() {
return runEnd(() -> io.setVoltage(SmartDashboard.getNumber("elevatorVoltage", 1.0)),
() -> io.setVoltage(0));
}

public Command moveDown() {
return runEnd(() -> io.setVoltage(-1.0), () -> io.setVoltage(0));
}
}
Loading