Gyro going crazy in teleop

I am using a PID to keep the robot straight while moving forward and strafing. But as soon as the gyro hits 360 it just keeps spinning in one direction and doesn’t stop. Does this have to do with my PID values or what?

*If LabVIEW’s PID controller has an option to handle continuous sensors, you should use that.

Otherwise, here’s a work-around:

Let G be your gyro reading (converted to degrees)

Let T be your desired angle position (in degrees)

the angle between them (let’s call it ERR) is found by the equation:

ERR = (T-G) - 360*floor(0.5+(T-G)/360);

the above returns a value for ERR between -180 and +180 degrees,
the shortest angle path to the target.

So it tells you which direction to rotate as well as how much to rotate.

So compute your setpoint:

SetPoint = G + ERR

After further investigation it also goes in the same direction no matter which way you turn left or right. So if i turn right it corrects the angle but if it goes left it keeps going more and more left.

It sounds like you’re taking an absolute value somewhere.

Example: The curve is implemented by slowing down the side you’re curving away from. An if-then-else handles which one, but slows the left motor in both cases.

If you can’t find it yourself, post your code, or a link to it.

I used this and it works accept i am using a case structure to update the desired angle everytime i hit the bumpers to turn. It was working like that but started driving crazy in circles again so i put Your code in and now it doesn’t update the header to the new desired angle. Attached is a screenshot of my code any help would be very appreciated.https://ibb.co/nHAhbF
https://ibb.co/cG5tiv
https://ibb.co/bWd2bF