Deutsch English |
YOU LEARN HERE... |
how you can measure and analyse distances with an ultrasonic sensor. |
HOW DOES AN ULTRASONIC SENSOR WORK? |
The Callibot 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. |
EXAMPLES |
Program: from callibot import * forward() setSpeed(30) repeat: d = getDistance() if d < 20: backward() else: forward() delay(100)
Program: from callibot import * def searchTarget(): repeat: right() delay(50) dist = getDistance() if dist != 255: right() delay(500) break setSpeed(20) searchTarget() setSpeed(50) 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) it rotates a little further so that it is directed towards the centre of the object. You can cancel the repeat loop with break to 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. You can optimise the program by stopping the robot as soon as it is closer than 5 cm to 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 in our little Callibot.
|
REMEMBER... |
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 |
|