get_sensor_value()
- 1 Minute to read
get_sensor_value()
- 1 Minute to read
Article summary
Did you find this summary helpful?
Thank you for your feedback
Synchronously get current value of a sensor.
Reference
Arguments
Argument | Type | |
---|---|---|
sensor_path | string | Path 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
Exception | Condition |
---|---|
RayaSensorsException | Exception from sensors method. |
RayaSensorsUnknownPath | Unknown sensor path. |
RayaSensorsIncompatiblePath | Sensor path not compatible with current robot. |
RayaSensorsInvalidPath | Incorrect 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?