Introduction: How to Make Mecanum Wheel Robot and Program It Correctly

About: Creator of things

Let's talk about Mecanum wheels. They are awesome and full of magic and I think everyone should try them once in their lifetime. The Mecanum wheel is an omnidirectional wheel design for a land-based vehicle to move in any direction.

You will find many DIY projects on the internet but none of them seems to program these correctly. All the projects that I came across use buttons to control these magnificent robots which limit their movements to just a few directions. The Mecanum wheels are weird so you can't just attach them to motors like regular wheels. We have to consider the mechanics of the Mecanum wheel while programming them.

In this article, I will show you how to make your own Mecanum wheel robot and program it correctly using a joystick.

Supplies

I have used off-the-shelf hobby parts to make this project. They are easily available on any website. If you want to cut some costs try to get them from Banggood or Aliexpress. If you are a student make a nice presentation or report how you are going to build this project present that to your school or college and ask them for funds I am sure they will help you.

  1. Wemos mini D1
  2. 4 x 360 Servo
  3. 2 x 16340 Li-ion battery
  4. 2 x 16340 battery holder
  5. 4 x Mecanum wheels
  6. SSD1306 0.96 inch I2C OLED display
  7. Perf board(7 x 5 cm)
  8. Male and female header pins
  9. Wires
  10. Soldering equipment

Step 1: Understanding Mechanics of the Mecanum Wheel

Instead of steering Mecanum wheels mechanically, we vary the motor speed and spinning direction to control the movement of the robot. Varying the motor speeds and spinning direction will produce movements in different directions. Please refer to the diagram above red arrows tell us the motor and robot spinning direction. I have explained this concept in the video.

Imagine a robot moving forward then all the forces acting on the wheels will look like this. Now if we try to find out net forces acting on the robot all the forces acting in the X direction and marked in red will cancel each other because they are in the equal and opposite directions to each other. The force in the Y direction will remain because they are parallel and are in the same direction. Now our bot will move forward.

Using the same concept we can find forces in all directions and at the end, we will get four equations one for each wheel. These equations will help us in controlling the bot and are shown below. 

LeftFrontWheel = Speed + Strafe - Turn;
RightFrontWheel = Speed - Strafe - Turn;
LeftBackWheel = Speed - Strafe + Turn;
RightBackWheel = Speed + Strafe - Turn;


Step 2: How to Control the Robt?

The answer is "joystick", this amazing device has two sticks that will allow us to give multiple inputs at the same time. Our control equation has three variables if we use buttons we will have to press 3 buttons at the same time to do any type of complex movement on the other hand joystick is very easy and natural to use.

I wrote an android app that works like a joystick and communicates over wifi. It has two sticks left side stick can move in both X and Y directions while the right side stick can only move in the X direction.

These sticks control the different variables of our control equation. If you move joysticks one at a time you will get very static movement to have some fun using both joysticks at the same time.

Ly 

Controls speed which also means forward and backward

Lx

Controls strafe which means sliding left and right

Rx

Controls the turning of the robot around its geometrical center

A combination of all these parameters will allow you to control the robot in any direction. You don't have to worry about the equations because the motor speeds are calculated in the app itself. App uses these equations to calculate the speed and sends it to the robot over wifi. 

You won't see these equations in the code of the robot because they are implemented in the app. For reference, the equation should be written like this.

Speed = Ly;
Strafe = Lx;
Turn = Rx;
LeftFrontWheel = Ly + Lx - Rx;
RightFrontWheel = Ly - Lx - Rx;
LeftBackWheel = Ly - Lx + Rx;
RightBackWheel = Ly + Lx - Rx;

There are much better ways to control the robot. This is the easiest one because the math is simple. I will implement better and faster methods in the next version. Please do not use this article for any serious work. This is a hobby project to know more about Mecanum wheels read some research papers.

Step 3: ASSEMBLY

The whole project is 3D printed and all the files can be downloaded from the link below. There are only three 3D printing files so it is straightforward to assemble. Please use the explode feature on grabcad to see how every part fits.

I'm using 2mm screws to join the complete chassis together and for attaching Motors to wheels I've designed a hub that can be screwed to the wheel. The Servo horn must be glued to the hub to make a good connection. 

Download CAD files

Step 4: How to Attach Motors and Wheel

We will use 360 servos because they are easy to wire and Wemos does not have enough ports for two motor drivers. The walls are quite thin so be careful not to put too much pressure while screwing. I have included the raw CAD file of the model you can change it there if you like. 

You cannot just attach any wheel to any position. Mecanum wheels are to be connected in a fixed pattern. Please refer to the image above.

Step 5: Circuit Diagram

I am using a 5X7cm, generic perf board. We have two batteries one for Wemos and one for servos. They are not connected together they power them separately but you have to connect the ground wire of both to complete the circuit otherwise it will not work. 

            "REMOVE ALL POWER BEFORE CONNECTING TO THE PC JUST FOR SAFETY"

You can use any other ESP board if you like just change the pins inside the code. The program should work on most boards.

Please refer to the diagram above. I have marked the servos in the diagram and in the code also. 

Fl = Front left wheel

Fr = Font right wheel

Bl = Back left wheel

Br = Back right wheel

Step 6: Code

We will use Arduino to program the robot. By default, you won't see Wemos mini in Arduino. We have to add it to Arduino IDE. Please refer to this article on how to add ESP32 to Arduino IDE

Install these libraries before compiling the code. 

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <Servo.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>   

Servo pins attach servos according to this also refer to the circuit diagram.

 fl.attach(15);//d8-Forward left
 fr.attach(D7);//Forward right
 bl.attach(D6);//Back left
 br.attach(D5);//Back right 

Change your wifi name and password according to your wifi hotspot. Both robot and phone should connect to the same hotspot.

// Set WiFi credentials
#define WIFI_SSID "SINGTEL-42E6" //Wifi name
#define WIFI_PASS "huiweimaev" //Wifi password
#define UDP_PORT 4210 //UDP port name

The robot receives the commands from the app for each wheel and then maps the value to servos.

flss=map(sParams[0].toInt() ,-99,99,1000,2000);//Forward left wheel speed
frs=map(sParams[1].toInt() ,-99,99,1000,2000);//Forward right wheel speed 
bls=map(sParams[2].toInt() ,-99,99,1000,2000);//Back left speed
brs=map(sParams[3].toInt() ,-99,99,1000,2000);//Back right speed

This function calls for various animations for the eyes. Don't be scared by the eyes part those are just random numbers we get after converting the image. The display does not have any practical use here you can ignore it if you don't have the budget.

void eyeMoves(){
 blink_eye();
 lookright();lookright();
 blink_eye();
 lookleft();lookleft();
}

Usually, you see four functions in these types of robot forward, back, left, and right but we have only two one is for stopping the motor and another one takes care of all the movements.

motor_forward() is actually a bad name because it is not just for forward direction this one function controls all direction movement because we pass the speed values as arguments. I am too lazy to change it :)

void motor_forward(int flss,int frs,int bls,int brs)
{
  fl.writeMicroseconds(flss);
  fr.writeMicroseconds(frs);
  bl.writeMicroseconds(bls);
  br.writeMicroseconds(brs);
 }
void motor_stop()
{
  fl.writeMicroseconds(1500);
  fr.writeMicroseconds(1500);
  bl.writeMicroseconds(1500);
  br.writeMicroseconds(1500);
  eyeMoves();  
   }

You might see some additional stuff in the code that is not being used. Feel free to delete it and recompile the code if the robot is still working good job.

Project Github

Step 7: How to Use the Joystick

The android app can be downloaded from Github. After installing it you will see an interface like shown above. Both the bot and phone should be connected to the same wifi hotspot.

To connect to the bot you have to enter the bot IP address and UDP. To get the bot IP address upload the code to Wemos mini and while it is connected to the PC open the serial monitor by going to Tools > Serial monitor then change the baud rate to 115200 and press the reset button on the Wemos. You should see some text out on the serial monitor. If the bot has connected successfully you should see the IP address and UDP port. Note this down and enter it in the app. You should now be able to control the bot.

Step 8: And We Are Done

Yay, you made a robot. At this point, everything must be working. Use both sticks together and do some crazy movements with the robot. The screen is optional it is just there to display the eyes. The eyes are actually animated like the Vector robot. I forgot to record that part later I realized that while editing the video :(

Don't worry I have learned a lot by making this project next version will be much smarter with lots of cool features.

You can contact me on Instagram or Discord if you need any help

Remote Control Contest

Second Prize in the
Remote Control Contest