Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FXOS8700CQ SDFileSystem mbed
Fork of AVC_Robot_Controled_Navigation by
lib/magnometer.cpp
- Committer:
- gerardo_carmona
- Date:
- 2014-10-16
- Revision:
- 1:ab09b233da7b
- Parent:
- 0:3a322aad8c88
File content as of revision 1:ab09b233da7b:
// ----- Libraries ------------------------------------------------------------------ #include "mbed.h" #include "FXOS8700CQ.h" #include "magnometer.h" // ----- I/O Pins ------------------------------------------------------------------- FXOS8700CQ fxos(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // SDA, SCL, (addr << 1) // ----- Others --------------------------------------------------------------------- SRAWDATA accel_data; SRAWDATA magn_data; // ----- Variables ------------------------------------------------------------------ double mag_x, mag_y; double avg_x, avg_y; //double average; // ----- Functions ------------------------------------------------------------------ double get_mag_x(){ fxos.get_data(&accel_data, &magn_data); return magn_data.x; } double get_mag_y(){ fxos.get_data(&accel_data, &magn_data); return magn_data.y; } double get_mag_angle(){ double _angle; int16_t _x=0; int16_t _y=0; for (int i = 0; i < 10; i++){ fxos.get_data(&accel_data, &magn_data); avg_x += magn_data.x; avg_y += magn_data.y; //pc.printf("X: %d \tY: %d\r\n", magn_data.x, magn_data.y); //pc.printf("%d\n", magn_data.x); } avg_x = avg_x / 10; avg_y = avg_y / 10; //pc.printf("%d\n", avg_x); _angle = atan2((double)_x, (double)_y) * 180.0 / 3.14159; return _angle; }