Paparazzi UAS  v7.0_unstable
Paparazzi is a free software Unmanned Aircraft System.
imu_mpu6000_hmc5883 module

IMU with MPU6000 and HMC5883.

MPU6000 via SPI and HMC5883 via I2C. Mag by default rotated by 90deg around z axis relative to MPU. E.g. for Aspirin 2.1

Example for airframe file

Add to your firmware section: This example contains all possible configuration options, not all of them are mandatory!

<module name="imu_mpu6000_hmc5883">
b'<define name="IMU_MPU_LOWPASS_FILTER" value="MPU60X0_DLPF_256HZ" />\n '
b'<define name="IMU_MPU_SMPLRT_DIV" value="3" />\n '
b'<define name="IMU_MPU_GYRO_RANGE" value="MPU60X0_GYRO_RANGE_2000" />\n '
b'<define name="IMU_MPU_ACCEL_RANGE" value="MPU60X0_ACCEL_RANGE_16G" />\n '
b'<define name="IMU_MPU_CHAN_X" value="0" />\n '
b'<define name="IMU_MPU_CHAN_Y" value="1" />\n '
b'<define name="IMU_MPU_CHAN_Z" value="2" />\n '
b'<define name="IMU_MPU_X_SIGN" value="1" />\n '
b'<define name="IMU_MPU_Y_SIGN" value="1" />\n '
b'<define name="IMU_MPU_Z_SIGN" value="1" />\n\n '
b'<define name="IMU_HMC_CHAN_X" value="1" />\n '
b'<define name="IMU_HMC_CHAN_Y" value="0" />\n '
b'<define name="IMU_HMC_CHAN_Z" value="2" />\n '
b'<define name="IMU_HMC_X_SIGN" value="1" />\n '
b'<define name="IMU_HMC_Y_SIGN" value="-1" />\n '
b'<define name="IMU_HMC_Z_SIGN" value="1" />\n '
b'<configure name="IMU_MPU_SPI_DEV" value="spi2" />\n '
b'<configure name="IMU_MPU_SPI_SLAVE_IDX" value="SPI_SLAVE0" />\n '
b'<configure name="IMU_HMC_I2C_DEV" value="i2c2" />\n '
</module>

Module configuration options

Configure Options

  • name: IMU_MPU_SPI_DEV value: spi2
    Description: SPI device to use for MPU6000
  • name: IMU_MPU_SPI_SLAVE_IDX value: SPI_SLAVE0
    Description: slave index of the MPU CS pin
  • name: IMU_HMC_I2C_DEV value: i2c2
    Description: I2C device to use for HMC5883

Define Options

  • name: IMU_MPU_LOWPASS_FILTER value: MPU60X0_DLPF_256HZ
    Description: DigitalLowPassFilter setting of the MPU
  • name: IMU_MPU_SMPLRT_DIV value: 3
    Description: sample rate divider setting of the MPU
  • name: IMU_MPU_GYRO_RANGE value: MPU60X0_GYRO_RANGE_2000
    Description: gyroscope range setting of the MPU
  • name: IMU_MPU_ACCEL_RANGE value: MPU60X0_ACCEL_RANGE_16G
    Description: accelerometer range setting of the MPU
  • name: IMU_MPU_CHAN_X value: 0
    Description: channel index
  • name: IMU_MPU_CHAN_Y value: 1
    Description: channel index
  • name: IMU_MPU_CHAN_Z value: 2
    Description: channel index
  • name: IMU_MPU_X_SIGN value: 1
    Description: axis sign
  • name: IMU_MPU_Y_SIGN value: 1
    Description: axis sign
  • name: IMU_MPU_Z_SIGN value: 1
    Description: axis sign
  • name: IMU_HMC_CHAN_X value: 1
    Description: channel index
  • name: IMU_HMC_CHAN_Y value: 0
    Description: channel index
  • name: IMU_HMC_CHAN_Z value: 2
    Description: channel index
  • name: IMU_HMC_X_SIGN value: 1
    Description: axis sign
  • name: IMU_HMC_Y_SIGN value: -1
    Description: axis sign
  • name: IMU_HMC_Z_SIGN value: 1
    Description: axis sign

Module functions

Init Functions

These initialization functions are called once on startup.

Event Functions

These event functions are called in each cycle of the module event loop.

Periodic Functions

These functions are called periodically at the specified frequency from the module periodic loop.

  • imu_mpu_hmc_periodic()
    • Running at maximum module frequency.
    • Autorun: LOCK
      Periodic function automatically starts after init and can't be stopped.

Files

Header Files

The following headers are automatically included in modules.h

Source Files

Raw imu_mpu6000_hmc5883.xml file:

<!DOCTYPE module SYSTEM "module.dtd">
<module name="imu_mpu6000_hmc5883" dir="imu" task="sensors">
<doc>
<description>
IMU with MPU6000 and HMC5883.
MPU6000 via SPI and HMC5883 via I2C.
Mag by default rotated by 90deg around z axis relative to MPU.
E.g. for Aspirin 2.1
</description>
<configure name="IMU_MPU_SPI_DEV" value="spi2" description="SPI device to use for MPU6000"/>
<configure name="IMU_MPU_SPI_SLAVE_IDX" value="SPI_SLAVE0" description="slave index of the MPU CS pin"/>
<configure name="IMU_HMC_I2C_DEV" value="i2c2" description="I2C device to use for HMC5883"/>
<define name="IMU_MPU_LOWPASS_FILTER" value="MPU60X0_DLPF_256HZ" description="DigitalLowPassFilter setting of the MPU"/>
<define name="IMU_MPU_SMPLRT_DIV" value="3" description="sample rate divider setting of the MPU"/>
<define name="IMU_MPU_GYRO_RANGE" value="MPU60X0_GYRO_RANGE_2000" description="gyroscope range setting of the MPU"/>
<define name="IMU_MPU_ACCEL_RANGE" value="MPU60X0_ACCEL_RANGE_16G" description="accelerometer range setting of the MPU"/>
<define name="IMU_MPU_CHAN_X" value="0" description="channel index"/>
<define name="IMU_MPU_CHAN_Y" value="1" description="channel index"/>
<define name="IMU_MPU_CHAN_Z" value="2" description="channel index"/>
<define name="IMU_MPU_X_SIGN" value="1" description="axis sign"/>
<define name="IMU_MPU_Y_SIGN" value="1" description="axis sign"/>
<define name="IMU_MPU_Z_SIGN" value="1" description="axis sign"/>
<define name="IMU_HMC_CHAN_X" value="1" description="channel index"/>
<define name="IMU_HMC_CHAN_Y" value="0" description="channel index"/>
<define name="IMU_HMC_CHAN_Z" value="2" description="channel index"/>
<define name="IMU_HMC_X_SIGN" value="1" description="axis sign"/>
<define name="IMU_HMC_Y_SIGN" value="-1" description="axis sign"/>
<define name="IMU_HMC_Z_SIGN" value="1" description="axis sign"/>
</doc>
<dep>
<depends>spi_master,i2c,imu_common</depends>
<provides>imu,mag</provides>
</dep>
<header>
<file name="imu_mpu6000_hmc5883.h"/>
</header>
<init fun="imu_mpu_hmc_init()"/>
<periodic fun="imu_mpu_hmc_periodic()"/>
<event fun="imu_mpu_hmc_event()"/>
<makefile target="!sim|nps|fbw">
<configure name="IMU_MPU_SPI_DEV" default="spi2" case="lower|upper"/>
<configure name="IMU_MPU_SPI_SLAVE_IDX" default="SPI_SLAVE0"/>
<define name="IMU_MPU_SPI_DEV" value="$(IMU_MPU_SPI_DEV_LOWER)"/>
<define name="USE_$(IMU_MPU_SPI_DEV_UPPER)"/>
<define name="IMU_MPU_SPI_SLAVE_IDX" value="$(IMU_MPU_SPI_SLAVE_IDX)"/>
<define name="USE_$(IMU_MPU_SPI_SLAVE_IDX)"/>
<configure name="IMU_HMC_I2C_DEV" default="i2c2" case="lower|upper"/>
<define name="IMU_HMC_I2C_DEV" value="$(IMU_HMC_I2C_DEV_LOWER)"/>
<define name="USE_$(IMU_HMC_I2C_DEV_UPPER)"/>
<file name="mpu60x0.c" dir="peripherals"/>
<file name="mpu60x0_spi.c" dir="peripherals"/>
<file name="hmc58xx.c" dir="peripherals"/>
<file name="imu_mpu6000_hmc5883.c"/>
<test>
<define name="SPI_MASTER"/>
<define name="IMU_MPU_SPI_DEV" value="spi1"/>
<define name="USE_SPI1"/>
<define name="IMU_MPU_SPI_SLAVE_IDX" value="0"/>
<define name="USE_SPI_SLAVE0"/>
<define name="IMU_HMC_I2C_DEV" value="i2c2"/>
<define name="USE_I2C2"/>
<define name="PERIODIC_FREQUENCY" value="512"/>
<define name="IMU_MPU_HMC_PERIODIC_FREQ" value="512"/>
</test>
</makefile>
</module>