NeoBirth / accelerometer.rs

Generic Rust accelerometer support, including traits and types for taking readings from 2 or 3-axis accelerometers
Apache License 2.0
26 stars 10 forks source link

Raw acceleration vs normalized #51

Closed tarcieri closed 4 years ago

tarcieri commented 4 years ago

Right now the Accelerometer::acceleration method returns a raw device-specific acceleration vector.

It'd be nice to also add a method for computing an acceleration vector normalized to the device's current sensitivity, e.g. an f32 G value normalized between 0.0..0.1.

Suggested API change:

Related: API for obtaining the current sensitivity? e.g. this example enum from the adxl343 crate

gerber4 commented 4 years ago

I second this idea. It's hard to write portable drivers if the data isn't normalized.

gerber4 commented 4 years ago

An alternative to the a normalized vector and a sensitivity value is having a single normalized vector. Simply return a vector of floats representing acceleration in G's.

{0.0, 5.2, 0.0} - 5.2 G's of acceleration in the y axis

tarcieri commented 4 years ago

Yeah, that’s a good idea. I think that’s what I meant to propose with accel_norm but re-reading what I wrote it’s a bit unclear.

tarcieri commented 4 years ago

Also happy to accept a PR for this

gerber4 commented 4 years ago

How would I go about selecting the appropriate f32 vector size?

tarcieri commented 4 years ago

Should just be F32x2 or F32x3?

tarcieri commented 4 years ago

Resolved by #53