From be328661c7429d9d6be7205cc96a845e561e5fc8 Mon Sep 17 00:00:00 2001 From: OnDYCLaptop Date: Wed, 11 Mar 2026 00:53:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E7=89=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/frc/robot/RobotContainer.java | 32 +++++++------- .../java/frc/robot/controls/Autocommand.java | 44 ++++++++++++------- .../frc/robot/controls/ClimberControls.java | 5 --- .../robot/subsystems/ClimberSubsystem.java | 42 +++++++++++------- 4 files changed, 70 insertions(+), 53 deletions(-) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 0cecc7e..ff63cd9 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -82,7 +82,7 @@ public class RobotContainer { configueClimber(); bingdingLED(); configueIntaker(); - //configureBindings(); + configureBindings(); Autocommand.preNameCommands( climberSubsystem, IntakerSubsystem, @@ -194,9 +194,7 @@ public class RobotContainer { } private void configueClimber() { - //enableTrigger.onTrue(climberControls.enableInitCommand()); climberSubsystem.setDefaultCommand(climberControls.defaultClimberCommand()); - //controllerupper.b().onTrue(climberControls.resetClimberEncoderCommand(climberSubsystem)); } private void configueIntaker() { @@ -204,21 +202,21 @@ public class RobotContainer { controllerupper.a().onTrue(intakerControls.resetIntakerRotaterEncoderCommand(IntakerSubsystem)); } - // private void configureBindings() { - // teleopStartTrigger.onTrue(handleClimberAtTeleopStartCommand()); - // } + private void configureBindings() { + teleopStartTrigger.onTrue(handleClimberAtTeleopStartCommand()); + } - // private Command handleClimberAtTeleopStartCommand() { - // return new InstantCommand(() -> { - // if (climberSubsystem.wasAutoClimbUsedInAuto()) { - // climberSubsystem.climbUp(); - // climberSubsystem.clearAutoClimbUsedInAutoFlag(); - // } - // }, climberSubsystem); - // } + private Command handleClimberAtTeleopStartCommand() { + return new InstantCommand(() -> { + if (climberSubsystem.wasAutoClimbUsedInAuto()) { + climberSubsystem.climbUp(); + climberSubsystem.clearAutoClimbUsedInAutoFlag(); + } + }, climberSubsystem); + } - // public ClimberSubsystem getClimberSubsystem() { - // return climberSubsystem; - // } + public ClimberSubsystem getClimberSubsystem() { + return climberSubsystem; + } } diff --git a/src/main/java/frc/robot/controls/Autocommand.java b/src/main/java/frc/robot/controls/Autocommand.java index 05528ac..d4eaccb 100644 --- a/src/main/java/frc/robot/controls/Autocommand.java +++ b/src/main/java/frc/robot/controls/Autocommand.java @@ -32,7 +32,7 @@ import frc.robot.Constants.RobotStatus; ShooterControls shooterControls ) { 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_timelimit", start_intake_timelimit(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("auto_align_to_climb", autoAlignToClimb(drivetrain)); NamedCommands.registerCommand("shoot", shoot(shooter)); - // NamedCommands.registerCommand("Shake", Autocommand.shake(driveControls)); - // NamedCommands.registerCommand("AutoAim", Autocommand.autoAim(driveControls)); - // NamedCommands.registerCommand("AutoShoot", Autocommand.autoShoot(shooterControls)); + NamedCommands.registerCommand("Shake", shake(driveControls)); + NamedCommands.registerCommand("AutoAim", autoAim(driveControls)); + NamedCommands.registerCommand("AutoShoot", autoShoot(shooterControls)); + NamedCommands.registerCommand("climber_init", climber_Zeroencoder(climber)); } @@ -57,14 +58,18 @@ import frc.robot.Constants.RobotStatus; }, climber)); } public static Command climb_down(ClimberSubsystem climber) { - return new RunCommand(() -> { + return new InstantCommand(() -> { + climber.markAutoClimbUsedInAuto(); // 标记自动攀爬已使用 + }, climber) + .andThen(new RunCommand(() -> { climber.climbDown(); // 控制爬升器下降 - }, climber).withTimeout(2.0) // + }, climber).withTimeout(2.0)) .andThen(new InstantCommand(() -> { climber.captureHoldPosition(); // 捕获当前爬升器位置以保持 - climber.holdPosition(); // 停止并锁定当前爬升器位置 + climber.holdPosition(); // 停止并锁定当前爬升器位置 }, climber)); } + public static Command start_intake(IntakerSubsystem intaker) { return new RunCommand(() -> { intaker.setIntakerGetterSpeed(Constants.Intaker.IntakeGetterSpeedforAuto); // 启动吸球 @@ -136,15 +141,22 @@ import frc.robot.Constants.RobotStatus; shooter.setConveyorSpeedByRPS(0); // 停止输送 }, shooter))); } - // public static Command autoAim(DriveControls driveControls) { - // return driveControls.autoAimCommand(); - // } - // public static Command autoShoot(ShooterControls shooterControl) { - // return shooterControl.autoShootToHubCommand(); - // } - // public static Command shake(DriveControls driveControls) { - // return driveControls.shakeCommand(); - // } + public static Command autoAim(DriveControls driveControls) { + return driveControls.autoAimCommand(); + } + + public static Command autoShoot(ShooterControls shooterControl) { + return shooterControl.autoShootToHubCommand(); + } + + public static Command shake(DriveControls driveControls) { + return driveControls.shakeCommand(); + } + + public static Command climber_Zeroencoder(ClimberSubsystem climber) { + return climber.initCommand(); + } + } diff --git a/src/main/java/frc/robot/controls/ClimberControls.java b/src/main/java/frc/robot/controls/ClimberControls.java index 2d3f6aa..d52bc87 100644 --- a/src/main/java/frc/robot/controls/ClimberControls.java +++ b/src/main/java/frc/robot/controls/ClimberControls.java @@ -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) { return Commands.runOnce(climber::zeroEncoder, climber); } diff --git a/src/main/java/frc/robot/subsystems/ClimberSubsystem.java b/src/main/java/frc/robot/subsystems/ClimberSubsystem.java index 954eeab..c50d994 100644 --- a/src/main/java/frc/robot/subsystems/ClimberSubsystem.java +++ b/src/main/java/frc/robot/subsystems/ClimberSubsystem.java @@ -10,13 +10,15 @@ import com.ctre.phoenix6.signals.InvertedValue; import edu.wpi.first.networktables.NetworkTable; 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 frc.robot.Constants; public class ClimberSubsystem extends SubsystemBase { - // private boolean autoClimbUsedInAuto = false; + private boolean autoClimbUsedInAuto = false; private final TalonFX climberMotor; private double targetPositionTicks; @@ -49,11 +51,6 @@ public class ClimberSubsystem extends SubsystemBase { public void initialize() { climberMotor.set(-0.07); } - - public void zeroEncoder(){ - climberMotor.setPosition(0); - stopMotor(); - } public double getPositionTicks() { return climberMotor.getPosition().getValueAsDouble(); @@ -101,18 +98,33 @@ public class ClimberSubsystem extends SubsystemBase { public void stopMotor() { climberMotor.set(0); } + public void setMotor(double speed) { + climberMotor.set(speed); + } - // public void markAutoClimbUsedInAuto() { - // autoClimbUsedInAuto = true; - // } + public Command initCommand() { + return Commands.sequence( + Commands.run(() -> climberMotor.set(-0.07), this).withTimeout(0.5), + Commands.runOnce(this::zeroEncoder, this) + ); + } - // public boolean wasAutoClimbUsedInAuto() { - // return autoClimbUsedInAuto; - // } + public void zeroEncoder() { + climberMotor.setPosition(0); + stopMotor(); + } - // public void clearAutoClimbUsedInAutoFlag() { - // autoClimbUsedInAuto = false; - // } + public void markAutoClimbUsedInAuto() { + autoClimbUsedInAuto = true; + } + + public boolean wasAutoClimbUsedInAuto() { + return autoClimbUsedInAuto; + } + + public void clearAutoClimbUsedInAutoFlag() { + autoClimbUsedInAuto = false; + } @Override public void periodic() {