adxrs610: Initial implementation

This module was developed and tested on a ADXRS610 Gyro Beakout
board.

http://www.dfrobot.com/index.php?route=product/product&product_id=642

Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
Jon Trulson 2015-10-15 11:19:35 -07:00 committed by Abhishek Malik
parent 639f99691b
commit 53bc249b75
10 changed files with 488 additions and 0 deletions

View File

@ -150,6 +150,7 @@ add_executable (micsv89-example micsv89.cxx)
add_executable (xbee-example xbee.cxx)
add_executable (urm37-example urm37.cxx)
add_executable (urm37-uart-example urm37-uart.cxx)
add_executable (adxrs610-example adxrs610.cxx)
include_directories (${PROJECT_SOURCE_DIR}/src/hmc5883l)
include_directories (${PROJECT_SOURCE_DIR}/src/grove)
@ -264,6 +265,7 @@ include_directories (${PROJECT_SOURCE_DIR}/src/lm35)
include_directories (${PROJECT_SOURCE_DIR}/src/micsv89)
include_directories (${PROJECT_SOURCE_DIR}/src/xbee)
include_directories (${PROJECT_SOURCE_DIR}/src/urm37)
include_directories (${PROJECT_SOURCE_DIR}/src/adxrs610)
target_link_libraries (hmc5883l-example hmc5883l ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (groveled-example grove ${CMAKE_THREAD_LIBS_INIT})
@ -415,3 +417,4 @@ target_link_libraries (micsv89-example micsv89 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (xbee-example xbee ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (urm37-example urm37 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (urm37-uart-example urm37 ${CMAKE_THREAD_LIBS_INIT})
target_link_libraries (adxrs610-example adxrs610 ${CMAKE_THREAD_LIBS_INIT})

71
examples/c++/adxrs610.cxx Normal file
View File

@ -0,0 +1,71 @@
/*
* 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
* "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 <unistd.h>
#include <iostream>
#include <signal.h>
#include "adxrs610.h"
using namespace std;
bool shouldRun = true;
void sig_handler(int signo)
{
if (signo == SIGINT)
shouldRun = false;
}
int main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a ADXRS610 sensor on analog pin A0 (dataout), and
// analog A1 (temp out) with an analog reference voltage of
// 5.0
upm::ADXRS610 *sensor = new upm::ADXRS610(0, 1, 5.0);
// set a deadband region around the zero point to report 0.0 (optional)
sensor->setDeadband(0.015);
// Every tenth of a second, sample the ADXRS610 and output it's
// corresponding temperature and angular velocity
while (shouldRun)
{
cout << "Vel (deg/s): " << sensor->getAngularVelocity() << endl;
cout << "Temp (C): " << sensor->getTemperature() << endl;
usleep(100000);
}
//! [Interesting]
cout << "Exiting" << endl;
delete sensor;
return 0;
}

View File

@ -0,0 +1,57 @@
/*jslint node:true, vars:true, bitwise:true, unparam:true */
/*jshint unused:true */
/*
* 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
* "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.
*/
var sensorObj = require('jsupm_adxrs610');
// Instantiate a ADXRS610 sensor on analog pin A0 (dataout), and
// analog A1 (temp out) with an analog reference voltage of
// 5.0
var sensor = new sensorObj.ADXRS610(0, 1, 5.0);
// set a deadband region around the zero point to report 0.0 (optional)
sensor.setDeadband(0.015);
// Every tenth of a second, sample the ADXRS610 and output it's
// corresponding temperature and angular velocity
setInterval(function()
{
console.log("Vel (deg/s): " + sensor.getAngularVelocity());
console.log("Temp (C): " + sensor.getTemperature());
}, 100);
// exit on ^C
process.on('SIGINT', function()
{
sensor = null;
sensorObj.cleanUp();
sensorObj = null;
console.log("Exiting.");
process.exit(0);
});

View File

@ -0,0 +1,55 @@
#!/usr/bin/python
# 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
# "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.
import time, sys, signal, atexit
import pyupm_adxrs610 as sensorObj
# Instantiate a ADXRS610 sensor on analog pin A0 (dataout), and
# analog A1 (temp out) with an analog reference voltage of
# 5.0
sensor = sensorObj.ADXRS610(0, 1, 5.0)
## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit
# This function lets you run code on exit
def exitHandler():
print "Exiting"
sys.exit(0)
# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)
# set a deadband region around the zero point to report 0.0 (optional)
sensor.setDeadband(0.015);
# Every tenth of a second, sample the ADXRS610 and output it's
# corresponding temperature and angular velocity
while (1):
print "Vel (deg/s):", sensor.getAngularVelocity()
print "Temp (C):", sensor.getTemperature()
time.sleep(.1)

View File

@ -0,0 +1,5 @@
set (libname "adxrs610")
set (libdescription "upm ADXRS610 gyroscope")
set (module_src ${libname}.cxx)
set (module_h ${libname}.h)
upm_module_init()

99
src/adxrs610/adxrs610.cxx Normal file
View File

@ -0,0 +1,99 @@
/*
* 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
* "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 <iostream>
#include "adxrs610.h"
using namespace std;
using namespace upm;
ADXRS610::ADXRS610(int dPin, int tPin, float aref) :
m_aioData(dPin), m_aioTemp(tPin)
{
// ADC resolution of data and temp should be the same...
m_aRes = (1 << m_aioData.getBit());
m_aref = aref;
setZeroPoint(calibrateZeroPoint());
setDeadband(0.0);
m_centerVolts = aref / 2.0;
}
ADXRS610::~ADXRS610()
{
}
float ADXRS610::getDataVolts()
{
int val = m_aioData.read();
return(float(val) * (m_aref / float(m_aRes)));
}
float ADXRS610::getTemperatureVolts()
{
int val = m_aioTemp.read();
return(float(val) * (m_aref / float(m_aRes)));
}
float ADXRS610::calibrateZeroPoint(unsigned int samples)
{
// The gyro should be in a stable, non-moving state
float sum = 0;
for (int i=0; i<samples; i++)
sum += getDataVolts();
return sum / samples;
}
float ADXRS610::getTemperature()
{
float tempV = getTemperatureVolts();
// nominal 2.5 volts at 25C
if (tempV > m_centerVolts)
return (m_temperatureNom + ((tempV - m_centerVolts) / m_temperatureCoeff));
else
return (m_temperatureNom - ((m_centerVolts - tempV) / m_temperatureCoeff));
}
float ADXRS610::getAngularVelocity()
{
float dataV = getDataVolts();
// check the deadband
if (dataV < (m_zeroPoint + m_deadband) &&
dataV > (m_zeroPoint - m_deadband))
return 0.0;
if (dataV > m_zeroPoint)
return ((dataV - m_zeroPoint) / m_degreeCoeff);
else
return -((m_zeroPoint - dataV) / m_degreeCoeff);
}

173
src/adxrs610/adxrs610.h Normal file
View File

@ -0,0 +1,173 @@
/*
* 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
* "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.
*/
#pragma once
#include <iostream>
#include <string>
#include <mraa/aio.hpp>
namespace upm {
/**
* @brief DFRobot ADXRS610 Gyro Beakout board
* @defgroup adxrs610 libupm-adxrs610
* @ingroup dfrobot analog compass
*/
/**
* @library adxrs610
* @sensor adxrs610
* @comname DFRobot ADXRS610 Gyro Beakout board
* @altname ADXRS610
* @type compass
* @man dfrobot
* @web http://www.dfrobot.com/index.php?route=product/product&product_id=642
* @con analog
*
* @brief DFRobot ADXRS610 Gyro Beakout board
*
* The ADXRS610 is a MEMS based single axis gyroscope with a range
* of +/- 300 degrees/sec. It also incorporates a temperature
* sensing unit that can be used for advanced calibration.
*
* This sensor returns an analog voltage proportional to the
* rotation about the Z-axis in degrees/sec. The temperature
* component returns a proportional analog values in degrees C.
*
* This driver was developed using the DFRobot ADXRS610 Gyro Beakout board.
*
* @snippet adxrs610.cxx Interesting
*/
class ADXRS610 {
public:
/**
* ADXRS610 constructor
*
* @param dPin Analog pin to use for DATAOUT
* @param tPin Analog pin to use for temperature measurement
* @param aref Analog reference voltage; default is 5.0 V
*/
ADXRS610(int dPin, int tPin, float aref=5.0);
/**
* ADXRS610 destructor
*/
~ADXRS610();
/**
* Returns the voltage detected on the DATA analog pin
*
* @return The detected voltage
*/
float getDataVolts();
/**
* Returns the voltage detected on the TEMP analog pin
*
* @return The detected voltage
*/
float getTemperatureVolts();
/**
* This method allows you to specify a deadband region around the
* zero point of the gyro (at rest). This can be used as a
* primitive filter to ignore movment around the zero point.
*
* @param deadband The voltage around the zero point which will be
* ignored
*/
void setDeadband(float deadband) { m_deadband = deadband; };
/**
* Set the zero point. This is the point measured and averaged
* when the sensor is not moving. It is set at construction time
* (averaged over a number of samples), but can be overriden here.
*
* @param zeroPoint The averaged zero point of the sensor at rest
*/
void setZeroPoint(float zeroPoint) { m_zeroPoint = zeroPoint; };
/**
* This method samples the data pin samples times to produce an
* average. This value can then be used as the zero point
* (setZeroPoint()).
*
* @param samples the number of samples to take an average over.
* The default is 50.
* @return the average of the reading over samples times.
*/
float calibrateZeroPoint(unsigned int samples=50);
/**
* Return the zero point value.
*
* @return the current zero point value
*/
float getZeroPoint() { return m_zeroPoint; };
/**
* Return the measured temperature in Celcius. Note, the
* datasheet says that this value is very repeatable, but is not
* an accurate absolute temperature.
*
* @return the current temperature in C
*/
float getTemperature();
/**
* Return the measured angular velocity in degrees/sec.
*
* @return the current angular velocity in degrees/sec
*/
float getAngularVelocity();
protected:
mraa::Aio m_aioData;
mraa::Aio m_aioTemp;
private:
float m_aref;
// ADC resolution
int m_aRes;
// measured or set zero point value
float m_zeroPoint;
// desired deadband, default is 0.0
float m_deadband;
// aref / 2
float m_centerVolts;
// volts per degree / second (typ)
static const float m_degreeCoeff = 0.006;
// volts per degree C (typ)
static const float m_temperatureCoeff = 0.009;
// nominal temperature at m_centerVolts
static const float m_temperatureNom = 25.0;
};
}

View File

@ -0,0 +1,8 @@
%module javaupm_adxrs610
%include "../upm.i"
%{
#include "adxrs610.h"
%}
%include "adxrs610.h"

View File

@ -0,0 +1,8 @@
%module jsupm_adxrs610
%include "../upm.i"
%{
#include "adxrs610.h"
%}
%include "adxrs610.h"

View File

@ -0,0 +1,9 @@
%module pyupm_adxrs610
%include "../upm.i"
%feature("autodoc", "3");
%include "adxrs610.h"
%{
#include "adxrs610.h"
%}