Skip to main content

Side sensors

The side sensors can be used to detect objects near OLEM. They can be seen up to 150 mm in a straight line from the sensor. [insert image of sensing area]

For convenience, the signal is already processed and the API can be used to :

  • Check if a hand is in range
  • Check if a game element is in range [May be deprecated]
  • Get the sensor value in LSB or percent

The module comes with constants for each side, and masks to test the values returned by ir_side_get_hand_mask() and ir_side_get_obstacle_mask().

Example​

The signal of the front sensor is printed: move your hand closer and further. See also the hand detection example.

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)

Constants and functions​

Constants​

ConstantValueDescription
FRONT0Front side of OLEM.
RIGHT1Right side of OLEM.
BACK2Back side of OLEM.
LEFT3Left side of OLEM.
FRONT_MASK1Bit of the front side in a side mask.
RIGHT_MASK2Bit of the right side in a side mask.
BACK_MASK4Bit of the back side in a side mask.
LEFT_MASK8Bit 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.

ParameterDescription
sensorFRONT, 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.

ParameterDescription
sensorFRONT, 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.

ParameterDescription
sideFRONT, 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.

ParameterDescription
sideFRONT, 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.

ParameterDescription
valuefilter coefficient, 1 or more