Problems with Mecanum Drive

We have been trying to put together a mecanum drive base. However, we cannot get it to turn. It strafes just fine and goes forward and reverse great. We are using the example code provided by WPILIB. We are coding in java. All help will be appreciated. Thanks, CD for all the help.

Please post your code.

1 Like

Are your wheels orientated correctly?

To expand on this, the wheels should form an X pattern viewed from above, so on the ground they form a diamond pattern.

Here is the code we have so far.

package frc.robot;
import com.kauailabs.navx.frc.AHRS;

import edu.wpi.first.wpilibj.DigitalInput;
import edu.wpi.first.wpilibj.DriverStation;
import edu.wpi.first.wpilibj.SPI;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.PWMTalonSRX;
import com.ctre.phoenix.motorcontrol.can.WPI_TalonSRX;
import edu.wpi.first.wpilibj.TimedRobot;
import edu.wpi.first.wpilibj.drive.MecanumDrive;

public class Robot extends TimedRobot {
private static final int kFrontLeftChannel = 0;
private static final int kRearLeftChannel = 1;
private static final int kFrontRightChannel = 2;
private static final int kRearRightChannel = 3;

private static final int kJoystickChannel = 0;
private AHRS ahrs;
private MecanumDrive m_robotDrive;
private Joystick m_stick;
private double joyX;

@Override
public void robotInit() {
WPI_TalonSRX frontLeft = new WPI_TalonSRX(kFrontLeftChannel);
WPI_TalonSRX rearLeft = new WPI_TalonSRX(kRearLeftChannel);
WPI_TalonSRX frontRight = new WPI_TalonSRX(kFrontRightChannel);
WPI_TalonSRX rearRight = new WPI_TalonSRX(kRearRightChannel);

frontLeft.setInverted(true);
rearRight.setInverted(true);

m_robotDrive = new MecanumDrive(frontLeft, rearLeft, frontRight, rearRight);

m_stick = new Joystick(kJoystickChannel);

try {
  ahrs = new AHRS(SPI.Port.kMXP); 
}catch (RuntimeException ex ) {
  DriverStation.reportError("Error instantiating navX MXP:  " + ex.getMessage(), true);
}

}

@Override
public void teleopPeriodic() {
m_robotDrive.driveCartesian(
stickY().8,
-stickX()
.8,
stickZ()*.8,
);
}
public double stickX() {
if(m_stick.getX() < .1 && m_stick.getX() > -.1) return 0;
else return m_stick.getX();
}
public double stickY() {
if(m_stick.getY() < .1 && m_stick.getY() > -.1) return 0;
else return m_stick.getY();
}
public double stickZ() {
if(m_stick.getZ() < .1 && m_stick.getZ() > -.1) return 0;
else return m_stick.getZ();
}
public static int bool2int(boolean value) {
return value ? 1 : 0;
}
}

Yes, our wheels are oriented correctly.

Double check your wiring/CAN IDs. If you have the front left and rear right signals exchanged (or the front right and real left), you can get this sort of behavior. The easy way to check if this is the problem is to put the robot on blocks, and drive for rotation. Are the wheels going forward on one side and reverse on the other?

2 Likes

Thank you so much, our robot is driving much better now.

2 Likes