Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 2 months ago.
where did you get roll, pitch, yaw??
I have been reading your code for some days now but i cant seem to figue out how did you get the pitch, roll and yaw. i tried to extract part of your code but its like im missing some stuff.
Question relating to:
1 Answer
10 years, 2 months ago.
The eCompass library uses the axis6 structure to pass data to/from the library. Accelerometer and magnetometer data go in, and calibrated magnetometer, Euiler angles (roll, pitch, yaw) and Quaternions come back out.
Thank you very much for answering! Just another question, i have managed to get it to work with a simple code so i can use it for another application (im trying to make an autonomus robot and im using the compass to find my direction) but i have a slight problem with the compass. When i run the program, the compass doesnt seem to be giving me true north, but when i start moving it around it begins to work correctly. i was wondering if you could tell me what im missing to get it to work since the beginning. heres my code (with the exact same libraries):
- include "mbed.h"
- include "eCompass_Lib.h"
- include "MAG3110.h"
- include "MMA8451Q.h"
- include "rtos.h"
- include "SLCD.h"
- define MMA8451_I2C_ADDRESS (0x1d<<1)
eCompass compass; MAG3110 mag( PTE25, PTE24); MMA8451Q acc( PTE25, PTE24, MMA8451_I2C_ADDRESS); DigitalOut red(LED_RED); DigitalOut green(LED_GREEN); Serial pc(USBTX, USBRX); SLCD slcd;
extern axis6_t axis6; extern uint32_t seconds; extern uint32_t compass_type; extern int32_t tcount; extern uint8_t cdebug;
MotionSensorDataCounts mag_raw; MotionSensorDataCounts acc_raw;
void hal_map( MotionSensorDataCounts * acc_data, MotionSensorDataCounts * mag_data) { int16_t t; swap and negate accelerometer x & y t = acc_data->y; acc_data->y = acc_data->x * -1; acc_data->x = t * -1;
negate magnetometer y mag_data->y *= -1;
}
int main() { mag.enable(); acc.enable(); acc.getAxis(acc_raw); mag.getAxis(mag_raw); compass_type = NED_COMPASS; compass.calibrate(); int i = 0; while(1){ acc.getAxis(acc_raw); mag.getAxis(mag_raw); compass.run(acc_raw, mag_raw); compass.calibrate(); pc.printf("Mag: X= %4.1f Y= %4.1f Z= %4.1f\r\n", axis6.fUTmx, axis6.fUTmy, axis6.fUTmz); pc.printf("Yaw = %d\r\n", axis6.yaw); wait(0.01); } }
posted by 09 Oct 2014The calibration of the magnetic compass is not saved to flash so it needs to br re-calibrated on power up. The good news is that the source code is now open source so I can post source when I get time. This would allow you to access the calibration arrays which could be stored, then used to reinitialize at power on to speed recalibration at power up. I have experimented with this and it works, but is not trivial. In the mean time if possible after power up (within the first 30 seconds for fastest calibration) pickup your robot and rotate it (not too fast) 360 degrees about the x, y, and z axles.
posted by 09 Oct 2014When you publish source code ? I need access to calibration arrays which could be stored.
Or how to insert calibration data from Freescale sensor fusion toolbox?
Today i find source code http://www.nxp.com/products/sensors/nxp-sensor-fusion:XTRSICSNSTLBOX?tid=vansensorfusion
posted by 12 Feb 2016