arduino-libraries / Arduino_LSM6DS3

LSM6DS3 Library for Arduino
GNU Lesser General Public License v2.1
31 stars 32 forks source link

Add calibration feature to determine "zero" position offsets #2

Open sandeepmistry opened 5 years ago

sandeepmistry commented 5 years ago

Suggested by @tigoe:

I'd do the calibration as a library function if we can. If people can call it in setup and know that the offset variables are available, it's more likely it'll get used. If not that, then I'd do one calibrate example, but not put it in every example unless the example needs it. We already have a few examples with too much stuff in them (see WiFi) so I'm all for keeping them simple when possible.

I think we can add the following:

// determine the accelerometer and gyro zero position offsets
// read data continuously for N milliseconds. The boards is expected
// to be lying flat. The calibrate values will not be persisters
IMU.calibrate(int ms);

// get offsets
IMU.getGyroOffsets(int& x, int& y, int& z);
IMU.getAccelerometerOffsets(int& x, int& y, int& z);

// set offsets
IMU.setGyroOffsets(int& x, int& y, int& z);
IMU.setAccelerometerOffsets(int& x, int& y, int& z);

I've added the getters and setting in the proposal above, for if someone wants to manually calibrate once and then persist elsewhere like an SD card.

Thoughts?

tigoe commented 5 years ago

Seems reasonable to me. Since the sensor doesn't support it, this seems like a reasonable backup approach.