Skip to content
New issue

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

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

Already on GitHub? # to your account

Elevator tune #10

Merged
merged 3 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 5 additions & 1 deletion src/main/java/frc/robot/RobotConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,11 @@ public static class ElevatorConstants {
0.3);// 0.107853495
public static final TunableNumber L4_EXTENSION_METERS = new TunableNumber("ELEVATOR SETPOINTS/L4",
0.4);
}
public static final TunableNumber ELEVATOR_ZEROING_CURRENT = new TunableNumber("Elevator zeroing current",
30);

}


/**
* Constants for the elevator motor gains.
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/frc/robot/RobotContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import edu.wpi.first.wpilibj2.command.button.*;

import frc.robot.auto.basics.AutoActions;
import frc.robot.commands.RumbleCommand;
import frc.robot.commands.*;
import frc.robot.display.Display;
import frc.robot.subsystems.apriltagvision.AprilTagVision;
import frc.robot.subsystems.apriltagvision.AprilTagVisionIONorthstar;
Expand Down Expand Up @@ -118,6 +118,8 @@ private void configureDriverBindings(CommandXboxController driverController) {
}
lastResetTime = Timer.getFPGATimestamp();
}).ignoringDisable(true));


}

//Configure all commands for operator
Expand All @@ -131,6 +133,7 @@ private void configureTesterBindings(CommandXboxController controller) {
controller.b().onTrue(Commands.runOnce(() -> elevatorSubsystem.setPosition(0.8),elevatorSubsystem).until(() ->elevatorSubsystem.isAtSetpoint(0.8)));
controller.x().onTrue(Commands.runOnce(() -> elevatorSubsystem.setPosition(1.1),elevatorSubsystem).until(() ->elevatorSubsystem.isAtSetpoint(1.1)));
controller.y().onTrue(Commands.runOnce(() -> elevatorSubsystem.setPosition(1.4),elevatorSubsystem).until(() ->elevatorSubsystem.isAtSetpoint(1.4)));
controller.povDown().onTrue(new ElevatorZeroingCommand(elevatorSubsystem));
}
/**
* Use this to pass the autonomous command to the main {@link Robot} class.
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/frc/robot/commands/ElevatorZeroingCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package frc.robot.commands;

import edu.wpi.first.wpilibj2.command.Command;
import frc.robot.Robot;
import frc.robot.subsystems.elevator.*;
import edu.wpi.first.math.MathUtil;
import frc.robot.RobotConstants;


public class ElevatorZeroingCommand extends Command {
private ElevatorSubsystem elevator;

public ElevatorZeroingCommand(ElevatorSubsystem elevator) {
this.elevator = elevator;
}

@Override
public void initialize() {

}

@Override
public void execute(){
elevator.setVoltage(-0.5);
}

@Override
public boolean isFinished() {
return elevator.getLeaderCurrent() > RobotConstants.ElevatorConstants.ELEVATOR_ZEROING_CURRENT.get();
}

@Override
public void end(boolean interrupted) {
elevator.setVoltage(0);
elevator.resetPosition();
}


}
6 changes: 6 additions & 0 deletions src/main/java/frc/robot/subsystems/elevator/ElevatorIO.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ public default void stop() {
setVoltage(0.0);
}

public default double getLeaderCurrent(){
return getLeaderCurrent();
}

public default void resetEncoder(double position) {}

public default void resetEncoder() {
resetEncoder(0.0);
}

public default void resetPosition() {}
}
14 changes: 12 additions & 2 deletions src/main/java/frc/robot/subsystems/elevator/ElevatorIOReal.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public ElevatorIOReal() {
currentLimitsConfigs = new CurrentLimitsConfigs();
currentLimitsConfigs.StatorCurrentLimitEnable = true;
currentLimitsConfigs.SupplyCurrentLimitEnable = true;
currentLimitsConfigs.StatorCurrentLimit = 60.0;
currentLimitsConfigs.SupplyCurrentLimit = 20.0;
currentLimitsConfigs.StatorCurrentLimit = 80.0;
currentLimitsConfigs.SupplyCurrentLimit = 30.0;

leaderMotorConfigs = new MotorOutputConfigs();
leaderMotorConfigs.NeutralMode = NeutralModeValue.Brake;
Expand Down Expand Up @@ -154,6 +154,16 @@ public void resetEncoder(final double position) {
follower.setPosition(position);
}

public double getLeaderCurrent(){
return leader.getStatorCurrent().getValueAsDouble();
}

public void resetPosistion(){
leader.setPosition(0.0);
follower.setPosition(0.0);
}


private double getHeight() {
return rotationsToMeters(leader.getPosition().getValueAsDouble());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,12 @@ public double getPositionMeters() {
public boolean isAtSetpoint(double setpoint) {
return MathUtil.isNear(setpoint, inputs.positionMeters, DEADZONE_DISTANCE);
}

public double getLeaderCurrent(){
return io.getLeaderCurrent();
}

public void resetPosition(){
io.resetPosition();
}
}