/* * mpu9150.h * * Created: 3/20/15 * Author: Andrew H. Fagg * * Interface library for the MPU9150 * */ #ifndef MPU9150_H #define MPU9150_H #include "oulib.h" /** Initialize the MPU9150 inertial measurement unit @param address The I2C address of the MPU9150. Can be 0 or 1, depending on hardware configuration @return Error code (=0 if no errors) */ int8_t imu_init(uint8_t address); /** Read the raw magnetometer values. @param mag[3] Array of raw magnetometer readings (modified by this function). Each is a 13-bit twos-complement number, with the range representing +/- 12T @return Error code (=0 if no errors) */ int8_t imu_read_magnetometer(int16_t mag[3]); /** Read the state of the 3-axis gyroscope @param gyro[3] Array of gyro readings (modified by this function). Each is a 16-bit twos-complement number, with a range of +/-500 deg/sec @return Error code (=0 if no errors) */ int8_t imu_read_gyro(int16_t gyro[3]); /** Read the state of the 3-axis accelerometer @param accel[3] Array of accelerometer readings (modified by this function). Each is a 16-bit twos-complement number, with a range of +/-2g @return Error code (=0 if no errors) */ int8_t imu_read_accel(int16_t accel[3]); /** Read the state of the compass @return Current heading of the "X axis" of the magnetometer in units of 1/(2^16) of a full rotation. IE: 0 = magnetic north, 0x8000 = PI, and 0xFFFF = PI * (2 - 1/32768). For those who are keeping track, this is a fixed-point number of type "0.16" */ uint16_t imu_read_compass(void); /** Compute and set the compass calibration parameters. Prompts the user to slowly rotate the compass through two cycles over a period of time. As this function is collecting data, it is printing period characters. Once complete, this function prints out the parameters offset0 and offset1 to the screen and sets these parameters internally. Note: this function only needs to be called once for calibration purposes (after the sensor is mounted to the craft). Afterwards, the reported offset values can be directly passed to imu_set_compass_offsets() @param fp File pointer for serial output. */ void imu_calibrate_compass(FILE *fp); /** Set the compass offsets. The correct values of these offsets are reported by imu_calibrate_compass(). @param offset0 Offset for the X-axis magnetometer @param offset1 Offset for the Y-axis magnetometer */ void imu_set_compass_offsets(int16_t offset0, int16_t offset1); #endif