本文整理汇总了C++中MPU6050::getAres方法的典型用法代码示例。如果您正苦于以下问题:C++ MPU6050::getAres方法的具体用法?C++ MPU6050::getAres怎么用?C++ MPU6050::getAres使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MPU6050
的用法示例。
在下文中一共展示了MPU6050::getAres方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main()
{
pc.baud(9600);
//Set up I2C
i2c.frequency(400000); // use fast (400 kHz) I2C
t.start();
lcd.init();
lcd.setBrightness(0.05);
// Read the WHO_AM_I register, this is a good test of communication
uint8_t whoami = mpu6050.readByte(MPU6050_ADDRESS, WHO_AM_I_MPU6050); // Read WHO_AM_I register for MPU-6050
pc.printf("I AM 0x%x\n\r", whoami); pc.printf("I SHOULD BE 0x68\n\r");
if (whoami == 0x68) // WHO_AM_I should always be 0x68
{
pc.printf("MPU6050 is online...");
wait(1);
lcd.clear();
lcd.printString("MPU6050 OK", 0, 0);
mpu6050.MPU6050SelfTest(SelfTest); // Start by performing self test and reporting values
pc.printf("x-axis self test: acceleration trim within : "); pc.printf("%f", SelfTest[0]); pc.printf("% of factory value \n\r");
pc.printf("y-axis self test: acceleration trim within : "); pc.printf("%f", SelfTest[1]); pc.printf("% of factory value \n\r");
pc.printf("z-axis self test: acceleration trim within : "); pc.printf("%f", SelfTest[2]); pc.printf("% of factory value \n\r");
pc.printf("x-axis self test: gyration trim within : "); pc.printf("%f", SelfTest[3]); pc.printf("% of factory value \n\r");
pc.printf("y-axis self test: gyration trim within : "); pc.printf("%f", SelfTest[4]); pc.printf("% of factory value \n\r");
pc.printf("z-axis self test: gyration trim within : "); pc.printf("%f", SelfTest[5]); pc.printf("% of factory value \n\r");
wait(1);
if(SelfTest[0] < 1.0f && SelfTest[1] < 1.0f && SelfTest[2] < 1.0f && SelfTest[3] < 1.0f && SelfTest[4] < 1.0f && SelfTest[5] < 1.0f)
{
mpu6050.resetMPU6050(); // Reset registers to default in preparation for device calibration
mpu6050.calibrateMPU6050(gyroBias, accelBias); // Calibrate gyro and accelerometers, load biases in bias registers
mpu6050.initMPU6050(); pc.printf("MPU6050 initialized for active data mode....\n\r"); // Initialize device for active mode read of acclerometer, gyroscope, and temperature
lcd.clear();
lcd.printString("MPU6050", 0, 0);
lcd.printString("pass self test", 0, 1);
lcd.printString("initializing", 0, 2);
wait(2);
}
else
{
pc.printf("Device did not the pass self-test!\n\r");
lcd.clear();
lcd.printString("MPU6050", 0, 0);
lcd.printString("no pass", 0, 1);
lcd.printString("self test", 0, 2);
}
}
else
{
pc.printf("Could not connect to MPU6050: \n\r");
pc.printf("%#x \n", whoami);
lcd.clear();
lcd.printString("MPU6050", 0, 0);
lcd.printString("no connection", 0, 1);
lcd.printString("0x", 0, 2); lcd.setXYAddress(20, 2); lcd.printChar(whoami);
while(1) ; // Loop forever if communication doesn't happen
}
while(1) {
// If data ready bit set, all data registers have new data
if(mpu6050.readByte(MPU6050_ADDRESS, INT_STATUS) & 0x01) { // check if data ready interrupt
mpu6050.readAccelData(accelCount); // Read the x/y/z adc values
mpu6050.getAres();
// Now we'll calculate the accleration value into actual g's
ax = (float)accelCount[0]*aRes - accelBias[0]; // get actual g value, this depends on scale being set
ay = (float)accelCount[1]*aRes - accelBias[1];
az = (float)accelCount[2]*aRes - accelBias[2];
mpu6050.readGyroData(gyroCount); // Read the x/y/z adc values
mpu6050.getGres();
// Calculate the gyro value into actual degrees per second
gx = (float)gyroCount[0]*gRes; // - gyroBias[0]; // get actual gyro value, this depends on scale being set
gy = (float)gyroCount[1]*gRes; // - gyroBias[1];
gz = (float)gyroCount[2]*gRes; // - gyroBias[2];
tempCount = mpu6050.readTempData(); // Read the x/y/z adc values
temperature = (tempCount) / 340. + 36.53; // Temperature in degrees Centigrade
}
Now = t.read_us();
deltat = (float)((Now - lastUpdate)/1000000.0f) ; // set integration time by time elapsed since last filter update
lastUpdate = Now;
sum += deltat;
//.........这里部分代码省略.........