diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index dbf71af..a578c4a 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -150,7 +150,6 @@ public final class Constants { public static final int mainConveyorID = 50; public static final double feedVoltage = 6.0; public static final double reverseVoltage = -5.0; - public static final double holdVoltage = 0.8; } public static class Superstructure { diff --git a/src/main/java/frc/robot/subsystems/ConveyorSubsystem.java b/src/main/java/frc/robot/subsystems/ConveyorSubsystem.java index 99cc837..d0428f1 100644 --- a/src/main/java/frc/robot/subsystems/ConveyorSubsystem.java +++ b/src/main/java/frc/robot/subsystems/ConveyorSubsystem.java @@ -17,44 +17,27 @@ import frc.robot.Constants; */ public class ConveyorSubsystem extends SubsystemBase { public final TalonFX mainConveyor; - private final VoltageOut voltageRequest = new VoltageOut(0); private final NetworkTable table = NetworkTableInstance.getDefault().getTable("Conveyor"); - private double voltage = 0.0; - public ConveyorSubsystem() { mainConveyor = new TalonFX(Constants.Conveyor.mainConveyorID); } - public void feedToShooter() { setVoltage(Constants.Conveyor.feedVoltage); } - public void reverse() { setVoltage(Constants.Conveyor.reverseVoltage); } - - public void hold() { - setVoltage(Constants.Conveyor.holdVoltage); - } - public void stop() { setVoltage(0.0); } - - public void setPercent(double percent) { - setVoltage(percent * 12.0); - } - public void setVoltage(double volts) { - voltage = MathUtil.clamp(volts, -12.0, 12.0); - mainConveyor.setControl(voltageRequest.withOutput(voltage)); + mainConveyor.setControl(voltageRequest.withOutput(volts)); } - + @Override public void periodic() { - table.getEntry("voltage").setDouble(voltage); table.getEntry("velocity").setDouble(mainConveyor.getVelocity().getValueAsDouble()); } } diff --git a/src/main/java/frc/robot/subsystems/IntakeRollerSubsystem.java b/src/main/java/frc/robot/subsystems/IntakeRollerSubsystem.java index e188409..e28a997 100644 --- a/src/main/java/frc/robot/subsystems/IntakeRollerSubsystem.java +++ b/src/main/java/frc/robot/subsystems/IntakeRollerSubsystem.java @@ -18,16 +18,13 @@ import frc.robot.Constants; * 本类只负责成对 TalonFX 输出和 follower 关系。 */ public class IntakeRollerSubsystem extends SubsystemBase { - public final TalonFX leftIntakeRoller; - public final TalonFX rightIntakeRoller; + private final TalonFX leftIntakeRoller; + private final TalonFX rightIntakeRoller; private final VoltageOut voltageRequest = new VoltageOut(0); private final Follower rightFollower; private final NetworkTable table = NetworkTableInstance.getDefault().getTable("IntakeRoller"); - private double leftVoltage = 0.0; - private double rightVoltage = 0.0; - public IntakeRollerSubsystem() { leftIntakeRoller = new TalonFX(Constants.Intaker.leftIntakeRollerID); rightIntakeRoller = new TalonFX(Constants.Intaker.rightIntakeRollerID); @@ -36,30 +33,19 @@ public class IntakeRollerSubsystem extends SubsystemBase { } public void intake() { - setVoltage(Constants.Intaker.intakeRollerVoltage, -Constants.Intaker.intakeRollerVoltage); + setVoltage(Constants.Intaker.intakeRollerVoltage); } public void outtake() { - setVoltage(Constants.Intaker.outtakeRollerVoltage, -Constants.Intaker.outtakeRollerVoltage); - } - - public void hold() { - setVoltage(Constants.Intaker.holdRollerVoltage, -Constants.Intaker.holdRollerVoltage); + setVoltage(Constants.Intaker.outtakeRollerVoltage); } public void stop() { - setVoltage(0.0, 0.0); + setVoltage(0); } - public void setPercent(double left, double right) { - setVoltage(left * 12.0, right * 12.0); - } - - public void setVoltage(double left, double right) { - // rightVoltage 仅用于 dashboard 显示;真实硬件通过反向 follower 跟随左侧电机。 - leftVoltage = MathUtil.clamp(left, -12.0, 12.0); - rightVoltage = MathUtil.clamp(right, -12.0, 12.0); - leftIntakeRoller.setControl(voltageRequest.withOutput(leftVoltage)); + public void setVoltage(double left) { + leftIntakeRoller.setControl(voltageRequest.withOutput(left)); followLeft(); } @@ -67,11 +53,16 @@ public class IntakeRollerSubsystem extends SubsystemBase { rightIntakeRoller.setControl(rightFollower); } + private double getVelocityDifference() { + double leftVelocity = leftIntakeRoller.getVelocity().getValueAsDouble(); + double rightVelocity = rightIntakeRoller.getVelocity().getValueAsDouble(); + return Math.abs(leftVelocity) - Math.abs(rightVelocity); + } + @Override public void periodic() { - table.getEntry("leftVoltage").setDouble(leftVoltage); - table.getEntry("rightVoltage").setDouble(rightVoltage); table.getEntry("leftVelocity").setDouble(leftIntakeRoller.getVelocity().getValueAsDouble()); table.getEntry("rightVelocity").setDouble(rightIntakeRoller.getVelocity().getValueAsDouble()); + table.getEntry("velocityDifference").setDouble(getVelocityDifference()); } } diff --git a/src/main/java/frc/robot/subsystems/Superstructure.java b/src/main/java/frc/robot/subsystems/Superstructure.java index 520a2df..17279da 100644 --- a/src/main/java/frc/robot/subsystems/Superstructure.java +++ b/src/main/java/frc/robot/subsystems/Superstructure.java @@ -179,7 +179,7 @@ public class Superstructure extends SubsystemBase { private void handleIdle() { // 安全默认状态:传球不动,intake 收回,背板保持受控。 - conveyor.hold(); + conveyor.stop(); intakeRoller.stop(); intakeRotater.stop(); shooter.stopFlywheel(); @@ -224,8 +224,8 @@ public class Superstructure extends SubsystemBase { } intakeRotater.moveToHandoff(); - intakeRoller.hold(); - conveyor.hold(); + intakeRoller.stop(); + conveyor.stop(); shooter.stopShooterConveyor(); // 距离到射速的映射由 LimelightSubsystem 提供;操作员 offset 用于现场微调, // 但不会绕过 Superstructure 状态机。