Deutsch English |
YOU LEARN HERE... |
how the robot can recognise the brightness of the surface with its infrared sensors. |
HOW DOES AN INFRARED SENSOR WORK? |
The infrared sensors can register changes in the immediate field of vision and are often used in practice as motion detectors. The Callibot has 2 infrared sensors. They are located on the lower side of the board. As infrared light reflects differently on light and dark surfaces, these sensors can differentiate between a light and dark surface and return a digital value of 0 (dark) or 1 (light). |
EXAMPLES |
Program: from callibot import * setSpeed(30) repeat: v = irLeftValue() if v == 0: rightArc(0.1) else: leftArc(0.1) delay(100) The robot control depends on the radius of the left or right arc. If it is too small (e.g. 0.05), the robot moves very slowly and unsteadily. If it is too large (e.g. 0.6), it often loses the track
Program: from callibot import * setSpeed(20) repeat: vR = irRightValue() vL = irLeftValue() if vL == 0 and vR == 0: forward() elif vL == 1 and vR == 0: rightArc(0.1) elif vL == 0 and vR == 1: leftArc(0.1) delay(100) Example 3: Move square
Program: from callibot import * def keepOnTrack(): if vL == 0 and vR == 0: forward() elif vL == 0 and vR == 1: leftArc(0.1) elif vL == 1 and vR == 0: rightArc(0.1) repeat: vR = irRightValue() vL = irLeftValue() if vL == 1 and vR == 1: left() delay(500) else: keepOnTrack() delay(100) |
REMEMBER... |
You can use the infrared sensors to measure the brightness of the surface. The irLeft.read_digital() function returns the value of the left infrared sensor as 0 if the base is dark or 1 if it is bright. |
TO SOLVE BY YOURSELF |
|
At the beginning, the state variable s = 0. The state is switched in the while loop
....
s = 0
forward()
repeat:
v = irLeft.read_digital()
if v == 0 and s == 0: # Bei Haltestelle s = 1 ... if v == 1 and s == 1: # Auf weisser Zwischenfahrt s = 2 if v == 0 and s == 2: # Am Endbahnhof ...