We are using vision for the first time this year, and we are having trouble with this chase tag command. Robot code crashes when running it sometimes, robot misaligns to April tag and oscillates around the goal indefinitely.
Sometimes it overshoots while oscillating, and even though it no longer sees the April tag, we don’t regain drive controls.
(This code is only meant for rotation, translation is not being used)
instead of getting the rotation of the April tag in the camera, get the robot’s position on the field. This thread is quite helpful. Then you can do something like this:
public Rotation2d calculateRequiredHeading() {
var pose = s_Swerve.getEstimatedPose();
return PhotonUtils.getYawToPose(pose, new Pose2d(0, 5.6, new Rotation2d(0, 0)));
}
then rotate towards it using your drivetrain function
We’re still having problems. The previously mentioned method didn’t work, the robot didn’t rotate.
This link leads to the fork of the member handling all vision updates on our code:
You can try a different approach that might be productive. With retroreflective tape we never used the camera in a PID loop to control the rotation of the robot. It sounds like you are doing something similar to that. It doesn’t work well. We used the camera to determine how much to rotate and used that as a setpoint and then used the gyro as controller input to rotate to that setpoint.
We used the camera to update the setpoint as needed and as the data were available. I’d use the AprilTag to set the setpoint for rotation from the robot pose on the field but use the wheel and gyro odometry as the feedback to the controller. Update the current and desired pose as they are available from the camera.
If you are updating the angle from vision using the angle to the AprilTag, make sure you are always picking up the tag which is centered on the Speaker. If you are not checking the fiducial id, you might pick up the tag too the side which will reek havoc with the control.