![]() |
WPILIB mecanum code not working properly
I have been working on getting our mecanum drive working for the past few days and have run into trouble while trying to program using the WPILIB mecanum class. When we try to drive, the forward and strafe commands work fine, but the turn command doesnt. instead of running the left side one direction and the right side another, it spins the wheels on the right towards each other, and the same on the left. If I invert 2 wheels of any pairing, the axis that doesnt work correctly changes. Below is the code that I am trying to use.
Code:
/*----------------------------------------------------------------------------*/Code:
wheelSpeeds[MotorType.kFrontLeft_val] = xIn + yIn + rotation;Code:
double mFL = strafe + forward + rotation;My thought is that if I can get the WPILIB mecanum working, I can see how their field centric control operates in comparison. I am really stumped at this point, any help is greatly appreciated. |
Re: WPILIB mecanum code not working properly
Your code and your wiring probably disagree on which motors are in which corner of the robot. Try making some code that lets you control each motor independently so you can verify which physical motor responds to each PWM channel, and in which direction. Note carefully the order that the RobotDrive constructor wants them to be in.
|
Re: WPILIB mecanum code not working properly
I double checked the port numbers again, all the ports corresponded with the proper wheels. I've taken notes as to the direction each wheel spins individually however at the moment the problem is still there.
|
Re: WPILIB mecanum code not working properly
Leave the code as is and change the PWM wires. Flip your back left with front right. Or back right with front left
|
Re: WPILIB mecanum code not working properly
If I change the pwm cables (front left and rear right or front right and rear left) it just changes the axis that is not operating properly (the wheels spin towards each other). just like when I invert the motor pairs in the code.
|
Re: WPILIB mecanum code not working properly
Do you have the wheels mechanically mounted correctly? When looking from the top, the rollers should look like an X across the robot.
Also, unless gearing is different for each side, one side of the drive should be reversed, and one side should be normal. This should allow rotation correctly. One way I like to check things is look at the lights on the motor controllers. When going straight, 2 should be red, and 2 should be green. When rotating, all 4 should be either red or green, depending on which direction you are rotating. When strafing, 2 of the corners should be red, and the other 2 corners should be green. 1 More thing to check. When driving at a 45 degree angle, only 2 of the motors should be spinning, and they should be the 2 perpendicular to the direction you want to move. If thats not working correctly, then its most likely that either motor reversing isnt right, or the PWM ports are wrong. |
Re: WPILIB mecanum code not working properly
What I would recommend doing is printing out your X and Y input and then your wheel outputs. Confirm X and Y are in-fact what you intend and then check that the correct wheels are moving. If that doesn't work, you could always subclass RobotDrive and then override the following methods:
public void mecanumDrive_Cartesian(double x, double y, double rotation, double gyroAngle); public void mecanumDrive_Polar(double magnitude, double direction, double rotation); If none of this works, could you make a codebase with only drive code and posting it here? Good luck! |
Re: WPILIB mecanum code not working properly
Can you describe exactly what each wheel does when given each command?
|
Re: WPILIB mecanum code not working properly
At the moment I've been able to get field centric control working using my own code but am still trying to work out what is wrong with my code that utilizes the robot drive class. Unfortunately I've had to go home for the night and won't be able to test any more code until at least tomorrow. Might just leave the wpilib for now and continue with my own mecanum code.
|
Re: WPILIB mecanum code not working properly
If it works then go for it. I'm glad its working now
|
Re: WPILIB mecanum code not working properly
You say this works:
Code:
double mFL = strafe + forward + rotation;That's weird. Your rear motors are reversed, and strafing definitely shouldn't run all the motors in the same direction. I suggest that you triple-check your wiring. And have someone else check it again afterwards. In fact, take some good photos of how you have it wired up and post them here so we can all go over them. Something is definitely wrong, and I do not believe it is the WPI library. |
Re: WPILIB mecanum code not working properly
Quote:
|
Re: WPILIB mecanum code not working properly
Is there a reason your robot drive is *10*,1,2,3? did you mean 0? And make sure the order you set the drive motors is frontLeft, rearLeft, frontRight, rearRight.
Check for inverted motors*** . If the transmission causes the motor to spin the same way as the wheel, then the left side should be inverted |
Re: WPILIB mecanum code not working properly
Quote:
|
Re: WPILIB mecanum code not working properly
We had a similar issue a few weeks ago. My student had swapped the x and y joystick inputs into the mechanum code call. It is not asking for field x and y but joystick x and y. Also the mechanum internally inverts the y so you don't have to.
|
| All times are GMT -5. The time now is 11:08. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi