History

Don't estimate acceleration before we know the gravity and don't update our matrices without acceleration.

Andrzej Kapolka committed 13 years ago

Commit 47bd3bc1 parent b88380d1 file · +5 −2Browse files

Showing the changes to interface/src/SerialInterface.cpp (1 of 1 file). Show all

Unified · Split

interface/src/SerialInterface.cpp+5−2
@@ -240,10 +240,12 @@ void SerialInterface::readData(float deltaTime) { · 239 unmodified lines
240 glm::quat(glm::radians(deltaTime * _lastRotationRates));240 glm::quat(glm::radians(deltaTime * _lastRotationRates));
241 241
242 // Update acceleration estimate: first, subtract gravity as rotated into current frame242 // Update acceleration estimate: first, subtract gravity as rotated into current frame
243 _estimatedAcceleration = _lastAcceleration - glm::inverse(estimatedRotation) * _gravity;243 _estimatedAcceleration = (totalSamples < GRAVITY_SAMPLES) ? glm::vec3() :
244 _lastAcceleration - glm::inverse(estimatedRotation) * _gravity;
244 245
245 // Consider updating our angular velocity/acceleration to linear acceleration mapping246 // Consider updating our angular velocity/acceleration to linear acceleration mapping
246 if (glm::length(_lastRotationRates) > EPSILON || glm::length(angularAcceleration) > EPSILON) {247 if (glm::length(_estimatedAcceleration) > EPSILON &&
248 glm::length(_lastRotationRates) > EPSILON || glm::length(angularAcceleration) > EPSILON) {
247 // compute predicted linear acceleration, find error between actual and predicted249 // compute predicted linear acceleration, find error between actual and predicted
248 glm::vec3 predictedAcceleration = _angularVelocityToLinearAccel * _lastRotationRates +250 glm::vec3 predictedAcceleration = _angularVelocityToLinearAccel * _lastRotationRates +
249 _angularAccelToLinearAccel * angularAcceleration;251 _angularAccelToLinearAccel * angularAcceleration;
@@ -338,6 +340,7 @@ void SerialInterface::resetAverages() { · 88 unmodified lines
338 _estimatedRotation = glm::vec3(0, 0, 0);340 _estimatedRotation = glm::vec3(0, 0, 0);
339 _estimatedPosition = glm::vec3(0, 0, 0);341 _estimatedPosition = glm::vec3(0, 0, 0);
340 _estimatedVelocity = glm::vec3(0, 0, 0);342 _estimatedVelocity = glm::vec3(0, 0, 0);
343 _estimatedAcceleration = glm::vec3(0, 0, 0);
341}344}
342 345
343void SerialInterface::resetSerial() {346void SerialInterface::resetSerial() {