Can someone check this April Tag code

I am trying to write code that allows me to automatically turn my swerve drive toward an April tag. When I run the code, I expect if the robot doesn’t see the April tag, it will not turn, but instead, it seems to set the setpoint for the rotation to around 180 degrees. Also, I can’t access my photon vision camera through the static IP address to check the data it is getting from the april tags too

For people to help you there is not code linked :slight_smile:

1 Like

Oops sorry :slight_smile:

Your condition for stopping the drivetrain is if the last target is equal to null, but you only update the last target variable if there is a target found.

EDIT: I’m also not sure if the logic is sound. Why would you stop the drivetrain if the last target was null? Wouldn’t you only stop it if the current target this loop iteration is null?

Sorry for taking a while to get back to you. Thanks for suggesting it might be a logic fault, but based on my understanding on the logic, the code first checks if there is a target, if there is a target the code will set lastesttarget to the current target, else, lastesttarget should equal null. The next if statement checks if the latesttarget isn’t null and if it isn’t, it will run the PID loop. I’m not sure I see the logic fault in that although maybe I should make it so that if latest doesn’t have targets, the latesttarget variable should be set back to null.

1 Like

Yeah I misunderstood a bit but I think the fix you mentioned at the end there should do the trick