Hi, so on my teams demo robot we’re using mecanum wheels, a 4 slot cRIO and some victor 884s and we cant seem to get it working right. I don’t know that much about code so it’d be great if I could get some help.
The code can be found below, any suggestions/correction are very much appreciated.
package edu.wpi.first.wpilibj.templates;
import edu.wpi.first.wpilibj.Joystick;
import edu.wpi.first.wpilibj.RobotDrive;
import edu.wpi.first.wpilibj.SimpleRobot;
import edu.wpi.first.wpilibj.Timer;
import edu.wpi.first.wpilibj.Victor;
public class RobotTemplate extends SimpleRobot {
RobotDrive myDrive;
Joystick driveStick;
public void robotInit() {
driveStick = new Joystick(1);
Victor frontLeft = new Victor(1);
Victor frontRight = new Victor(2);
Victor rearLeft = new Victor(3);
Victor rearRight = new Victor(4);
myDrive = new RobotDrive(frontLeft, rearLeft, frontRight, rearRight);
System.out.println("Sample Text");
}
public void autonomous() {
}
public void operatorControl() {
while (isOperatorControl() && isEnabled()) {
myDrive.mecanumDrive_Cartesian(driveStick.getX(), driveStick.getY(), driveStick.getTwist(), 0);
Timer.delay(0.01);
}
}
public void test() {
}
}
3 of our wheels don’t go in the same direction and one doesn’t move unless told to turn on the spot. Tried swapping some PWMs and that didn’t help. I’m also not getting any errors with the code either…
First, I would make sure you have the PWMs mapped correctly. If you are sure these are correct, it will make debugging everything else much easier.
Also, if you haven’t already, put the robot on blocks so you can see what the motors are doing without having it try to drive around.
My guess is that you need to invert some of the motors. You can do this either in code (using myDrive.setInvertedMotor()), or by reversing the polarity of the wires that go from the Victor to the motor. When you push the joystick forward, all the wheels should move. If they don’t you either have a problem with your joystick axes (what joystick are you using?) or your motor controller. Once all 4 wheels are moving when you command the robot to go forward, invert all the ones that are going backwards.
So after trying some stuff out, here’s the list of things you asked for Ether. We’re also using a Logitech Extreme 3D Pro for our joystick.
Pure Forward:
Front Right = Spins forward
Front Left = Not working at all
Back Right = Spins forward
Back Left = Spins forward
Strafe Right:
Front Right = Spins forwards
Front Left = Not working at all
Back Right = Spins backwards
Back Left = Spins forwards
Rotating clockwise:
Front Right = Spins forwards
Front Left = Not working at all
Back Right = Spins forwards
Back Left = Spins backwards
***NOTE: FRONT LEFT TURNS FORWARDS WHEN TURNING COUNTER-CLOCKWISE
It sounds like you issued the commands by moving the joystick (hardware) instead of commanding them directly in software. Or am I misreading your post?
There is obviously something very wrong here. I suggest you try to get to the bottom of this first:
Try swapping Front Right and Front Left PWM cables and re-run the test. See if the problem follows the cables.
The motor controller wasn’t working correctly. We replaced it with another Victor 884 and it worked just fine. We also had a little incident of it another 884 sparking out and dying today so we’ll also be changing it to use Talon SRs shortly.
The problem solving process was swapping PWM cables as well as remembering that our old mecanum drive train had a major problems with shorting Victor 884s. Under further inspection, the controller was also having trouble initializing and didn’t initialize most of the time.