|
|
|
![]() |
|
|||||||
|
||||||||
|
|
Thread Tools |
Rating:
|
Display Modes |
|
#4
|
||||
|
||||
|
Re: Mechanum wheel programming in C++
Quote:
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
|
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|