Hej there
I’m building a device, which should give me its orientation in 360 degrees. To accomplish that, I want to use the Open Source MadgwickAHRS library from http://www.x-io.co.uk/open-source-imu-and-ahrs-algorithms/.
But I don’t even get to compile my code. I’m getting this error message:
“undefined reference to `MadgwickAHRSupdate(float, float, float, float, float, float, float, float, float)’”
I have added the MadgwickAHRS library to my arduino librarys. I’m not the most experienced coder and I have no clue why this error message appears.
Here’s my code:
#include <Wire.h>
#include <LSM303.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_LSM303_U.h>
#include <Adafruit_L3GD20_U.h>
#include "MadgwickAHRS.h"
#include "math.h"
Adafruit_L3GD20_Unified gyro = Adafruit_L3GD20_Unified(20);
Adafruit_LSM303_Accel_Unified accel = Adafruit_LSM303_Accel_Unified(54321);
Adafruit_LSM303_Mag_Unified mag = Adafruit_LSM303_Mag_Unified(12345);
//Serial.write Übertragung
float pitch, roll, yaw;
float gx;
float gy;
float gz;
float ax;
float ay;
double az;
float mx, my, mz;
void displaySensorDetails(void)
{
sensor_t sensor;
accel.getSensor(&sensor);
gyro.getSensor(&sensor);
delay(500);
}
void setup() {
Serial.begin(57600);
Wire.begin();
}
void loop() {
sensors_event_t event;
gyro.getEvent(&event);
gx = 0.1;
gy = 0.1;
gz = 0.5;
accel.getEvent(&event);
ax = 0.1;
ay = 0.1;
az = 0.5;
mag.getEvent(&event);
mx = 0.1;
my = 0.1;
mz = 0.5;
MadgwickAHRSupdate(gx, gy, gz, ax, ay, az, mx, my, mz);
GetEuler();
Serial.print(roll); Serial.print("\t");
Serial.print(pitch);Serial.print("\t");
Serial.print(yaw);Serial.print("\t");
Serial.print("\r\n");
delay(10);
}
void GetEuler(void){
roll = atan2(2 * (q0 * q1 + q2 * q3), 1 - 2 * (q1 * q1 + q2 * q2)) * 360/(2*PI);
pitch = asin(2 * (q0 * q2 - q3 * q1)) * 360/(2*PI);
yaw = atan2(2 * (q0 * q3 + q1 * q2), 1 - 2* (q2 * q2 + q3 * q3)) * 360/(2*PI);
if (yaw < 0){
yaw +=360;
}
}
I really appreciate any help you could offer me, since I should finish this project in 1,5 weeks
Greetz,
kirky