README.md 3.1 KB

DMP-ICM20948

// app.cpp

extern SPI_HandleTypeDef hspi1;


void app(){

	DMP_ICM20948 icm;
	DMP_ICM20948Settings icmSettings =
	{
	  .i2c_speed = 400000,                // i2c clock speed
	  .is_SPI = false,                    // Enable SPI, if disable use i2c
	  .cs_pin = 10,                       // SPI chip select pin
	  .spi_speed = 7000000,               // SPI clock speed in Hz, max speed is 7MHz
	  .mode = 1,                          // 0 = low power mode, 1 = high performance mode
	  .enable_gyroscope = true,           // Enables gyroscope output
	  .enable_accelerometer = true,       // Enables accelerometer output
	  .enable_magnetometer = true,        // Enables magnetometer output // Enables quaternion output
	  .enable_gravity = true,             // Enables gravity vector output
	  .enable_linearAcceleration = true,  // Enables linear acceleration output
	  .enable_quaternion6 = true,         // Enables quaternion 6DOF output
	  .enable_quaternion9 = true,         // Enables quaternion 9DOF output
	  .enable_har = true,                 // Enables activity recognition
	  .enable_steps = true,               // Enables step counter
	  .gyroscope_frequency = 1,           // Max frequency = 225, min frequency = 1
	  .accelerometer_frequency = 1,       // Max frequency = 225, min frequency = 1
	  .magnetometer_frequency = 1,        // Max frequency = 70, min frequency = 1
	  .gravity_frequency = 1,             // Max frequency = 225, min frequency = 1
	  .linearAcceleration_frequency = 1,  // Max frequency = 225, min frequency = 1
	  .quaternion6_frequency = 50,        // Max frequency = 225, min frequency = 50
	  .quaternion9_frequency = 50,        // Max frequency = 225, min frequency = 50
	  .har_frequency = 50,                // Max frequency = 225, min frequency = 50
	  .steps_frequency = 50               // Max frequency = 225, min frequency = 50

	};

	icm.init(icmSettings);

	while(1){

		    icm.task();
		    //run_icm20948_accel_controller();
		    //run_icm20948_gyro_controller();
		    //run_icm20948_mag_controller();
		    //run_icm20948_linearAccel_controller();
		    //run_icm20948_grav_controller();
		    run_icm20948_quat6_controller(&icm, true);
		    //run_icm20948_quat9_controller(true);
		    //run_icm20948_har_controller();
		    //run_icm20948_steps_controller();
		  HAL_Delay(100);
	}

}


void run_icm20948_quat6_controller(DMP_ICM20948 *icm20948, uint8_t inEuler)
{
    float quat_w, quat_x, quat_y, quat_z;
    float roll, pitch, yaw;
    //char sensor_string_buff[128];
    if (inEuler)
    {
        if (icm20948->euler6DataIsReady())
        {
            icm20948->readEuler6Data(&roll, &pitch, &yaw);
            //sprintf(sensor_string_buff, "Euler6 roll, pitch, yaw(deg): [%f,%f,%f]", roll, pitch, yaw);
            //Serial.println(sensor_string_buff);
        }
    }
    else
    {
        if (icm20948->quat6DataIsReady())
        {
            icm20948->readQuat6Data(&quat_w, &quat_x, &quat_y, &quat_z);
            //sprintf(sensor_string_buff, "Quat6 w, x, y, z (deg): [%f,%f,%f,%f]", quat_w, quat_x, quat_y, quat_z);
            //Serial.println(sensor_string_buff);
        }
    }

}