# How to use/program mechanum wheels

Hey guys,

my team is using mechanum wheels and we are want to know how to power and program them. We attachted them and now we have no idea how to power and program them. Thanks

If you use the search functions of the forum for mechanum,
you’ll find this thread with code examples.
https://vexforum.com/t/programming-mecanum-drive/21429/1&highlight=mechanum

Mechanums are used for holonomic drive, so holonomic and omni might be good keywords to search for also.

There is also a holonomic drive function in EasyC, which can help you get started.

The Advanced Search of this Forum is very good at locating information in Threads… But spelling does count!!

Search for “mecanum” or “holonomic” or both.

This has been one of my favorite Mecanum threads, Programming Mecanum Wheels.

Another search found this thread
https://vexforum.com/t/omni-directional-motion/22139/1

which has the code I posted before.

``````task
DriveSystem()
{
int drive_l_front;
int drive_l_back;
int drive_r_front;
int drive_r_back;

int forward, right, clockwise;

while(true)
{
// Get joystick values
// deadband near center of joysticks
forward = vexRT Ch3 ];
if( abs( forward ) < 10 )
forward = 0;

right = vexRT Ch4 ];
if( abs( right ) < 10 )
right = 0;

clockwise = vexRT Ch1 ];
if( abs( clockwise ) < 10 )
clockwise = 0;

// Set drive
drive_l_front = forward + clockwise + right;
drive_l_back  = forward + clockwise - right;
drive_r_back  = forward - clockwise + right;
drive_r_front = forward - clockwise - right;

// normalize drive so max is 127 if any drive is over 127
int max = abs(drive_l_front);
if (abs(drive_l_back)  > max)
max = abs(drive_l_back);
if (abs(drive_r_back)  > max)
max = abs(drive_r_back);
if (abs(drive_r_front) > max)
max = abs(drive_r_front);

if (max>127) {
drive_l_front = 127 * drive_l_front / max;
drive_l_back  = 127 * drive_l_back  / max;
drive_r_back  = 127 * drive_r_back  / max;
drive_r_front = 127 * drive_r_front / max;
}

// Send to motors
// left drive
SetMotor( MotorLF, drive_l_front);
SetMotor( MotorLB, drive_l_back);

// right drive
SetMotor( MotorRF, drive_r_front);
SetMotor( MotorRB, drive_r_back);

wait1Msec( 25 );
}
}``````

The key part of this code is

``````        // Set drive
drive_l_front = forward + clockwise + right;
drive_l_back  = forward + clockwise - right;
drive_r_back  = forward - clockwise + right;
drive_r_front = forward - clockwise - right;
``````

It’s not that different from arcade drive for four wheels, the one extra variable in these equations is called “right” which is the strafing motion.