Programming help for tracking april tags with limelight

We’re using a limelight2, our goal is to track an april tag and make the robot move towards it. We’ve successfully set up the limelight and it recognizes april tags without problems. We’re stuck on the programming stage, since we’re not sure how to process the data retrieved from the network table. We referenced from this example code from limelight docs, but our robot is not functioning as expected. Here’s our code, any help would be greatly appreciated!

You need a WPILIB swerve drive pose estimator which tracks the robot pose on the field using wheel encoders and gyro. It has an addVisionMeasurement method which allows Limelight to correct the pose from AprilTag data.

See this Swerve Drive Pose Estimator and Add Vision Measurement using Limelight is very jittery - Technical - Chief Delphiand other threads - search “swerve drive pose estimator” for more complete information. Also be aware of the final posts in this thread
Introducing Limelight 3 - FIRST / General Forum - Chief Delphi

2 Likes

Here is a link to how my team approaches retrieving and processing Limelight data for reference: FRC-2024/robotbase/src/main/java/frc/robot/subsystems/Limelight.java at main · frc2357/FRC-2024 · GitHub

I didn’t make it and I’ve never needed to understand how it all worked, but I can try to help answer any questions you have. I’m also working on a DriveToApriltagCommand that uses the limelight output if you’d like to see that as a reference.

1 Like

depending on what your goal is, you might not have to use a pose estimator. If you just want to drive to a fixed position, first make sure 3d tracking is enabled on the limelight - see 3D AprilTags | Limelight Documentation. Then, the simplest way to drive to a point is to use the targetpose_cameraspace NetworkTables field, which will give you the pose of the tag relative to the camera. You can directly offset the X/Y/Rotation and feed it into a PID controller to get you to your point of interest.

3 Likes

Do you have any example java code or documentation for feeding the position into a PID controller? I would love to do this for my team but I wouldn’t know where to start.

Check limelight_aim_proportional() and please let me know if we need to clarify anything.

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.