mpu9150: rewrite from scratch

This driver has been rewritten from scratch.  It is implemented as 3
seperate drivers now (but all included as part of the mpu9150 UPM
library):

AK8975 (Magnetometer)
MPU60X0 (Accelerometer, Gyroscope, and Temperature sensor)
MPU9150 (composed of AK8975 and MPU60X0)

Each driver can be used independently and includes examples in
C++/JS/Python.

Commonly used capabilities are supported, and methods/register
definitions exist to easily implement any desired functionality that
is missing.  Interrupt support has also been added.

Scaling support has also been properly implemented for both the
Accelerometer and Gyroscope.

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Jon Trulson
2015-07-16 16:56:23 -06:00
committed by Mihai Tudor Panu
parent 6613dea552
commit 03e72e02f8
19 changed files with 2590 additions and 390 deletions

View File

@ -1,6 +1,6 @@
/*
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@intel.com>
* Copyright (c) 2014 Intel Corporation.
* Author: Jon Trulson <jtrulson@ics.com>
* Copyright (c) 2015 Intel Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@ -24,36 +24,58 @@
#include <unistd.h>
#include <iostream>
#include <signal.h>
#include "mpu9150.h"
int
main(int argc, char **argv)
using namespace std;
int shouldRun = true;
void sig_handler(int signo)
{
//! [Interesting]
upm::Vector3D data;
upm::MPU9150 *sensor = new upm::MPU9150(0, ADDR);
sensor->getData ();
sensor->getAcceleromter (&data);
std::cout << "*************************************************" << std::endl;
std::cout << "DEVICE ID (" << (int) sensor->getDeviceID () << ")" << std::endl;
std::cout << "*************************************************" << std::endl;
std::cout << "ACCELEROMETER :: X (" << data.axisX << ")" << " Y (" << data.axisY << ")"
<< " Z (" << data.axisZ << ")" << std::endl;
sensor->getGyro (&data);
std::cout << "GYRO :: X (" << data.axisX << ")" << " Y (" << data.axisY << ")"
<< " Z (" << data.axisZ << ")" << std::endl;
sensor->getMagnometer (&data);
std::cout << "MAGNOMETER :: X (" << data.axisX << ")" << " Y (" << data.axisY << ")"
<< " Z (" << data.axisZ << ")" << std::endl;
std::cout << "TEMPERATURE (" << sensor->getTemperature () << ")" << std::endl;
std::cout << "*************************************************" << std::endl;
//! [Interesting]
std::cout << "exiting application" << std::endl;
delete sensor;
return 0;
if (signo == SIGINT)
shouldRun = false;
}
int main(int argc, char **argv)
{
signal(SIGINT, sig_handler);
//! [Interesting]
upm::MPU9150 *sensor = new upm::MPU9150();
sensor->init();
while (shouldRun)
{
sensor->update();
float x, y, z;
sensor->getAccelerometer(&x, &y, &z);
cout << "Accelerometer: ";
cout << "AX: " << x << " AY: " << y << " AZ: " << z << endl;
sensor->getGyroscope(&x, &y, &z);
cout << "Gryoscope: ";
cout << "GX: " << x << " GY: " << y << " GZ: " << z << endl;
sensor->getMagnetometer(&x, &y, &z);
cout << "Magnetometer: ";
cout << "MX = " << x << " MY = " << y << " MZ = " << z << endl;
cout << "Temperature: " << sensor->getTemperature() << endl;
cout << endl;
usleep(500000);
}
//! [Interesting]
cout << "Exiting..." << endl;
delete sensor;
return 0;
}