Go to Post Who wouldn't love to see a circular FRC field, on the backs of four elephants, all riding on a gigantic turtle? - Taylor [more]
Home
Go Back   Chief Delphi > Technical > Programming > C/C++
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Reply
Thread Tools Rating: Thread Rating: 4 votes, 4.75 average. Display Modes
  #1   Spotlight this post!  
Unread 10-01-2011, 16:41
johncap100 johncap100 is offline
Registered User
FTC #0658
 
Join Date: Aug 2009
Location: Capital High School
Posts: 95
johncap100 is an unknown quantity at this point
Mechanum wheel programming in C++

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

thanks
Reply With Quote
  #2   Spotlight this post!  
Unread 10-01-2011, 19:57
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
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);
__________________

Last edited by mikets : 10-01-2011 at 20:21.
Reply With Quote
  #3   Spotlight this post!  
Unread 10-01-2011, 20:25
johncap100 johncap100 is offline
Registered User
FTC #0658
 
Join Date: Aug 2009
Location: Capital High School
Posts: 95
johncap100 is an unknown quantity at this point
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?
Reply With Quote
  #4   Spotlight this post!  
Unread 10-01-2011, 20:33
Ether's Avatar
Ether Ether is offline
systems engineer (retired)
no team
 
Join Date: Nov 2009
Rookie Year: 1969
Location: US
Posts: 8,044
Ether has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond reputeEther has a reputation beyond repute
Re: Mechanum wheel programming in C++

Quote:
Originally Posted by johncap100 View Post
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.


Reply With Quote
  #5   Spotlight this post!  
Unread 10-01-2011, 21:01
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
Re: Mechanum wheel programming in C++

Quote:
Originally Posted by johncap100 View Post
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.
__________________

Last edited by mikets : 10-01-2011 at 21:12.
Reply With Quote
  #6   Spotlight this post!  
Unread 11-01-2011, 02:28
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: Mechanum wheel programming in C++

Quote:
Originally Posted by mikets View Post
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.

-Joe
Reply With Quote
  #7   Spotlight this post!  
Unread 11-01-2011, 09:37
johncap100 johncap100 is offline
Registered User
FTC #0658
 
Join Date: Aug 2009
Location: Capital High School
Posts: 95
johncap100 is an unknown quantity at this point
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
Reply With Quote
  #8   Spotlight this post!  
Unread 11-01-2011, 12:26
mikets's Avatar
mikets mikets is offline
Software Engineer
FRC #0492 (Titan Robotics)
Team Role: Mentor
 
Join Date: Jan 2010
Rookie Year: 2008
Location: Bellevue, WA
Posts: 667
mikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of lightmikets is a glorious beacon of light
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.
__________________
Reply With Quote
  #9   Spotlight this post!  
Unread 11-01-2011, 15:01
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: Mechanum wheel programming in C++

Quote:
Originally Posted by mikets View Post
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.
Reply With Quote
  #10   Spotlight this post!  
Unread 11-01-2011, 20:32
johncap100 johncap100 is offline
Registered User
FTC #0658
 
Join Date: Aug 2009
Location: Capital High School
Posts: 95
johncap100 is an unknown quantity at this point
Re: Mechanum wheel programming in C++

Quote:
Originally Posted by jhersh View Post
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
Reply With Quote
  #11   Spotlight this post!  
Unread 11-01-2011, 23:28
ChiefDelphi ChiefDelphi is offline
Registered User
no team
 
Join Date: Jan 2011
Location: Canada
Posts: 2
ChiefDelphi is an unknown quantity at this point
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
Reply With Quote
  #12   Spotlight this post!  
Unread 11-01-2011, 23:41
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: Mechanum wheel programming in C++

Quote:
Originally Posted by johncap100 View Post
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 View Post
Did you use two joysticks?
Nope. Just one Extreme 3D Pro.

-Joe
Attached Files
File Type: cpp MecanumDefaultCode.cpp (1.4 KB, 240 views)
Reply With Quote
  #13   Spotlight this post!  
Unread 11-01-2011, 23:48
ChiefDelphi ChiefDelphi is offline
Registered User
no team
 
Join Date: Jan 2011
Location: Canada
Posts: 2
ChiefDelphi is an unknown quantity at this point
Re: Mechanum wheel programming in C++

Quote:
Originally Posted by jhersh View Post
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
Reply With Quote
  #14   Spotlight this post!  
Unread 12-01-2011, 00:55
jhersh jhersh is offline
National Instruments
AKA: Joe Hershberger
FRC #2468 (Appreciate)
Team Role: Mentor
 
Join Date: May 2008
Rookie Year: 1997
Location: Austin, TX
Posts: 1,006
jhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond reputejhersh has a reputation beyond repute
Re: Mechanum wheel programming in C++

Quote:
Originally Posted by ChiefDelphi View Post
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
Reply With Quote
  #15   Spotlight this post!  
Unread 12-01-2011, 07:56
johncap100 johncap100 is offline
Registered User
FTC #0658
 
Join Date: Aug 2009
Location: Capital High School
Posts: 95
johncap100 is an unknown quantity at this point
Re: Mechanum wheel programming in C++

Quote:
Originally Posted by jhersh View Post
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
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 13:23.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


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