View Full Version : Programming Mecanum
PANTHERPROJECT
04-02-2014, 14:43
Hi! I'm having trouble programming the mecanum wheels. I can make the robot move sideways and rotate but I cannot make it move forward and backward and I'm not sure why. I included the important parts of my code below.
Joystick joy1 = new Joystick(1);
RobotDrive drivetrain = new RobotDrive(1, 3, 2, 4);//Front Left - 1, Rear Left - 2, Front Right - 3, Rear Right - 4
double magnitude = joy1.getMagnitude();
double direction = joy1.getDirectionDegrees();
double rotation = joy1.getZ();
drivetrain.mecanumDrive_Polar(magnitude, direction, rotation);
I know for certain that it isn't an issue with the wiring. I tried using two joysticks instead of one but that didn't work either. I've pretty much run out of ideas at this point and hope someone can help. Thank you!
notmattlythgoe
04-02-2014, 14:58
Have you tried just using the X, Y, and Z axis instead of the Magnitude and Direction?
PANTHERPROJECT
04-02-2014, 15:00
I have but it didn't help.
Put the bot up on blocks (wheels off the ground) and give it a pure forward command. Tell us what each of the four wheels do.
Joe Derrick
04-02-2014, 18:19
You could check to see if your drive motors need to be inverted. You could do this in code, or just swap red/black on one side of your robot.
Might not be the answer but another thing to try!
nyaculak
04-02-2014, 22:09
Joystick joy1 = new Joystick(1);
RobotDrive drivetrain = new RobotDrive(1, 3, 2, 4);//Front Left - 1, Rear Left - 2, Front Right - 3, Rear Right - 4
I think you instantiated your RobotDrive instance with the motors in the wrong order. Correct me if I'm wrong, but the order should be frontLeft, rearLeft, frontRight, rearRight. Try changing the instatiation to
RobotDrive drivetrain = new RobotDrive(1, 2, 3, 4);
If that doesn't work, try as others have suggested and mount the robot up on blocks to isolate the wheels. This helps tremendously in debugging a faulty drive train.
PANTHERPROJECT
09-02-2014, 17:40
Put the bot up on blocks (wheels off the ground) and give it a pure forward command. Tell us what each of the four wheels do.
All the wheels spin inwards
PANTHERPROJECT
09-02-2014, 17:42
I think you instantiated your RobotDrive instance with the motors in the wrong order. Correct me if I'm wrong, but the order should be frontLeft, rearLeft, frontRight, rearRight. Try changing the instatiation to
RobotDrive drivetrain = new RobotDrive(1, 2, 3, 4);
If that doesn't work, try as others have suggested and mount the robot up on blocks to isolate the wheels. This helps tremendously in debugging a faulty drive train.
That is how I instantiated it originally. When I did that, the wheels moved forward, backward and rotated but did not move side to side.
All the wheels spin inwards
That's why it won't go forward of course.
What do the wheels do when you give a pure reverse command?
A pure strafe right command?
etc
PANTHERPROJECT
09-02-2014, 21:28
That's why it won't go forward of course.
What do the wheels do when you give a pure reverse command?
A pure strafe right command?
etc
When given the pure reverse command, I believe they all spin outward but the wheels work fine while shifting to the right, left and rotating so if I were to invert the motors it wouldn't help much.
notmattlythgoe
10-02-2014, 07:47
When given the pure reverse command, I believe they all spin outward but the wheels work fine while shifting to the right, left and rotating so if I were to invert the motors it wouldn't help much.
I'm pretty sure nyaculak is correct that you have the motors going into the RobotDrive object incorrectly. It should be frontLeft, rearLeft, frontRight, rearRight.
RobotDrive(int frontLeftMotor, int rearLeftMotor, int frontRightMotor, int rearRightMotor)
Constructor for RobotDrive with 4 motors specified with channel numbers.
BradAMiller
10-02-2014, 21:35
Code for doing Mecanum with joysticks looks like this:
myRobotDrive.mecanumDrive_Cartesian(joy1.getX(), joy1.getY(), joy1.getTwist());
Optionally you can put the angle from a gyro in as the optional 4th parameter.
One possible problem is that some of the motors may need to be inverted depending on how they are configured. To determine that, put the robot on blocks and drive it with the joysticks and see what it is doing. You can call the
setInvertedMotor()
method on the side that is going in the wrong direction.
vBulletin® v3.6.4, Copyright ©2000-2017, Jelsoft Enterprises Ltd.