From 76064029804cc8986d95e3ed7a17ed31bd12f603 Mon Sep 17 00:00:00 2001 From: OnDYCLaptop Date: Tue, 3 Mar 2026 14:18:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0intaker=E9=87=8D=E5=8A=9B?= =?UTF-8?q?=E5=89=8D=E9=A6=88=EF=BC=88=E6=9C=AA=E5=90=AF=E7=94=A8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/frc/robot/Constants.java | 1 + src/main/java/frc/robot/RobotContainer.java | 1 + .../java/frc/robot/controls/IntakerControls.java | 2 +- .../frc/robot/subsystems/IntakerSubsystem.java | 15 +++++++++++++-- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/frc/robot/Constants.java b/src/main/java/frc/robot/Constants.java index c6bfa7c..7ec47e8 100644 --- a/src/main/java/frc/robot/Constants.java +++ b/src/main/java/frc/robot/Constants.java @@ -99,6 +99,7 @@ public final class Constants { public static final double intakeRotaterUpLimit = 0.0; // rotator上限角度 public static final double intakeRotaterDownLimit = 0.0; // rotator下限角度 public static final double intakeRotaterVelocity = 10; // rotater的速度(如果你用速度控制的话) + public static final double IntakeRotaterGravityFF = 0.0; // 重力前馈增益(需要实测调整) public static final Slot0Configs intakeGetterSlot0Configs = new Slot0Configs() .withKP(0.00).withKI(0.00).withKD(0.00) diff --git a/src/main/java/frc/robot/RobotContainer.java b/src/main/java/frc/robot/RobotContainer.java index 76057f1..3054905 100644 --- a/src/main/java/frc/robot/RobotContainer.java +++ b/src/main/java/frc/robot/RobotContainer.java @@ -77,6 +77,7 @@ public class RobotContainer { configueShooter(); configueClimber(); bingdingLED(); + configueIntaker(); } /* ====================== */ diff --git a/src/main/java/frc/robot/controls/IntakerControls.java b/src/main/java/frc/robot/controls/IntakerControls.java index 32c29ec..4b13fcc 100644 --- a/src/main/java/frc/robot/controls/IntakerControls.java +++ b/src/main/java/frc/robot/controls/IntakerControls.java @@ -13,7 +13,7 @@ public class IntakerControls { private final IntakerSubsystem IntakerSubsystem; private final CommandXboxController controller; - private static final double ROTATER_STEP_PER_CYCLE = 0.00; + //private static final double ROTATER_STEP_PER_CYCLE = 0.00; public IntakerControls(IntakerSubsystem Intaker, CommandXboxController controller) { this.IntakerSubsystem = Intaker; diff --git a/src/main/java/frc/robot/subsystems/IntakerSubsystem.java b/src/main/java/frc/robot/subsystems/IntakerSubsystem.java index 644e14c..50259f4 100644 --- a/src/main/java/frc/robot/subsystems/IntakerSubsystem.java +++ b/src/main/java/frc/robot/subsystems/IntakerSubsystem.java @@ -4,6 +4,7 @@ import com.ctre.phoenix6.controls.PositionVoltage; import com.ctre.phoenix6.controls.VelocityVoltage; import com.ctre.phoenix6.hardware.TalonFX; + import edu.wpi.first.wpilibj2.command.SubsystemBase; import frc.robot.Constants; @@ -18,12 +19,23 @@ public class IntakerSubsystem extends SubsystemBase{ private double intakeRotaterTargetPosition = 0.0; + public double getGravityFFVolts(){ + double intakerotaterPosition = getIntakerotaterPosition(); + double gravityFFVolts = Constants.Intaker.IntakeRotaterGravityFF * intakerotaterPosition; + return gravityFFVolts; + } + + public void setIntakerRotaterVelocityRps(double IntakeRotaterTargetVelocity) { + double gravityFeedforward = getGravityFFVolts(); + intakerotater.setControl(velocityRequest.withVelocity(IntakeRotaterTargetVelocity).withFeedForward(gravityFeedforward));// 重力前馈); + } + public IntakerSubsystem() { //初始化rotater&getter intakegetter = new TalonFX(47); intakerotater = new TalonFX(48); intakegetter.getConfigurator().apply(Constants.Intaker.intakeGetterSlot0Configs); - intakerotater.getConfigurator().apply(Constants.Intaker.intakeRotaterSlot0Configs); + intakerotater.getConfigurator().apply(Constants.Intaker.intakeRotaterSlot0Configs); } public void setIntakerRotaterPosition(double targetPosition) { @@ -35,7 +47,6 @@ public class IntakerSubsystem extends SubsystemBase{ } intakeRotaterTargetPosition = targetPosition; - intakerotater.setControl(positionRequest.withPosition(targetPosition)); // 设置rotater位置(TalonFX 内部闭环 PID) }