Rotary Encoder can get motor position and speed. This feature of encoder is often used for PID algorithm.

Mecanum wheel often has some problem to move straight because of its irregular wheel shape. In this tutorial, we will write a program to use PID algorithm and make a Mecanum car moving straight.

Rotary Encoder Connection:

Right Encoder OSOYOO Basic Board for Arduino
White wire(GND) GND
Yellow wire(C1) D52
Green wire(C2) D53
Blue wire(VCC) 5V

 

Left Encoder OSOYOO Basic Board for Arduino
White wire(GND) GND
Yellow wire(C1) D50
Green wire(C2) D51
Blue wire(VCC) 5V

Model Y control Pins are same as previous projects:

Motor Connections:
In this project,   the motor connection are different from previous lessons,
Move rear-left motor rom AK3 to BK4
Move rear-right motor from AK1 to BK2

After above change, the new motor connections are:
Front-Right motor to BK1
Rear-Right motor  to BK2
Front-Left motor to BK3
Rear-Left motor to BK4
All AK1,2,3,4 slot has no motor connections

Software Download:
https://osoyoo.com/driver/v5car/pid520.zip

Unzip and run above code, the car will move forward.

As PID algorithm is a little bit complicated to explain in detail,  you need to do some research on PID theory and read   above code carefully.