Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Mechanum wheel programming in C++ (http://www.chiefdelphi.com/forums/showthread.php?t=88686)

johncap100 10-01-2011 16:41

Mechanum wheel programming in C++
 
Has anyone programmed the mechanum wheels using C++?/
if so could you share?

thanks

mikets 10-01-2011 19:57

Re: Mechanum wheel programming in C++
 
The WPI library provides the RobotDrive object that includes a method:
Code:

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:
Code:

MecanumDrive_Polar(joystick->GetMagnitude(), joystick->GetDirectionDegrees(), 0.0);

johncap100 10-01-2011 20:25

Re: Mechanum wheel programming in C++
 
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?

Ether 10-01-2011 20:33

Re: Mechanum wheel programming in C++
 
Quote:

Originally Posted by johncap100 (Post 996101)
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:

Code:

// 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.



mikets 10-01-2011 21:01

Re: Mechanum wheel programming in C++
 
Quote:

Originally Posted by johncap100 (Post 996101)
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 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.
Code:

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.

jhersh 11-01-2011 02:28

Re: Mechanum wheel programming in C++
 
Quote:

Originally Posted by mikets (Post 996074)
The WPI library provides the RobotDrive object that includes a method:
Code:

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:
Code:

MecanumDrive_Polar(joystick->GetMagnitude(), joystick->GetDirectionDegrees(), 0.0);

Note that the MecanumDrive_Cartesian is much more suited to driving with a joystick. It was designed to directly pass 3 joystick axes in.

Quote:

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. :D

-Joe

johncap100 11-01-2011 09:37

Re: Mechanum wheel programming in C++
 
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

mikets 11-01-2011 12:26

Re: Mechanum wheel programming in C++
 
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.

jhersh 11-01-2011 15:01

Re: Mechanum wheel programming in C++
 
Quote:

Originally Posted by mikets (Post 996818)
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.

johncap100 11-01-2011 20:32

Re: Mechanum wheel programming in C++
 
Quote:

Originally Posted by jhersh (Post 996984)
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

ChiefDelphi 11-01-2011 23:28

Re: Mechanum wheel programming in C++
 
Yes, It would be extremely helpful if the sample C++ Code for Mechanum Wheels is provided with a good explaination :)

Thanks

jhersh 11-01-2011 23:41

Re: Mechanum wheel programming in C++
 
1 Attachment(s)
Quote:

Originally Posted by johncap100 (Post 997393)
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

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).

Quote:

Originally Posted by johncap100 (Post 997393)
Did you use two joysticks?

Nope. Just one Extreme 3D Pro.

-Joe

ChiefDelphi 11-01-2011 23:48

Re: Mechanum wheel programming in C++
 
Quote:

Originally Posted by jhersh (Post 997653)
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).

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

jhersh 12-01-2011 00:55

Re: Mechanum wheel programming in C++
 
Quote:

Originally Posted by ChiefDelphi (Post 997667)
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?

While I haven't tested it out, I believe it should move the robot if all mechanical and wiring is correct.

-Joe

johncap100 12-01-2011 07:56

Re: Mechanum wheel programming in C++
 
Quote:

Originally Posted by jhersh (Post 997653)
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

Thanks Joe will give it a try
John


All times are GMT -5. The time now is 14:55.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi