Go to Post Engineering fundamentally comes down to problem solving, and if the students can't get excited and inspired by the problem solving process because someone has spoon fed them a solution, then nobody wins. Give a man a fish, he'll eat for a day. Teach a man to fish, he'll eat for a lifetime. - kevinw [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #6   Spotlight this post!  
Unread 13-02-2008, 22:46
Lesman's Avatar
Lesman Lesman is offline
Registered User
FRC #1014 (Bad Robot)
Team Role: Engineer
 
Join Date: Feb 2008
Rookie Year: 2006
Location: Dublin
Posts: 35
Lesman will become famous soon enough
Re: Code For Mecanum Wheels

Could you please explain this code? Ours is a bit uglier (and slower)... I am our team lead for the mechanical aspect of mecanum, but I'm also a bit of a coder (java, but this code is all basic math anyway) so I wrote up our mecanum code. Here is what I have (no rotation in this version):

public static double[] printMotorOutputs(int x, int y)
{
/*
* When not turning mecanum drive has 2 logical pairs of wheels located at opposite corners.
* One of the pairs runs at a constant speed throughout a quadrant, and is scaled only on the
* basis of magnitude. The other pair of wheels change speed based on angle and magnitude.
*/

int angleDrive, magDrive, ratio;

int absX= x<127 ? -(x-127): (x-127); //make 0-255 into 0-127
int absY = y<127 ? -(y-127)y-127);

//we did the math, this SHOULD fit in 16bit integers,
if(absY<absX)
{
ratio = (absY<<7)/absX; // calculate ratio, shift to avoid floats
angleDrive = ((176-((48*ratio)>>7))*ratio)>>7; // = (176*x/y)-(48*x^2/y^2) + magic (tan(y/x) approximation)
angleDrive-=127; // shift 0-255 to -127 to 127 for scaling
angleDrive = (angleDrive*absX)>>7; // scale angleDrive * (x/128)
angleDrive+=127; // shift back
magDrive = absX; // (absX/maxValue)*outputRange = (absX/128)/128
}
else
{
ratio = (absX<<7)/absY;
angleDrive = 255-(((176-((48*ratio)>>7))*ratio)>>7);
angleDrive-=127;
angleDrive = (angleDrive*absY)>>7;
angleDrive+=127;
magDrive = absY;
}

double r1, r2, l1, l2;

if(x > 127)
{
if(y > 127)
{
//System.out.println("Q1");
r1 = angleDrive;
l2 = angleDrive;
r2 = 127+magDrive;
l1 = 127+magDrive;
}
else
{
//System.out.println("Q4");
r1 = 127-magDrive;
l2 = 127-magDrive;
r2 = 255-angleDrive;
l1 = 255-angleDrive;
}
}
else
{
if(y < 127)
{
//System.out.println("Q3");
r1 = 255-angleDrive;
l2 = 255-angleDrive;
r2 = 127-magDrive;
l1 = 127-magDrive;
}
else
{
//System.out.println("Q2");
r1 = 127+magDrive;
l2 = 127+magDrive;
r2 = angleDrive;
l1 = angleDrive;
}
}

return new double[] {(r1-127)/127, (l1-127)/127, (r2-127)/127, (l2-127)/127};
}

the doubles and such are there only because it was integrated with a gui which took a double array, for the real code the doubles were simply replaced with ints. The code is completely commented. It took me a lot of tweaking to make this run fast (yay bit shift). But the code posted looks AMAZINGLY fast, but makes absolutely no sense to me. If you could explain it I would be very grateful.
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Mecanum wheels akash155 General Forum 12 20-02-2007 22:15
Friction coefficients for Omni wheels and Mecanum wheels from AndyMark Andy Baker Technical Discussion 11 16-12-2006 19:40
Looking for Mecanum Wheels Armando Gonzalez General Forum 30 24-05-2006 12:54
Mecanum Wheels chaolin2007 Control System 1 25-02-2006 19:16
Mixing Joystick Values for mecanum wheels Leav Programming 10 15-01-2006 14:51


All times are GMT -5. The time now is 22:33.

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