-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1,088 changed files
with
390,808 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
= Madgwick Library = | ||
|
||
This library wraps the official implementation of MadgwickAHRS algorithm to get orientation of an object based on accelerometer and gyroscope readings | ||
|
||
== License == | ||
|
||
Copyright (c) Arduino LLC. All right reserved. | ||
|
||
This library is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU Lesser General Public | ||
License as published by the Free Software Foundation; either | ||
version 2.1 of the License, or (at your option) any later version. | ||
|
||
This library is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
Lesser General Public License for more details. | ||
|
||
You should have received a copy of the GNU Lesser General Public | ||
License along with this library; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
|
||
|
||
Implementation of Madgwick's IMU and AHRS algorithms. | ||
See: http://www.x-io.co.uk/node/8#open_source_ahrs_and_imu_algorithms | ||
|
||
Date Author Notes | ||
29/09/2011 SOH Madgwick Initial release | ||
02/10/2011 SOH Madgwick Optimised for reduced CPU load | ||
19/02/2012 SOH Madgwick Magnetometer measurement is normalised |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
#include <CurieIMU.h> | ||
#include <MadgwickAHRS.h> | ||
|
||
Madgwick filter; | ||
unsigned long microsPerReading, microsPrevious; | ||
float accelScale, gyroScale; | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
|
||
// start the IMU and filter | ||
CurieIMU.begin(); | ||
CurieIMU.setGyroRate(25); | ||
CurieIMU.setAccelerometerRate(25); | ||
filter.begin(25); | ||
|
||
// Set the accelerometer range to 2G | ||
CurieIMU.setAccelerometerRange(2); | ||
// Set the gyroscope range to 250 degrees/second | ||
CurieIMU.setGyroRange(250); | ||
|
||
// initialize variables to pace updates to correct rate | ||
microsPerReading = 1000000 / 25; | ||
microsPrevious = micros(); | ||
} | ||
|
||
void loop() { | ||
int aix, aiy, aiz; | ||
int gix, giy, giz; | ||
float ax, ay, az; | ||
float gx, gy, gz; | ||
float roll, pitch, heading; | ||
unsigned long microsNow; | ||
|
||
// check if it's time to read data and update the filter | ||
microsNow = micros(); | ||
if (microsNow - microsPrevious >= microsPerReading) { | ||
|
||
// read raw data from CurieIMU | ||
CurieIMU.readMotionSensor(aix, aiy, aiz, gix, giy, giz); | ||
|
||
// convert from raw data to gravity and degrees/second units | ||
ax = convertRawAcceleration(aix); | ||
ay = convertRawAcceleration(aiy); | ||
az = convertRawAcceleration(aiz); | ||
gx = convertRawGyro(gix); | ||
gy = convertRawGyro(giy); | ||
gz = convertRawGyro(giz); | ||
|
||
// update the filter, which computes orientation | ||
filter.updateIMU(gx, gy, gz, ax, ay, az); | ||
|
||
// print the heading, pitch and roll | ||
roll = filter.getRoll(); | ||
pitch = filter.getPitch(); | ||
heading = filter.getYaw(); | ||
Serial.print("Orientation: "); | ||
Serial.print(heading); | ||
Serial.print(" "); | ||
Serial.print(pitch); | ||
Serial.print(" "); | ||
Serial.println(roll); | ||
|
||
// increment previous time, so we keep proper pace | ||
microsPrevious = microsPrevious + microsPerReading; | ||
} | ||
} | ||
|
||
float convertRawAcceleration(int aRaw) { | ||
// since we are using 2G range | ||
// -2g maps to a raw value of -32768 | ||
// +2g maps to a raw value of 32767 | ||
|
||
float a = (aRaw * 2.0) / 32768.0; | ||
return a; | ||
} | ||
|
||
float convertRawGyro(int gRaw) { | ||
// since we are using 250 degrees/seconds range | ||
// -250 maps to a raw value of -32768 | ||
// +250 maps to a raw value of 32767 | ||
|
||
float g = (gRaw * 250.0) / 32768.0; | ||
return g; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
####################################### | ||
# Syntax Coloring Map For MadgwickAHRS | ||
####################################### | ||
|
||
####################################### | ||
# Datatypes (KEYWORD1) | ||
####################################### | ||
|
||
Madgwick KEYWORD1 | ||
|
||
####################################### | ||
# Methods and Functions (KEYWORD2) | ||
####################################### | ||
|
||
update KEYWORD2 | ||
updateIMU KEYWORD2 | ||
getPitch KEYWORD2 | ||
getYaw KEYWORD2 | ||
getRoll KEYWORD2 | ||
|
||
|
||
####################################### | ||
# Constants (LITERAL1) | ||
####################################### | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
name=Madgwick | ||
version=1.2.0 | ||
author=Arduino | ||
maintainer=Arduino <[email protected]> | ||
sentence=Helpers for MadgwickAHRS algorithm | ||
paragraph=This library wraps the official implementation of MadgwickAHRS algorithm to get orientation of an object based on accelerometer and gyroscope readings | ||
category=Data Processing | ||
url=https://github.com/arduino-libraries/MadgwickAHRS | ||
architectures=* |
Oops, something went wrong.