我本周将建立一个Oculus Quest。它的意思是一个有趣的(便宜的)项目,而且我想出了如果在正位跟踪一个恒定的(脚的放置)位置,如何计算肢体位移的方法。我已经必须设法在同一台arduino上一次添加2个以上的MPU-6050。问题是当我想从MPU中获取串行数据并将其统一时。旋转数据非常错误,看起来像这样:

gyro    -8.00   -171.00 -148.00  |||    gyro    117.00  -639.00 -1105.00
gyro    -4.00   -160.00 -125.00  |||    gyro    -20.00  -640.00 -1081.00
gyro    -9.00   -160.00 -128.00  |||    gyro    -86.00  -694.00 -1074.00
gyro    13.00   -141.00 -120.00  |||    gyro    -309.00 -713.00 -1040.00
gyro    -8.00   -136.00 -134.00  |||    gyro    -184.00 -683.00 -1045.00
gyro    -6.00   -150.00 -158.00  |||    gyro    -214.00 -696.00 -1058.00
gyro    -12.00  -143.00 -147.00  |||    gyro    -5.00   -644.00 -1086.00
gyro    16.00   -157.00 -140.00  |||    gyro    42.00   -662.00 -1153.00
gyro    -9.00   -151.00 -136.00  |||    gyro    54.00   -644.00 -1154.00
gyro    8.00    -143.00 -143.00  |||    gyro    81.00   -662.00 -1149.00
gyro    -17.00  -124.00 -134.00  |||    gyro    -126.00 -698.00 -1088.00
gyro    -11.00  -150.00 -138.00  |||    gyro    -28.00  -703.00 -1169.00
gyro    -1.00   -129.00 -161.00  |||    gyro    -187.00 -744.00 -1125.00
gyro    -23.00  -145.00 -133.00  |||    gyro    -43.00  -713.00 -1117.00
gyro    1.00    -143.00 -139.00  |||    gyro    -7.00   -662.00 -1160.00
gyro    11.00   -156.00 -136.00  |||    gyro    20.00   -697.00 -1178.00
gyro    21.00   -132.00 -116.00  |||    gyro    168.00  -651.00 -1162.00
gyro    -1.00   -133.00 -153.00  |||    gyro    -41.00  -688.00 -1151.00
gyro    -5.00   -174.00 -144.00  |||    gyro    107.00  -699.00 -1157.00
gyro    2.00    -144.00 -146.00  |||    gyro    -177.00 -710.00 -1105.00
gyro    -31.00  -134.00 -133.00  |||    gyro    -124.00 -687.00 -1091.00
gyro    -8.00   -169.00 -121.00  |||    gyro    -114.00 -695.00 -1133.00
gyro    -11.00  -178.00 -151.00  |||    gyro    -132.00 -662.00 -1074.00
gyro    -20.00  -154.00 -132.00  |||    gyro    62.00   -659.00 -1136.00
gyro    22.00   -142.00 -135.00  |||    gyro    -88.00  -665.00 -1116.00
gyro    -30.00  -148.00 -131.00  |||    gyro    51.00   -683.00 -1144.00
gyro    -2.00   -163.00 -129.00  |||    gyro    -111.00 -699.00 -1119.00
gyro    -9.00   -164.00 -128.00  |||    gyro    -58.00  -706.00 -1114.00
gyro    4.00    -146.00 -146.00  |||    gyro    -52.00  -699.00 -1121.00
gyro    12.00   -149.00 -138.00  |||    gyro    -147.00 -707.00 -1092.00
gyro    -24.00  -146.00 -131.00  |||    gyro    -2.00   -701.00 -1164.00
gyro    -7.00   -135.00 -142.00  |||    gyro    -38.00  -700.00 -1137.00
gyro    -2.00   -169.00 -139.00  |||    gyro    92.00   -636.00 -1156.00
gyro    -12.00  -160.00 -145.00  |||    gyro    -52.00  -658.00 -1094.00
gyro    -12.00  -145.00 -131.00  |||    gyro    -27.00  -689.00 -1137.00
gyro    -22.00  -139.00 -134.00  |||    gyro    -42.00  -723.00 -1122.00
gyro    0.00    -149.00 -133.00  |||    gyro    -54.00  -682.00 -1096.00
gyro    -15.00  -173.00 -124.00  |||    gyro    24.00   -688.00 -1127.00
gyro    9.00    -163.00 -139.00  |||    gyro    -117.00 -682.00 -1080.00
gyro    -21.00  -151.00 -128.00  |||    gyro    21.00   -662.00 -1137.00
gyro    20.00   -101.00 -159.00  |||    gyro    -96.00  -636.00 -1051.00
gyro    -5.00   -166.00 -132.00  |||    gyro    -135.00 -693.00 -1128.00
gyro    -10.00  -149.00 -123.00  |||    gyro    -173.00 -699.00 -1112.00
gyro    14.00   -165.00 -135.00  |||    gyro    -91.00  -723.00 -1134.00
gyro    -12.00  -163.00 -151.00  |||    gyro    255.00  -670.00 -1163.00
gyro    -10.00  -158.00 -144.00  |||    gyro    95.00   -612.00 -1163.00
gyro    0.00    -150.00 -130.00  |||    gyro    17.00   -693.00 -1195.00
gyro    -18.00  -159.00 -146.00  |||    gyro    -59.00  -728.00 -1161.00
gyro    2.00    -183.00 -114.00  |||    gyro    -40.00  -740.00 -1148.00
gyro    3.00    -164.00 -107.00  |||    gyro    80.00   -729.00 -1201.00
gyro    -17.00  -148.00 -128.00  |||    gyro    -141.00 -682.00 -1147.00
gyro    14.00   -158.00 -147.00  |||    gyro    112.00  -696.00 -1145.00
gyro    -1.00   -139.00 -136.00  |||    gyro    -116.00 -731.00 -1091.00
gyro    -11.00  -136.00 -128.00  |||    gyro    -64.00  -735.00 -1111.00
gyro    -2.00   -150.00 -133.00  |||    gyro    -151.00 -757.00 -1092.00
gyro    -21.00  -136.00 -129.00  |||    gyro    -156.00 -714.00 -1139.00
gyro    -20.00  -163.00 -111.00  |||    gyro    42.00   -738.00 -1116.00
gyro    -16.00  -160.00 -141.00  |||    gyro    -141.00 -681.00 -1108.00
gyro    -8.00   -176.00 -129.00  |||    gyro    80.00   -691.00 -1142.00
gyro    -6.00   -167.00 -159.00  |||    gyro    -52.00  -725.00 -1119.00
gyro    -10.00  -178.00 -135.00  |||    gyro    -62.00  -706.00 -1069.00
gyro    -16.00  -173.00 -136.00  |||    gyro    -129.00 -735.00 -1112.00
gyro    9.00    -147.00 -158.00  |||    gyro    -203.00 -734.00 -1132.00
gyro    12.00   -152.00 -131.00  |||    gyro    -12.00  -720.00 -1158.00
gyro    -24.00  -163.00 -146.00  |||    gyro    -76.00  -737.00 -1141.00
gyro    27.00   -153.00 -128.00  |||    gyro    190.00  -676.00 -1162.00
gyro    1.00    -150.00 -129.00  |||    gyro    23.00   -669.00 -1123.00
gyro    -14.00  -146.00 -131.00  |||    gyro    51.00   -672.00 -1180.00
gyro    0.00    -134.00 -115.00  |||    gyro    -4.00   -706.00 -1171.00
gyro    -6.00   -145.00 -139.00  |||    gyro    -160.00 -730.00 -1147.00
gyro    -16.00  -165.00 -152.00  |||    gyro    -82.00  -705.00 -1112.00
gyro    14.00   -152.00 -147.00  |||    gyro    -246.00 -696.00 -1089.00
gyro    -14.00  -162.00 -137.00  |||    gyro    33.00   -705.00 -1162.00
gyro    -22.00  -174.00 -152.00  |||    gyro    -31.00  -664.00 -1161.00
gyro    -1.00   -138.00 -131.00  |||    gyro    137.00  -642.00 -1141.00
gyro    4.00    -173.00 -134.00  |||    gyro    165.00  -652.00 -1168.00
gyro    9.00    -152.00 -133.00  |||    gyro    -23.00  -666.00 -1111.00
gyro    -12.00  -146.00 -134.00  |||    gyro    64.00   -697.00 -1128.00
gyro    -20.00  -132.00 -141.00  |||    gyro    -221.00 -695.00 -1046.00
gyro    -7.00   -143.00 -141.00  |||    gyro    -122.00 -684.00 -1116.00
gyro    -7.00   -118.00 -150.00  |||    gyro    -188.00 -699.00 -1097.00
gyro    -9.00   -148.00 -126.00  |||    gyro    -56.00  -686.00 -1107.00
gyro    6.00    -169.00 -130.00  |||    gyro    132.00  -665.00 -1152.00
gyro    -1.00   -150.00 -119.00  |||    gyro    22.00   -615.00 -1144.00
gyro    12.00   -157.00 -120.00  |||    gyro    212.00  -678.00 -1163.00
gyro    5.00    -156.00 -153.00  |||    gyro    -42.00  -745.00 -1169.00
gyro    -2.00   -143.00 -130.00  |||    gyro    22.00   -732.00 -1171.00
gyro    3.00    -129.00 -142.00  |||    gyro    -145.00 -730.00 -1123.00
gyro    -2.00   -132.00 -154.00  |||    gyro    -147.00 -705.00 -1140.00
gyro    -9.00   -120.00 -132.00  |||    gyro    -85.00  -691.00 -1143.00
gyro    -12.00  -156.00 -153.00  |||    gyro    -157.00 -696.00 -1087.00
gyro    -11.00  -149.00 -141.00  |||    gyro    67.00   -681.00 -1095.00
gyro    -21.00  -167.00 -140.00  |||    gyro    -72.00  -673.00 -1100.00
gyro    19.00   -156.00 -138.00  |||    gyro    76.00   -687.00 -1139.00
gyro    -17.00  -135.00 -144.00  |||    gyro    -55.00  -693.00 -1107.00
gyro    -6.00   -136.00 -129.00  |||    gyro    -72.00  -721.00 -1091.00
gyro    26.00   -146.00 -146.00  |||    gyro    -42.00  -681.00 -1084.00
gyro    5.00    -133.00 -125.00  |||    gyro    -135.00 -694.00 -1101.00
gyro    -1.00   -152.00 -124.00  |||    gyro    5.00    -674.00 -1173.00
gyro    1.00    -144.00 -116.00  |||    gyro    -81.00  -676.00 -1110.00
gyro    -8.00   -140.00 -127.00  |||    gyro    32.00   -671.00 -1144.00
gyro    17.00   -144.00 -144.00  |||    gyro    60.00   -682.00 -1163.00
gyro    8.00    -169.00 -122.00  |||    gyro    16.00   -671.00 -1151.00
gyro    16.00   -163.00 -128.00  |||    gyro    134.00  -703.00 -1200.00
gyro    -16.00  -178.00 -133.00  |||    gyro    -62.00  -671.00 -1127.00
gyro    -2.00   -157.00 -141.00  |||    gyro    128.00  -738.00 -1190.00
gyro    -32.00  -147.00 -134.00  |||    gyro    -189.00 -664.00 -1139.00

在我看来,似乎2个MPU-6050的数据进行了不同的计算(它们现在应该没有任何功能)。最后,我希望它是映射到0-359的旋转数据。我知道Jeff Rowberg为此提供了一个不错的库,但我想自己做,这样我以后就可以理解它,因此可以对其进行修改。我的代码:
#include <Wire.h>

long accelX, accelY, accelZ;
float gForceX, gForceY, gForceZ, gyroX, gyroY, gyroZ,rotX, rotY, rotZ;
long accelX2, accelY2, accelZ2;
float gForceX2, gForceY2, gForceZ2;

void setup(){
  //write all ADO's to high to raise thieR adress to 0x69
  pinMode(22, OUTPUT);
  digitalWrite(22, HIGH);
  pinMode(23, OUTPUT);
  digitalWrite(23, HIGH);
  pinMode(24, OUTPUT);
  digitalWrite(24, HIGH);

  Wire.begin();
  Wire.beginTransmission(0x69);
  Wire.write(0x6B);
  Wire.write(0b00000000);
  Wire.endTransmission();
  Wire.beginTransmission(0x69);
  Wire.write(0x1B);
  Wire.write(0x00000000);
  Wire.endTransmission();
  Wire.beginTransmission(0x69);
  Wire.write(0x1C);
  Wire.write(0b00000000);
  Wire.endTransmission();

  Wire.begin();
  Wire.beginTransmission(0x68);
  Wire.write(0x6B);
  Wire.write(0b00000000);
  Wire.endTransmission();
  Wire.beginTransmission(0x68);
  Wire.write(0x1B);
  Wire.write(0x00000000);
  Wire.endTransmission();
  Wire.beginTransmission(0x68);
  Wire.write(0x1C);
  Wire.write(0b00000000);
  Wire.endTransmission();

  Serial.begin(115200);
}

void loop(){
  GetMpuValue(22);
  Serial.print("\t ||| \t");
  GetMpuValue(23);
  Serial.println("\t");
}

void GetMpuValue(int pin){
  digitalWrite(pin, LOW);
  Wire.beginTransmission(0x68);
  Wire.write(0x3B);
  Wire.endTransmission();
  Wire.requestFrom(0x68,6);

  Wire.beginTransmission(0x68);
  Wire.write(0x43);
  Wire.endTransmission();
  Wire.requestFrom(0x68,6);
  while(Wire.available() < 6);
  gyroX = Wire.read()<<8|Wire.read();
  gyroY = Wire.read()<<8|Wire.read();
  gyroZ = Wire.read()<<8|Wire.read();
  digitalWrite(pin, HIGH);

  Serial.print("gyro\t");
  Serial.print(gyroX);
  Serial.print("\t");
  Serial.print(gyroY);
  Serial.print("\t");
  Serial.print(gyroZ);
}

提前告诉你们!

最佳答案

陀螺仪的配置由以下几行给出:

Wire.beginTransmission(0x68); // Start communication with MPU-1
Wire.write(0x1B);             // Request the GYRO_CONFIG register
Wire.write(0x00);             // Apply the desired configuration to the register : + or -250°/s
Wire.endTransmission();       // End the transmission


Wire.beginTransmission(0x69); // Start communication with MPU-2
Wire.write(0x1B);             // Request the GYRO_CONFIG register
Wire.write(0x00);             // Apply the desired configuration to the register : + or -250°/s
Wire.endTransmission();       // End the transmission

因此它们必须具有相同的配置...

陀螺仪的配置由下式给出:

c&#43;&#43; - 有没有一种方法可以将MPU-6050原始数据转换为0-359旋转数据-LMLPHP

因此,在您的程序中,我看到地址为0X68的MPU的演算,而不是地址为0x69的MPU?一个多路复用器结?

另一件事,我看不到两个MPU的过滤器配置:(我不知道所有MPU是否都具有此功能,请阅读您MPU的数据表,请参阅我的评论)

c&#43;&#43; - 有没有一种方法可以将MPU-6050原始数据转换为0-359旋转数据-LMLPHP
Wire.beginTransmission(0x68); // Start communication with MPU
Wire.write(0x1A);             // Request the CONFIG register
Wire.write(0x03);             // Apply the desired config to the register : DLPF about 43Hz
Wire.endTransmission();       // End the transmission

如果要从原始数据读取 Angular 测量值,则只需将其除以131,如mpu所示:(您已将FS_SEL选择为0(-+ 250deg / sec),因此您的值为rawvalue / 131 = deg / seconde

您会看到250 x 131 = 32750(整数最大值= 32767)

c&#43;&#43; - 有没有一种方法可以将MPU-6050原始数据转换为0-359旋转数据-LMLPHP

陀螺仪只是一回事,看到here

所以我在设置中使用的完整代码

我的完整样本
//----------------------------------------------------------------------------------------------------------------------
#include <Wire.h>
//----------------------------------------------------------------------------------------------------------------------
#define YAW   0
#define PITCH 1
#define ROLL  2

#define X     0     // X axis
#define Y     1     // Y axis
#define Z     2     // Z axis

#define MPU_ADDRESS 0x68  // I2C address of the MPU-6050
#define FREQ        250   // Sampling frequency
#define SSF_GYRO    65.5  // Sensitivity Scale Factor of the gyro from datasheet
//----------------------------------------------------------------------------------------------------------------------
// The RAW values got from gyro (in °/sec) in that order: X, Y, Z
int gyro_raw[3] = {0, 0, 0};

// Average gyro offsets of each axis in that order: X, Y, Z
long gyro_offset[3] = {0, 0, 0};

// Calculated angles from gyro's values in that order: X, Y, Z
float gyro_angle[3]  = {0, 0, 0};

// The RAW values got from accelerometer (in m/sec²) in that order: X, Y, Z
int acc_raw[3] = {0 , 0 , 0};

// Calculated angles from accelerometer's values in that order: X, Y, Z
float acc_angle[3] = {0, 0, 0};

// Total 3D acceleration vector in m/s²
long acc_total_vector;

/**
 * Real measures on 3 axis calculated from gyro AND accelerometer in that order : Yaw, Pitch, Roll
 *  - Left wing up implies a positive roll
 *  - Nose up implies a positive pitch
 *  - Nose right implies a positive yaw
 */
float measures[3] = {0, 0, 0};

// MPU's temperature
int temperature;

// Init flag set to TRUE after first loop
boolean initialized;

unsigned int  period; // Sampling period
unsigned long loop_timer;
//----------------------------------------------------------------------------------------------------------------------
void setup() {
//  Serial.begin(57600); Only for debug
  Wire.begin();
  TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)

  setupMpu6050Registers();
  calibrateMpu6050();

  loop_timer = micros();
  period = (1000000 / FREQ) ; // Sampling period in µs
}
void loop() {
  readSensor();
  calculateAngles();

  while (micros() - loop_timer < period);
  loop_timer = micros();
}

关于c++ - 有没有一种方法可以将MPU-6050原始数据转换为0-359旋转数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/61754933/

10-11 20:05