dirtbikerxz / BaseTalonFXSwerve

Other
145 stars 176 forks source link

Question on Gyro Angle Wrapping #42

Open Squid5678 opened 8 months ago

Squid5678 commented 8 months ago

Does 364 have support for wrapping the gyro angle so it fits within the range of [-180, 180)? If not, any recommendations on how to implement this? Would using something from the IEEE library work? @dirtbikerxz

WOFsoftware51 commented 6 months ago

Not sure if this is the best solution, but here's how our team wraps the gryo angle within [0, 360]:

yawFixed = Math.abs((360-gyro.getAngle())% 360); The "360 - " part might not be necessary for what you want, but it works on our robot so it shouldn't be a problem. If you want to wrap the angle within [-180, 180], you could just subtract 180 from the equation above. yawFixed = 180 - Math.abs((360-gyro.getAngle())% 360); I've never tried it so I'm not sure if the subtracting 180 part works, but I'd definitely recommend you try it.