Capteurs latéraux
Les capteurs latéraux permettent de détecter des objets proches d'OLEM. Ils les voient jusqu'à 150 mm en ligne droite depuis le capteur. [insérer une image de la zone de détection]
Par commodité, le signal est déjà traité et l'API permet de :
- vérifier si une main est à portée
- vérifier si un élément de jeu est à portée [pourrait devenir obsolète]
- obtenir la valeur du capteur en LSB ou en pourcentage
Le module fournit des constantes pour chaque côté, et des masques pour tester les valeurs renvoyées par ir_side_get_hand_mask() et ir_side_get_obstacle_mask().
Exemple
Le signal du capteur avant est affiché : approchez et éloignez votre main. Voir aussi l'exemple de détection de la main.
import olem
start = olem.get_time_ms()
while olem.get_time_ms() - start < 20000:
value = olem.ir_side_get_sensor_value(olem.FRONT)
percent = olem.ir_side_get_sensor_percent(olem.FRONT)
print(str(value) + " LSB, " + str(percent) + "%")
olem.delay_ms(100)
Constantes et fonctions
Constants
| Constant | Value | Description |
|---|---|---|
FRONT | 0 | Front side of OLEM. |
RIGHT | 1 | Right side of OLEM. |
BACK | 2 | Back side of OLEM. |
LEFT | 3 | Left side of OLEM. |
FRONT_MASK | 1 | Bit of the front side in a side mask. |
RIGHT_MASK | 2 | Bit of the right side in a side mask. |
BACK_MASK | 4 | Bit of the back side in a side mask. |
LEFT_MASK | 8 | Bit of the left side in a side mask. |
ir_side_get_sensor_value(sensor)
Get the signal of a side sensor. Side sensors see objects up to about 150 mm away.
| Parameter | Description |
|---|---|
sensor | FRONT, RIGHT, BACK or LEFT |
Returns: filtered signal in ADC units (LSB), it increases when an object gets closer
ir_side_get_sensor_percent(sensor)
Get the signal of a side sensor as a percentage.
| Parameter | Description |
|---|---|
sensor | FRONT, RIGHT, BACK or LEFT |
Returns: from 0 when nothing is detected to 100 when an object is very close
ir_side_is_hand_present(side)
Check if a hand is in front of a side sensor. A hand gives a weaker signal than an obstacle.
| Parameter | Description |
|---|---|
side | FRONT, RIGHT, BACK or LEFT |
Returns: True if a hand is detected, False otherwise or if side is not valid
ir_side_is_obstacle_present(side)
Check if an obstacle is in front of a side sensor. An obstacle gives a stronger signal than a hand.
| Parameter | Description |
|---|---|
side | FRONT, RIGHT, BACK or LEFT |
Returns: True if an obstacle is detected, False otherwise or if side is not valid
ir_side_get_hand_mask()
Returns: mask with the bit of each side where a hand is detected, test it with FRONT_MASK, RIGHT_MASK, BACK_MASK and LEFT_MASK
ir_side_get_obstacle_mask()
Returns: mask with the bit of each side where an obstacle is detected, test it with FRONT_MASK, RIGHT_MASK, BACK_MASK and LEFT_MASK
ir_side_get_number_of_hands()
Returns: number of sides where a hand is detected, from 0 to 4
ir_side_set_filter(value)
Set the filter applied to the side sensors. A higher value makes them slower to react but more stable. The default value is 5.
| Parameter | Description |
|---|---|
value | filter coefficient, 1 or more |