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:
deadprogram 2016-03-18 10:58:51 -07:00 committed by Brendan Le Foll
parent ee19daedee
commit 90983fde9d
3 changed files with 132 additions and 40 deletions

View File

@ -42,12 +42,16 @@ main(int argc, char **argv)
std::cout << "temperature is: " << (sensor->getTemperature() * pow(0.5, 9) + 23) << std::endl;
int x, y, z;
sensor->readAccelerometer(&x, &y, &z);
sensor->updateAccel();
int x = sensor->getAccelX(),
y = sensor->getAccelY(),
z = sensor->getAccelZ();
printf("accelerometer is: %d, %d, %d\n", x, y, z);
int a, b, c;
sensor->readGyro(&a, &b, &c);
sensor->updateGyro();
int a = sensor->getGyroX(),
b = sensor->getGyroY(),
c = sensor->getGyroZ();
printf("gyroscope is: %d, %d, %d\n", a, b, c);
int axis, direction;
@ -60,8 +64,13 @@ main(int argc, char **argv)
usleep(10000);
}
int m, n, o, p, q, r;
sensor->readMotion(&m, &n, &o, &p, &q, &r);
sensor->updateMotion();
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);
delete sensor;

View File

@ -158,19 +158,55 @@ CurieImu::processResponse()
int16_t*
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*
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*
CurieImu::getMotion()
{
return &motion[0];
return &m_motion[0];
}
void
@ -190,9 +226,9 @@ CurieImu::updateAccel()
waitForResponse();
accel[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
accel[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
accel[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
m_accel[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
m_accel[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
m_accel[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
delete m_results;
unlock();
@ -217,9 +253,9 @@ CurieImu::updateGyro()
waitForResponse();
gyro[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
gyro[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
gyro[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
m_gyro[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
m_gyro[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
m_gyro[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
delete m_results;
unlock();
@ -244,12 +280,18 @@ CurieImu::updateMotion()
waitForResponse();
motion[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
motion[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
motion[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
motion[3] = ((m_results[9] & 0x7f) | ((m_results[10] & 0x7f) << 7));
motion[4] = ((m_results[11] & 0x7f) | ((m_results[12] & 0x7f) << 7));
motion[5] = ((m_results[13] & 0x7f) | ((m_results[13] & 0x7f) << 7));
m_motion[0] = ((m_results[3] & 0x7f) | ((m_results[4] & 0x7f) << 7));
m_motion[1] = ((m_results[5] & 0x7f) | ((m_results[6] & 0x7f) << 7));
m_motion[2] = ((m_results[7] & 0x7f) | ((m_results[8] & 0x7f) << 7));
m_motion[3] = ((m_results[9] & 0x7f) | ((m_results[10] & 0x7f) << 7));
m_motion[4] = ((m_results[11] & 0x7f) | ((m_results[12] & 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;
unlock();

View File

@ -65,6 +65,10 @@ namespace upm {
#define FIRMATA_CURIE_IMU_TAP_DETECT 0x05
#define FIRMATA_CURIE_IMU_READ_MOTION 0x06
#define X 0
#define Y 1
#define Z 2
struct IMUDataItem {
int axis;
int direction;
@ -86,37 +90,77 @@ class CurieImu {
~CurieImu();
/**
* Updates the latest accelerometer readings by calling Firmata
*/
void updateAccel();
/**
*
* Updates the latest gyroscope readings by calling Firmata
*/
void updateGyro();
/**
*
* Updates the both the latest accelerometer & gyroscope readings
* by calling Firmata
*/
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
* @param yVal Pointer to returned Y-axis value
* @param zVal Pointer to returned Z-axis value
* @return pointer to array with X-axis, Y-axis & Z-axis value
*/
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
*
* @param xVal Pointer to returned X-axis value
* @param yVal Pointer to returned Y-axis value
* @param zVal Pointer to returned Z-axis value
* @return pointer to array with X-axis, Y-axis & Z-axis value
*/
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
*
@ -127,12 +171,9 @@ class CurieImu {
/**
* Reads the X, Y, and Z axis of both gyroscope and accelerometer
*
* @param xA Pointer to returned X-axis value of accelerometer
* @param yA Pointer to returned Y-axis value of accelerometer
* @param zA Pointer to returned Z-axis value of accelerometer
* @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
* @return pointer to array with X-axis, Y-axis & Z-axis values for
* accelerometer, and then X-axis, Y-axis & Z-axis values for
* gyroscope
*/
int16_t* getMotion();
@ -245,9 +286,9 @@ class CurieImu {
std::queue<int> m_stepData;
std::queue<IMUDataItem*> m_tapData;
int16_t accel[3];
int16_t gyro[3];
int16_t motion[6];
int16_t m_accel[3];
int16_t m_gyro[3];
int16_t m_motion[6];
};
}