Skip to content
Open
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
f6e39ed
adds IntakeCommandGroup
p-ifka Mar 12, 2025
951b160
tune PID values for Elevator
p-ifka Mar 12, 2025
d0b8195
adds ElevatorCommand, adds Elevator subsystem function to get the cur…
p-ifka Mar 12, 2025
62ea704
clarify comments and update SmartDashboard outputs for two-stage elev…
gbuckholtz Mar 12, 2025
05248fe
add detailed PID tuning strategy documentation for Elevator subsystem
gbuckholtz Mar 12, 2025
748fc9f
refactor PID tuning documentation for Elevator subsystem
gbuckholtz Mar 12, 2025
879158b
update Elevator documentation to clarify FF tuning independence from …
gbuckholtz Mar 12, 2025
223b1fd
Changed initial FF_UP to 0.02.
AdamG825 Mar 12, 2025
03f3047
change how drivetowardsthing works
p-ifka Mar 12, 2025
c9ec8b2
add operator controls, add manual drive for the elevator, temporarily…
p-ifka Mar 13, 2025
acdc4a3
Merge branch 'pre-durham' of github.com:LakeEffectRobotics/LER-2025 i…
p-ifka Mar 13, 2025
398ab97
Add AprilTag recognition and distance calculations to Camera subsystem
gbuckholtz Mar 13, 2025
6dbba3f
Implement distance calculation for tracked objects and optimize objec…
gbuckholtz Mar 13, 2025
51d1a42
refactor ScoreCommandGroup to use ElevatorLevel enum for target levels
gbuckholtz Mar 13, 2025
55e59a2
refactor Drivetrain speed control to use constants for speed modifiers
gbuckholtz Mar 13, 2025
28a4985
move driver slowdown to 'driveCommand', create DoubleSupplier for dri…
p-ifka Mar 13, 2025
04d9bbb
adjust elevator amounts, fix drivecommand speed up
p-ifka Mar 13, 2025
fdde410
Merge branch 'pre-durham' into relative_pos_from_apriltag_gb
gbuckholtz Mar 13, 2025
7d1ab1e
Merge remote-tracking branch 'origin/pre-durham' into relative_pos_fr…
gbuckholtz Mar 13, 2025
3edf28c
write more autos, make drivedistance max speed be set as argument, re…
p-ifka Mar 14, 2025
25756cb
apply coralclaw motor enabling/disabling to intake and outtake functions
p-ifka Mar 14, 2025
c5b414e
refactor ScoreTest command to use wpilib wait times
gbuckholtz Mar 14, 2025
13e390c
Merge branch 'pre-durham' into relative_pos_from_apriltag_gb
gbuckholtz Mar 14, 2025
f23fc6f
Add modified huskylens library
gregk27 Mar 15, 2025
e6c2793
Migrate from GPIOZero to RPi.GPIO
gregk27 Mar 15, 2025
7ac4560
Fix minor bugs causing crashes
gregk27 Mar 15, 2025
31fe1a9
Add newtorktables initialization line
gregk27 Mar 15, 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
6 changes: 4 additions & 2 deletions src/main/java/frc/robot/ElevatorLevel.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package frc.robot;


public enum ElevatorLevel {
LOW, MED, HIGH, EXTRA_HIGH, STATION
public enum ElevatorLevel {
LOW, MED, HIGH, EXTRA_HIGH, STATION
}



60 changes: 31 additions & 29 deletions src/main/java/frc/robot/OI.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,23 @@
public class OI {

// Reference to RobotContainer for accessing subsystems
private static RobotContainer robotContainer;

/**
* Initialize OI with a reference to RobotContainer
* @param container The RobotContainer instance
*/
public static void initialize(RobotContainer container) {
robotContainer = container;
// Removed initializeBindings call - now handled in RobotContainer
}


/**
* Controller port mappings
*/
private static class PORT {
private static final int DRIVE_CONTROLLER_PORT = 0;
private static final int OPERATOR_CONTROLLER_PORT = 1; // Added operator controller port
}
// Trigger thresholds
public static final double TRIGGER_THRESHOLD = 0.1;


/**
* Bidings on driver controls
*/
Expand All @@ -37,6 +36,7 @@ private static class PORT {

private static class DRIVER_MAP {
private static final int ABUTTON = XboxController.Button.kA.value;
private static final int BBUTTON = XboxController.Button.kB.value;
}

// drive sticks
Expand All @@ -47,43 +47,46 @@ private static class DRIVER_MAP {

// drive buttons
public static final JoystickButton driveControllerA = new JoystickButton(xboxController, DRIVER_MAP.ABUTTON);

public static final JoystickButton driveControllerB = new JoystickButton(xboxController, DRIVER_MAP.BBUTTON);
public static final Trigger driveRightTrigger = new Trigger(() ->
xboxController.getRightTriggerAxis() > TRIGGER_THRESHOLD);

private static double processDriveInput(double raw) {
if (Math.abs(raw) < 0.1) {
raw = 0;
raw = 0 ;
}
return raw/2;
return raw;
}

private static double processRotationInput(double raw) {
if (Math.abs(raw) < 0.1) {
raw = 0;
}
return raw;
return raw*4;
}

/**
* Bindings on operator controls
*/
public static class OperatorBindings {
public static final int A_BUTTON = XboxController.Button.kA.value;
public static final int B_BUTTON = XboxController.Button.kB.value;
public static final int X_BUTTON = XboxController.Button.kX.value;
public static final int Y_BUTTON = XboxController.Button.kY.value;
public static final int LEFT_BUMPER = XboxController.Button.kLeftBumper.value;
public static final int RIGHT_BUMPER = XboxController.Button.kRightBumper.value;
public static final int START_BUTTON = XboxController.Button.kStart.value;
private static class operatorBindings {
private static final int A_BUTTON = XboxController.Button.kA.value;
private static final int B_BUTTON = XboxController.Button.kB.value;
private static final int X_BUTTON = XboxController.Button.kX.value;
private static final int Y_BUTTON = XboxController.Button.kY.value;
private static final int LEFT_BUMPER = XboxController.Button.kLeftBumper.value;
private static final int RIGHT_BUMPER = XboxController.Button.kRightBumper.value;
private static final int START_BUTTON = XboxController.Button.kStart.value;
private static final int BACK_BUTTON = XboxController.Button.kBack.value;

// Trigger thresholds
public static final double TRIGGER_THRESHOLD = 0.1;

public static final JoystickButton operatorControllerA = new JoystickButton(operatorController, A_BUTTON);
public static final JoystickButton operatorControllerB = new JoystickButton(operatorController, B_BUTTON);
public static final JoystickButton operatorControllerX = new JoystickButton(operatorController, X_BUTTON);
public static final JoystickButton operatorControllerY = new JoystickButton(operatorController, Y_BUTTON);
public static final JoystickButton operatorControllerLeftBumper = new JoystickButton(operatorController, LEFT_BUMPER);
public static final JoystickButton operatorControllerRightBumper = new JoystickButton(operatorController, RIGHT_BUMPER);
public static final JoystickButton operatorControllerStart = new JoystickButton(operatorController, START_BUTTON);
}
public static final JoystickButton operatorControllerA = new JoystickButton(operatorController, operatorBindings.A_BUTTON);
public static final JoystickButton operatorControllerB = new JoystickButton(operatorController, operatorBindings.B_BUTTON);
public static final JoystickButton operatorControllerX = new JoystickButton(operatorController, operatorBindings.X_BUTTON);
public static final JoystickButton operatorControllerY = new JoystickButton(operatorController, operatorBindings.Y_BUTTON);
public static final JoystickButton operatorControllerLeftBumper = new JoystickButton(operatorController, operatorBindings.LEFT_BUMPER);
public static final JoystickButton operatorControllerRightBumper = new JoystickButton(operatorController, operatorBindings.RIGHT_BUMPER);
public static final JoystickButton operatorControllerStart = new JoystickButton(operatorController, operatorBindings.START_BUTTON);
public static final JoystickButton operatorControllerBack = new JoystickButton(operatorController, operatorBindings.BACK_BUTTON);

// Trigger controls for coral claw
public static final Trigger operatorRightTrigger = new Trigger(() ->
Expand All @@ -95,5 +98,4 @@ public static class OperatorBindings {
public static double processElevatorInput(double input) {
return -Math.signum(input) * Math.pow(Math.abs(input), 2) * 0.7;
}
}
}
2 changes: 2 additions & 0 deletions src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import frc.robot.commands.test.MoveElevatorToLevelCommand;
import frc.robot.commands.FetchCoralFromStationCommand;

import frc.robot.ElevatorLevel;

public class Robot extends TimedRobot {
private Command m_autonomousCommand;

Expand Down
76 changes: 46 additions & 30 deletions src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,28 @@
import frc.robot.subsystems.*;
import frc.robot.commands.*;
import frc.robot.commands.auto.*;
import frc.robot.OI.OperatorBindings;
import frc.robot.commands.instant.*;

public class RobotContainer {

// Constants
private static final double BEVEL_IN_CORRECTION = 0.25;

/* init subsystems */
/* init subsystems */

public SwerveModule leftFrontSwerve = new SwerveModule(RobotMap.leftFrontDrive, RobotMap.leftFrontRotate, RobotMap.leftFrontEncoder, 0.4675 + BEVEL_IN_CORRECTION, 0.0, 0.0, false);
public SwerveModule rightFrontSwerve = new SwerveModule(RobotMap.rightFrontDrive, RobotMap.rightFrontRotate, RobotMap.rightFrontEncoder, 0.7705 - BEVEL_IN_CORRECTION, 0.0, 0.0, true);
public SwerveModule leftBackSwerve = new SwerveModule(RobotMap.leftBackDrive, RobotMap.leftBackRotate, RobotMap.leftBackEncoder, 0.1280 - BEVEL_IN_CORRECTION, 0.0, 0.0, false);
public SwerveModule rightBackSwerve = new SwerveModule(RobotMap.rightBackDrive, RobotMap.rightBackRotate, RobotMap.rightBackEncoder, 0.4992 + BEVEL_IN_CORRECTION, 0.0, 0.0, true);

// Create subsystem instances directly here instead of referencing from RobotMap
public Wrist wrist = new Wrist(RobotMap.wristSolenoid);
public CoralClaw coralClaw = new CoralClaw(RobotMap.coralClawPrimaryMotor, RobotMap.coralClawSecondaryMotor, RobotMap.coralLimitSwitch);
public Elevator elevator = new Elevator();


public Gyro gyro = new Gyro(RobotMap.gyro);
public Drivetrain drivetrain = new Drivetrain(leftBackSwerve, rightBackSwerve, leftFrontSwerve, rightFrontSwerve, gyro);
public Camera camera = new Camera();
public Gyro gyro = new Gyro(RobotMap.gyro);
public Elevator elevator = new Elevator();
public Wrist wrist = new Wrist(RobotMap.wristSolenoid);
public CoralClaw coralClaw = new CoralClaw(RobotMap.coralClawPrimaryMotor, RobotMap.coralClawSecondaryMotor, RobotMap.coralLimitSwitch);

public Camera camera = new Camera();
public Drivetrain drivetrain = new Drivetrain(leftBackSwerve, rightBackSwerve, leftFrontSwerve, rightFrontSwerve, gyro);

/**
* The RobotContainer class is where the bulk of the robot should be declared.
* Since Command-based is a "declarative" paradigm, very little robot logic
Expand All @@ -45,14 +43,12 @@ public class RobotContainer {
*/
public RobotContainer() {
// Initialize OI with a reference to this RobotContainer instance
OI.initialize(this);

configureBindings();

drivetrain.setDefaultCommand(new DriveCommand(drivetrain, OI.xboxLeftStickXSupplier, OI.xboxLeftStickYSupplier, OI.xboxRightStickXSupplier));
RobotMap.compressor.enableAnalog(70, 120);
// set the default drive command to use the left and right stick values from the Xbox controller
// The left stick controls the forward and backward movement of the robot, while the right stick
// controls the rotation of the robot.
drivetrain.setDefaultCommand(new DriveCommand(drivetrain, OI.xboxLeftStickXSupplier, OI.xboxLeftStickYSupplier, OI.xboxRightStickXSupplier));
}

/**
Expand All @@ -65,30 +61,50 @@ private void configureBindings() {
OI.driveControllerA.onTrue(Commands.runOnce(() -> {
drivetrain.resetPosition();
}));


OI.driveRightTrigger.onTrue(new InstantCommand(() -> drivetrain.setSlow(true)));
OI.driveRightTrigger.onFalse(new InstantCommand(() -> drivetrain.setSlow(false)));

// Operator controller bindings
// Elevator level controls
OperatorBindings.operatorControllerA.onTrue(new InstantCommand(() -> elevator.moveToLevel(ElevatorLevel.LOW)));
OperatorBindings.operatorControllerB.onTrue(new InstantCommand(() -> elevator.moveToLevel(ElevatorLevel.HIGH)));
OperatorBindings.operatorControllerX.onTrue(new InstantCommand(() -> elevator.moveToLevel(ElevatorLevel.MED)));
OperatorBindings.operatorControllerY.onTrue(new InstantCommand(() -> elevator.moveToLevel(ElevatorLevel.EXTRA_HIGH)));
// OperatorBindings.operatorControllerA.onTrue(new InstantCommand(() -> elevator.moveToLevel(ElevatorLevel.LOW)));
// OperatorBindings.operatorControllerB.onTrue(new InstantCommand(() -> elevator.moveToLevel(ElevatorLevel.HIGH)));
// OperatorBindings.operatorControllerX.onTrue(new InstantCommand(() -> elevator.moveToLevel(ElevatorLevel.MED)));
// OperatorBindings.operatorControllerY.onTrue(new InstantCommand(() -> elevator.moveToLevel(ElevatorLevel.EXTRA_HIGH)));

// OPERATOR B : INTAKE
OI.operatorControllerB.onTrue(new IntakeCommandGroup(elevator, wrist, coralClaw));
// OPERATOR RB : TROUGH(L1)
OI.operatorControllerRightBumper.onTrue(new ScoreCommandGroup(elevator, wrist, coralClaw, 1));
// OPERATOR A : L2 (lowest pole)
OI.operatorControllerA.onTrue(new ScoreCommandGroup(elevator, wrist, coralClaw, 2));
// OPERATOR X : L3 (2nd pole)
OI.operatorControllerX.onTrue(new ScoreCommandGroup(elevator, wrist, coralClaw, 3));
// OPERATOR Y : L4 (last pole)
OI.operatorControllerY.onTrue(new ScoreCommandGroup(elevator, wrist, coralClaw, 4));

// OPERATOR LB: WRIST TOGGLE
OI.operatorControllerLeftBumper.onTrue(new InstantCommand(() -> wrist.toggle()));

OI.operatorControllerStart.onTrue(new InstantCommand(() -> elevator.trimTarget(0.0175)));
OI.operatorControllerBack.onTrue(new InstantCommand(() -> elevator.trimTarget(-0.0175)));

// Wrist toggle control with left bumper
OperatorBindings.operatorControllerLeftBumper.onTrue(new InstantCommand(() -> wrist.toggle()));

// Coral Claw controls with triggers
OperatorBindings.operatorRightTrigger.onTrue(new InstantCommand(() -> coralClaw.intake()));
OperatorBindings.operatorRightTrigger.onFalse(new InstantCommand(() -> coralClaw.stop()));

OperatorBindings.operatorLeftTrigger.onTrue(new InstantCommand(() -> coralClaw.outtake()));
OperatorBindings.operatorLeftTrigger.onFalse(new InstantCommand(() -> coralClaw.stop()));
// Coral Claw controls with triggers
// OI.operatorRightTrigger.onTrue(new InstantCommand(() -> coralClaw.intake()));
// OI.operatorRightTrigger.onFalse(new InstantCommand(() -> coralClaw.stop()));
OI.operatorRightTrigger.whileTrue(new ClawCommand(coralClaw, 1));
OI.operatorLeftTrigger.whileTrue(new ClawCommand(coralClaw, 0));
// OI.operatorLeftTrigger.onTrue(new InstantCommand(() -> coralClaw.setOutput(coralClaw.OUTTAKE_SPEED)));
// OI.operatorLeftTrigger.onFalse(new InstantCommand(() -> coralClaw.stop()));

// Reset encoder with Start button
OperatorBindings.operatorControllerStart.onTrue(new InstantCommand(() -> elevator.resetEncoder()));
// OI.operatorControllerStart.onTrue(new InstantCommand(() -> elevator.resetEncoder()));

// Manual control with right stick for testing in simulation
OperatorBindings.operatorControllerRightBumper.whileTrue(new InstantCommand(() ->
elevator.setSpeed(OperatorBindings.processElevatorInput(OI.operatorController.getRightY())), elevator));
OI.operatorControllerRightBumper.whileTrue(new InstantCommand(() ->
elevator.setSpeed(OI.processElevatorInput(OI.operatorController.getRightY())), elevator));
}

public Command getAutonomousCommand() {
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/frc/robot/RobotMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.ctre.phoenix6.hardware.TalonFX;
import edu.wpi.first.wpilibj.DoubleSolenoid;
import edu.wpi.first.wpilibj.PneumaticsModuleType;
import edu.wpi.first.wpilibj.PneumaticHub;
import edu.wpi.first.wpilibj.Compressor;

public class RobotMap {

Expand All @@ -29,8 +31,8 @@ private class CAN {
private static final int RIGHT_BACK_DRIVE_CAN = 3;
private static final int RIGHT_BACK_ROTATE_CAN = 4;

private static final int ELEVATOR_MOTOR_LEADER_CAN = 9; // Leader elevator motor
private static final int ELEVATOR_MOTOR_FOLLOWER_CAN = 10; // Follower elevator motor
private static final int ELEVATOR_MOTOR_LEADER_CAN = 10; // Leader elevator motor
private static final int ELEVATOR_MOTOR_FOLLOWER_CAN = 9; // Follower elevator motor

/* PNEUMATICS */
private static final int PCM_CAN_ID = 27; // Updated PCM ID (moved from 10)
Expand Down Expand Up @@ -94,6 +96,9 @@ private class Pneumatics {
public static final SparkMax elevatorMotorFollower = new SparkMax(CAN.ELEVATOR_MOTOR_FOLLOWER_CAN, MotorType.kBrushless);

// Pneumatic components
public static final PneumaticHub pneumaticHub = new PneumaticHub(CAN.PCM_CAN_ID);
public static final Compressor compressor = new Compressor(CAN.PCM_CAN_ID, PneumaticsModuleType.REVPH);

public static final DoubleSolenoid wristSolenoid = new DoubleSolenoid(
CAN.PCM_CAN_ID,
PneumaticsModuleType.REVPH,
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/frc/robot/commands/ElevatorSequenceCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ public ElevatorSequenceCommand(Elevator elevator) {
// Add commands to the sequence
addCommands(
// Move to LOW level first
new InstantCommand(() -> elevator.moveToLevel(ElevatorLevel.LOW)),
new InstantCommand(() -> elevator.setTarget(ElevatorLevel.LOW)),
new WaitCommand(DELAY_SECONDS),

// Move to MED level
new InstantCommand(() -> elevator.moveToLevel(ElevatorLevel.MED)),
new InstantCommand(() -> elevator.setTarget(ElevatorLevel.MED)),
new WaitCommand(DELAY_SECONDS),

// Move to HIGH level
new InstantCommand(() -> elevator.moveToLevel(ElevatorLevel.HIGH)),
new InstantCommand(() -> elevator.setTarget(ElevatorLevel.HIGH)),
new WaitCommand(DELAY_SECONDS),

// Move to EXTRA_HIGH level
new InstantCommand(() -> elevator.moveToLevel(ElevatorLevel.EXTRA_HIGH)),
new InstantCommand(() -> elevator.setTarget(ElevatorLevel.EXTRA_HIGH)),
new WaitCommand(DELAY_SECONDS),

// Return to initial position (LOW)
new InstantCommand(() -> elevator.moveToLevel(ElevatorLevel.LOW))
new InstantCommand(() -> elevator.setTarget(ElevatorLevel.LOW))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public FetchCoralFromStationCommand(Elevator elevator, CoralClaw coralClaw) {

addCommands(
// Move the elevator to STATION level
new InstantCommand(() -> elevator.moveToLevel(ElevatorLevel.STATION), elevator),
new InstantCommand(() -> elevator.setTarget(ElevatorLevel.STATION), elevator),

// Wait until the elevator reaches the target position
new WaitUntilCommand(elevator::isAtTarget),
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/frc/robot/commands/IntakeCommandGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

package frc.robot.commands;

import frc.robot.subsystems.Elevator;
import frc.robot.subsystems.Wrist;
import frc.robot.subsystems.CoralClaw;


import frc.robot.ElevatorLevel;
import edu.wpi.first.wpilibj2.command.ParallelCommandGroup;
import edu.wpi.first.wpilibj2.command.InstantCommand;

public class IntakeCommandGroup extends ParallelCommandGroup {
public IntakeCommandGroup(Elevator elevator, Wrist wrist, CoralClaw claw) {
addCommands(
new InstantCommand(() -> elevator.setTarget(ElevatorLevel.STATION)),
new InstantCommand(() -> wrist.retract())
);
}
}
4 changes: 2 additions & 2 deletions src/main/java/frc/robot/commands/ReleaseCoralCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import edu.wpi.first.wpilibj2.command.SequentialCommandGroup;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import frc.robot.ElevatorLevel;
import frc.robot.subsystems.CoralClaw;
import frc.robot.subsystems.Elevator;
import frc.robot.ElevatorLevel;

/**
* A command that handles waiting for coral release and then moving the elevator back to the STATION position.
Expand All @@ -32,7 +32,7 @@ public ReleaseCoralCommand(CoralClaw coralClaw, Elevator elevator) {
SmartDashboard.putString("Coral Claw State", "Coral released - returning to station")),

// Move elevator to STATION level
Commands.runOnce(() -> elevator.moveToLevel(ElevatorLevel.STATION))
Commands.runOnce(() -> elevator.setTarget(ElevatorLevel.STATION))
);
}
}
Loading