![]() |
Controlling the individual speed of mecanum wheels within the main programme
Hello! We're on our third day of of four day "build season", and are almost ready to test drive. I've been reading about mecanum wheels here for a while, and am starting to worry that our motors may not be capable of spinning synchronously (well, we haven't tested yet, but it seems to happen to a lot of other people). We're using C++, and I don't currently have one of the developer laptops with the programming environment and WPI source to use as a reference. What I was hoping we could do was to drag the entire Mecanum_Cartesian method out of WPI and insert it into a method below the periodic portion of our code so we could easily manipulate the individual motor values to get the correct speeds (and so that we can see the math involved instead of putting all our faith in the library). Could someone give me some direction? Thanks!
|
Re: Controlling the individual speed of mecanum wheels within the main programme
The source for wpilib is included as a project in Java, but I don't know if it's included in the C++ release.
If you want to right your own mecanum code, it's pretty easy. Here's the important part from the Java library. Code:
frontLeft = xIn + yIn + rotation;As for the wheel speed issue, it can definitely help to use closed loop control for the velocity of the wheels, but it can be fairly difficult to implement well, and it will take a long time to tune it well. I would recommend just sticking with the simpler method unless your robot really isn't controllable. If it is, make sure there's no excess friction in any gearboxes/drive components/rollers on the wheels. |
Re: Controlling the individual speed of mecanum wheels within the main programme
Quote:
|
Re: Controlling the individual speed of mecanum wheels within the main programme
Quote:
Code:
double max2(double a,b){ return (a>b)?a:b; } |
Re: Controlling the individual speed of mecanum wheels within the main programme
You need to find the max absolute value, since speeds can be +/-. Let fr, fl, rl, and rr be the 4 wheel speed commands in the range +/- 1. Then here's the pseudo-code: Code:
max=fabs(fr); |
Re: Controlling the individual speed of mecanum wheels within the main programme
Quote:
Now you've taken all the fun out of it! :D |
Re: Controlling the individual speed of mecanum wheels within the main programme
Thank you!! Since we just finished the chassis, we're trying to get it working using the library code... and there have been some complications. We can rotate flawlessly, and we can drive in a more-or-less straight line (probably due to our ancient 2 axis joystick with no deadzone). The problem we're having is that we can't strafe (and the x axis, y axis, and rotation are all mixed up). When we try to strafe, the robot simply spins the wheels towards or away from the central point of the robot (i.e the front two wheels spin inwards and the back two wheels spin inwards xor vice versa) and it stays in place or runs in circles. The rollers are arranged in an "X" pattern when viewed from the top. Here's the code we're using, in case it's related to that...
Code:
#include <WPILib.h>[edit] Also, if we tell an individual motor to do something (i.e just sending a value to a single motor controller), the other motors move and twitch... I have no idea how to fix this |
Re: Controlling the individual speed of mecanum wheels within the main programme
Quote:
The code looks like this: Code:
stick_LeftY = stick->GetLeftY(); |
Re: Controlling the individual speed of mecanum wheels within the main programme
Thanks :) How on earth are we supposed to get which motor goes where and which need to be inverted and which need to be switched and...? Is there some standard way of doing this? Also... the twitching and creeping while no commands are being sent really weirds me out...
|
Re: Controlling the individual speed of mecanum wheels within the main programme
Quote:
Forward- all wheels forward Backward- all wheels backward Rotate right- 2 left wheels forward, 2 right wheels backward Rotate left- 2 left wheels backward, 2 right wheels forward Strafe right- front left and back right wheels forward, front right and back left wheels backward Strafe left - front left and back right wheels backward, front right and back left wheels forward Quote:
|
Re: Controlling the individual speed of mecanum wheels within the main programme
Thanks! We ended up telling identifying each motor as "frontleft" etc, and then calling them one by one and replacing the PWM cables to get the right wheel to correspond with the right motor controller name (regardless of the direction). Then we put the motor values into MacanumDrive_Cartesian and set it to drive in a straight line (while on blocks) and reversed all the motors that needed to be reversed. We don't know how to use "SetInvertedMotor()".... Now we only have one problem... Talon SRs spin signifigantly (and consistently) faster in reverse than while going forwards (so we can't simply multiply individual motor values to regulate them). Thanks, by the way! We printed out your response and cable-tied it to the robot (just the directional stuff). *edit* also, it creeps without the joysticks plugged in. It only creeps and jitters when on blocks or low friction surfaces (although the motor controller lights do change colours while on high-friction surfaces, but don't give the motors enough power to move). *edit2* I just realized that the speed controllers are not initialized in the right order. Fixing that shouldn't mess anything up, right?
|
Re: Controlling the individual speed of mecanum wheels within the main programme
Glad I could help! The fact that the wheels twitch when there's no joysticks plugged in is rather bizarre. Unfortunately I'm not really sure what to tell you about that.
If you change the order that the motors are initialized this would change the order they would need to be put into the Mecanum_Cartesian function. This would change things but can be easily fixed on the robot by moving the PWM cables around |
Re: Controlling the individual speed of mecanum wheels within the main programme
Creeping and twitching. Sounds like me after too much sugar.
Have you changed the calibration on your talons at all? I have no experience with talons at all, but i have plenty with victors. Someone was calibrating a drivetrain to stop creeping, but did it wrong. The victor now only knew full front and full reverse. But your problem is not that extreme. Also, make sure your joysticks are centered when they are first plugged in, and the driver station loads. Otherwise whatever position they were in when they were plugged in will be the new origin. You could also program in a deadzone function to set values between -.01 and .01 to = 0. for both axes, and a function to set a new origin (rezero). |
Re: Controlling the individual speed of mecanum wheels within the main programme
The twitching is most likely that the Talons are not calibrated. Calibration basically tells the Talons what input values correspond to full forward, full reverse, and neutral.
To calibrate the Talons (from the Talon user manual): Quote:
|
Re: Controlling the individual speed of mecanum wheels within the main programme
We just tried calibrating the motor controllers. It fixed the twitching issue, but the motors still spin too fast in reverse. The input voltage for all three motor controllers is the same, but the output for the forwards ones is consistently more than the reversed ones (by around 50%). Would fixing the arrangement of the declarations in the code possibly fix this? Probably not... I'm running out of ideas
|
Re: Controlling the individual speed of mecanum wheels within the main programme
If your robot drives OK, you may not have to do anything. You'll need to check with something close to the expected weight and weight distribution. You probably want to hook things up so that going forward has all four motors running faster than going in reverse -- this may mean you need to reverse the two motor wires that attach to the output of two of the speed controllers. This way, forward and reverse should work well. If rotation and going to one side or the other don't work as you like, you can reduce the power in the forward direction so that it matches that in reverse, via software. Of course, you'll only want to do this when you need to, not for forward and reverse. Hopefully, this makes sense...
|
Re: Controlling the individual speed of mecanum wheels within the main programme
I'm going to guess that you meant to do all the other things recommended here in this thread (i.e. write my own Mecanum code and place it into it's own method below the main method) and then modify the motor controller speeds as needed. I'm not on our development laptop right now, so I threw together the following code:
Code:
#include <WPILib.h> |
Re: Controlling the individual speed of mecanum wheels within the main programme
|
Re: Controlling the individual speed of mecanum wheels within the main programme
You have the right idea. I imagine a little trial and error will get you there!
It might be good to only apply the 'fix' logic if not all wheels are going in the same direction -- this way, you only cut the power if it is needed. Good luck, and if you have further trouble, just post... |
Re: Controlling the individual speed of mecanum wheels within the main programme
Hey! I just wanted to let you all know that the robot worked flawlessly :D I'll put up some pictures of the robot we built in four days when we can get a hold of a decent resolution camera. Thank you all so much! This is hands down the most helpful and informative thread I've ever seen. Much appreciated, CD.
|
Re: Controlling the individual speed of mecanum wheels within the main programme
Thanks for the update!
A further refinement would be to move the normalization to last -- in other words, add the 'fix' logic before the normalization is done. In case others come across this thread, you can compensate for a lot of things in software but, in general, when you have different wheels behaving differently, you should first look for other possible causes: - check for mechanical issues, make sure they all have the same feel, etc.; - check for electrical issues, lose connections, very uneven length wire runs with too-small gage wire, etc.; - consider swapping various components to see if you can isolate the source of the difference as this will provide insight into what is going on; - realize that some motors do have some bias for running faster in one direction than the other, this usually is going to be lost in the noise but it could be a factor; - be on the lookout for non-repeatable results, such as when things shift around without explanation from test-to-test (if you find yourself chasing a moving target, take a break and then think things through again). |
| All times are GMT -5. The time now is 21:21. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi