check_sensor_in_range()
  • 1 Minute to read

check_sensor_in_range()


Article Summary

Check if the current value of a continuous sensor is inside/outside a range.

Reference

Arguments

ArgumentsTypeDefault value
sensor_pathstringPath of the sensor to read, see the list of sensors.
lower_boundfloat-infThe lower bound against which the sensor value will be compared.
higher_boundfloatinfThe higher bound against which the sensor value will be compared.
inside_rangeboolTrueBoolean representing return value when sensor is inside the range.
abs_valboolFalseIf true, take absolute value of sensor value before comparing it (lower and higher bound must be positive).

Note that if abs_val is True, lower_bound or/and higher_bound must be positive to have effect.

Return

TypeDescription
boolTrue if the value of the sensor inside (inside_range=True) / outside (inside_range=False) the specified range.

Exceptions

  • RayaSensorsInvalidPath

See the complete sensors exceptions.

Examples

Checking obstacle

Chek if there are any object behind the robot (using ultrasonic sensor number 2), less than 30 centimeters:

...
if self.sensors.check_sensor_in_range("/sonar/2", lower_bound=0.3):
    self.log.info('Obstacle detected!')
else:
    self.log.info('No obstacle')
...

Checking temperature

Chek if ambient temperature is not between 20 and 25 degrees.

...
if self.sensors.check_sensor_in_range("/temperature/ambient", lower_bound=20.0, higher_bound=25.0, inside_range=False):
    self.log.info('Not good temperature!!')
...

Was this article helpful?