整合 IMU 加速度计数据来估计位置

问题描述 投票:0回答:1

我正在尝试使用 MPU6050 IMU 来估计位置变化。我知道漂移是个问题,但我只是想在不到几秒钟的短时间内做到这一点。

我已经使用传感器融合 madgwick 滤波器调整了重力,调整后我的加速度读数看起来不错,但是当我对它们进行双重积分时,结果位置非常非常小。

对我可能做错了什么有任何见解吗?

VectorFloat getAccelerationNoGravity() {
  frame++;
  auto timeSinceLastSample = ReadTime(); 

  /**
   * Get the current acceleration readings compensated for gravity
   * 1. Get raw readings from acc & gyro
   * 2. Feed into madgwick filter, get quaternion
   * 3. Get gravity vector from quaternion
   * 4. subtract gravity from raw acceleration readings
   */

  // 1. Get raw readings from acc & gyro
  sensors_event_t acc, gyro, temp;
  mpu.getEvent(&acc, &gyro, &temp);

  // 2. Feed into madgwick filter, get quaternion
  float x = acc.acceleration.x;
  float y = acc.acceleration.y;
  float z = acc.acceleration.z;
  float gx = gyro.gyro.x;
  float gy = gyro.gyro.y;
  float gz = gyro.gyro.z;
  float deltat = timeSinceLastSample / 1000000.0;

  madgwickQuaternionUpdate(q, x, y, z, gx, gy, gz, deltat);
  Quaternion quat = Quaternion(q[0], q[1], q[2], q[3]);

  // 3. Get gravity vector from quaternion
  VectorFloat gravity = getGravity(&quat); // returns percentages of gravity

  // 4. subtract gravity from raw acceleration readings
  VectorFloat accAdj = getLinearAcceleration(VectorFloat(x, y, z), gravity);

  // 5. calculate bias & adjust
  calibrateBias(accAdj); // average of x samples
  accAdj.x -= bias.x;
  accAdj.y -= bias.y;
  accAdj.z -= bias.z;

  // calc position
  auto accMagnitude = accAdj.getMagnitude();
  if (biasComputed /*&& accMagnitude > 0.1*/) {
    // v0 (initial velocity) = v
    auto v0x = currVel.x;
    auto v0y = currVel.y;
    auto v0z = currVel.z;

    // currVel (current velocity) = v0 + a * t
    currVel.x = v0x + deltat * accAdj.x;
    currVel.y = v0y + deltat * accAdj.y;
    currVel.z = v0z + deltat * accAdj.z;

    // delta_x = v0 * t + 1/2 * a * t^2 * 100 (m -> cm)
    float deltat_sq = deltat * deltat;
    currPos.x += v0x * deltat + 0.5 * accAdj.x * deltat_sq * 100;
    currPos.y += v0y * deltat + 0.5 * accAdj.y * deltat_sq * 100;
    currPos.z += v0z * deltat + 0.5 * accAdj.z * deltat_sq * 100;
  }

  t_compute = micros() - t_compute;
  if (biasComputed && frame % 50 == 0) {
    Serial.printf("%f,%f,%f\n", accAdj.x, accAdj.y, accAdj.z);
  }

  return accAdj;
}

这导致这样的读数

0.117377,0.135253,0.010953
0.117308,0.133007,0.010974
0.117446,0.129459,0.010982
0.117550,0.125331,0.010972
0.117732,0.120880,0.010971
0.117961,0.115567,0.011018
0.118101,0.111308,0.011070
0.118161,0.112330,0.011132
0.118256,0.114275,0.011229
0.118401,0.116992,0.011322

但是我将 IMU 移动了超过 50 厘米,所以看起来结果相差了几个数量级。

再一次,我调整后的加速度计读数是有意义的,所以也许我在执行运动学时犯了一个错误?

arduino accelerometer imu
1个回答
0
投票

我没有足够的声誉来发表评论,这就是为什么写作作为答案,但这实际上是评论。我认为您的

deltat
应该是
1/sampling_rate
(例如:如果您获得100Hz数据,则为1/100)。

© www.soinside.com 2019 - 2024. All rights reserved.