ADXRS450 Straight Drive Not Working

My team is using mecanum wheels this year, and we’ve found that it’s very hard to drive in a straight line. Along with that, it is impossible to drive straight in auton. We decided to use the gyroscope that comes with the kit of parts (ADXRS450). I’ve used the code in the screensteps, and it does not work whatsoever. I’m unable to set the sensitivity for the gyro, but I assume it’s because there is no need since the class is specifically for that gyroscope.

Here is the code.



package org.usfirst.frc.team6077.robot;


import edu.wpi.first.wpilibj.SampleRobot;
import edu.wpi.first.wpilibj.ADXRS450_Gyro;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.VictorSP;
import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;


public class Robot extends SampleRobot {
    RobotDrive drive;
    VictorSP leftFront, leftBack, rightFront, rightBack;
    ADXRS450_Gyro gyro;
    double kP = 0.03;

    public Robot() {
    	leftFront = new VictorSP(0);
    	leftBack = new VictorSP(1);
    	rightFront = new VictorSP(2);
    	rightBack = new VictorSP(3);
        drive = new RobotDrive(leftFront, leftBack, rightFront, rightBack);
        gyro = new ADXRS450_Gyro();
        gyro.calibrate();
    }

    public void autonomous() {
    	gyro.reset();
    	while (isAutonomous() && isEnabled()) {
    		SmartDashboard.putNumber("Gyro Angle", gyro.getAngle());
    		//X and Y are switched because of inversion
    		drive.mecanumDrive_Cartesian(-0.5, 0, -gyro.getAngle()*kP, 0);
    	}
    }

The only noticeable effect of the gyroscope is that when kP is above 0.005 the robot spins at full speed in a circle.

Thanks!

We did mecanum code back in 2014, so I am not familiar with using it on the new gyro. However, unless you get better advice, the first thing I would try would be to remove the negative from the gyro input to mecanumDrive_Cartesian(). If your gyro input is of the incorrect sign (or moves rapidly in one direction independently of what is going on), this will cause a high-speed spin as the drive pushes farther and faster away from the desired set point.

Do you have trouble driving straight manually? When we implemented this in 2014 with 6 inch wheels, drivers were able to quickly adapt even to our prototype robot, which had about 6x as much weight on the right rear wheel as on the front left. (That prototype is the only team robot I drove for more than an hour, and it took me less than a minute to compensate for the pull.) If straight driving is difficult for people, you probably have some significant physical problem, whether swapped gearboxes or a gearbox which is not rotating freely. Having some of the roller bolts so tight so that they do not rotate freely might also cause this issue.

I think you are using the gyro the wrong way for the cartesian form:

mecanumDrive_Cartesian(x speed, y speed, rotation rate, gyro angle)
Use gyro for “field oriented driving”
see: https://wpilib.screenstepslive.com/s/4485/m/13809/l/599704-driving-a-robot-using-mecanum-drive

The polar form may be more appropriate here:
mecanumDrive_Polar(driveSpeed, angle, rotation rate)

Use the Gyro for the angle: use -gyro.getAngle() to go straight (0 degrees) and use zero for rotation rate.