Initial implementation of iAcceleration

Signed-off-by: Serban Waltter <serban.waltter@rinftech.com>
Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Serban Waltter
2018-07-26 18:06:33 +03:00
committed by Mihai Tudor Panu
parent 90524273ec
commit f992876461
48 changed files with 512 additions and 35 deletions

View File

@ -106,6 +106,28 @@ std::vector<float> ADXL335::acceleration()
return v;
}
std::vector<float> ADXL335::getAcceleration()
{
std::vector<float> v(3);
int x, y, z;
float xVolts, yVolts, zVolts;
x = mraa_aio_read(m_aioX);
y = mraa_aio_read(m_aioY);
z = mraa_aio_read(m_aioZ);
xVolts = float(x) * m_aref / 1024.0;
yVolts = float(y) * m_aref / 1024.0;
zVolts = float(z) * m_aref / 1024.0;
v[0] = (xVolts - m_zeroX) / ADXL335_SENSITIVITY;
v[1] = (yVolts - m_zeroY) / ADXL335_SENSITIVITY;
v[2] = (zVolts - m_zeroZ) / ADXL335_SENSITIVITY;
return v;
}
void ADXL335::calibrate()
{
// make sure the sensor is still before running calibration.

View File

@ -30,6 +30,8 @@
#include <vector>
#include <mraa/aio.h>
#include <interfaces/iAcceleration.hpp>
#define ADXL335_DEFAULT_AREF 5.0
#define ADXL335_SENSITIVITY 0.25 // 0.25v/g
@ -60,7 +62,7 @@ namespace upm {
* @image html adxl335.jpg
* @snippet adxl335.cxx Interesting
*/
class ADXL335 {
class ADXL335: virtual public iAcceleration {
public:
/**
* ADXL335 constructor
@ -130,6 +132,13 @@ namespace upm {
*/
std::vector<float> acceleration();
/**
* get acceleration values
*
* @return stl vector of size 3 representing the 3 axis
*/
virtual std::vector<float> getAcceleration();
/**
* While the sensor is still, measures the X-axis, Y-axis, and Z-axis
* values and uses those values as the zero values.