修改版

This commit is contained in:
OnDYCLaptop
2026-03-11 00:53:35 +08:00
parent 1d0454dc58
commit be328661c7
4 changed files with 70 additions and 53 deletions
+15 -17
View File
@@ -82,7 +82,7 @@ public class RobotContainer {
configueClimber(); configueClimber();
bingdingLED(); bingdingLED();
configueIntaker(); configueIntaker();
//configureBindings(); configureBindings();
Autocommand.preNameCommands( Autocommand.preNameCommands(
climberSubsystem, climberSubsystem,
IntakerSubsystem, IntakerSubsystem,
@@ -194,9 +194,7 @@ public class RobotContainer {
} }
private void configueClimber() { private void configueClimber() {
//enableTrigger.onTrue(climberControls.enableInitCommand());
climberSubsystem.setDefaultCommand(climberControls.defaultClimberCommand()); climberSubsystem.setDefaultCommand(climberControls.defaultClimberCommand());
//controllerupper.b().onTrue(climberControls.resetClimberEncoderCommand(climberSubsystem));
} }
private void configueIntaker() { private void configueIntaker() {
@@ -204,21 +202,21 @@ public class RobotContainer {
controllerupper.a().onTrue(intakerControls.resetIntakerRotaterEncoderCommand(IntakerSubsystem)); controllerupper.a().onTrue(intakerControls.resetIntakerRotaterEncoderCommand(IntakerSubsystem));
} }
// private void configureBindings() { private void configureBindings() {
// teleopStartTrigger.onTrue(handleClimberAtTeleopStartCommand()); teleopStartTrigger.onTrue(handleClimberAtTeleopStartCommand());
// } }
// private Command handleClimberAtTeleopStartCommand() { private Command handleClimberAtTeleopStartCommand() {
// return new InstantCommand(() -> { return new InstantCommand(() -> {
// if (climberSubsystem.wasAutoClimbUsedInAuto()) { if (climberSubsystem.wasAutoClimbUsedInAuto()) {
// climberSubsystem.climbUp(); climberSubsystem.climbUp();
// climberSubsystem.clearAutoClimbUsedInAutoFlag(); climberSubsystem.clearAutoClimbUsedInAutoFlag();
// } }
// }, climberSubsystem); }, climberSubsystem);
// } }
// public ClimberSubsystem getClimberSubsystem() { public ClimberSubsystem getClimberSubsystem() {
// return climberSubsystem; return climberSubsystem;
// } }
} }
@@ -32,7 +32,7 @@ import frc.robot.Constants.RobotStatus;
ShooterControls shooterControls ShooterControls shooterControls
) { ) {
NamedCommands.registerCommand("climb_up", climb_up(climber)); NamedCommands.registerCommand("climb_up", climb_up(climber));
//NamedCommands.registerCommand("climb_down", climb_down(climber)); NamedCommands.registerCommand("climb_down", climb_down(climber));
NamedCommands.registerCommand("start_intake", start_intake(intaker)); NamedCommands.registerCommand("start_intake", start_intake(intaker));
NamedCommands.registerCommand("start_intake_timelimit", start_intake_timelimit(intaker)); NamedCommands.registerCommand("start_intake_timelimit", start_intake_timelimit(intaker));
NamedCommands.registerCommand("stop_intake", stop_intake(intaker)); NamedCommands.registerCommand("stop_intake", stop_intake(intaker));
@@ -40,9 +40,10 @@ import frc.robot.Constants.RobotStatus;
NamedCommands.registerCommand("intaker_up", intaker_up(intaker)); NamedCommands.registerCommand("intaker_up", intaker_up(intaker));
NamedCommands.registerCommand("auto_align_to_climb", autoAlignToClimb(drivetrain)); NamedCommands.registerCommand("auto_align_to_climb", autoAlignToClimb(drivetrain));
NamedCommands.registerCommand("shoot", shoot(shooter)); NamedCommands.registerCommand("shoot", shoot(shooter));
// NamedCommands.registerCommand("Shake", Autocommand.shake(driveControls)); NamedCommands.registerCommand("Shake", shake(driveControls));
// NamedCommands.registerCommand("AutoAim", Autocommand.autoAim(driveControls)); NamedCommands.registerCommand("AutoAim", autoAim(driveControls));
// NamedCommands.registerCommand("AutoShoot", Autocommand.autoShoot(shooterControls)); NamedCommands.registerCommand("AutoShoot", autoShoot(shooterControls));
NamedCommands.registerCommand("climber_init", climber_Zeroencoder(climber));
} }
@@ -57,14 +58,18 @@ import frc.robot.Constants.RobotStatus;
}, climber)); }, climber));
} }
public static Command climb_down(ClimberSubsystem climber) { public static Command climb_down(ClimberSubsystem climber) {
return new RunCommand(() -> { return new InstantCommand(() -> {
climber.markAutoClimbUsedInAuto(); // 标记自动攀爬已使用
}, climber)
.andThen(new RunCommand(() -> {
climber.climbDown(); // 控制爬升器下降 climber.climbDown(); // 控制爬升器下降
}, climber).withTimeout(2.0) // }, climber).withTimeout(2.0))
.andThen(new InstantCommand(() -> { .andThen(new InstantCommand(() -> {
climber.captureHoldPosition(); // 捕获当前爬升器位置以保持 climber.captureHoldPosition(); // 捕获当前爬升器位置以保持
climber.holdPosition(); // 停止并锁定当前爬升器位置 climber.holdPosition(); // 停止并锁定当前爬升器位置
}, climber)); }, climber));
} }
public static Command start_intake(IntakerSubsystem intaker) { public static Command start_intake(IntakerSubsystem intaker) {
return new RunCommand(() -> { return new RunCommand(() -> {
intaker.setIntakerGetterSpeed(Constants.Intaker.IntakeGetterSpeedforAuto); // 启动吸球 intaker.setIntakerGetterSpeed(Constants.Intaker.IntakeGetterSpeedforAuto); // 启动吸球
@@ -136,15 +141,22 @@ import frc.robot.Constants.RobotStatus;
shooter.setConveyorSpeedByRPS(0); // 停止输送 shooter.setConveyorSpeedByRPS(0); // 停止输送
}, shooter))); }, shooter)));
} }
// public static Command autoAim(DriveControls driveControls) { public static Command autoAim(DriveControls driveControls) {
// return driveControls.autoAimCommand(); return driveControls.autoAimCommand();
// } }
// public static Command autoShoot(ShooterControls shooterControl) {
// return shooterControl.autoShootToHubCommand(); public static Command autoShoot(ShooterControls shooterControl) {
// } return shooterControl.autoShootToHubCommand();
// public static Command shake(DriveControls driveControls) { }
// return driveControls.shakeCommand();
// } public static Command shake(DriveControls driveControls) {
return driveControls.shakeCommand();
}
public static Command climber_Zeroencoder(ClimberSubsystem climber) {
return climber.initCommand();
}
} }
@@ -50,11 +50,6 @@ public class ClimberControls {
} }
public Command enableInitCommand() {
return Commands.run(climber::initialize, climber)
.withTimeout(0.5)
.andThen(Commands.runOnce(climber::zeroEncoder, climber));
}
public Command resetClimberEncoderCommand(ClimberSubsystem climber) { public Command resetClimberEncoderCommand(ClimberSubsystem climber) {
return Commands.runOnce(climber::zeroEncoder, climber); return Commands.runOnce(climber::zeroEncoder, climber);
} }
@@ -10,13 +10,15 @@ import com.ctre.phoenix6.signals.InvertedValue;
import edu.wpi.first.networktables.NetworkTable; import edu.wpi.first.networktables.NetworkTable;
import edu.wpi.first.networktables.NetworkTableInstance; import edu.wpi.first.networktables.NetworkTableInstance;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.SubsystemBase; import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants; import frc.robot.Constants;
public class ClimberSubsystem extends SubsystemBase { public class ClimberSubsystem extends SubsystemBase {
// private boolean autoClimbUsedInAuto = false; private boolean autoClimbUsedInAuto = false;
private final TalonFX climberMotor; private final TalonFX climberMotor;
private double targetPositionTicks; private double targetPositionTicks;
@@ -50,11 +52,6 @@ public class ClimberSubsystem extends SubsystemBase {
climberMotor.set(-0.07); climberMotor.set(-0.07);
} }
public void zeroEncoder(){
climberMotor.setPosition(0);
stopMotor();
}
public double getPositionTicks() { public double getPositionTicks() {
return climberMotor.getPosition().getValueAsDouble(); return climberMotor.getPosition().getValueAsDouble();
} }
@@ -101,18 +98,33 @@ public class ClimberSubsystem extends SubsystemBase {
public void stopMotor() { public void stopMotor() {
climberMotor.set(0); climberMotor.set(0);
} }
public void setMotor(double speed) {
climberMotor.set(speed);
}
// public void markAutoClimbUsedInAuto() { public Command initCommand() {
// autoClimbUsedInAuto = true; return Commands.sequence(
// } Commands.run(() -> climberMotor.set(-0.07), this).withTimeout(0.5),
Commands.runOnce(this::zeroEncoder, this)
);
}
// public boolean wasAutoClimbUsedInAuto() { public void zeroEncoder() {
// return autoClimbUsedInAuto; climberMotor.setPosition(0);
// } stopMotor();
}
// public void clearAutoClimbUsedInAutoFlag() { public void markAutoClimbUsedInAuto() {
// autoClimbUsedInAuto = false; autoClimbUsedInAuto = true;
// } }
public boolean wasAutoClimbUsedInAuto() {
return autoClimbUsedInAuto;
}
public void clearAutoClimbUsedInAutoFlag() {
autoClimbUsedInAuto = false;
}
@Override @Override
public void periodic() { public void periodic() {