小改
This commit is contained in:
@@ -150,7 +150,6 @@ public final class Constants {
|
|||||||
public static final int mainConveyorID = 50;
|
public static final int mainConveyorID = 50;
|
||||||
public static final double feedVoltage = 6.0;
|
public static final double feedVoltage = 6.0;
|
||||||
public static final double reverseVoltage = -5.0;
|
public static final double reverseVoltage = -5.0;
|
||||||
public static final double holdVoltage = 0.8;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Superstructure {
|
public static class Superstructure {
|
||||||
|
|||||||
@@ -17,44 +17,27 @@ import frc.robot.Constants;
|
|||||||
*/
|
*/
|
||||||
public class ConveyorSubsystem extends SubsystemBase {
|
public class ConveyorSubsystem extends SubsystemBase {
|
||||||
public final TalonFX mainConveyor;
|
public final TalonFX mainConveyor;
|
||||||
|
|
||||||
private final VoltageOut voltageRequest = new VoltageOut(0);
|
private final VoltageOut voltageRequest = new VoltageOut(0);
|
||||||
private final NetworkTable table = NetworkTableInstance.getDefault().getTable("Conveyor");
|
private final NetworkTable table = NetworkTableInstance.getDefault().getTable("Conveyor");
|
||||||
|
|
||||||
private double voltage = 0.0;
|
|
||||||
|
|
||||||
public ConveyorSubsystem() {
|
public ConveyorSubsystem() {
|
||||||
mainConveyor = new TalonFX(Constants.Conveyor.mainConveyorID);
|
mainConveyor = new TalonFX(Constants.Conveyor.mainConveyorID);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void feedToShooter() {
|
public void feedToShooter() {
|
||||||
setVoltage(Constants.Conveyor.feedVoltage);
|
setVoltage(Constants.Conveyor.feedVoltage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reverse() {
|
public void reverse() {
|
||||||
setVoltage(Constants.Conveyor.reverseVoltage);
|
setVoltage(Constants.Conveyor.reverseVoltage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void hold() {
|
|
||||||
setVoltage(Constants.Conveyor.holdVoltage);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
setVoltage(0.0);
|
setVoltage(0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPercent(double percent) {
|
|
||||||
setVoltage(percent * 12.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVoltage(double volts) {
|
public void setVoltage(double volts) {
|
||||||
voltage = MathUtil.clamp(volts, -12.0, 12.0);
|
mainConveyor.setControl(voltageRequest.withOutput(volts));
|
||||||
mainConveyor.setControl(voltageRequest.withOutput(voltage));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void periodic() {
|
public void periodic() {
|
||||||
table.getEntry("voltage").setDouble(voltage);
|
|
||||||
table.getEntry("velocity").setDouble(mainConveyor.getVelocity().getValueAsDouble());
|
table.getEntry("velocity").setDouble(mainConveyor.getVelocity().getValueAsDouble());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,16 +18,13 @@ import frc.robot.Constants;
|
|||||||
* 本类只负责成对 TalonFX 输出和 follower 关系。
|
* 本类只负责成对 TalonFX 输出和 follower 关系。
|
||||||
*/
|
*/
|
||||||
public class IntakeRollerSubsystem extends SubsystemBase {
|
public class IntakeRollerSubsystem extends SubsystemBase {
|
||||||
public final TalonFX leftIntakeRoller;
|
private final TalonFX leftIntakeRoller;
|
||||||
public final TalonFX rightIntakeRoller;
|
private final TalonFX rightIntakeRoller;
|
||||||
|
|
||||||
private final VoltageOut voltageRequest = new VoltageOut(0);
|
private final VoltageOut voltageRequest = new VoltageOut(0);
|
||||||
private final Follower rightFollower;
|
private final Follower rightFollower;
|
||||||
private final NetworkTable table = NetworkTableInstance.getDefault().getTable("IntakeRoller");
|
private final NetworkTable table = NetworkTableInstance.getDefault().getTable("IntakeRoller");
|
||||||
|
|
||||||
private double leftVoltage = 0.0;
|
|
||||||
private double rightVoltage = 0.0;
|
|
||||||
|
|
||||||
public IntakeRollerSubsystem() {
|
public IntakeRollerSubsystem() {
|
||||||
leftIntakeRoller = new TalonFX(Constants.Intaker.leftIntakeRollerID);
|
leftIntakeRoller = new TalonFX(Constants.Intaker.leftIntakeRollerID);
|
||||||
rightIntakeRoller = new TalonFX(Constants.Intaker.rightIntakeRollerID);
|
rightIntakeRoller = new TalonFX(Constants.Intaker.rightIntakeRollerID);
|
||||||
@@ -36,30 +33,19 @@ public class IntakeRollerSubsystem extends SubsystemBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void intake() {
|
public void intake() {
|
||||||
setVoltage(Constants.Intaker.intakeRollerVoltage, -Constants.Intaker.intakeRollerVoltage);
|
setVoltage(Constants.Intaker.intakeRollerVoltage);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void outtake() {
|
public void outtake() {
|
||||||
setVoltage(Constants.Intaker.outtakeRollerVoltage, -Constants.Intaker.outtakeRollerVoltage);
|
setVoltage(Constants.Intaker.outtakeRollerVoltage);
|
||||||
}
|
|
||||||
|
|
||||||
public void hold() {
|
|
||||||
setVoltage(Constants.Intaker.holdRollerVoltage, -Constants.Intaker.holdRollerVoltage);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stop() {
|
public void stop() {
|
||||||
setVoltage(0.0, 0.0);
|
setVoltage(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPercent(double left, double right) {
|
public void setVoltage(double left) {
|
||||||
setVoltage(left * 12.0, right * 12.0);
|
leftIntakeRoller.setControl(voltageRequest.withOutput(left));
|
||||||
}
|
|
||||||
|
|
||||||
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));
|
|
||||||
followLeft();
|
followLeft();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,11 +53,16 @@ public class IntakeRollerSubsystem extends SubsystemBase {
|
|||||||
rightIntakeRoller.setControl(rightFollower);
|
rightIntakeRoller.setControl(rightFollower);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private double getVelocityDifference() {
|
||||||
|
double leftVelocity = leftIntakeRoller.getVelocity().getValueAsDouble();
|
||||||
|
double rightVelocity = rightIntakeRoller.getVelocity().getValueAsDouble();
|
||||||
|
return Math.abs(leftVelocity) - Math.abs(rightVelocity);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void periodic() {
|
public void periodic() {
|
||||||
table.getEntry("leftVoltage").setDouble(leftVoltage);
|
|
||||||
table.getEntry("rightVoltage").setDouble(rightVoltage);
|
|
||||||
table.getEntry("leftVelocity").setDouble(leftIntakeRoller.getVelocity().getValueAsDouble());
|
table.getEntry("leftVelocity").setDouble(leftIntakeRoller.getVelocity().getValueAsDouble());
|
||||||
table.getEntry("rightVelocity").setDouble(rightIntakeRoller.getVelocity().getValueAsDouble());
|
table.getEntry("rightVelocity").setDouble(rightIntakeRoller.getVelocity().getValueAsDouble());
|
||||||
|
table.getEntry("velocityDifference").setDouble(getVelocityDifference());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ public class Superstructure extends SubsystemBase {
|
|||||||
|
|
||||||
private void handleIdle() {
|
private void handleIdle() {
|
||||||
// 安全默认状态:传球不动,intake 收回,背板保持受控。
|
// 安全默认状态:传球不动,intake 收回,背板保持受控。
|
||||||
conveyor.hold();
|
conveyor.stop();
|
||||||
intakeRoller.stop();
|
intakeRoller.stop();
|
||||||
intakeRotater.stop();
|
intakeRotater.stop();
|
||||||
shooter.stopFlywheel();
|
shooter.stopFlywheel();
|
||||||
@@ -224,8 +224,8 @@ public class Superstructure extends SubsystemBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
intakeRotater.moveToHandoff();
|
intakeRotater.moveToHandoff();
|
||||||
intakeRoller.hold();
|
intakeRoller.stop();
|
||||||
conveyor.hold();
|
conveyor.stop();
|
||||||
shooter.stopShooterConveyor();
|
shooter.stopShooterConveyor();
|
||||||
// 距离到射速的映射由 LimelightSubsystem 提供;操作员 offset 用于现场微调,
|
// 距离到射速的映射由 LimelightSubsystem 提供;操作员 offset 用于现场微调,
|
||||||
// 但不会绕过 Superstructure 状态机。
|
// 但不会绕过 Superstructure 状态机。
|
||||||
|
|||||||
Reference in New Issue
Block a user