Heres my suggestions/info on the three topics you don’t know.
Finding Robot Position:
Note: This is very complex, and has been something i have been tuning, rewriting, and updating the system on my team for 2ish years. Don’t expect it to work out of the box
Limelight publishes a the estimated robot position to networktables, the format of which can be seen here. Alternatively, you could use limelightlib, a file of functions you can copy-paste into your robot code. The data can then be fused with your drive odometry data with WPILib’s SwerveDrivePoseEstimator as described by those above. You can check the WPILib docs if you want more info on that.
Limelight also has a few tutorials, one of which is “Localization with limelight”
Another thing to think about is, with limelight, you can use normal pose estimation, called MegaTag. This requires nothing special, just a limelight set to apriltag mode in the web ui. MegaTag2, alternatively, uses the robot’s heading, which you pass into limelightlib, and can produce a more accurate position.
If you don’t want to mess with position, you can just have a button on the driver controller enable aim mode, and use the tx and an aim controller to aim at an apriltag.
Calcuating Direction
The simplest way i can think of to do this is use Arctan2. This is a function in java, kotlin, and python (as far as i know) that takes an x and y component and gives an angle. It may not be the exact angle you want, and you may need to add an offset to it or negate it to match your robot. To get the x and y components, you can simply subtract your robot position from a known location on the field. This is about how it was done in our code.
// both of these are translations/vectors
val vector = AprilTag.position - speakerPos
val angleToSpeaker atan2(vector.y, vector.x)
Detect when in location:
I would map this to a button instead, as it offers more flexibility (ex. not wanting to always shoot into speaker in 2024). If you want to do it automatically, you could simply check if the robot’s y coordinate is greater or less than a specific number (depending on alliance). This worked really well in 2024. If you want to check for whether the robot is in a box, you could look if both coordinates of the robot’s position is within two values.
Just as a closing note, if you still have questions feel free to ask, but the WPILib and Limelight docs both have really good explanations on certain things, like coordinate systems.