Has anyone programmed the mechanum wheels using C++?/
if so could you share?
thanks
Has anyone programmed the mechanum wheels using C++?/
if so could you share?
thanks
The WPI library provides the RobotDrive object that includes a method:
void RobotDrive::MecanumDrive_Polar(float magnitude, float direction, float rotation)
You can call this method to drive the mechanum wheels. It is using polar coordinate system where you specify the magnitude and direction you want to go. Rotation will specify the heading you want the robot to face.
To calculate the magnitude and direction from joystick reading, you can do:
MecanumDrive_Polar(joystick->GetMagnitude(), joystick->GetDirectionDegrees(), 0.0);
my understand is that we need to specify each motor/wheel assembly , ie all four individually as each wheel is connected indepedently to a single motor.
so then do we use the above statements for each motor/wheel assembly?
thanks
have you actually written some code just to move the bot with mechanum wheels?
You take the commands from the joysticks and you process them (it’s called inverse kinematics) to create the 4 wheel speeds.
The drive interface could be a single 3-axis joystick, or two 2-axis joysticks, or any other input device(s).
Mecanum has three completely independent degrees of freedom:
fore/aft
strafe (right/left)
rotate (turn, yaw)
A mecanum vehicle can perform all three of these motions simultaneously.
Here’s some reference C code for you:
// 3-axis joystick interface to a mecanum drive
// define your driver interface,
// in this case a 3-axis joystick:
forward = -Y;
right = X;
clockwise = Z;
// put any drivability adjustments here for forward, right, and clockwise,
// for example gain, deadband, etc:
// if rotate gain is too hot, tweak it down:
clockwise /= 2;
// add deadband so you don't get strafe when you don't want it:
if ((right>-0.1)&&(right<0.1)) right = 0;
// now apply the inverse kinematic tranformation:
front_left = forward + clockwise + right;
front_right = forward - clockwise - right;
rear_left = forward + clockwise - right;
rear_right = forward - clockwise + right;
// finally, normalize so that no wheel speed command
// exceeds magnitude of 1:
max = abs(front_left);
temp = abs(front_right);
if (temp>max) max = temp;
temp = abs(rear_left);
if (temp>max) max = temp;
temp = abs(rear_right);
if (temp>max) max = temp;
if (max>1)
{front_left/=max; front_right/=max; rear_left/=max; rear_right/=max;}
// you're done. send these four wheel commands to their respective wheels
Questions? Fire away.
**
You have 4 individual motors one for each wheel but you don’t have to deal with them yourself, the WPI library will take care the rest for you. So when you instantiate the RobotDrive object, you will need to initialize it with four motors in its constructor. Once you define the RobotDrive object with four motors, you can make the MecanumDrive_Polar call to drive it around. The RobotDrive object will figure out the power and direction for each wheel for you.
Either:
RobotDrive(UINT32 frontLeftMotorChannel, UINT32 rearLeftMotorChannel,
UINT32 frontRightMotorChannel, UINT32 rearRightMotorChannel,
float sensitivity = 0.5);
Or:
RobotDrive(SpeedController *frontLeftMotor, SpeedController *rearLeftMotor,
SpeedController *frontRightMotor, SpeedController *rearRightMotor,
float sensitivity = 0.5);
And yes, we were using Mecanum wheels last year so we did write some code for them.
Note that the MecanumDrive_Cartesian is much more suited to driving with a joystick. It was designed to directly pass 3 joystick axes in.
void MecanumDrive_Cartesian(float x, float y, float rotation, float gyroAngle = 0.0);
This also allows you to simply pass in the current reading from a gyro to accomplish field-oriented-control.
-Joe
so does one need only two joysticks or do you need to use 4 with two drivers. seems to me two joysticks would work. Did you find any brand or type better than another. I am looking at the Logitech Extreme 3D Pro. It has the 3 axis capability.
thanks
For driving mecanum, two joysticks would work. Even one would work if the joystick has at least 3 axes (e.g. X, Y and Twist). I don’t have the Logitech Extreme 3D Pro, so I can’t comment on it.
Our team used the 3D Pro to drive a mecanum bot last year and it was very natural. The kids picked up how to control it very quickly.
so Joe would you have an example of code we might use just to see how we might drive our bot? I have some kids who can program but they are just starting out and it would help alot if we had some code we knew worked and then could build on it
Did you use two joysticks?
thanks John
Yes, It would be extremely helpful if the sample C++ Code for Mechanum Wheels is provided with a good explaination
Thanks
I’ve attached an example. It’s based on the IterativeRobot base class but could be moved to SimpleRobot (by just putting a loop around the Drive method).
Nope. Just one Extreme 3D Pro.
-Joe
MecanumDefaultCode.cpp (1.4 KB)
MecanumDefaultCode.cpp (1.4 KB)
Wow, the Example is well detailed and easy to understand. But the question is does this code move the robot or its given for example purpose?
Thanks
While I haven’t tested it out, I believe it should move the robot if all mechanical and wiring is correct.
-Joe
Thanks Joe will give it a try
John
Ok, I am really new to C++, we are using the SimpleRobot class. can help me out by telling me what kind of a loop I put around it (MecanumDefaultCode.cpp) and some details like that. Do I need a .h file to go with it? What else do I need to add to make it work with the default sample code? by the way, does anyone know of a tutorial that explains how to use most/all of the WPI Library commands? I don’t know how to use hardly any of them. this is my first year coding and all of the programmers graduated last year so I’m looking for any possible help.
Most likely, you would want to put the mecanum code inside of the “while(IsOperatorControl())” loop of the OperatorControl function of the SimpleRobot class. Also, I believe the code would change slightly as the SimpleRobot template uses different variable names, and does not use pointers. (I don’t have our classmate in front of me, so someone correct my code if I’m mistaken)
while(IsOperatorControl())
{
myRobot.MecanumDrive_Cartesian(stick.GetX(), stick.GetY(), stick.GetTwist());
...
This is a good document for getting started in C++ and making sure that Windriver is properly set up (which you may or may not need).
http://firstforge.wpi.edu/sf/docman/do/downloadDocument/projects.wpilib/docman.root.c_and_java_documentation/doc1197
While I haven’t looked through this very much yet, this should document most, if not all the WPILib classes with examples of using them. It is written for both Java and C++, so make sure you don’t get the code mixed up.
http://firstforge.wpi.edu/sf/docman/do/downloadDocument/projects.wpilib/docman.root.c_and_java_documentation/doc1196
Our team used mecanum wheels with the Logitech Extreme 3D Pro joystick last year for Breakaway and it worked very well. Programming was a little tricky but on the whole that was offset by how quickly we could change directions with only one joystick. I highly recommend the single joystick solution.
So with that code I can just pop it into my code and it should work or will it have to be modified.?
So Joe I downloaded your code and am trying to get it to build in Windriver.
Sorry but myself and the kids are just getting familiar with Windriver. I opened it but it would build. Any suggestions?
thanks John