This guide has been refactored and updated for more sensors, calibration storage, and more algorithms, including quaternion output. Please visit https://learn.adafruit.com/how-to-fuse-motion-sensor-data-into-ahrs-orientation-euler-quaternions to read the new guide!
To help you visualize the data, we've put together a basic Processing sketch that loads a 3D model (in the .obj file format) and renders it using the data generated by the AHRS sketch on the Uno. The ahsr sketch on the uno published data over UART, which the Processing sketch reads in, rotating the 3D model based on the incoming orientation data.
Requirements
- Processing 2.x
- Saito's OBJ Loader library for Processing (installation tips here)
- G4P GUI library for Processing (download the latest version here and copy the zip into the processing libraries folder like the tip for the OBJ loader library above mentions).
Opening the Processing Sketch
The processing sketch to render the 3D model is contained in the sample folder as the ahrs sketch for the Uno.With Processing open, navigate to you Adafruit_AHRS library folder (ex.: 'libraries/Adafruit_AHRS'), and open 'processing/bunnyrotate/bunnyrotate.pde'. You should see something like this in Processing:
Please use Processing 2.2.1 with this sketch ... newer versions have breaking changes at the API level!
Run the AHRS Sketch on the Uno
Make sure that the appropriate AHRS example sketch is running on the Uno (as described on the previous page), and that the Serial Monitor is closed.With the sample sketch running on the Uno, click the triangular 'play' icon in Processing to start the sketch.
Before the rabbit will rotate you will need to click the : to the right of the serial port name. This will open a list of available serial ports, and you will need to click the appropriate serial port that your Arduino uses (check the Arduino IDE to see the port name if you're unsure). The chosen serial port should be remembered if you later run the sketch again.
As you rotate your breakout board, the rabbit should rotate to reflect the movement of the breakout in 3D-space, as seen in the video below (note that this video is using an older version of the cuberotate example and won't look exactly like what you see now):
As you rotate your breakout board, the rabbit should rotate to reflect the movement of the breakout in 3D-space, as seen in the video below (note that this video is using an older version of the cuberotate example and won't look exactly like what you see now):
A Note on Accuracy and Calibration
Note that the movement seen on the screen won't correlate exactly to the breakout since we are currently using uncalibrated sensor data, specifically uncalibrated magnetometer data which will throw the heading off. The magnetometer is required to generate 360° data, and if you want to improve the accuracy of your orientation data we have a tutorial on calibrating the LSM303, but this particular example starts with raw data for simplicity sake.Page last edited March 08, 2024
Text editor powered by tinymce.