Deutsch English |
YOU LEARN HERE... |
how you can measure and analyse distances with an ultrasonic sensor. |
HOW DOES AN ULTRASONIC SENSOR WORK? |
The Maqueen sensor can measure distances in the range from approx. 5 to 200 cm and returns the values in cm. If there is no object in the measuring range, it returns the value 255 or -1. |
EXAMPLES |
Program: from mbrobot import * #from mbrobot_plus import * setSpeed(30) forward() repeat: d = getDistance() if d < 20: backward() else: forward() delay(100)
Program: from mbrobot import * #from mbrobot_plus import * def searchTarget(): repeat: right() delay(50) dist = getDistance() if dist != 255: right() delay(500) break setSpeed(20) searchTarget() forward() You define the search process in the searchTarget() function. The robot turns a small angle to the right and measures the distance. If it detects an object (the sensor no longer returns the value 255 or value -1), it rotates a little further so that it is directed towards the centre of the object. You can cancel the repeat loop with breakto end the search process. The searchTarge() function is called in the main programme and the robot moves to the object after the successful search process. Solve task 3 and complete the programme so that the robot stops in front of the object. A modern industrial plant without sensors is hardly conceivable today. We are also surrounded by sensors in our everyday lives. Modern cars have 50 - 100 different sensors: Distance sensors, RPM and speed sensors, petrol tank fill level sensor, temperature sensor, etc. When parking, distance sensors are used that work in a similar way to those of our little mbRobot.
|
REMEMBER YOU... |
The getDistance() instruction returns the value of the ultrasonic sensor. The sensor values are measured periodically in a repeat loop, delay(100) determines the measurement period. This instruction is important because otherwise the values are queried too frequently, which can lead to the microprocessor being overloaded. |
TO SOLVE BY YOURSELF |
|