Follow an object using the LEGO Mindstorms Ultrasonic Sensor. Object moves away, the robot moves with the object. The program is very useful if you are doing STEM classes and you want to demonstrate results. People react very well to a robot following you like a dog for example.
- 15 Oct 2015
Previous video tutorials:
EV3-G program for following and object with the LEGO Mindstorms EV3 robots
The next program with our ultrasonic sensor is to make the robot follow my hand. Аs I move my hand away from the robot, I would like the robot to follow it and to keep at a distance of about 4 inches, like this.
Download, run the program.
Now I move my hand and the robot moves forward. The only thing that we should add to this program is that when I move my hand the robot should move at exactly the same distance, so it should keep 10 cm.
Move, stop and move my hand and it continues moving. How can we make this process repeatable, moving and keeping distance of 10 cm? Since we want this whole process of moving forward, stopping and moving forward to repeat we need to use a loop.
What we want to repeat are the following blocks. First moving forward, waiting until we see an object, stopping and then waiting until the object moves away and when the object moves away we return to the beginning of the loop and we'll move the motor forward until we detect an object and when the object moves away we start again and move forward for undefined amount of time. This way we'll get our robot to follow the object in this case my hand. Let's see if the program works correctly.
The robot moves forward, reaches my hand, I move my hand and the robot moves with the hand.
What you can see is that we have this not very smooth movement of the motors. How can we improve this? What we want to change in our program is the Tank block with the stop option. We want to change it so it does not break when stopping but to coast, so it's stopping very slowly not immediately and this will probably make following the object a little smoother. Let's see if this works.
I'll stop the program now. Let's run it again and what happens. We move with the robot forward until it sees my hand
but it does not stop.
It moves it's smother but there is a glitch and the glitch happens if the sensor is very near to my hand. Now is following, it's very smooth but if my hand is very near to the sensor, like this, the robot won't stop.
So we have the program for following my hand but as we have the coast option it is possible if the object moves very slowly we actually touch the object and when we are touching the sensor is not able to detect any distance to the object and it's not working as expected. It might return a maximum distance or it might return 0 but if the object touches the sensor, the sensor is not returning correct values. As a result from this video we have a program for following an object that is moving.
In the next video we'll set few tasks that you can implement for the ultrasonic sensor so that you can learn more about it.
Курсове и занятия включващи този Урок
Този Урок е използван в следните курсове и занятия.