How to DIY Mecanum Wheel Vehicle at Home?

How to DIY Mecanum Wheel Vehicle at Home?

In this article, I will teach you how to DIY a simple Mecanum wheel at home,  the parts in the article you can buy online or at a nearby retail store.

1. The first step is to assemble a rectangular frame.

2. The second step is to assemble the motor module.

Since the four-wheel speeds of the Mecanum Wheel chassis are constrained, the speed of each wheel must be precisely controlled. Otherwise, the roller will rub against the ground, which will not only make the chassis move abnormally, but also reduce the life of the wheat wheel. Therefore, a coded motor is also needed.

3. In the third step, install the motor module to the prepared frame.

4. Step 4: Install the wheel onto the frame.

5.install the board and wire it.

6. Battery

7. Control

According to the kinematic model of the chassis of the Mecanum Wheel, to fully control its motion, three control quantities are required: X-axis speed, Y-axis speed, and rotation angular speed. There are many ways to generate these three controls. This article uses a USB gamepad. The joystick on the left produces the panning speed and the rocker on the right produces the angular velocity.

8. Coding

#include <Wire.h>
#include <SoftwareSerial.h>
#include “MeOrion.h”

MeUSBHost joypad(PORT_3);
// handle code (red light mode)
// Default: 128-127-128-127-15-0-0-128
// Left one: 128-127-128-127-15-1-0-128
// Right one: 128-127-128-127-15-2-0-128
// Left two: 128-127-128-127-15-4-0-128
// Right second: 128-127-128-127-15-8-0-128
// Triangle: 128-127-128-127-31-0-0-128 (0001 1111)
// Square: 128-127-128-127-143-0-0-128 (1000 1111)
// Fork number: 128-127-128-127-79-0-0-128 (0100 1111)
// Circle: 128-127-128-127-47-0-0-128 (0010 1111)
// Up: 128-127-128-127-0-0-0-128 (0000 0000)
// Down: 128-127-128-127-4-0-0-128 (0000 0100)
// to the left: 128-127-128-127-6-0-0-128 (0000 0110)
// Right: 128-127-128-127-2-0-0-128 (0000 0010)
// Top left: 128-127-128-127-7-0-0-128 (0000 0111)
// Bottom left: 128-127-128-127-5-0-0-128 (0000 0101)
// Upper right: 128-127-128-127-1-0-0-128 (0000 0001)
// Bottom right: 128-127-128-127-3-0-0-128 (0000 0011)
// Choose: 128-127-128-127-15-16-0-128
// Start: 128-127-128-127-15-32-0-128
// Rocker: Right X-Right Y-Left X-Left Y-15-0-0-128

MeEncoderMotor motor1(0x02, SLOT2);
MeEncoderMotor motor2(0x02, SLOT1);
MeEncoderMotor motor3(0x0A, SLOT2);
MeEncoderMotor motor4(0x0A, SLOT1);

// Chassis: a = 130mm, b = 120mm

Float linearSpeed ​​= 100;
Float angularSpeed ​​= 100;
Float maxLinearSpeed ​​= 200;
Float maxAngularSpeed ​​= 200;
Float minLinearSpeed ​​= 30;
Float minAngularSpeed ​​= 30;

Void setup()
{
    // To power on, you can’t just plug in the USB cable to debug.
Motor1.begin();
Motor2.begin();
Motor3.begin();
Motor4.begin();

Serial.begin(57600);
Joypad.init(USB1_0);
}

Void loop()
{
    Serial.println(“loop:”);
//setEachMotorSpeed(100, 50, 50, 100);
If(!joypad.device_online)
    {
        // If the output is offline, re-plug the USB Host’s RJ25 cable and try it out.
        Serial.println(“Device offline.”);
        joypad.probeDevice();
        Delay(1000);
    }
    Else
    {
        Int len ​​= joypad.host_recv();
        parseJoystick(joypad.RECV_BUFFER);
        Delay(5);
    }
//delay(500);
}

Void setEachMotorSpeed(float speed1, float speed2, float speed3, float speed4)
{
motor1.runSpeed(speed1);
motor2.runSpeed(-speed2);
motor3.runSpeed(-speed3);
motor4.runSpeed(-speed4);
}

Void parseJoystick(unsigned char *buf) //Analytic function, print 8 bytes from USB Host
{
    / / Output the data of the handle, debugging
    // int i = 0;
    // for(i = 0; i < 7; i++)
    // {
    // Serial.print(buf[i]); //It won’t work if you connect to the Makeblock Orion.
    // Serial.print(‘-‘);
    // }
    // Serial.println(buf[7]);
    // delay(10);

    // speed increase and decrease
    Switch (buf[5])
    {
        Case 1:
            linearSpeed ​​+= 5;
            If (linearSpeed ​​> maxLinearSpeed)
            {
                linearSpeed ​​= maxLinearSpeed;
            }
            Break;
        Case 2:
            angularSpeed ​​+= 5;
            If (angularSpeed ​​> maxAngularSpeed)
            {
                angularSpeed ​​= maxAngularSpeed;
            }
            Break;
        Case 4:
            linearSpeed ​​-= 5;
            If (linearSpeed ​​< minLinearSpeed)
            {
                linearSpeed ​​= minLinearSpeed;
            }
            Break;
        Case 8:
            angularSpeed ​​-= 5;
            If (angularSpeed ​​< minAngularSpeed)
            {
                angularSpeed ​​= minAngularSpeed;
            }
            Break;
        Default:
            Break;
    }

    
    If ((128 != buf[0]) || (127 != buf[1]) || (128 != buf[2]) || (127 != buf[3]))
    {
        // handle the joystick
        Float x = ((float)(buf[2]) – 127) / 128;
        Float y = (127 – (float)(buf[3])) / 128;
        Float a = (127 – (float)(buf[0])) / 128;
        mecanumRun(x * linearSpeed, y * linearSpeed, a * angularSpeed);
    }
    Else
    {
        Switch (buf[4])
        {
            Case 0:
                mecanumRun(0, linearSpeed, 0);
                Break;
            Case 4:
                mecanumRun(0, -linearSpeed, 0);
                Break;
            Case 6:
                mecanumRun(-linearSpeed, 0, 0);
                Break;
            Case 2:
                mecanumRun(linearSpeed, 0, 0);
                Break;
            Case 7:
                mecanumRun(-linearSpeed/2, linearSpeed/2, 0);
                Break;
            Case 5:
                mecanumRun(-linearSpeed/2, -linearSpeed/2, 0);
                Break;
            Case 1:
                mecanumRun(linearSpeed/2, linearSpeed/2, 0);
                Break;
            Case 3:
                mecanumRun(linearSpeed/2, -linearSpeed/2, 0);
                Break;
            Default:
                mecanumRun(0, 0, 0);
                Break;
        }
    }
}

Void mecanumRun(float xSpeed, float ySpeed, float aSpeed)
{
    Float speed1 = ySpeed ​​- xSpeed ​​+ aSpeed;
    Float speed2 = ySpeed ​​+ xSpeed ​​- aSpeed;
    Float speed3 = ySpeed ​​- xSpeed ​​- aSpeed;
    Float speed4 = ySpeed ​​+ xSpeed ​​+ aSpeed;
    
    Float max = speed1;
    If (max < speed2) max = speed2;
    If (max < speed3) max = speed3;
    If (max < speed4) max = speed4;
    
    If (max > maxLinearSpeed)
    {
        Speed1 = speed1 / max * maxLinearSpeed;
        Speed2 = speed2 / max * maxLinearSpeed;
        Speed3 = speed3 / ma

Share this post