Limelight 3.0 adjusting swerve drive orientation (autoaim)

Hello this is my first post on CD and I was struggling with the limelight network tables and it has to do with the tx and ty values not being resolved and the limelight not being able to be resolved and not being a field (pretty new to this so any help is greatly appriciated)

public void autoaim() {
    // Check if a target is detected
    if (limelightTable.getEntry("tv").getDouble(0.0) == 1.0) {
        // Get X and Y coordinates of the target
        double targetX = tx.getDouble(0.0);
        double targetY = ty.getDouble(0.0);

        // Calculate the robot's rotation angle to face the target
        double robotAngle = swerve.getRealYaw();
        double targetAngle = Math.atan2(targetY - Constants.limelight.targetHeight, targetX) - Math.PI / 2;
        double rotation = targetAngle - robotAngle;

        // Rotate the robot towards the target
        swerve.drive(new Translation2d(0, 0), rotation, false, false);
    } else {
        // If no target is detected, stop the robot
        swerve.drive(new Translation2d(0, 0), 0, false, false);
    }
}



Just curious, what is your targetHeight Constang?

Have you thought of taking the Pose2d of the item you want to align with. Example, take the constant position of the speaker, then take your robot’s pose and substract it from the speaker’s position. Then just pass the norm and angle to your swerves. That way you can align with anything and not have to worry about there being AprilTags.

I recommend using LimelightHelpers. It makes interacting with the limelight network tables a lot easier. Aside from that, if you’re having problems communicating with your limelight through network tables, make sure that you have set a static IP address, and that you have set your team number on your limelight via Limelight finder. (It might be called Limelight hardware manager now)

How would you go about doing this? Is there perhaps an example? I was attempting to do this but I do not think my logic would actually work