
17-01-2011, 23:03
|
|
Registered User
 FRC #3038 (I.C.E. Robotics)
Team Role: Mentor
|
|
Join Date: Jan 2009
Rookie Year: 2009
Location: Stacy, Minnesota
Posts: 494
|
|
|
Re: Mechanum wheel programming in C++
Quote:
Originally Posted by Ether
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.
|
So with that code I can just pop it into my code and it should work or will it have to be modified.?
|