Help with field oriented swerve

We were driving around our swerve drive today and we noticed something weird happening: When our robot was facing forwards or backwards, the field oriented drive worked fine, but when the robot was rotated 90 degrees left or right, the controls became inverted (pushing joystick forward went backwards and pushing joystick to the right caused the robot to go left.) I was wondering if anyone had any suggestions to why this was happening.
Github: 3984-2023/testingPID2/src/main/java/frc/robot at NEW-Pid-test · DesteoyerRZSS/3984-2023 · GitHub

We had the exact same problem. You’ll also notice that if you rotate your bot 45 degrees, the wheels are off by 90 degrees of where they should be.

Your getYaw() method should simply return the result of m_gyro.getAngle() * (invertGyro ? 1 : -1)

Your gyro’s value is increasing when it should be decreasing and the 360 wrapping won’t fix that

1 Like

Ok, I will try that tomorrow. Thank you!

We’ve also had a similar problem, so I figured I’d share how we fixed it;
Our NavX is mounted upside-down, but it was calibrated upright, leading to the same issue. Recalibrating it while upside-down got rid of the problem. I wouldn’t recalibrate it unless you have some sort of physical justification first

3 Likes

Ok, it ended up not working, but we took act’s suggestion for changing out the gyro and that ended up working for us. Thanks for the help!

Thanks, your suggestion ended working!

1 Like