mirror of
https://github.com/overte-org/overte.git
synced 2025-04-21 19:04:32 +02:00
Converted gyro values to floats and converted to exact degrees/second per docs.
This commit is contained in:
parent
7d4663a2d5
commit
131377aaf9
3 changed files with 27 additions and 19 deletions
|
@ -266,9 +266,9 @@ void Avatar::UpdateGyros(float frametime, SerialInterface* serialInterface, glm:
|
|||
float measured_pitch_rate = 0.0f;
|
||||
float measured_roll_rate = 0.0f;
|
||||
if (serialInterface->active && USING_INVENSENSE_MPU9150) {
|
||||
measured_pitch_rate = serialInterface->getLastPitch();
|
||||
_head.yawRate = serialInterface->getLastYaw();
|
||||
measured_roll_rate = -1 * serialInterface->getLastRoll();
|
||||
measured_pitch_rate = serialInterface->getLastPitchRate();
|
||||
_head.yawRate = serialInterface->getLastYawRate();
|
||||
measured_roll_rate = -1 * serialInterface->getLastRollRate();
|
||||
} else {
|
||||
measured_pitch_rate = serialInterface->getRelativeValue(HEAD_PITCH_RATE);
|
||||
_head.yawRate = serialInterface->getRelativeValue(HEAD_YAW_RATE);
|
||||
|
|
|
@ -173,12 +173,12 @@ void SerialInterface::renderLevels(int width, int height) {
|
|||
const int LEVEL_CORNER_X = 10;
|
||||
const int LEVEL_CORNER_Y = 200;
|
||||
|
||||
// Draw the text values
|
||||
sprintf(val, "Yaw %d", _lastYaw);
|
||||
// Draw the numeric degree/sec values from the gyros
|
||||
sprintf(val, "Yaw %4.1f", _lastYawRate);
|
||||
drawtext(LEVEL_CORNER_X, LEVEL_CORNER_Y, 0.10, 0, 1.0, 1, val, 0, 1, 0);
|
||||
sprintf(val, "Pitch %d", _lastPitch);
|
||||
sprintf(val, "Pitch %4.1f", _lastPitchRate);
|
||||
drawtext(LEVEL_CORNER_X, LEVEL_CORNER_Y + 15, 0.10, 0, 1.0, 1, val, 0, 1, 0);
|
||||
sprintf(val, "Roll %d", _lastRoll);
|
||||
sprintf(val, "Roll %4.1f", _lastRollRate);
|
||||
drawtext(LEVEL_CORNER_X, LEVEL_CORNER_Y + 30, 0.10, 0, 1.0, 1, val, 0, 1, 0);
|
||||
|
||||
// Draw the levels as horizontal lines
|
||||
|
@ -187,11 +187,11 @@ void SerialInterface::renderLevels(int width, int height) {
|
|||
glColor4f(1, 1, 1, 1);
|
||||
glBegin(GL_LINES);
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y - 3);
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + _lastYaw, LEVEL_CORNER_Y - 3);
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + _lastYawRate, LEVEL_CORNER_Y - 3);
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 12);
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + _lastPitch, LEVEL_CORNER_Y + 12);
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + _lastPitchRate, LEVEL_CORNER_Y + 12);
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER, LEVEL_CORNER_Y + 27);
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + _lastRoll, LEVEL_CORNER_Y + 27);
|
||||
glVertex2f(LEVEL_CORNER_X + LEVEL_CENTER + _lastRollRate, LEVEL_CORNER_Y + 27);
|
||||
glEnd();
|
||||
// Draw green vertical centerline
|
||||
glColor4f(0, 1, 0, 0.5);
|
||||
|
@ -238,9 +238,17 @@ void SerialInterface::readData() {
|
|||
write(_serialDescriptor, "RD684306\n", 9);
|
||||
read(_serialDescriptor, gyroBuffer, 20);
|
||||
|
||||
convertHexToInt(gyroBuffer + 6, _lastYaw);
|
||||
convertHexToInt(gyroBuffer + 10, _lastRoll);
|
||||
convertHexToInt(gyroBuffer + 14, _lastPitch);
|
||||
int rollRate, yawRate, pitchRate;
|
||||
|
||||
convertHexToInt(gyroBuffer + 6, rollRate);
|
||||
convertHexToInt(gyroBuffer + 10, yawRate);
|
||||
convertHexToInt(gyroBuffer + 14, pitchRate);
|
||||
|
||||
// Convert the integer rates to floats
|
||||
const float LSB_TO_DEGREES_PER_SECOND = 1.f / 16.4f; // From MPU-9150 register map, 2000 deg/sec.
|
||||
_lastRollRate = (float) rollRate * LSB_TO_DEGREES_PER_SECOND;
|
||||
_lastYawRate = (float) yawRate * LSB_TO_DEGREES_PER_SECOND;
|
||||
_lastPitchRate = (float) pitchRate * LSB_TO_DEGREES_PER_SECOND;
|
||||
|
||||
totalSamples++;
|
||||
} else {
|
||||
|
|
|
@ -42,9 +42,9 @@ public:
|
|||
void pair();
|
||||
void readData();
|
||||
|
||||
int getLastYaw() const { return _lastYaw; }
|
||||
int getLastPitch() const { return _lastPitch; }
|
||||
int getLastRoll() const { return _lastRoll; }
|
||||
float getLastYawRate() const { return _lastYawRate; }
|
||||
float getLastPitchRate() const { return _lastPitchRate; }
|
||||
float getLastRollRate() const { return _lastRollRate; }
|
||||
|
||||
int getLED() {return LED;};
|
||||
int getNumSamples() {return samplesAveraged;};
|
||||
|
@ -69,9 +69,9 @@ private:
|
|||
int totalSamples;
|
||||
timeval lastGoodRead;
|
||||
glm::vec3 gravity;
|
||||
int _lastYaw;
|
||||
int _lastPitch;
|
||||
int _lastRoll;
|
||||
float _lastYawRate; // Rates are in degrees per second.
|
||||
float _lastPitchRate;
|
||||
float _lastRollRate;
|
||||
int _failedOpenAttempts;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue