Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0434c2c
Make feeding use SOTM
SCool62 Mar 1, 2026
cb5d0ea
reorder auto aim stuff for clarity
vivi-o Mar 2, 2026
7c2638f
make score actually use sotm?
vivi-o Mar 2, 2026
4359bf9
get sotm data based on turret pose not the entire robot
vivi-o Mar 2, 2026
de2a702
iterate sotm so its more accurate
vivi-o Mar 2, 2026
5c59a2b
use existing virtual target method
vivi-o Mar 2, 2026
a86e100
get turret pose
vivi-o Mar 2, 2026
20920c7
revert because that iteration wouldn't help
vivi-o Mar 2, 2026
691fe0e
trying newtons method
vivi-o Mar 2, 2026
995766f
nvm velocity should already be accounted for
vivi-o Mar 2, 2026
e853f27
implement newtons method with correct required velocity
vivi-o Mar 5, 2026
f772b89
update comments
vivi-o Mar 5, 2026
3d4074d
build to format
vivi-o Mar 5, 2026
b71c4f0
Merge branch 'main' into sotm-adjustment
vivi-o Mar 5, 2026
1579c0a
wtf (what the fuel)
spellingcat Mar 11, 2026
b05c5fe
Merge branch 'main' into exp/fuel-sim
spellingcat Mar 18, 2026
2439ad8
this isn't really working
spellingcat Mar 18, 2026
e246a59
i suspect there's some goofy fudge factor
spellingcat Mar 19, 2026
e47e06a
Merge branch 'main' into sotm-adjustment
spellingcat Mar 19, 2026
1ea1995
oh what the heck
spellingcat Mar 19, 2026
da1e424
Merge branch 'exp/fuel-sim' into sotm-adjustment
spellingcat Mar 19, 2026
f31db0c
Fix flowstate and remove latency
SCool62 Mar 20, 2026
89f8c51
Merge branch '3-19-sotm-testing' into sotm-adjustment
SCool62 Mar 20, 2026
d827cd9
Use newtons method where already implemented
SCool62 Mar 20, 2026
c4775ed
Moar iterations
SCool62 Mar 20, 2026
277fa5e
Remove velocity threshold condition in loop
SCool62 Mar 20, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 67 additions & 73 deletions src/main/deploy/choreo/OtoCR.traj

Large diffs are not rendered by default.

34 changes: 33 additions & 1 deletion src/main/java/frc/robot/Robot.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import frc.robot.utils.FieldUtils.ClimbTargets;
import frc.robot.utils.FieldUtils.FeedTargets;
import frc.robot.utils.FieldUtils.TrenchPoses;
import frc.robot.utils.FuelSim;
import frc.robot.utils.autoaim.AutoAim;
import java.io.File;
import java.util.Arrays;
Expand Down Expand Up @@ -207,6 +208,8 @@ public enum RobotEdition {
private final CANdleSubsystem candle =
new CANdleSubsystem(new CANdleIOReal(0, CANdleSubsystem.getCandleConfig(), canivore));

private FuelSim fuelSim = new FuelSim();

// climber only exists for the comp bot - this is accounted for later

private final Superstructure superstructure;
Expand Down Expand Up @@ -419,7 +422,8 @@ public Robot() {
: new CANcoderIOSim(5, TurretSubsystem.getCancoder24tConfigs(), canivore),
ROBOT_MODE == RobotMode.REAL
? new CANcoderIO(4, TurretSubsystem.getCancoder26tConfigs(), canivore)
: new CANcoderIOSim(4, TurretSubsystem.getCancoder26tConfigs(), canivore));
: new CANcoderIOSim(4, TurretSubsystem.getCancoder26tConfigs(), canivore),
fuelSim);
break;
}
climber =
Expand Down Expand Up @@ -588,6 +592,31 @@ public Robot() {
"Interrputing: "
+ (interrupting.isPresent() ? interrupting.get().getName() : "none"));
});

// fuelSim.spawnStartingFuel();

fuelSim.registerRobot(
Units.inchesToMeters(28), // from left to right in meters
Units.inchesToMeters(28), // from front to back in meters
Units.inchesToMeters(4), // from floor to top of bumpers in meters
swerve::getPose, // Supplier<Pose2d> of robot pose
swerve
::getVelocityFieldRelative); // Supplier<ChassisSpeeds> of field-centric chassis speeds

fuelSim.registerIntake(
Units.inchesToMeters(-14),
Units.inchesToMeters(14),
Units.inchesToMeters(14),
Units.inchesToMeters(20), // robot-centric coordinates for bounding box in meters
() ->
Superstructure.getState()
.isAnIntakeState() // (optional) BooleanSupplier for whether the intake should be
// active at a given moment
); // (optional) Runnable called whenever a fuel is intaked

fuelSim.setSubticks(5);

fuelSim.start();
}

/** Scales a joystick value for teleop driving */
Expand Down Expand Up @@ -697,6 +726,7 @@ private void addControllerBindings(Indexer indexer, Shooter shooter, Intake inta
// .and(
new Trigger(AutoAim::targetInTurretDeadzone)
.and(() -> Superstructure.getState().isAScoreState())
.and(() -> !Superstructure.getState().isAFlowState())
.and(() -> !Superstructure.getPoseOverride())
.and(() -> superstructure.inScoringArea())
.whileTrue(
Expand All @@ -713,6 +743,7 @@ private void addControllerBindings(Indexer indexer, Shooter shooter, Intake inta

new Trigger(AutoAim::targetInTurretDeadzone)
.and(() -> Superstructure.getState().isAFeedState())
.and(() -> !Superstructure.getState().isAFlowState())
.and(() -> !Superstructure.getPoseOverride())
.and(() -> !superstructure.inScoringArea())
.whileTrue(
Expand Down Expand Up @@ -919,6 +950,7 @@ public void simulationInit() {

@Override
public void simulationPeriodic() {
fuelSim.updateSim();
// Log zeroed poses for mechs and robot for debugging in sim
Logger.recordOutput(
"Robot/Zeroed Mechanism Poses",
Expand Down
60 changes: 43 additions & 17 deletions src/main/java/frc/robot/Superstructure.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,21 @@ public boolean isAScoreState() {
public boolean isAFeedState() {
return this == FEED || this == SPIN_UP_FEED || this == SPIN_UP_FEED_FLOW || this == FEED_FLOW;
}

public boolean isAnIntakeState() {
return this == INTAKE
|| this == SPIN_UP_FEED_FLOW
|| this == FEED_FLOW
|| this == SPIN_UP_SCORE_FLOW
|| this == SCORE_FLOW;
}

public boolean isAFlowState() {
return this == FEED_FLOW
|| this == SCORE_FLOW
|| this == SPIN_UP_FEED_FLOW
|| this == SPIN_UP_SCORE_FLOW;
}
}

public enum ShotTarget {
Expand Down Expand Up @@ -293,7 +308,8 @@ private void addTriggers() {
new Trigger(shooter::atFlywheelVelocitySetpoint)
// .debounce(0.05)
.and(new Trigger(shooter::atHoodSetpoint).debounce(0.05))
.and(new Trigger(shooter::atTurretSetpoint).debounce(0.05));
.and(new Trigger(shooter::atTurretSetpoint).debounce(0.05))
.and(new Trigger(AutoAim::targetInTurretDeadzone).negate());
}

private void addTransitions() {
Expand Down Expand Up @@ -325,6 +341,11 @@ private void addTransitions() {

bindTransition(SuperState.SPIN_UP_SCORE_FLOW, SuperState.SCORE_FLOW, readyTrigger);

bindTransition(
SuperState.SCORE_FLOW,
SuperState.SPIN_UP_SCORE_FLOW,
new Trigger(AutoAim::targetInTurretDeadzone));

bindTransition(
SuperState.SPIN_UP_SCORE_FLOW,
SuperState.IDLE,
Expand Down Expand Up @@ -360,6 +381,11 @@ private void addTransitions() {

bindTransition(SuperState.SPIN_UP_FEED_FLOW, SuperState.FEED_FLOW, readyTrigger);

bindTransition(
SuperState.FEED_FLOW,
SuperState.SPIN_UP_FEED_FLOW,
new Trigger(AutoAim::targetInTurretDeadzone));

bindTransition(
SuperState.SPIN_UP_FEED_FLOW, SuperState.IDLE, intakeReq.negate().and(shootReq.negate()));

Expand Down Expand Up @@ -455,7 +481,7 @@ private void addCommands() {
shooter.feed(
swerve::getPose,
() ->
AutoAim.getCompensatedSOTMShotData(
AutoAim.getSOTMShotDataNewtonsMethod(
shooter.getTurretPose(swerve.getPose()),
FeedTargets.getFeedTarget(feedTarget).getTranslation(),
swerve.getVelocityFieldRelative(),
Expand All @@ -469,7 +495,7 @@ private void addCommands() {
intake.agitate(),
indexer.kick(
() ->
AutoAim.getCompensatedSOTMShotData(
AutoAim.getSOTMShotDataNewtonsMethod(
shooter.getTurretPose(swerve.getPose()),
FeedTargets.getFeedTarget(feedTarget).getTranslation(),
swerve.getVelocityFieldRelative(),
Expand All @@ -478,7 +504,7 @@ private void addCommands() {
shooter.feed(
swerve::getPose,
() ->
AutoAim.getCompensatedSOTMShotData(
AutoAim.getSOTMShotDataNewtonsMethod(
shooter.getTurretPose(swerve.getPose()),
FeedTargets.getFeedTarget(feedTarget).getTranslation(),
swerve.getVelocityFieldRelative(),
Expand All @@ -494,7 +520,7 @@ private void addCommands() {
shooter.feed(
swerve::getPose,
() ->
AutoAim.getCompensatedSOTMShotData(
AutoAim.getSOTMShotDataNewtonsMethod(
shooter.getTurretPose(swerve.getPose()),
FeedTargets.getFeedTarget(feedTarget).getTranslation(),
swerve.getVelocityFieldRelative(),
Expand All @@ -508,7 +534,7 @@ private void addCommands() {
intake.intake(),
indexer.kick(
() ->
AutoAim.getCompensatedSOTMShotData(
AutoAim.getSOTMShotDataNewtonsMethod(
shooter.getTurretPose(swerve.getPose()),
FeedTargets.getFeedTarget(feedTarget).getTranslation(),
swerve.getVelocityFieldRelative(),
Expand All @@ -517,7 +543,7 @@ private void addCommands() {
shooter.feed(
swerve::getPose,
() ->
AutoAim.getCompensatedSOTMShotData(
AutoAim.getSOTMShotDataNewtonsMethod(
shooter.getTurretPose(swerve.getPose()),
FeedTargets.getFeedTarget(feedTarget).getTranslation(),
swerve.getVelocityFieldRelative(),
Expand All @@ -533,7 +559,7 @@ private void addCommands() {
shooter.score(
swerve::getPose,
() ->
AutoAim.getCompensatedSOTMShotData(
AutoAim.getSOTMShotDataNewtonsMethod(
shooter.getTurretPose(swerve.getPose()),
FieldUtils.getCurrentHubTranslation(),
swerve.getVelocityFieldRelative(),
Expand All @@ -549,7 +575,7 @@ private void addCommands() {
// intake.restExtended(),
indexer.kick(
() ->
AutoAim.getCompensatedSOTMShotData(
AutoAim.getSOTMShotDataNewtonsMethod(
shooter.getTurretPose(swerve.getPose()),
FieldUtils.getCurrentHubTranslation(),
swerve.getVelocityFieldRelative(),
Expand All @@ -560,7 +586,7 @@ private void addCommands() {
shooter.score(
swerve::getPose,
() ->
AutoAim.getCompensatedSOTMShotData(
AutoAim.getSOTMShotDataNewtonsMethod(
shooter.getTurretPose(swerve.getPose()),
FieldUtils.getCurrentHubTranslation(),
swerve.getVelocityFieldRelative(),
Expand All @@ -572,12 +598,12 @@ private void addCommands() {

bindCommands(
SuperState.SPIN_UP_SCORE_FLOW,
intake.restExtended(),
intake.intake(),
indexer.rest(),
shooter.score(
swerve::getPose,
() ->
AutoAim.getCompensatedSOTMShotData(
AutoAim.getSOTMShotDataNewtonsMethod(
shooter.getTurretPose(swerve.getPose()),
FieldUtils.getCurrentHubTranslation(),
swerve.getVelocityFieldRelative(),
Expand All @@ -592,7 +618,7 @@ private void addCommands() {
intake.intake(),
indexer.kick(
() ->
AutoAim.getCompensatedSOTMShotData(
AutoAim.getSOTMShotDataNewtonsMethod(
shooter.getTurretPose(swerve.getPose()),
FieldUtils.getCurrentHubTranslation(),
swerve.getVelocityFieldRelative(),
Expand All @@ -603,7 +629,7 @@ private void addCommands() {
shooter.score(
swerve::getPose,
() ->
AutoAim.getCompensatedSOTMShotData(
AutoAim.getSOTMShotDataNewtonsMethod(
shooter.getTurretPose(swerve.getPose()),
FieldUtils.getCurrentHubTranslation(),
swerve.getVelocityFieldRelative(),
Expand Down Expand Up @@ -653,7 +679,7 @@ private void addCommands() {
shooter.score(
swerve::getPose,
() ->
AutoAim.getCompensatedSOTMShotData(
AutoAim.getSOTMShotDataNewtonsMethod(
shooter.getTurretPose(swerve.getPose()),
FieldUtils.getCurrentHubTranslation(),
swerve.getVelocityFieldRelative(),
Expand All @@ -668,7 +694,7 @@ private void addCommands() {
intake.restRetracted(),
indexer.kick(
() ->
AutoAim.getCompensatedSOTMShotData(
AutoAim.getSOTMShotDataNewtonsMethod(
shooter.getTurretPose(swerve.getPose()),
FieldUtils.getCurrentHubTranslation(),
swerve.getVelocityFieldRelative(),
Expand All @@ -679,7 +705,7 @@ private void addCommands() {
shooter.score(
swerve::getPose,
() ->
AutoAim.getCompensatedSOTMShotData(
AutoAim.getSOTMShotDataNewtonsMethod(
shooter.getTurretPose(swerve.getPose()),
FieldUtils.getCurrentHubTranslation(),
swerve.getVelocityFieldRelative(),
Expand Down
41 changes: 39 additions & 2 deletions src/main/java/frc/robot/subsystems/shooter/TurretSubsystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

package frc.robot.subsystems.shooter;

import static edu.wpi.first.units.Units.Inches;
import static edu.wpi.first.units.Units.Meters;
import static edu.wpi.first.units.Units.MetersPerSecond;
import static edu.wpi.first.units.Units.RadiansPerSecond;
import static edu.wpi.first.units.Units.RotationsPerSecond;

import com.ctre.phoenix6.configs.CANcoderConfiguration;
import com.ctre.phoenix6.configs.TalonFXConfiguration;
import com.ctre.phoenix6.signals.GravityTypeValue;
Expand All @@ -17,15 +23,20 @@
import edu.wpi.first.math.geometry.Transform2d;
import edu.wpi.first.math.geometry.Translation2d;
import edu.wpi.first.math.kinematics.ChassisSpeeds;
import edu.wpi.first.units.measure.AngularVelocity;
import edu.wpi.first.units.measure.Distance;
import edu.wpi.first.units.measure.LinearVelocity;
import edu.wpi.first.wpilibj.Alert;
import edu.wpi.first.wpilibj.Alert.AlertType;
import edu.wpi.first.wpilibj2.command.Command;
import edu.wpi.first.wpilibj2.command.Commands;
import edu.wpi.first.wpilibj2.command.SubsystemBase;
import edu.wpi.first.wpilibj2.command.button.Trigger;
import frc.robot.Superstructure;
import frc.robot.components.cancoder.CANcoderIO;
import frc.robot.components.cancoder.CANcoderIOInputsAutoLogged;
import frc.robot.utils.FieldUtils;
import frc.robot.utils.FuelSim;
import frc.robot.utils.autoaim.AutoAim;
import frc.robot.utils.autoaim.InterpolatingShotTree.ShotData;
import java.util.function.BooleanSupplier;
Expand All @@ -46,7 +57,7 @@ public class TurretSubsystem extends SubsystemBase implements Shooter {
public static final double HOOD_CURRENT_ZERO_THRESHOLD = 30.0;
public static final double TURRET_CURRENT_ZERO_THRESHOLD = 30.0; // TODO find

public static final double FLYWHEEL_DIAMETER_INCHES = 4;
public static final double FLYWHEEL_DIAMETER_INCHES = 4.0;

public static final Rotation2d TURRET_LEFT_FIXED_SHOT_ANGLE = Rotation2d.kZero;
public static final Rotation2d TURRET_RIGHT_FIXED_SHOT_ANGLE = Rotation2d.kZero;
Expand Down Expand Up @@ -113,17 +124,21 @@ public class TurretSubsystem extends SubsystemBase implements Shooter {
"Turret may have gone past hardstop!! Reoffset cancoders + min/max position",
AlertType.kError);

private FuelSim fuelSim;

public TurretSubsystem(
FlywheelIO flywheelIO,
HoodIO hoodIO,
TurretIO turretIO,
CANcoderIO cancoder24t,
CANcoderIO cancoder26t) {
CANcoderIO cancoder26t,
FuelSim fuelSim) {
this.flywheelIO = flywheelIO;
this.hoodIO = hoodIO;
this.turretIO = turretIO;
this.cancoder24t = cancoder24t;
this.cancoder26t = cancoder26t;
this.fuelSim = fuelSim;

// assume we start up at min angle and not 0
hoodIO.resetEncoder(HOOD_MIN_ANGLE);
Expand Down Expand Up @@ -175,8 +190,30 @@ public void periodic() {
// && (getCalculatedTurretRotations().getDegrees()
// < TurretSubsystem.TURRET_REAR_HARDSTOP_ANGLE.getDegrees()));
// if (pastHardstop) turretPastHardstopAlert.set(pastHardstop); // sticky alert

if (Superstructure.getState().isAScoreState()) {
System.out.println("launching fuel");
fuelSim.launchFuel(
// there are few things i despise more than the units library\
// InchesPerSecond.of(
// flywheelIO.getSetpointRotPerSec() * FLYWHEEL_DIAMETER_INCHES * Math.PI),
// InchesPerSecond.of(200),
angularToLinearVelocity(
RotationsPerSecond.of(flywheelIO.getSetpointRotPerSec()),
Inches.of(FLYWHEEL_DIAMETER_INCHES / 2)),
Rotation2d.fromDegrees(90).minus(hoodIO.getHoodSetpoint()).getMeasure(),
turretIO.getTurretSetpoint().getMeasure(),
Inches.of(13.75));
}
}

public static LinearVelocity angularToLinearVelocity(AngularVelocity vel, Distance radius) {
return MetersPerSecond.of(vel.in(RadiansPerSecond) * radius.in(Meters) * 0.54 + 1);
}

@Override
public void simulationPeriodic() {}

@Override
public Command feed(
Supplier<Pose2d> robotPoseSupplier,
Expand Down
Loading
Loading