mirror of
https://github.com/eclipse/upm.git
synced 2025-03-15 04:57:30 +03:00
Complete accel and gyro implementations for new dynamic friendly interface
Signed-off-by: deadprogram <ron@hybridgroup.com> Signed-off-by: Brendan Le Foll <brendan.le.foll@intel.com>
This commit is contained in:
parent
ee19daedee
commit
90983fde9d
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
* Author: Brendan Le Foll <brendan.le.foll@intel.com>
|
||||||
* Author: Ron Evans (@deadprogram)
|
* Author: Ron Evans (@deadprogram)
|
||||||
* Author: Justin Zemlyansky (@JustInDevelopment)
|
* Author: Justin Zemlyansky (@JustInDevelopment)
|
||||||
* Copyright (c) 2016 Intel Corporation.
|
* Copyright (c) 2016 Intel Corporation.
|
||||||
*
|
*
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining
|
* Permission is hereby granted, free of charge, to any person obtaining
|
||||||
@ -42,12 +42,16 @@ main(int argc, char **argv)
|
|||||||
|
|
||||||
std::cout << "temperature is: " << (sensor->getTemperature() * pow(0.5, 9) + 23) << std::endl;
|
std::cout << "temperature is: " << (sensor->getTemperature() * pow(0.5, 9) + 23) << std::endl;
|
||||||
|
|
||||||
int x, y, z;
|
sensor->updateAccel();
|
||||||
sensor->readAccelerometer(&x, &y, &z);
|
int x = sensor->getAccelX(),
|
||||||
|
y = sensor->getAccelY(),
|
||||||
|
z = sensor->getAccelZ();
|
||||||
printf("accelerometer is: %d, %d, %d\n", x, y, z);
|
printf("accelerometer is: %d, %d, %d\n", x, y, z);
|
||||||
|
|
||||||
int a, b, c;
|
sensor->updateGyro();
|
||||||
sensor->readGyro(&a, &b, &c);
|
int a = sensor->getGyroX(),
|
||||||
|
b = sensor->getGyroY(),
|
||||||
|
c = sensor->getGyroZ();
|
||||||
printf("gyroscope is: %d, %d, %d\n", a, b, c);
|
printf("gyroscope is: %d, %d, %d\n", a, b, c);
|
||||||
|
|
||||||
int axis, direction;
|
int axis, direction;
|
||||||
@ -60,8 +64,13 @@ main(int argc, char **argv)
|
|||||||
usleep(10000);
|
usleep(10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
int m, n, o, p, q, r;
|
sensor->updateMotion();
|
||||||
sensor->readMotion(&m, &n, &o, &p, &q, &r);
|
int m = sensor->getAccelX(),
|
||||||
|
n = sensor->getAccelY(),
|
||||||
|
o = sensor->getAccelZ(),
|
||||||
|
p = sensor->getGyroX(),
|
||||||
|
q = sensor->getGyroY(),
|
||||||
|
r = sensor->getGyroZ();
|
||||||
printf("motion is: %d, %d, %d, %d, %d, %d\n", m, n, o, p, q, r);
|
printf("motion is: %d, %d, %d, %d, %d, %d\n", m, n, o, p, q, r);
|
||||||
|
|
||||||
delete sensor;
|
delete sensor;
|
||||||
|
@ -158,19 +158,55 @@ CurieImu::processResponse()
|
|||||||
int16_t*
|
int16_t*
|
||||||
CurieImu::getAccel()
|
CurieImu::getAccel()
|
||||||
{
|
{
|
||||||
return &accel[0];
|
return &m_accel[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getAccelX()
|
||||||
|
{
|
||||||
|
return m_accel[X];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getAccelY()
|
||||||
|
{
|
||||||
|
return m_accel[Y];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getAccelZ()
|
||||||
|
{
|
||||||
|
return m_accel[Z];
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t*
|
int16_t*
|
||||||
CurieImu::getGyro()
|
CurieImu::getGyro()
|
||||||
{
|
{
|
||||||
return &gyro[0];
|
return &m_gyro[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getGyroX()
|
||||||
|
{
|
||||||
|
return m_gyro[X];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getGyroY()
|
||||||
|
{
|
||||||
|
return m_gyro[Y];
|
||||||
|
}
|
||||||
|
|
||||||
|
int16_t
|
||||||
|
CurieImu::getGyroZ()
|
||||||
|
{
|
||||||
|
return m_gyro[Z];
|
||||||
}
|
}
|
||||||
|
|
||||||
int16_t*
|
int16_t*
|
||||||
CurieImu::getMotion()
|
CurieImu::getMotion()
|
||||||
{
|
{
|
||||||
return &motion[0];
|
return &m_motion[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -190,9 +226,9 @@ CurieImu::updateAccel()
|
|||||||
|
|
||||||
waitForResponse();
|
waitForResponse();
|
||||||
|
|
||||||
accel[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
m_accel[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
||||||
accel[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
|
m_accel[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
|
||||||
accel[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
|
m_accel[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
|
||||||
|
|
||||||
delete m_results;
|
delete m_results;
|
||||||
unlock();
|
unlock();
|
||||||
@ -217,9 +253,9 @@ CurieImu::updateGyro()
|
|||||||
|
|
||||||
waitForResponse();
|
waitForResponse();
|
||||||
|
|
||||||
gyro[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
m_gyro[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
||||||
gyro[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
|
m_gyro[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
|
||||||
gyro[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
|
m_gyro[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
|
||||||
|
|
||||||
delete m_results;
|
delete m_results;
|
||||||
unlock();
|
unlock();
|
||||||
@ -244,12 +280,18 @@ CurieImu::updateMotion()
|
|||||||
|
|
||||||
waitForResponse();
|
waitForResponse();
|
||||||
|
|
||||||
motion[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
m_motion[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
|
||||||
motion[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
|
m_motion[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
|
||||||
motion[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
|
m_motion[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
|
||||||
motion[3] = ((m_results[9] & 0x7f) | ((m_results[10] & 0x7f) << 7));
|
m_motion[3] = ((m_results[9] & 0x7f) | ((m_results[10] & 0x7f) << 7));
|
||||||
motion[4] = ((m_results[11] & 0x7f) | ((m_results[12] & 0x7f) << 7));
|
m_motion[4] = ((m_results[11] & 0x7f) | ((m_results[12] & 0x7f) << 7));
|
||||||
motion[5] = ((m_results[13] & 0x7f) | ((m_results[13] & 0x7f) << 7));
|
m_motion[5] = ((m_results[13] & 0x7f) | ((m_results[13] & 0x7f) << 7));
|
||||||
|
|
||||||
|
for (int i=0; i<3; i++)
|
||||||
|
m_accel[i] = m_motion[i];
|
||||||
|
|
||||||
|
for (int i=0; i<3; i++)
|
||||||
|
m_gyro[i] = m_motion[i+3];
|
||||||
|
|
||||||
delete m_results;
|
delete m_results;
|
||||||
unlock();
|
unlock();
|
||||||
|
@ -65,6 +65,10 @@ namespace upm {
|
|||||||
#define FIRMATA_CURIE_IMU_TAP_DETECT 0x05
|
#define FIRMATA_CURIE_IMU_TAP_DETECT 0x05
|
||||||
#define FIRMATA_CURIE_IMU_READ_MOTION 0x06
|
#define FIRMATA_CURIE_IMU_READ_MOTION 0x06
|
||||||
|
|
||||||
|
#define X 0
|
||||||
|
#define Y 1
|
||||||
|
#define Z 2
|
||||||
|
|
||||||
struct IMUDataItem {
|
struct IMUDataItem {
|
||||||
int axis;
|
int axis;
|
||||||
int direction;
|
int direction;
|
||||||
@ -86,37 +90,77 @@ class CurieImu {
|
|||||||
~CurieImu();
|
~CurieImu();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Updates the latest accelerometer readings by calling Firmata
|
||||||
*/
|
*/
|
||||||
void updateAccel();
|
void updateAccel();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Updates the latest gyroscope readings by calling Firmata
|
||||||
*/
|
*/
|
||||||
void updateGyro();
|
void updateGyro();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Updates the both the latest accelerometer & gyroscope readings
|
||||||
|
* by calling Firmata
|
||||||
*/
|
*/
|
||||||
void updateMotion();
|
void updateMotion();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read accelerometer X, Y, and Z axis
|
* Returns last accelerometer reading X, Y, and Z axis
|
||||||
*
|
*
|
||||||
* @param xVal Pointer to returned X-axis value
|
* @return pointer to array with X-axis, Y-axis & Z-axis value
|
||||||
* @param yVal Pointer to returned Y-axis value
|
|
||||||
* @param zVal Pointer to returned Z-axis value
|
|
||||||
*/
|
*/
|
||||||
int16_t* getAccel();
|
int16_t* getAccel();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last accelerometer reading X axis
|
||||||
|
*
|
||||||
|
* @return X-axis value
|
||||||
|
*/
|
||||||
|
int16_t getAccelX();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last accelerometer reading Y axis
|
||||||
|
*
|
||||||
|
* @return Y-axis value
|
||||||
|
*/
|
||||||
|
int16_t getAccelY();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last accelerometer reading Z axis
|
||||||
|
*
|
||||||
|
* @return Z-axis value
|
||||||
|
*/
|
||||||
|
int16_t getAccelZ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read gyroscope X, Y, and Z axis
|
* Read gyroscope X, Y, and Z axis
|
||||||
*
|
*
|
||||||
* @param xVal Pointer to returned X-axis value
|
* @return pointer to array with X-axis, Y-axis & Z-axis value
|
||||||
* @param yVal Pointer to returned Y-axis value
|
|
||||||
* @param zVal Pointer to returned Z-axis value
|
|
||||||
*/
|
*/
|
||||||
int16_t* getGyro();
|
int16_t* getGyro();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last gyroscope reading X axis
|
||||||
|
*
|
||||||
|
* @return X-axis value
|
||||||
|
*/
|
||||||
|
int16_t getGyroX();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last gyroscope reading Y axis
|
||||||
|
*
|
||||||
|
* @return Y-axis value
|
||||||
|
*/
|
||||||
|
int16_t getGyroY();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns last gyroscope reading Z axis
|
||||||
|
*
|
||||||
|
* @return Z-axis value
|
||||||
|
*/
|
||||||
|
int16_t getGyroZ();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reads the internal temperature
|
* Reads the internal temperature
|
||||||
*
|
*
|
||||||
@ -127,12 +171,9 @@ class CurieImu {
|
|||||||
/**
|
/**
|
||||||
* Reads the X, Y, and Z axis of both gyroscope and accelerometer
|
* Reads the X, Y, and Z axis of both gyroscope and accelerometer
|
||||||
*
|
*
|
||||||
* @param xA Pointer to returned X-axis value of accelerometer
|
* @return pointer to array with X-axis, Y-axis & Z-axis values for
|
||||||
* @param yA Pointer to returned Y-axis value of accelerometer
|
* accelerometer, and then X-axis, Y-axis & Z-axis values for
|
||||||
* @param zA Pointer to returned Z-axis value of accelerometer
|
* gyroscope
|
||||||
* @param xG Pointer to returned X-axis value of Gyroscope
|
|
||||||
* @param yG Pointer to returned Y-axis value of Gyroscope
|
|
||||||
* @param zG Pointer to returned Z-axis value of Gyroscope
|
|
||||||
*/
|
*/
|
||||||
int16_t* getMotion();
|
int16_t* getMotion();
|
||||||
|
|
||||||
@ -245,9 +286,9 @@ class CurieImu {
|
|||||||
std::queue<int> m_stepData;
|
std::queue<int> m_stepData;
|
||||||
std::queue<IMUDataItem*> m_tapData;
|
std::queue<IMUDataItem*> m_tapData;
|
||||||
|
|
||||||
int16_t accel[3];
|
int16_t m_accel[3];
|
||||||
int16_t gyro[3];
|
int16_t m_gyro[3];
|
||||||
int16_t motion[6];
|
int16_t m_motion[6];
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user