1

I have one temperature sensor that provides values with 0.25 °C of resolution but has an accuracy of ± 3 °C.

So if I get 23.75 °C it could actually be anything between 26.75 °C and 20.75 °C. How can I specify this using the UserSensor.Builder()?

Should I use setResolution()? And what value should I provide? 6? 3? 0.25?

Edit
I just want to explain why this feature could be needed: I might have multiple sensors of the same kind, each with different accuracy, and I would like to take the one with better accuracy.

For example I can have my sensor, with resolution of 0.25 °C and an accuracy of ± 3 °C, and another temperature sensor with resolution of 0.5 but accuracy of ± 1 °C. I would like the system to pick the second sensor since the accuracy is better than the 1st one.

Roberto Leinardi
  • 10,641
  • 6
  • 65
  • 69

1 Answers1

1

"I have one temperature sensor that has an accuracy of ± 3 °C. So if I get 23.75 °C it could actually be anything between 26.75 °C and 20.75 °C. How can I specify this using the UserSensor.Builder()?"

There is no method for setting sensor accuracy in UserSensor.Builder.

"Should I use setResolution()? And what value should I provide? 6? 3? 0.25?"

According to the HAL documentation, resolution is "the smallest difference in value that the sensor can measure. Usually computed based on maxRange and the number of bits in the measurement."

As your sensor "provides values with 0.25 °C of resolution" you should use setResolution() with the value for setting its resolution, not accuracy.

"I might have multiple sensors of the same kind, each with different accuracy, and I would like the system to pick the one with better accuracy".

The system can't do it for you. You should implement an algorithm for "picking the right" sensor. As a criteria you could take the one with higher accuracy according to specification of the sensors.

Onik
  • 19,396
  • 14
  • 68
  • 91
  • The use case is the following: a system can have multiple temperature sensors with different accuracy, I would like for the system to pick the one with better accuracy, similarly to what happens with the location service when both GPS and network are available. – Roberto Leinardi Jan 08 '18 at 10:18
  • @Roberto Leinardi, _"similarly to what happens with the location service when both GPS and network are available"_ I believe it happens not on the "system-sensor-level". There is some level of abstraction whose implementation decides which sensor it trusts the most among the signals measured by the system... Anyways, I edited the answer – Onik Jan 08 '18 at 14:34
  • _"Doubt, the system can do it for you. Implement an algorithm that would pick the "right" sensor. As a criteria you could take the one with higher accuracy :)"_ But how do I know which one has the higher accuracy if there is no way to specify that in the `UserSensor`? And why the `SensorEventListener` has a callback `onAccuracyChanged()`? – Roberto Leinardi Jan 08 '18 at 14:41
  • @Roberto Leinardi, can you distinguish which sensor a signal came from (after setting sensors names or UUIDs)? If so, you know each sensor's accuracy (w.r.t its specs)... Can't really say much about `onAccuracyChanged()`. I guess one can write an own implementation of `UserSensor` class for location and notify via the listener when accuracy has changed, say, from km to m, according to some internal algorithm... – Onik Jan 08 '18 at 14:53
  • @Roberto Leinardi, can you extend `UserSensor` and `UserSensor.Builder` adding some `setAccuracy()` method? – Onik Jan 08 '18 at 15:28
  • the sources are not available and the library is providing only stubs for the documented public methods (that are also final btw). – Roberto Leinardi Jan 08 '18 at 16:22
  • @Roberto Leinardi, I was talking about inheritance and adding a new method, not overriding a final method of parent... The key point is that you cannot set accuracy via `UserSensor.Builder`. I have answered your questions. By me, the part about "different accuracy" is a subject of discussion and your concrete implementation, not system. – Onik Jan 08 '18 at 17:03