My team has our autonomous code ready, but the robot keeps drifting to one side. I was considering using a gyroscope to help us drive straight, but I have no idea how to do that, we have a NavX-MXP gyro and we are using a mecanum drive train.
Have a look at these WPILib examples on using a gyro to drive straight.
(Note, C++ examples also exist) Timed Robot Command
If you want to be really fancy, you can look into using a Trajectory.
The basic premise is as follows:
You have a setPoint heading you want to follow
You calculate the error in your heading (setPoint - currentHeading)
You scale the error down to adjust how strongly the robot tries to correct for the error
You use this error as your turn rate (eg driveCartesian(0.0, 0.5, error))
Note, You may need to negate the error depending on whether the NavX reports positive CW or CCW.
Ok, so, robot is still drifting to one side instead of going straight backwards. I tried the example program, but it didn’t change anything. At this point I don’t think the NavX sensor is ‘plug and play’ like the electrical team told me. Does anyone know how to set it up properly? Also i’m a little confused about ‘setPoint’ and ‘currentHeading’ mean, what values do I use for them?
I would look into implementing a MecanumOdometry object.
Then you could use 2 feedback loops. One for correcting your rotation, the other for correcting your sideways drift.
My one concern is I don’t know how accurate encoders on a Mecanum bot is, at slow speeds in autonomous the slip may be manageable.