In the previous post, I introduced the structure of a LEGO MindStorms EV3 model – Droid Bot 2. One important feature of this vehicle is the external framework and the guiding wheels mounted on the corners. This design is very popular in both FLL and WRO competitions since it facilitates the squaring up with a wall and running alone the wall.
In this post, I will present the sample code of squaring up and running along the wall in both LEGO block language and MicroPython 2.0. So let’s start now.
Using LEGO Block Language
The following diagram decomposes the overall process of squaring up and running along the wall. Step 1 to 4 are about squaring up. Step 5 and 6 are about running alone the wall. I will introduce them separately in the following sections.
Square up with the wall
What is the purpose of squaring up with the wall? In FLL and WRO competition, a vehicle needs to accomplish several missions without human interference. If you interfere with the vehicle, the referee will deduct some scores. When a vehicle runs a long distance or conducts some missions, it will not always follow a route or stop at a position precisely, due to motor rotation speed deviation or sensor measurement errors, etc.
When the vehicle squares up with the wall, it could erase the accumulated direction deviation and then get ready for the next mission.
First, the vehicle drives toward the wall. It might be not perpendicular to the wall. By using the ultrasonic sensor to measure the distance, it stops when the distance to the wall is less than 20 centimetres. After that, it turns around and reverses back to the wall.
When it is reversing, it could just go back straight. The wheel which reaches the wall first will be blocked by the wall and then wait for the other wheel to reach the wall, thus squaring up finishes.
In the following videos, you could see that no matter the vehicle deviates to left or right, it could always square up with the wall.
However, if the deviation angle is too big, the squaring up will fail, as shown in the left video. In this scenario, the ultrasonic sensor could not identify the existence of wall, so the vehicle will continue moving forward till it touches the wall. When trying to turn around, its body is blocked by the wall and could not turn around to a proper position. After that, it fails to reverse back to the wall and square up.
For this simple code example, you should try to keep the deviation angle within a small range to ensure the success of squaring up. If you want the program to be able to handle situation more flexibly, you should add code to identify the wall’s position and adjust its angle toward the wall first. That is another topic and I will not explain it here.
Run along the wall
After squaring up, the vehicle would turn and then move forward along the wall. To avoid deviating from the wall, you could set the motor power of left motor and right motor slightly different, so the vehicle will run forward with a very slight turn into the wall.
However, don’t set the motor power of the two motors too much different. Otherwise, the vehicle will turn back and lost its direction.
Realize the Same Result by Using LEGO MicroPython 2.0
Using LEGO MicroPython 2.0, we could realize the same result. When you read the following sample code, please note that the power value of MoveTank block in the LEGO EV3 software has different meaning from motor rotation speed in MicroPython 2.0. Therefore, some parameters, such as rotation speed, running time, etc. have been set to different values in MicroPython 2.0.
What I introduced in this post is a passive method, which means, it doesn’t depend on any sensors for measuring status and making adjustment. We could also use sensors to square up with the wall, run along the wall or align with a line. I will introduce those proactive methods in my future post. Stay tuned. Don’t forget to enjoy the coding and have fun!
Note: All the analysis articles are copyright products of http://www.thecodingfun.com. Anyone re-posting them should credit author and original source. Anyone using them for commercial purposes or translating them into other languages should notify TheCodingFun and get confirmation first. All Rights Reserved.
One thought on “Make Your LEGO EV3 Model Square Up and Run Along a Wall”
Pingback: LEGO MindStorms EV3 – Align with a Line – The Coding Fun
Comments are closed.