2016-08-09 15:54:14 -06:00
|
|
|
/*
|
|
|
|
* Author: Jon Trulson <jtrulson@ics.com>
|
|
|
|
* Copyright (c) 2016 Intel Corporation.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iomanip>
|
2017-08-30 15:00:29 -07:00
|
|
|
#include <iostream>
|
2016-08-09 15:54:14 -06:00
|
|
|
#include <math.h>
|
|
|
|
#include <signal.h>
|
2017-08-30 15:00:29 -07:00
|
|
|
|
2016-08-09 15:54:14 -06:00
|
|
|
#include "l3gd20.hpp"
|
2017-08-30 15:00:29 -07:00
|
|
|
#include "upm_utilities.h"
|
2016-08-09 15:54:14 -06:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int shouldRun = true;
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
void
|
|
|
|
sig_handler(int signo)
|
2016-08-09 15:54:14 -06:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
if (signo == SIGINT)
|
|
|
|
shouldRun = false;
|
2016-08-09 15:54:14 -06:00
|
|
|
}
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
float
|
|
|
|
rad2deg(float x)
|
2016-08-09 15:54:14 -06:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
return x * (180.0 / M_PI);
|
2016-08-09 15:54:14 -06:00
|
|
|
}
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
int
|
|
|
|
main(int argc, char** argv)
|
2016-08-09 15:54:14 -06:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
signal(SIGINT, sig_handler);
|
|
|
|
//! [Interesting]
|
2016-08-09 15:54:14 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// Instantiate an L3GD20 using default parameters
|
|
|
|
upm::L3GD20 sensor(L3GD20_DEFAULT_I2C_BUS, L3GD20_DEFAULT_I2C_ADDR);
|
2016-08-09 15:54:14 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// set some parameters (these are already the defaults, but are
|
|
|
|
// provided here as an example)
|
2016-08-09 15:54:14 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// 250 deg/s sensitivity
|
|
|
|
sensor.setRange(sensor.FS_250);
|
2016-08-09 15:54:14 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// Set ODR to 95Hz, 25Hz cut-off
|
|
|
|
sensor.setODR(sensor.ODR_CUTOFF_95_25);
|
2016-08-09 15:54:14 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// If you already have calibration data, you can specify it here
|
|
|
|
// sensor.loadCalibratedData(-0.0296269637, -0.0080939643, -0.0077121737);
|
2016-08-09 15:54:14 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// now output data every 100 milliseconds
|
|
|
|
while (shouldRun) {
|
|
|
|
float x, y, z;
|
2016-08-09 15:54:14 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
sensor.update();
|
2016-08-09 15:54:14 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << "Calibrated: " << sensor.getCalibratedStatus() << endl;
|
2016-08-09 15:54:14 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// output is in radians/s
|
|
|
|
sensor.getGyroscope(&x, &y, &z);
|
|
|
|
cout << fixed << setprecision(1) << "Gyroscope x: " << x << " y: " << y << " z: " << z
|
|
|
|
<< " radians" << endl;
|
2016-08-09 15:54:14 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// same data converted to degrees/s
|
|
|
|
cout << "Gyroscope x: " << rad2deg(x) << " y: " << rad2deg(y) << " z: " << rad2deg(z)
|
|
|
|
<< " degrees" << endl;
|
2016-08-09 15:54:14 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// we show both C and F for temperature
|
|
|
|
cout << "Compensation Temperature: " << sensor.getTemperature(false) << " C / "
|
|
|
|
<< sensor.getTemperature(true) << " F" << endl;
|
2016-08-09 15:54:14 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << endl;
|
2016-08-09 15:54:14 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
upm_delay_us(100000);
|
2016-08-09 15:54:14 -06:00
|
|
|
}
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// dump the calibration values if we managed to calibrate
|
|
|
|
if (sensor.getCalibratedStatus()) {
|
|
|
|
float calX, calY, calZ;
|
|
|
|
sensor.getCalibratedData(&calX, &calY, &calZ);
|
2016-08-09 15:54:14 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << setprecision(10) << "Calibration values x: " << calX << " y: " << calY
|
|
|
|
<< " z: " << calZ << endl;
|
|
|
|
}
|
2016-08-09 15:54:14 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << "Exiting..." << endl;
|
2016-08-09 15:54:14 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
|
|
|
return 0;
|
2016-08-09 15:54:14 -06:00
|
|
|
}
|