Skip to content

WIP: initial support for fixed-point data for sensors#17408

Draft
raiden00pl wants to merge 10 commits intoapache:masterfrom
raiden00pl:sensors_fixedmath
Draft

WIP: initial support for fixed-point data for sensors#17408
raiden00pl wants to merge 10 commits intoapache:masterfrom
raiden00pl:sensors_fixedmath

Conversation

@raiden00pl
Copy link
Copy Markdown
Member

@raiden00pl raiden00pl commented Nov 29, 2025

Summary

WIP code for fixed-math data type for sensors.

All sensor math operations will require modification to use sensor_data_xxx macros.

At the moment, no sensor is modified to handle this properly. I'll probably choose the easiest sensor to port with a small amount of math operations to provide PoC.

EDIT: ported bmp280_uorb to fixed-math, probably the easiest one :)

Ultimately, all sensor units must be checked to see if the data unit make sense for the b16_t type.

Doing this work all at once is a lot of work which I don't want to do, so I suggest introducing this change gradually:

  1. introducing a configurable sensor data type and raise compilation error in all sensors that don't support fixed-point data type
  2. gradually port sensors to use fixed-point data and remove compilation errors
  3. on the app side we need to modify uorb tools to work with fixed-point data. At this moment we can just raise compilation error for fixed-point data type, and add depends on SENSORS_USE_FLOAT

Impact

Testing

@github-actions github-actions Bot added Area: OS Components OS Components issues Area: Sensors Sensors issues Size: L The size of the change in this PR is large labels Nov 29, 2025
@raiden00pl raiden00pl force-pushed the sensors_fixedmath branch 2 times, most recently from 4dfeb92 to 8cd1558 Compare November 29, 2025 21:15
Comment thread include/nuttx/uorb.h Outdated
@raiden00pl raiden00pl force-pushed the sensors_fixedmath branch 8 times, most recently from 5fdb41a to 329d6ff Compare December 1, 2025 14:22
@github-actions github-actions Bot added the Area: Documentation Improvements or additions to documentation label Dec 1, 2025
@raiden00pl raiden00pl force-pushed the sensors_fixedmath branch 3 times, most recently from 0404a32 to dde5a82 Compare December 1, 2025 16:52
Comment thread drivers/sensors/Kconfig
@linguini1 linguini1 added this to the v13.0.0 milestone Feb 25, 2026
@linguini1
Copy link
Copy Markdown
Contributor

One more thing about this; we should investigate if b16 is ever too small for a sensor's resolution. I would imagine float might have this same problem when compared to double for high-resolution sensors, but if there are any values that would fit in float and not b16, we should consider:

a) having those sensors depend on the float representation, so users can only use them with floats
b) allowing the user to choose b16 vs b32 (and maybe also float vs double)?

What do you think?

@raiden00pl
Copy link
Copy Markdown
Member Author

It would be best to choose sensor units that make sense for both float and fixed-point.

With this architecture it should be possible to add other data types for sensors, but using 64-bit data seems like a overkill to me. So far, the highest resolution of data in commercial available sensors that I have seen is 24 bits.

@lupyuen
Copy link
Copy Markdown
Member

lupyuen commented Mar 20, 2026

Hi @raiden00pl: I'm testing a new way to Build PRs in Our Own NuttX Repos, wonder if you would like to try out, and give your feedback to @simbit18 and me? Thank you so much :-)

  1. Demo Video in YouTube
    Demo Video in Google Drive
  2. Browse to github.com/NuttX/manual-nuttx-ci
  3. Click "Fork" to clone the repo
  4. Click "Actions > Enable GitHub Actions"
  5. Click "Manually Build NuttX > Run Workflow"
  6. Enter the following:
    • Repo for NuttX: raiden00pl/nuttx
    • NuttX Branch: sensors_fixedmath
    • Repo for NuttX Apps: apache/nuttx-apps
    • NuttX Apps Branch: master
    • Host Platform: all
  7. And the PR Build should start. Lemme know if it doesn't work thanks!
  8. Why are we doing this? Earlier this year, we saw very high usage of GitHub Runners. By building PRs in Our Own NuttX Repos, we will greatly reduce our usage of GitHub Runners, so that ASF Infrastructure Team won't revoke our access to GitHub CI. So we hope everyone can help out thanks :-)
Screenshot 2026-03-20 at 5 00 45 PM

@github-actions github-actions Bot added Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. Board: arm and removed Size: L The size of the change in this PR is large labels Mar 29, 2026
new sensor framework can now select between float data type and
fixed-point data type

Signed-off-by: raiden00pl <raiden00@railab.me>
support for fixed-point data for bmp280_uorb

Signed-off-by: raiden00pl <raiden00@railab.me>
support for fixed-point data for bmp180_uorb

Signed-off-by: raiden00pl <raiden00@railab.me>
support for fixed-point data for hyt271_uorb

Signed-off-by: raiden00pl <raiden00@railab.me>
support for fixed-point data for adxl362_uorb

Signed-off-by: raiden00pl <raiden00@railab.me>
support for fixed-point data for adxl372_uorb

Signed-off-by: raiden00pl <raiden00@railab.me>
support for fixed-point data for bh1749nuc_uorb

Signed-off-by: raiden00pl <raiden00@railab.me>
support for fixed-point data for bmm150_uorb

Signed-off-by: raiden00pl <raiden00@railab.me>
support for fixed-point data for bmi270_uorb

Signed-off-by: raiden00pl <raiden00@railab.me>
add sensors scope demo with fixed16 as sensor data type

Signed-off-by: raiden00pl <raiden00@railab.me>
@raiden00pl
Copy link
Copy Markdown
Member Author

I've done some tests with thingy53 and it works well. The only problem is that b16_t saturates faster than float and for some sensors full sensor range can't be achieved. But this is something we have to accept when choosing this type of data.

Here sensors with float:

thingy53_f32

Here sensors with b16_t (you can observe that rgb0 saturate at ~32k) :
thingy53_b16

@linguini1
Copy link
Copy Markdown
Contributor

I'm hoping to try using this with an upcoming project; do you think we could add an option so that the user can choose between b16 and b32? I'm using a barometer in a rocket which should experience a pretty wide range of pressures, I'd like to avoid saturation but like the integer format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Documentation Improvements or additions to documentation Board: arm Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants