diff --git a/IoT/Eulerangles.svg.png b/IoT/Eulerangles.svg.png new file mode 100644 index 0000000..8429479 Binary files /dev/null and b/IoT/Eulerangles.svg.png differ diff --git a/IoT/SensorNode.adoc b/IoT/SensorNode.adoc index 17c2840..f62a4a5 100644 --- a/IoT/SensorNode.adoc +++ b/IoT/SensorNode.adoc @@ -138,6 +138,121 @@ image:./piandrroll.png[alt="pitchroll"] +== A real AHRS system + + +=== Loading the AHRS Sketch + +.AHRS Sketch +[source,c] +---- +#include +#include +#include +#include +#include + +// Create sensor instances. +Adafruit_LSM303_Accel_Unified accel(30301); +Adafruit_LSM303_Mag_Unified mag(30302); +Adafruit_BMP085_Unified bmp(18001); + +// Create simple AHRS algorithm using the above sensors. +Adafruit_Simple_AHRS ahrs(&accel, &mag); + +// Update this with the correct SLP for accurate altitude measurements +float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA; + +void setup() +{ + Serial.begin(115200); + Serial.println(F("Adafruit 10 DOF Board AHRS Example")); Serial.println(""); + + // Initialize the sensors. + accel.begin(); + mag.begin(); + bmp.begin(); +} + +void loop(void) +{ + sensors_vec_t orientation; + + // Use the simple AHRS function to get the current orientation. + if (ahrs.getOrientation(&orientation)) + { + /* 'orientation' should have valid .roll and .pitch fields */ + Serial.print(F("Orientation: ")); + Serial.print(orientation.roll); + Serial.print(F(" ")); + Serial.print(orientation.pitch); + Serial.print(F(" ")); + Serial.print(orientation.heading); + Serial.println(F("")); + } + + // Calculate the altitude using the barometric pressure sensor + sensors_event_t bmp_event; + bmp.getEvent(&bmp_event); + if (bmp_event.pressure) + { + /* Get ambient temperature in C */ + float temperature; + bmp.getTemperature(&temperature); + /* Convert atmospheric pressure, SLP and temp to altitude */ + Serial.print(F("Alt: ")); + Serial.print(bmp.pressureToAltitude(seaLevelPressure, + bmp_event.pressure, + temperature)); + Serial.println(F("")); + /* Display the temperature */ + Serial.print(F("Temp: ")); + Serial.print(temperature); + Serial.println(F("")); + } + + delay(500); +} +---- + +=== compile + +- Compile the sketch, +- open up the Serial Monitor (Tools > Serial Monitor), +- set the baud rate to 115200 + + +.output +image:./sensors_01_AHRSOutput.png[alt="AHRS raw data"] + + +This raw data shows the main orientation data, consisting of 'roll', 'pitch' and 'heading' (or 'yaw) in degrees, followed by the current altitude and temperature + + +[NOTE] +==== +The AHRS sketchs reads raw data from the board's accelerometer/magnetometer and converts the raw data into easy to understand Euler angles. + +.Euler angles, one of the possible ways to describe an orientation +image:./Eulerangles.svg.png[alt="Euler angles"] + +The first attempt to represent an orientation is attributed to Leonhard Euler. He imagined three reference frames that could rotate one around the other, and realized that by starting with a fixed reference frame and performing three rotations, he could get any other reference frame in the space (using two rotations to fix the vertical axis and other to fix the other two axes). The values of these three rotations are called Euler angles. + +.Tait–Bryan angles, another way to describe orientation +image:./Taitbrianzyx.svg.png[alt="Tait–Bryan angles"] + +These are three angles, also known as yaw, pitch and roll, Navigation angles and Cardan angles. Mathematically they constitute a set of six possibilities inside the twelve possible sets of Euler angles, the ordering being the one best used for describing the orientation of a vehicle such as an airplane. In aerospace engineering they are usually referred to as Euler angles. + +[More info]https://en.wikipedia.org/wiki/Rigid_body_dynamics [More info]https://en.wikipedia.org/wiki/Euler_angles [More info]https://en.wikipedia.org/wiki/Leonhard_Euler + +==== + + + + + + + :hardbreaks: {empty} + diff --git a/IoT/Taitbrianzyx.svg.png b/IoT/Taitbrianzyx.svg.png new file mode 100644 index 0000000..e61ed42 Binary files /dev/null and b/IoT/Taitbrianzyx.svg.png differ diff --git a/IoT/sensors_01_AHRSOutput.png b/IoT/sensors_01_AHRSOutput.png new file mode 100644 index 0000000..8bd88ab Binary files /dev/null and b/IoT/sensors_01_AHRSOutput.png differ