Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addition of the ability to get accel in earth frame #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Linux/python/PyRTIMU_RTIMU.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ static PyMethodDef RTIMU_RTIMU_methods[] = {
METH_NOARGS,
"Return the accel residual readings" },

//////// getAccelGlobalFrame
{"getAccelGlobalFrame", (PyCFunction)([] (PyObject *self, PyObject* args) -> PyObject* {
const RTVector3& r = ((RTIMU_RTIMU*)self)->val->getAccelGlobalFrame();
return Py_BuildValue("(d,d,d)", r.x(), r.y(), r.z());
}),
METH_NOARGS,
"Return the accel rotated into the Earth Frame" },

//////// setExtIMUData
{"setExtIMUData", (PyCFunction)([] (PyObject *self, PyObject* args) -> PyObject* {
double gx, gy, gz, ax, ay, az, mx, my, mz;
Expand Down
1 change: 1 addition & 0 deletions RTIMULib/IMUDrivers/RTIMU.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ class RTIMU
const RTVector3& getCompass() { return m_imuData.compass; } // gets compass data in uT

RTVector3 getAccelResiduals() { return m_fusion->getAccelResiduals(CalibratedAccel()); }
RTVector3 getAccelGlobalFrame() { return m_fusion->getAccelGlobalFrame(CalibratedAccel()); }

protected:
void gyroBiasInit(); // sets up gyro bias calculation
Expand Down
26 changes: 26 additions & 0 deletions RTIMULib/RTFusion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,29 @@ RTVector3 RTFusion::getAccelResiduals(RTVector3 accel)
residuals.setZ(-(accel.z() - rotatedGravity.z()));
return residuals;
}

RTVector3 RTFusion::getAccelGlobalFrame(RTVector3 accel)
{
RTQuaternion rotatedAccel;
RTQuaternion fusedConjugate;
RTQuaternion qTemp;
RTVector3 accelGCS;

// simply rotate measured accel with the fusion pose quaternion

// create the conjugate of the pose

fusedConjugate = m_fusionQPose.conjugate();

// now do the rotation - takes two steps with qTemp as the intermediate variable
RTQuaternion measuredAccel(0, accel.x(), accel.y(), accel.z());
qTemp = measuredAccel * fusedConjugate;
rotatedAccel = m_fusionQPose * qTemp;

// now set the accel in Global Coordinate System as the rotated accel

accelGCS.setX(rotatedAccel.x());
accelGCS.setY(rotatedAccel.y());
accelGCS.setZ(rotatedAccel.z());
return accelGCS;
}
6 changes: 6 additions & 0 deletions RTIMULib/RTFusion.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ class RTFusion

RTVector3 getAccelResiduals(RTVector3 accel);

// getAccelGlobalFrame() returns the rotated acceleration
// from the sensor Local Coordinate System to the Earth/Global Coordinate System
// useful for inertial navigation systems (like indoor positioning systems)

RTVector3 getAccelGlobalFrame(RTVector3 accel);

void setDebugEnable(bool enable) { m_debug = enable; }
void calculatePose(const RTVector3& accel, const RTVector3& mag, float magDeclination); // generates pose from accels and mag

Expand Down