This commit is contained in:
OnDYCLaptop
2026-07-10 11:35:22 +08:00
parent 915b1b1af0
commit 6abdf34cf0
8 changed files with 38 additions and 1766 deletions
-116
View File
@@ -100,23 +100,6 @@
"false_icon": "None"
}
},
{
"title": "Shooter At Voltage",
"x": 192.0,
"y": 128.0,
"width": 192.0,
"height": 128.0,
"type": "Boolean Box",
"properties": {
"topic": "/Superstructure/shooterAtVoltage",
"period": 0.06,
"data_type": "boolean",
"true_color": 4283215696,
"false_color": 4294198070,
"true_icon": "None",
"false_icon": "None"
}
},
{
"title": "Drive Aimed",
"x": 384.0,
@@ -292,37 +275,6 @@
"line_width": 2.0
}
},
{
"title": "Flywheel Target Voltage",
"x": 384.0,
"y": 0.0,
"width": 256.0,
"height": 128.0,
"type": "Text Display",
"properties": {
"topic": "/Shooter/flywheelTargetVoltage",
"period": 0.06,
"data_type": "double",
"show_submit_button": false
}
},
{
"title": "Flywheel At Voltage",
"x": 640.0,
"y": 0.0,
"width": 256.0,
"height": 128.0,
"type": "Boolean Box",
"properties": {
"topic": "/Shooter/flywheelAtVoltage",
"period": 0.06,
"data_type": "boolean",
"true_color": 4283215696,
"false_color": 4294198070,
"true_icon": "None",
"false_icon": "None"
}
},
{
"title": "Flywheel Velocity Difference",
"x": 384.0,
@@ -1058,33 +1010,6 @@
"data_type": "boolean"
}
},
{
"title": "Flywheel Run",
"x": 128.0,
"y": 192.0,
"width": 128.0,
"height": 128.0,
"type": "Toggle Switch",
"properties": {
"topic": "/Tuning/flywheel/flywheelEnableRunning",
"period": 0.06,
"data_type": "boolean"
}
},
{
"title": "Flywheel Run Volts",
"x": 256.0,
"y": 192.0,
"width": 256.0,
"height": 128.0,
"type": "Text Display",
"properties": {
"topic": "/Tuning/flywheel/flywheelRunningVolts",
"period": 0.06,
"data_type": "double",
"show_submit_button": true
}
},
{
"title": "Shooter Conv Enable",
"x": 0.0,
@@ -1098,33 +1023,6 @@
"data_type": "boolean"
}
},
{
"title": "Shooter Conv Run",
"x": 128.0,
"y": 384.0,
"width": 128.0,
"height": 128.0,
"type": "Toggle Switch",
"properties": {
"topic": "/Tuning/conveyor/conveyorEnableRunning",
"period": 0.06,
"data_type": "boolean"
}
},
{
"title": "Shooter Conv Run Volts",
"x": 256.0,
"y": 384.0,
"width": 256.0,
"height": 128.0,
"type": "Text Display",
"properties": {
"topic": "/Tuning/conveyor/conveyorRunningVolts",
"period": 0.06,
"data_type": "double",
"show_submit_button": true
}
},
{
"title": "Backboard Enable",
"x": 0.0,
@@ -2689,20 +2587,6 @@
"line_width": 2.0
}
},
{
"title": "Target Volts Estimate",
"x": 0.0,
"y": 1024.0,
"width": 256.0,
"height": 128.0,
"type": "Text Display",
"properties": {
"topic": "/Shooter/flywheelTargetVoltage",
"period": 0.06,
"data_type": "double",
"show_submit_button": false
}
},
{
"title": "Left Output Volts",
"x": 256.0,
-1582
View File
File diff suppressed because it is too large Load Diff
+7 -16
View File
@@ -11,7 +11,7 @@ public final class Constants {
public static final boolean LEDUsing = false;
public static class Shooter {
// 机构 CAN ID 目前是占位值;季后赛最终接线确认后,只需要改这里。
// Placeholder mechanism CAN IDs; update here after final wiring.
public static final int leftFlywheelID = 38;
public static final int rightFlywheelID = 39;
public static final int leftConveyorID = 40;
@@ -26,16 +26,7 @@ public final class Constants {
public static final double flywheelReadyVelocityTolerance = 2.0;
public static final double flywheelReadyDelaySeconds = 0.5;
// 距离(米) -> 飞轮电压(V) 射表。当前为占位点;
// 真车试射后按实测数据加点即可,查表自动线性插值并在两端取边界值。
public static final InterpolatingDoubleTreeMap flywheelVoltageByDistance = new InterpolatingDoubleTreeMap();
static {
flywheelVoltageByDistance.put(1.2, 2.0);
flywheelVoltageByDistance.put(2.5, 2.1);
flywheelVoltageByDistance.put(3.5, 2.2);
flywheelVoltageByDistance.put(5.0, 2.3);
}
// Distance (meters) -> flywheel velocity (rotations per second).
public static final InterpolatingDoubleTreeMap flywheelVelocityByDistance = new InterpolatingDoubleTreeMap();
static {
flywheelVelocityByDistance.put(1.2, 2.0 / flywheelNominalKv);
@@ -140,7 +131,7 @@ public final class Constants {
}
public static class Intaker {
// 进球机构 CAN ID 同样是占位值,真实 ID 确认后集中在这里修改。
// Placeholder intake CAN IDs; update here after wiring is confirmed.
public static final int leftIntakeRollerID = 20;
public static final int rightIntakeRollerID = 47;
public static final int leftIntakeRotaterID = 48;
@@ -162,7 +153,7 @@ public final class Constants {
.withKV(0.00).withKA(0.00).withKS(0.00);
public static final double IntakeGetterSpeedforAuto = 0.5;
// 这里给出可用的占位值,真车调好位置闭环后再收紧。
// Placeholder values; tighten after the real mechanism is tuned.
}
public static class Conveyor {
@@ -176,7 +167,7 @@ public final class Constants {
}
public static class Superstructure {
// 状态机时间和门控容差。真车基础动作验证后,需要现场调这些值。
// State-machine timing and gate tolerances; tune on the real robot.
public static final double shooterFeedVoltage = Shooter.shooterConveyorFeedVoltage;
public static final double shooterReverseVoltage = Shooter.shooterConveyorReverseVoltage;
public static final double shooterFeedVelocity = Shooter.shooterConveyorFeedVelocity;
@@ -188,10 +179,10 @@ public final class Constants {
public static final double passBallFlywheelVelocity = Shooter.defaultFlywheelVelocity;
public static final double passBallBackboardPosition = 175.0;
// 射击时背板的目标位置(外接编码器计数)。
// Shoot backboard target position in external encoder counts.
public static final double backboardShootPosition = 175.0;
public static final double backboardReadyPositionTolerance = 100.0;
// 射击门控是否要求底盘接近静止。
// Whether the shooting gate requires the drivetrain to be nearly still.
public static final boolean stationaryGateEnabled = true;
}
}
+2 -2
View File
@@ -77,9 +77,9 @@ public class RobotContainer {
private final DriveGainsTuner driveGainsTuner = new DriveGainsTuner(drivetrain);
private final GameData2026 gameData2026 = new GameData2026();
private ConfigTalonFXMotorTuner configFlywheelTuner =
new ConfigTalonFXMotorTuner(shooterSubsystem.leftFlywheel, "flywheel", Constants.Shooter.flyWheelSlot0Configs);
new ConfigTalonFXMotorTuner(shooterSubsystem.leftFlywheel, "flywheel", Constants.Shooter.flyWheelSlot0Configs, false);
private ConfigTalonFXMotorTuner configConveyorTuner =
new ConfigTalonFXMotorTuner(shooterSubsystem.leftConveyor, "conveyor", Constants.Shooter.conveyorSlot0Configs);
new ConfigTalonFXMotorTuner(shooterSubsystem.leftConveyor, "conveyor", Constants.Shooter.conveyorSlot0Configs, false);
private ConfigTalonFXSMotorTuner configBackboardTuner =
new ConfigTalonFXSMotorTuner(shooterSubsystem.backboardMotor, "backboard", Constants.Shooter.backboardSlot0Configs);
private ConfigTalonFXMotorTuner configMainConveyorTuner =
@@ -6,10 +6,10 @@ import edu.wpi.first.wpilibj2.command.SubsystemBase;
import frc.robot.Constants;
/**
* 对现有 LimelightHelpers 的薄只读封装。
* Thin read-only wrapper around the existing LimelightHelpers.
*
* 本类不做视觉融合,也不控制任何机构;只给 Superstructure 提供稳定的
* 目标和距离读取接口。
* This subsystem does not fuse vision or command mechanisms; it only gives
* Superstructure stable target and distance read APIs.
*/
public class LimelightSubsystem extends SubsystemBase {
private final String limelightName;
@@ -35,8 +35,8 @@ public class LimelightSubsystem extends SubsystemBase {
}
public double getDistanceToTarget() {
// DriveControls 已经把基于场地位姿计算的距离发布到 AutoControl;
// 这里复用该值,保留旧定位和目标计算逻辑。
// DriveControls publishes the field-pose distance under AutoControl.
// Reuse that value to preserve the existing target calculation path.
return NetworkTableInstance.getDefault()
.getTable("AutoControl")
.getEntry("distanceToHub")
@@ -47,11 +47,6 @@ public class LimelightSubsystem extends SubsystemBase {
return LimelightHelpers.getBotPoseEstimate_wpiBlue_MegaTag2(limelightName).pose;
}
public double getShooterVoltageByDistance() {
// 查 Constants 里的插值射表;真车试射后往表里加实测点即可。
return Constants.Shooter.flywheelVoltageByDistance.get(getDistanceToTarget());
}
public double getShooterVelocityByDistance() {
return Constants.Shooter.flywheelVelocityByDistance.get(getDistanceToTarget());
}
@@ -136,11 +136,6 @@ public class ShooterSubsystem extends SubsystemBase {
rightFlywheel.getConfigurator().apply(configs);
}
public void setFlywheelVoltage(double outputVolts) {
double clampedOutputVolts = MathUtil.clamp(outputVolts, -12.0, 12.0);
setFlywheelVelocity(clampedOutputVolts / Constants.Shooter.flywheelNominalKv);
}
public void setFlywheelVelocity(double targetVelocityRps) {
double clampedTargetVelocity = MathUtil.clamp(
targetVelocityRps,
@@ -155,15 +150,6 @@ public class ShooterSubsystem extends SubsystemBase {
setRightFlywheelFollowLeft();
}
public void setFlywheelVoltageByDistance(double distance) {
setFlywheelVelocityByDistance(distance);
}
public void setFlywheelVelocityByDistance(double distance) {
double targetVelocity = Constants.Shooter.flywheelVelocityByDistance.get(distance);
setFlywheelVelocity(targetVelocity);
}
public void stopFlywheel() {
setFlywheelVelocity(0.0);
}
@@ -181,9 +167,6 @@ public class ShooterSubsystem extends SubsystemBase {
>= Constants.Shooter.flywheelReadyDelaySeconds;
}
public boolean atVoltage() {
return atVelocity();
}
public double getLeftFlywheelVelocity() {
return leftFlywheel.getVelocity().getValueAsDouble();
}
@@ -208,10 +191,6 @@ public class ShooterSubsystem extends SubsystemBase {
return Math.abs(flywheelTargetVelocity) - getAverageFlywheelVelocity();
}
public double getTargetFlywheelVoltage() {
return flywheelTargetVelocity * Constants.Shooter.flywheelNominalKv;
}
/* ====================== */
/* shooter conveyor */
/* ====================== */
@@ -226,11 +205,6 @@ public class ShooterSubsystem extends SubsystemBase {
setRightConveyorFollowLeft();
}
public void runShooterConveyorVoltage(double outputVolts) {
double clampedOutputVolts = MathUtil.clamp(outputVolts, -12.0, 12.0);
runShooterConveyorVelocity(clampedOutputVolts / Constants.Shooter.shooterConveyorNominalKv);
}
public void stopShooterConveyor() {
runShooterConveyorVelocity(0.0);
}
@@ -369,17 +343,13 @@ public class ShooterSubsystem extends SubsystemBase {
}
public boolean isFlywheelTuningControlActive() {
boolean voltageTunerEnabled = flywheelTuningTable.getEntry("flywheelEnable").getBoolean(false);
boolean voltageTunerRunning = flywheelTuningTable.getEntry("flywheelEnableRunning").getBoolean(false);
boolean velocityTunerEnabled = flywheelTuningTable.getEntry("flywheelVelocityEnable").getBoolean(false);
return (voltageTunerEnabled && voltageTunerRunning) || velocityTunerEnabled;
return velocityTunerEnabled;
}
public boolean isShooterConveyorTuningControlActive() {
boolean voltageTunerEnabled = conveyorTuningTable.getEntry("conveyorEnable").getBoolean(false);
boolean voltageTunerRunning = conveyorTuningTable.getEntry("conveyorEnableRunning").getBoolean(false);
boolean velocityTunerEnabled = conveyorTuningTable.getEntry("conveyorVelocityEnable").getBoolean(false);
return (voltageTunerEnabled && voltageTunerRunning) || velocityTunerEnabled;
return velocityTunerEnabled;
}
public void resetbackboardencoder() {
@@ -490,9 +460,7 @@ public class ShooterSubsystem extends SubsystemBase {
shooterNetworkTable.getEntry("flywheelAtVelocity").setBoolean(atVelocity());
shooterNetworkTable.getEntry("flywheelVelocityTuningActive").setBoolean(flywheelVelocityTuningActive);
shooterNetworkTable.getEntry("flywheelFollowerOpposed").setBoolean(true);
shooterNetworkTable.getEntry("flywheelTargetVoltage").setDouble(getTargetFlywheelVoltage());
shooterNetworkTable.getEntry("flywheelOutputVolts").setDouble(flywheelOutputVolts);
shooterNetworkTable.getEntry("flywheelAtVoltage").setBoolean(atVoltage());
shooterNetworkTable.getEntry("leftFlywheelOutputVolts").setDouble(leftFlywheel.getMotorVoltage().getValueAsDouble());
shooterNetworkTable.getEntry("rightFlywheelOutputVolts").setDouble(rightFlywheel.getMotorVoltage().getValueAsDouble());
shooterNetworkTable.getEntry("leftFlywheelStatorCurrent").setDouble(leftFlywheel.getStatorCurrent().getValueAsDouble());
@@ -396,7 +396,6 @@ public class Superstructure extends SubsystemBase {
table.getEntry("timeInState").setDouble(timeInState());
table.getEntry("canShoot").setBoolean(canShoot());
table.getEntry("shooterAtVelocity").setBoolean(shooter.atVelocity());
table.getEntry("shooterAtVoltage").setBoolean(shooter.atVoltage());
table.getEntry("driveAimed").setBoolean(drive.isAimed());
table.getEntry("driveHeadingError").setDouble(drive.getHeadingError());
table.getEntry("driveStationary").setBoolean(isDriveStationary());
@@ -10,6 +10,7 @@ public class ConfigTalonFXMotorTuner {
private final String motorName;
private final Slot0Configs motorSlot0Configs;
private final NetworkTable table;
private final boolean voltageRunEnabled;
// ---- Subscribers:读取 Elastic 改过的新值 ----
private final BooleanSubscriber enableSub;
@@ -27,9 +28,19 @@ public class ConfigTalonFXMotorTuner {
private final VoltageOut voltageRequest = new VoltageOut(0);
public ConfigTalonFXMotorTuner(TalonFX motor_, String motorName_, Slot0Configs motorSlot0Configs_) {
this(motor_, motorName_, motorSlot0Configs_, true);
}
public ConfigTalonFXMotorTuner(
TalonFX motor_,
String motorName_,
Slot0Configs motorSlot0Configs_,
boolean voltageRunEnabled_
) {
this.motor = motor_;
this.motorName = motorName_;
this.motorSlot0Configs = motorSlot0Configs_;
this.voltageRunEnabled = voltageRunEnabled_;
this.table = NetworkTableInstance.getDefault().getTable("Tuning/" + motorName);
@@ -41,8 +52,10 @@ public class ConfigTalonFXMotorTuner {
table.getDoubleTopic(motorName+"kA").publish().set(motorSlot0Configs.kA);
table.getDoubleTopic(motorName+"kS").publish().set(motorSlot0Configs.kS);
table.getBooleanTopic(motorName+"EnableRunning").publish().set(false);;
table.getDoubleTopic(motorName+"RunningVolts").publish().set(0);;
if (voltageRunEnabled) {
table.getBooleanTopic(motorName+"EnableRunning").publish().set(false);;
table.getDoubleTopic(motorName+"RunningVolts").publish().set(0);;
}
this.enableSub = table.getBooleanTopic(motorName+"Enable").subscribe(false);
this.KpSub = table.getDoubleTopic(motorName+"kP").subscribe(motorSlot0Configs.kP);
@@ -51,8 +64,12 @@ public class ConfigTalonFXMotorTuner {
this.KvSub = table.getDoubleTopic(motorName+"kV").subscribe(motorSlot0Configs.kV);
this.KaSub = table.getDoubleTopic(motorName+"kA").subscribe(motorSlot0Configs.kA);
this.KsSub = table.getDoubleTopic(motorName+"kS").subscribe(motorSlot0Configs.kS);
this.enableRuningSub = table.getBooleanTopic(motorName+"EnableRunning").subscribe(false);
this.runningVolts = table.getDoubleTopic(motorName+"RunningVolts").subscribe(0);
this.enableRuningSub = voltageRunEnabled
? table.getBooleanTopic(motorName+"EnableRunning").subscribe(false)
: null;
this.runningVolts = voltageRunEnabled
? table.getDoubleTopic(motorName+"RunningVolts").subscribe(0)
: null;
}
public void periodic(Runnable func) {
@@ -79,7 +96,7 @@ public class ConfigTalonFXMotorTuner {
}
}
if (enableRuningSub.get()) {;
if (voltageRunEnabled && enableRuningSub.get()) {;
double volts = MathUtil.clamp(runningVolts.get(), -12.0, 12.0);
motor.setControl(voltageRequest.withOutput(volts));
wasRunning = true;