check_sensor_in_range()
- 1 Minute to read
check_sensor_in_range()
- 1 Minute to read
Article summary
Did you find this summary helpful?
Thank you for your feedback
Check if the current value of a continuous sensor is inside/outside a range.
Reference
Arguments
Note that if abs_val
is True, lower_bound
or/and higher_bound
must be positive to have effect.
Return
Boolean. True
if the value of the sensor inside (inside_range=True
) / outside (inside_range=False
) the specified range.
Exceptions
Exception | Condition |
---|---|
RayaSensorsException | Exception from sensors method. |
RayaSensorsUnknownPath | Unknown sensor path. |
RayaSensorsIncompatiblePath | Sensor path not compatible with current robot. |
RayaSensorsInvalidPath | Incorrect sensor path. |
RayaInvalidNumericRange | Invalid numeric range: low value ir greater than high value, or one of the range limits is not a number. |
See the Full List of 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):
print('Obstacle detected!')
else:
print('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):
print('Not good temperature!!')
...
Was this article helpful?