get_sensor_value()
  • 1 Minute to read

get_sensor_value()


Article summary

Synchronously get current value of a sensor.

Reference

Arguments

ArgumentType
sensor_pathstringPath of the sensor to read, see the list of sensors

Return

Curent value of the sensor or group of sensors (see the examples below).

Exceptions

ExceptionCondition
RayaSensorsExceptionException from sensors method.
RayaSensorsUnknownPathUnknown sensor path.
RayaSensorsIncompatiblePathSensor path not compatible with current robot.
RayaSensorsInvalidPathIncorrect sensor path.

See the Full List of Exceptions

Examples

Reading temperature

Works with any continuous sensor

...
temp = self.sensors.get_sensor_value('/temperature')
print(f'Temperature = {temp}C')
print(f'Data type = {type(temp)}')
...

Output:

Temperature = 19.4C
Data type = <class 'float'>

Reading center line sensor

Works with any boolean sensor

...
center_line = self.sensors.get_sensor_value('/line_sensor/1')
print(f'Line state = {center_line}')
print(f'Data type = {type(center_line)}')
...

Output:

Line state = False
Data type = <class 'bool'>

Reading IMU Acceleration

Works with any group of sensors, or any 'incomplete' path

...
imu_acc = self.sensors.get_sensor_value('/imu/lin_acc')
print(f'IMU Acceleration = {imu_acc}')
print(f'Data type = {type(imu_acc)}')
...

Output:

IMU Acceleration = {
    'x' : 0.0024,
    'y' : 0.0438,
    'z' : 0.9763,
}
Data type = <class 'dict'>

Reading all the Sonars

Works with any group of sensors, or any 'incomplete' path

...
sonars = self.sensors.get_sensor_value('/sonar')
print(f'Sonars = {sonars}')
print(f'Data type = {type(sonars)}')
...

Output:

Sonars = {
    '1': 0.25,
    '2': 0.12,
    '3': 0.54,
    ...
}
Data type = <class 'dict'>

Was this article helpful?