是否有将MPU-6050原始数据转换为0-259旋转数据的方法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了是否有将MPU-6050原始数据转换为0-259旋转数据的方法相关的知识,希望对你有一定的参考价值。
我本周正在建立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-259的旋转数据。我知道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(" ||| ");
GetMpuValue(23);
Serial.println(" ");
}
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 ");
Serial.print(gyroX);
Serial.print(" ");
Serial.print(gyroY);
Serial.print(" ");
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
因此,它们必须具有相同的配置...因此,如果您没有两个MPU都需要的值,那么在计算中就很难捕获MPU的数据,而其他数据不在同一范围内...可能是接线问题?
陀螺仪的配置如下:
所以在您的程序中,我看到地址为0X68而不是地址为0x69的MPU演算?一个多路复用结???
另一件事,我看不到两个MPU的过滤器配置:
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
如果要将数据从[-250,250]范围转换为[0,259],则通常应采用
从[oldMin,oldMax]到[newMin,newMax]:
oldRange = oldMax - oldMin newRange = newMax - newMin newValue = ((oldValue - oldMin) * newRange / oldRange) + newMin
所以在这里:
newValue = ((oldValue + 250) * 259 / 500) - 0
以上是关于是否有将MPU-6050原始数据转换为0-259旋转数据的方法的主要内容,如果未能解决你的问题,请参考以下文章
Arduino ESP8266网页同步更新MPU6050数据模型化显示