FRC 180 S.P.A.M. Code Release 2024

Hello, everyone!

We’re happy to release our code for our 2024 robot “Sonic”.

Some noteworthy features:

We used the CTRE Swerve API & project generator for our swerve (Mk4 L3 gearing w/ Krakens) & Choreo for our autonomous paths. We welcome any questions. :slight_smile:

19 Likes

Congratulations on IRI Championship!

I have a few questions.
Why is 180 added to angleToGoal to get speakerDegrees? (Maybe due to shooting is from the back of bot? Line 270
What is the SHOOTER_DEGREE_OFFSET?
Do you have to make any adjustments to speakerDegrees for Red vs Blue other than the speakerTranslationBlue/Red = speakerPoseBlue/Red.getTranslation() (VisionSubsytem.java) ?

When on RedAlliance what adjustments do you make to gyro heading?

Big Thanks

 double speakerDegrees;
        if (speakerFiducial != null && directTagAiming && !isShootingOnTheFly) {
            speakerDegrees = RobotContainer.instance.drivetrain.getGyroscopeDegrees() - speakerFiducial.txnc;
            speakerAngleType = HeadingTarget.GYRO;
        } else {
            speakerDegrees = Helpers.angleToGoal(robotPose, speakerTranslation) + 180;
            speakerAngleType = HeadingTarget.POSE;
        }
        speakerDegrees += SHOOTER_DEGREE_OFFSET;
        speakerAngle = MathUtil.inputModulus(speakerDegrees, -180, 180);
2 Likes

Just landed back in Florida, thanks for the kind words!

You nailed it, our shooter is on the back of the bot, so we need to flip the angle by 180 degrees to get it to face the correct direction.

Our shooter has a bit of a leftward curve to it, so SHOOTER_DEGREE_OFFSET is used to negate most of the effects of the curve. We found it by putting the robot at it’s “average” shooting distance (past the first stage leg) and incrementing the offset until shots went into the middle of the speaker.

We didn’t need to add any alliance-specific changes for speaker targeting besides changing what speaker we target, except for when handling a disconnected Limelight: in that case, we returned an angle of 0 or 180 based off our alliance color, since we always use gyro 0 as “forward” regardless of alliance.

We let our gyro heading work the same way on red as blue (i.e. 0 is facing forward). Because of this, there’s a couple places where we just mirror gyro values by alliance (like line 243 of RobotContainer.java). The only non-mirroring change is our feed shot angle, which is -45 degrees on blue and 25 degrees on red because those are what seemed to work best.

1 Like

Having a problem on Red alliance. Our CanCoders are increasing in the wrong direction. So Pose is off.
We are setting 180 on gyro when we boot on red, so the bot drives correctly. But we are not doing any kind of field flip or mirror. Not sure here to go from here.
Any help is appreciated.

 public void zeroHeading() {

        if (Robot.isRed()) {
            gyro.setYaw(180);

        } else {
            gyro.setYaw(0);

        }

        // gyro.setYaw(0);
        swerveOdometry.resetPosition(getGyroYaw(), getModulePositions(),
                new Pose2d(getPose().getTranslation(), new Rotation2d()));

    }

Do things work well on the blue alliance? If so, I recommend leaving the gyro angle as “0” for forward regardless of alliance.