Programming Mecanum drive

I am the programmer for my robotics team. This year we are considering a mecanum drive system. Does anybody have any ideas for a good drive straight function?

Are you looking for tank or arcade? We use Mecanum wheels with arcade controls and basically we use (±)y(±)x1(±)x2. This is just different combinations of the channels on the two joysticks. I’m sure that there were other ways to do it but we find that this system works.

This is actually for autonomous, I have seen many tutorials for programming driver control and I’m not too worried about that yet. What I’m more stumped on is comparing 4 different encoder values, then what to do with them. Also how to proportionality give different power to those different motors.

I’ve uploaded my robot control code here:

push both of the rods left/right for horizontal movement, and push forward/backward for normal tank drive style.

you may adjust the motor ports and reverse if required (1 for reverse) by editing global variables & macros (press F6)

Wow this is going to be very helpful, Thank you!
I think I have to download EasyC in the near future…

I’m not sure the best way to do it with 4 encoders, but this year one of my teams used a gyro for keeping straight and a single encoder to track distance.


x drive or
square drive?


Aperture science

good luck,

Richard P

if you have two encoders then subtract one value from another the tell the code wait1msc is it does not change by that much the tell it to stop and in auto you won`t burn your motors out on the mecanums


Aperture science

good luck,

Richard P

how much is a gyro?


Aperture science

cheers and good luck,

Richard P


How precise is that? I know that the gyro has drift, but is it very complicated to compensate for this? Also would you just modify the power for the left and right side instead of left front, right front, left back, and right back?

That is a very good idea for a software breaker! I used a timeout function this year, although I think I’m going to implement this in sack attack.

We had a Mechanum drive on our robot this past year.
A simple three axis (stick) drive code would be:

motor[frontRight] = Y1 - X2 - X1;
motor[backRight] =  Y1 - X2 + X1;
motor[frontLeft] = Y1 + X2 + X1;
motor[backLeft] =  Y1 + X2 - X1;

(from the ROBOTC blog post:

We made sure all our wheels went straight when the drive motors were set to full power. In Autonomous, we just made the motors go full power for the duration we wanted the robot to go straight. That would be the simplest approach. If that weren’t accurate enough, I’d lower the output power and use a gyro and a PID loop to correct the drive by + or - some value to make sure it goes straight. Third, I’d use encoders on two of the wheels and make sure that they were going the same Speed/Derivative/Delta.

There still would be one problem left though; how would the robot make sure it was not unintentionally strafing off to the side?

You might want to check out this video I mad back when they were released:

Last year we used a single encoder and a gyro to do all our autonomous controls, and this worked perfectly fine. We were able to consistently score 4 of the 5 isolation game pieces, with the errors coming mostly from how the driver set the robot up on the field.

The robot is field-orientated, meaning that it does not matter how the robot is orientated, the driver will always push forward to move the robot away from him backwards for towards him, ect. The same code that was used in telly-op for the drive, was also used in our autonomous. The only thing different was that, instead of the driver setting the drive values by moving the joystick, the values were coded into the drive function calls.

To answer the question about gyro drift/accuracy, they are accurate down to 1/10 of a degree, and we were seeing only about 1/10 of a degree of drift every 10 seconds, or 1/100 of a degree a second. This puts the total drift for a match under 2 degrees, which is well below vales that might effect performance. I was also pleasantly surprised about how well they did when they got hit. I expected them to quickly get misaligned, but that rarely ever happened.

I’m willing to help out anyone that would like it, and I can also put up the code for our field-orientated drive.

Excellent Tutorial!!

Paint might be simple, but it gets the Point Across to the Viewer.

You might Post your Pseudocode, or at least a Screen Shot of it in the Video…

I have Subscribed to your YouTube Channel… I am expecting more excellent work in the Future…

Alright, this has been irking me far too long…

MarkO, why do you capitalize every few words?

It sounds like you’re really excited about everything :smiley:

Yes, I tend to Over Capitalize…

I do it for Emphasis. :wink: ( I do use italic and bold on the Forum too, or Better Yet, Combine Both… )

I realize that I tend to do this Emphasizing while Speaking as well. My written words are a reflection of my speech. But the written word is much harder for me to bring the points across. ( There… bold rather than Capitols… )

Also, I really am Excited about this stuff…

( I also use multiple periods at the ends of sentences, to imply a Longer Pause. As well as liberal whitespace between thoughts, just to slow you down…)

Well, thank you. I don’t normally do things like that, but when I saw the mecanum wheels released, I wanted to make sure people had info on how to program them. I was going to post code as well, but then I saw that ROBOTC had posted their’s, so I didn’t. Hopefully I can provide more “excellent work” :smiley: .