4 Wheel Drive Omnidirectional Maze-Solving Robotic Car
by AnRobot in Circuits > Microcontrollers
256 Views, 2 Favorites, 0 Comments
4 Wheel Drive Omnidirectional Maze-Solving Robotic Car
My teammate and I used this robot(which we decorated to look like Alice in Wonderland) in a recent showcase, as it is one of many robots we created to assemble a robotic performance. Be on the lookout for more Instructables to recreate our Lorax in Wonderland performance, and gain many new skills along the way.
This particular robot is a 4WD robotic car, which uses mecanum wheels to be able to move omni-directionally(a.k.a turn without turning its direction) and ultrasonic sensors to independently travel through a maze!
We used a Raspberry Pi Pico microcontroller as well, in order to run the code.
Skill Level: Intermediate
- Basic Understanding of MicroPython
- Familiar with ultrasonic sensors and circuitry components
Supplies
- Raspberry Pi Pico: Use this link from the official Raspberry Pi website to get started with Pico
- 4 DC motors
- Motor Controller hat(Pico RPD board) to control the 4 DC motors from Pico
- 4 Mecanum Wheels
- 3 ultrasonic sensors
- Car Chassis(or you may make your own like I did using acrylic sheets)
Many of the components above can be found in the following material kit: link
Connect Motors to Motor Controller Hat
The motor controller(Pico RPD board) allows us to connect the 4DC motors, PWM pins, and GPIO pins to the pico. The hat acts as an extension board for pico.
Understanding Mecanum Wheels
Mecanum wheels move forward, backwards, as well as spinning in opposite directions to shift right or left. This can be described as "strafing". The rollers of these wheels are placed at a 45 degree angle, allowing them to move this way, and can be altered to achieve movements in different directions. For example, in addition to strafing, the wheels can move diagonally in all four directions.
Mecanum Wheel Orientation
Because they are oriented diagonally, it is important to arrange Mecanum wheels in a particular alignment. The rollers should be in an "X" shape, pointing to the center of the car chassis.
Mecanum Wheel Control Principle
Now that we understand what the wheels are, and have oriented them correctly, lets get into how we get them to move in the desired directions.
The image above shows the direction each individual wheel on a 4WD moves in to achieve different actions. For example, while going forward means all 4 wheels go forward, going sideways means diagonals move in the same direction).
Tip: When you begin coding, it helps to name each wheel(ie: "top left")
Coding Omnidirectional Feature
When it comes to coding the functions for the various directions you want to move your robot, you can use the Mecanum Wheel Control Principle chart as a guidance for designating power frequencies to each motor.
In order to provide a differing amount of power to each motor, you need to utilize PWM(Pulse with Modulation) which allows for varying duty cycles. The power is provided through a series of pulses, which allows the power to "increase" and "decrease" rather than just turn "on" or "off".
Now, you can set different PWM Duty Cycles to each motor for each function, according to the motion you want your robot to achieve.
Adding Ultrasonic Sensors
The ultrasonic sensors(3x) will use sound waves to detect obstacles in front of them. While one side transmits the sound waves, the other receives the bounced-back wave. Above, I've included both a diagram on how to connect your ultrasonic sensor to RaspberryPico as well as the code logic for calculating the distance of an object, or wall.
By incorporating 3 sensors(one on the left side of the robot, middle, and right), we will ensure that the robot is receiving data from all 3 sides that it will potentially move in, preventing crashes.
If you would like to make your robot move in other directions(ie backwards or diagonal), you could either add a servo motor to turn the existing sensors or simply add more sensors.
Maze Solving Code Logic
Now that the ultrasonic sensors are attached, you can implement while true and if loops to perform the various actions and movements that your omnidirectional robot is capable of doing.
For our project, my teammate and I implemented a "maze solving" logic, where the default movement was going forward. However, if there was an obstacle in the front of the robot, it would stop, check the left side for any obstacles(and move left if there was nothing), then check right. This made for an intelligent robot that can adopt to its given scenario.
That being said, the code took a lot of testing and calibration, especially because it is DIY.
Code Reference
Refer to a copy of the entire code for the Omnidirectional-Maze Solving robot here. It has been tested and run many times:
Downloads
Callibration
Calibrating the motors will take a lot of work, especially as this is a DIY project. Mecanum wheels are not only different from conventional ones(making them more complex) but they are also prone to slipping. Thus, a slight shift in their trajectory can result in an altered path. To avoid this, it is important to change the duty cycle until you achieve the most balanced test runs.
Happy Testing!