int main()
{
    MPU6050 *mpu = new MPU6050();
    mpu->setDebug(true);
    
    mpu->reset();
    if (mpu->whoAmI())
    {
        printf("WhoAmI was okay\n");
        
        // i2c bypass enabled
        mpu->setBypassEnable(true);
        printf("Set and Get BypassEnable to true - %s\n", mpu->getBypassEnable() ? "SUCCESS" : "FAILED");
        mpu->setBypassEnable(false);
        printf("Set and Get BypassEnable to false - %s\n", !mpu->getBypassEnable() ? "SUCCESS" : "FAILED");

        // gyro ranges
        mpu->setFullScaleGyroRange(fullScaleGyroRange::FS_GYRO_250DEG_S);
        printf("Set and Get FullScaleGyroRange to 250deg/sec - %s\n", (mpu->getFullScaleGyroRange() == fullScaleGyroRange::FS_GYRO_250DEG_S) ? "SUCCESS" : "FAILED");
        mpu->setFullScaleGyroRange(fullScaleGyroRange::FS_GYRO_500DEG_S);
        printf("Set and Get FullScaleGyroRange to 500deg/sec - %s\n", (mpu->getFullScaleGyroRange() == fullScaleGyroRange::FS_GYRO_500DEG_S) ? "SUCCESS" : "FAILED");
        mpu->setFullScaleGyroRange(fullScaleGyroRange::FS_GYRO_1000DEG_S);
        printf("Set and Get FullScaleGyroRange to 1000deg/sec - %s\n", (mpu->getFullScaleGyroRange() == fullScaleGyroRange::FS_GYRO_1000DEG_S) ? "SUCCESS" : "FAILED");
        mpu->setFullScaleGyroRange(fullScaleGyroRange::FS_GYRO_2000DEG_S);
        printf("Set and Get FullScaleGyroRange to 2000deg/sec - %s\n", (mpu->getFullScaleGyroRange() == fullScaleGyroRange::FS_GYRO_2000DEG_S) ? "SUCCESS" : "FAILED");

        // accelerometer ranges
        mpu->setFullScaleAccRange(fullScaleAccRange::FS_ACCL_2G);
        printf("Set and Get FullScaleAccRange to 2G - %s\n", (mpu->getFullScaleAccRange() == fullScaleAccRange::FS_ACCL_2G) ? "SUCCESS" : "FAILED");
        mpu->setFullScaleAccRange(fullScaleAccRange::FS_ACCL_4G);
        printf("Set and Get FullScaleAccRange to 4G - %s\n", (mpu->getFullScaleAccRange() == fullScaleAccRange::FS_ACCL_4G) ? "SUCCESS" : "FAILED");
        mpu->setFullScaleAccRange(fullScaleAccRange::FS_ACCL_8G);
        printf("Set and Get FullScaleAccRange to 8G - %s\n", (mpu->getFullScaleAccRange() == fullScaleAccRange::FS_ACCL_8G) ? "SUCCESS" : "FAILED");
        mpu->setFullScaleAccRange(fullScaleAccRange::FS_ACCL_16G);
        printf("Set and Get FullScaleAccRange to 16G - %s\n", (mpu->getFullScaleAccRange() == fullScaleAccRange::FS_ACCL_16G) ? "SUCCESS" : "FAILED");

        return 1;
    }
    return 0;
}
示例#2
0
int main() 
{
    pc.baud(9600);                              // baud rate: 9600
    mpu6050.whoAmI();                           // Communication test: WHO_AM_I register reading 
    wait(1);
    mpu6050.calibrate(accelBias,gyroBias);      // Calibrate MPU6050 and load biases into bias registers
    pc.printf("Calibration is completed. \r\n");
    wait(0.5);
    mpu6050.init();                             // Initialize the sensor
    wait(1);
    pc.printf("MPU6050 is initialized for operation.. \r\n\r\n");
    wait_ms(500);
    
    while(1) 
    {
     
     /* Uncomment below if you want to see accel and gyro data */
        
//        pc.printf(" _____________________________________________________________  \r\n");
//        pc.printf("| Accelerometer(g) | ax=%.3f | ay=%.3f | az=%.3f                \r\n",ax,ay,az);
//        pc.printf("| Gyroscope(deg/s) | gx=%.3f | gy=%.3f | gz=%.3f                \r\n",gx,gy,gz);
//        pc.printf("|_____________________________________________________________  \r\n\r\n");
//        
//        wait(2.5);
                
        filter.attach(&compFilter, 0.005);    // Call the complementaryFilter func. every 5 ms (200 Hz sampling period)
        
        pc.printf(" _______________\r\n");
        pc.printf("| Pitch: %.3f   \r\n",pitchAngle);
        pc.printf("| Roll:  %.3f   \r\n",rollAngle);
        pc.printf("|_______________\r\n\r\n");
        
        wait(1);
     
    }
}