This code in the Nano 33 BLE IMU tutorial says to use map() to convert accelerations to degrees:
/*
Arduino LSM9DS1 - Accelerometer Application
This example reads the acceleration values as relative direction and degrees,
from the LSM9DS1 sensor and prints them to the Serial Monitor or Serial Plotter.
The circuit:
- Arduino Nano 33 BLE
Created by Riccardo Rizzo
Modified by Jose García
27 Nov 2020
This example code is in the public domain.
*/
#include <Arduino_LSM9DS1.h>
float x, y, z;
int degreesX = 0;
int degreesY = 0;
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("Started");
if (!IMU.begin()) {
Serial.println("Failed to initialize IMU!");
while (1);
}
Serial.print("Accelerometer sample rate = ");
Serial.print(IMU.accelerationSampleRate());
Serial.println("Hz");
}
void loop() {
if (IMU.accelerationAvailable()) {
IMU.readAcceleration(x, y, z);
}
if (x > 0.1) {
x = 100 * x;
degreesX = map(x, 0, 97, 0, 90);
Serial.print("Tilting up ");
Serial.print(degreesX);
Serial.println(" degrees");
}
if (x < -0.1) {
x = 100 * x;
degreesX = map(x, 0, -100, 0, 90);
Serial.print("Tilting down ");
Serial.print(degreesX);
Serial.println(" degrees");
}
if (y > 0.1) {
y = 100 * y;
degreesY = map(y, 0, 97, 0, 90);
Serial.print("Tilting left ");
Serial.print(degreesY);
Serial.println(" degrees");
}
if (y < -0.1) {
y = 100 * y;
degreesY = map(y, 0, -100, 0, 90);
Serial.print("Tilting right ");
Serial.print(degreesY);
Serial.println(" degrees");
}
delay(1000);
}
Does this mean that the Nano 33 BLE's accelerometer and the Arduino Library (at github) returns accelerations as degrees around the axes? Or is is map(x*100, 0, 97, 0, 90)
just a sloppy estimate of atan2(x,z)*180/pi
?
How is x_acc=0.97 supposed to mean "Tilting up 90 degrees"?