修改版

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();
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;
}
}
@@ -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();
}
}
@@ -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);
}
@@ -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;
@@ -50,11 +52,6 @@ public class ClimberSubsystem extends SubsystemBase {
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() {