inv_error_t MPU9250_DMP::dmpSetOrientation(const signed char * orientationMatrix)
{
	unsigned short scalar;
	scalar = orientation_row_2_scale(orientationMatrix);
	scalar |= orientation_row_2_scale(orientationMatrix + 3) << 3;
	scalar |= orientation_row_2_scale(orientationMatrix + 6) << 6;

    dmp_register_android_orient_cb(orient_cb);

	return dmp_set_orientation(scalar);
}
Example #2
0
// Private
int8_t IMUTask::MPUSetup()
{
    // TODO: should check here to see if IMU is already setup and just init the lib

    int8_t result = 0;
    struct int_param_s int_param;
    int_param.cb = IMU_interrupt;
    int_param.pin = MPU_INT;
    int_param.arg = FALLING;

    unsigned char accel_fsr;
    unsigned short gyro_rate, gyro_fsr;
    unsigned long timestamp;

    result = mpu_init(&int_param);
    debug::log("IMUTask: mpu_init returned " + String(result));
    if (result != 0) {
        return -1;
    }

    /* Wake up all sensors. */
    result = mpu_set_sensors(INV_XYZ_GYRO | INV_XYZ_ACCEL);
    debug::log("IMUTask: mpu_set_sensors returned " + String(result));

    result = mpu_set_sample_rate(IMU_DEFAULT_MPU_HZ);
    debug::log("IMUTask: mpu_set_sample_rate returned " + String(result));

    debug::log("Pre laod");

    result = dmp_load_motion_driver_firmware();
    debug::log("IMUTask: dmp_load_motion_driver_firmware returned " + String(result));
    if (result != 0) {
        return -2;
    }
    result = dmp_set_orientation( inv_orientation_matrix_to_scalar(gyro_orientation) );
    debug::log("IMUTask: dmp_set_orientation returned " + String(result));
    if (result != 0) {
        return -3;
    }

    /*
     * Known Bug -
     * DMP when enabled will sample sensor data at 200Hz and output to FIFO at the rate
     * specified in the dmp_set_fifo_rate API. The DMP will then sent an interrupt once
     * a sample has been put into the FIFO. Therefore if the dmp_set_fifo_rate is at 25Hz
     * there will be a 25Hz interrupt from the MPU device.
     *
     * There is a known issue in which if you do not enable DMP_FEATURE_TAP
     * then the interrupts will be at 200Hz even if fifo rate
     * is set at a different rate. To avoid this issue include the DMP_FEATURE_TAP
     */
    unsigned short dmp_features = DMP_FEATURE_TAP |                // Don't remove this, see above
                                  DMP_FEATURE_ANDROID_ORIENT;      // we use this for the screen
    // Disableing the rest for now as we dont yet have a use for them
    //      DMP_FEATURE_SEND_RAW_ACCEL |
    //      DMP_FEATURE_SEND_RAW_GYRO;

    result = dmp_enable_feature(dmp_features);
    if (result != 0) {
        debug::log("IMUTask: mp_enable_feature returned " + String(result));
        return -4;
    }


    result = dmp_set_fifo_rate(IMU_DEFAULT_MPU_HZ);
    if (result != 0) {
        debug::log("IMUTask: dmp_set_fifo_rate returned " + String(result));
        return -5;
    }

    dmp_register_tap_cb(IMU_tap_cb);
    dmp_register_android_orient_cb(IMU_android_orient_cb);
    dmp_set_interrupt_mode(DMP_INT_GESTURE);

    return 0;
}