icm20948

package
Version: v0.0.0-...-d83dac8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2021 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MPU_ADDRESS               = 0x68
	ICMREG_XG_OFFS_TC         = 0x00
	ICMREG_YG_OFFS_TC         = 0x01
	ICMREG_ZG_OFFS_TC         = 0x02
	ICMREG_X_FINE_GAIN        = 0x03
	ICMREG_Y_FINE_GAIN        = 0x04
	ICMREG_Z_FINE_GAIN        = 0x05
	ICMREG_XA_OFFS_H          = 0x06
	ICMREG_XA_OFFS_L          = 0x07
	ICMREG_YA_OFFS_H          = 0x08
	ICMREG_YA_OFFS_L          = 0x09
	ICMREG_ZA_OFFS_H          = 0x0A
	ICMREG_ZA_OFFS_L          = 0x0B
	ICMREG_PRODUCT_ID         = 0x0C
	ICMREG_SELF_TEST_X        = 0x0D
	ICMREG_SELF_TEST_Y        = 0x0E
	ICMREG_SELF_TEST_Z        = 0x0F
	ICMREG_SELF_TEST_A        = 0x10
	ICMREG_SMPLRT_DIV         = 0x19
	ICMREG_CONFIG             = 0x1A
	ICMREG_LP_ACCEL_ODR       = 0x1E
	ICMREG_MOT_THR            = 0x1F
	ICMREG_FIFO_EN            = 0x23
	ICMREG_INT_PIN_CFG        = 0x37
	ICMREG_INT_ENABLE         = 0x38
	ICMREG_ACCEL_XOUT_H       = 0x2D //
	ICMREG_ACCEL_XOUT_L       = 0x2E //
	ICMREG_ACCEL_YOUT_H       = 0x2F //
	ICMREG_ACCEL_YOUT_L       = 0x30 //
	ICMREG_ACCEL_ZOUT_H       = 0x31 //
	ICMREG_ACCEL_ZOUT_L       = 0x32 //
	ICMREG_TEMP_OUT_H         = 0x39 //
	ICMREG_TEMP_OUT_L         = 0x3A //
	ICMREG_GYRO_XOUT_H        = 0x33 //
	ICMREG_GYRO_XOUT_L        = 0x34 //
	ICMREG_GYRO_YOUT_H        = 0x35 //
	ICMREG_GYRO_YOUT_L        = 0x36 //
	ICMREG_GYRO_ZOUT_H        = 0x37 //
	ICMREG_GYRO_ZOUT_L        = 0x38 //
	ICMREG_EXT_SENS_DATA_00   = 0x3B // EXT_SLV_SENS_DATA_00.
	ICMREG_EXT_SENS_DATA_01   = 0x3C // EXT_SLV_SENS_DATA_01.
	ICMREG_EXT_SENS_DATA_02   = 0x3D // EXT_SLV_SENS_DATA_02.
	ICMREG_EXT_SENS_DATA_03   = 0x3E // EXT_SLV_SENS_DATA_03.
	ICMREG_EXT_SENS_DATA_04   = 0x3F // EXT_SLV_SENS_DATA_04.
	ICMREG_EXT_SENS_DATA_05   = 0x40 // EXT_SLV_SENS_DATA_05.
	ICMREG_EXT_SENS_DATA_06   = 0x41 // EXT_SLV_SENS_DATA_06.
	ICMREG_EXT_SENS_DATA_07   = 0x42 // EXT_SLV_SENS_DATA_07.
	ICMREG_EXT_SENS_DATA_08   = 0x43 // EXT_SLV_SENS_DATA_08.
	ICMREG_EXT_SENS_DATA_09   = 0x44 // EXT_SLV_SENS_DATA_09.
	ICMREG_EXT_SENS_DATA_10   = 0x45 // EXT_SLV_SENS_DATA_10.
	ICMREG_EXT_SENS_DATA_11   = 0x46 // EXT_SLV_SENS_DATA_11.
	ICMREG_EXT_SENS_DATA_12   = 0x47 // EXT_SLV_SENS_DATA_12.
	ICMREG_EXT_SENS_DATA_13   = 0x48 // EXT_SLV_SENS_DATA_13.
	ICMREG_EXT_SENS_DATA_14   = 0x49 // EXT_SLV_SENS_DATA_14.
	ICMREG_EXT_SENS_DATA_15   = 0x4A // EXT_SLV_SENS_DATA_15.
	ICMREG_EXT_SENS_DATA_16   = 0x4B // EXT_SLV_SENS_DATA_16.
	ICMREG_EXT_SENS_DATA_17   = 0x4C // EXT_SLV_SENS_DATA_17.
	ICMREG_EXT_SENS_DATA_18   = 0x4D // EXT_SLV_SENS_DATA_18.
	ICMREG_EXT_SENS_DATA_19   = 0x4E // EXT_SLV_SENS_DATA_19.
	ICMREG_EXT_SENS_DATA_20   = 0x4F // EXT_SLV_SENS_DATA_20.
	ICMREG_EXT_SENS_DATA_21   = 0x50 // EXT_SLV_SENS_DATA_21.
	ICMREG_EXT_SENS_DATA_22   = 0x51 // EXT_SLV_SENS_DATA_22.
	ICMREG_EXT_SENS_DATA_23   = 0x52 // EXT_SLV_SENS_DATA_23.
	ICMREG_I2C_SLV0_DO        = 0x63
	ICMREG_I2C_SLV1_DO        = 0x64
	ICMREG_I2C_SLV2_DO        = 0x65
	ICMREG_I2C_SLV3_DO        = 0x66
	ICMREG_I2C_MST_DELAY_CTRL = 0x67
	ICMREG_SIGNAL_PATH_RESET  = 0x68
	ICMREG_MOT_DETECT_CTRL    = 0x69
	ICMREG_USER_CTRL          = 0x6A
	ICMREG_PWR_MGMT_1         = 0x06
	ICMREG_PWR_MGMT_2         = 0x6C
	ICMREG_BANK_SEL           = 0x7F // New use.
	ICMREG_MEM_START_ADDR     = 0x6E
	ICMREG_MEM_R_W            = 0x6F
	ICMREG_DMP_CFG_1          = 0x70
	ICMREG_DMP_CFG_2          = 0x71
	ICMREG_FIFO_COUNTH        = 0x72
	ICMREG_FIFO_COUNTL        = 0x73
	ICMREG_FIFO_R_W           = 0x74
	ICMREG_WHOAMI             = 0x75
	ICMREG_XA_OFFSET_H        = 0x14
	ICMREG_XA_OFFSET_L        = 0x15
	ICMREG_YA_OFFSET_H        = 0x17
	ICMREG_YA_OFFSET_L        = 0x18
	ICMREG_ZA_OFFSET_H        = 0x1A
	ICMREG_ZA_OFFSET_L        = 0x1B

	// Reg bank 2.
	ICMREG_ACCEL_CONFIG       = 0x14
	ICMREG_GYRO_CONFIG        = 0x01
	ICMREG_ACCEL_CONFIG_2     = 0x15
	ICMREG_TEMP_CONFIG        = 0x53
	ICMREG_GYRO_SMPLRT_DIV    = 0x00
	ICMREG_XG_OFFS_USRH       = 0x03
	ICMREG_XG_OFFS_USRL       = 0x04
	ICMREG_YG_OFFS_USRH       = 0x05
	ICMREG_YG_OFFS_USRL       = 0x06
	ICMREG_ZG_OFFS_USRH       = 0x07
	ICMREG_ZG_OFFS_USRL       = 0x08
	ICMREG_ACCEL_SMPLRT_DIV_1 = 0x10
	ICMREG_ACCEL_SMPLRT_DIV_2 = 0x11

	BITS_DLPF_GYRO_CFG_197HZ = 0x01 // GYRO_CONFIG
	BITS_DLPF_GYRO_CFG_152HZ = 0x09 // GYRO_CONFIG
	BITS_DLPF_GYRO_CFG_120HZ = 0x11 // GYRO_CONFIG
	BITS_DLPF_GYRO_CFG_51HZ  = 0x19 // GYRO_CONFIG
	BITS_DLPF_GYRO_CFG_24HZ  = 0x21 // GYRO_CONFIG
	BITS_DLPF_GYRO_CFG_12HZ  = 0x29 // GYRO_CONFIG
	BITS_DLPF_GYRO_CFG_6HZ   = 0x31 // GYRO_CONFIG

	BITS_DLPF_ACCEL_CFG_246HZ = 0x01 // ACCEL_CONFIG
	BITS_DLPF_ACCEL_CFG_111HZ = 0x11 // ACCEL_CONFIG
	BITS_DLPF_ACCEL_CFG_50HZ  = 0x19 // ACCEL_CONFIG
	BITS_DLPF_ACCEL_CFG_24HZ  = 0x21 // ACCEL_CONFIG
	BITS_DLPF_ACCEL_CFG_12HZ  = 0x29 // ACCEL_CONFIG
	BITS_DLPF_ACCEL_CFG_5HZ   = 0x31 // ACCEL_CONFIG

	BITS_FS_250DPS  = 0x00 // GYRO_CONFIG
	BITS_FS_500DPS  = 0x02 // GYRO_CONFIG
	BITS_FS_1000DPS = 0x04 // GYRO_CONFIG
	BITS_FS_2000DPS = 0x06 // GYRO_CONFIG

	BITS_FS_2G  = 0x00 // ACCEL_CONFIG
	BITS_FS_4G  = 0x02 // ACCEL_CONFIG
	BITS_FS_8G  = 0x04 // ACCEL_CONFIG
	BITS_FS_16G = 0x06 // ACCEL_CONFIG

	// Reg bank 3.
	ICMREG_I2C_MST_CTRL  = 0x01
	ICMREG_I2C_SLV0_ADDR = 0x03
	ICMREG_I2C_SLV0_REG  = 0x04
	ICMREG_I2C_SLV0_CTRL = 0x05
	ICMREG_I2C_SLV1_ADDR = 0x07
	ICMREG_I2C_SLV1_REG  = 0x08
	ICMREG_I2C_SLV1_CTRL = 0x09
	ICMREG_I2C_SLV4_CTRL = 0x15

	/* ---- AK8963 Reg In MPU9250 ----------------------------------------------- */
	AK8963_I2C_ADDR        = 0x0C //0x18
	AK8963_Device_ID       = 0x48
	AK8963_MAX_SAMPLE_RATE = 0x64 // 100 Hz
	// Read-only Reg
	AK8963_WIA  = 0x00
	AK8963_INFO = 0x01
	AK8963_ST1  = 0x02
	AK8963_HXL  = 0x03
	AK8963_HXH  = 0x04
	AK8963_HYL  = 0x05
	AK8963_HYH  = 0x06
	AK8963_HZL  = 0x07
	AK8963_HZH  = 0x08
	AK8963_ST2  = 0x09
	// Write/Read Reg
	AK8963_CNTL1  = 0x0A
	AK8963_CNTL2  = 0x0B
	AK8963_ASTC   = 0x0C
	AK8963_TS1    = 0x0D
	AK8963_TS2    = 0x0E
	AK8963_I2CDIS = 0x0F
	// Read-only Reg ( ROM )
	AK8963_ASAX = 0x10
	AK8963_ASAY = 0x11
	AK8963_ASAZ = 0x12
	// Configuration bits from mpu9250.
	BIT_SLEEP                  = 0x40
	BIT_H_RESET                = 0x80
	BITS_CLKSEL                = 0x07
	MPU_CLK_SEL_PLLGYROX       = 0x01
	MPU_CLK_SEL_PLLGYROZ       = 0x03
	MPU_EXT_SYNC_GYROX         = 0x02
	BITS_FS_MASK               = 0x18
	BITS_DLPF_CFG_256HZ_NOLPF2 = 0x00
	BITS_DLPF_CFG_188HZ        = 0x01
	BITS_DLPF_CFG_98HZ         = 0x02
	BITS_DLPF_CFG_42HZ         = 0x03
	BITS_DLPF_CFG_20HZ         = 0x04
	BITS_DLPF_CFG_10HZ         = 0x05
	BITS_DLPF_CFG_5HZ          = 0x06
	BITS_DLPF_CFG_2100HZ_NOLPF = 0x07
	BITS_DLPF_CFG_MASK         = 0x07
	BIT_INT_ANYRD_2CLEAR       = 0x10
	BIT_RAW_RDY_EN             = 0x01
	BIT_I2C_IF_DIS             = 0x10

	// Misc
	READ_FLAG                    = 0x80
	MPU_BANK_SIZE                = 0xFF
	CFG_MOTION_BIAS              = 0x4B8 // Enable/disable gyro bias compensation
	BIT_FIFO_SIZE_1024           = 0x40  // FIFO buffer size
	BIT_AUX_IF_EN          uint8 = 0x20
	BIT_BYPASS_EN                = 0x02
	AKM_POWER_DOWN               = 0x00
	BIT_I2C_READ                 = 0x80
	BIT_SLAVE_EN                 = 0x80
	AKM_SINGLE_MEASUREMENT       = 0x01
	INV_CLK_PLL                  = 0x01
	AK89xx_FSR                   = 9830
	AKM_DATA_READY               = 0x01
	AKM_DATA_OVERRUN             = 0x02
	AKM_OVERFLOW                 = 0x80

	MPU9250M_4800uT                       = 0.6            // 0.6 uT/LSB
	MPU9250T_85degC                       = 0.002995177763 // 0.002995177763 degC/LSB
	Magnetometer_Sensitivity_Scale_Factor = 0.15
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ICM20948

type ICM20948 struct {
	C    <-chan *MPUData // Current instantaneous sensor values
	CAvg <-chan *MPUData // Average sensor values (since CAvg last read)
	CBuf <-chan *MPUData // Buffer of instantaneous sensor values
	// contains filtered or unexported fields
}

ICM20948 represents an InvenSense ICM20948 9DoF chip. All communication is via channels.

func NewICM20948

func NewICM20948(i2cbus *embd.I2CBus, sensitivityGyro, sensitivityAccel, sampleRate int, enableMag bool, applyHWOffsets bool) (*ICM20948, error)

NewICM20948 creates a new ICM20948 object according to the supplied parameters. If there is no ICM20948 available or there is an error creating the object, an error is returned.

func (*ICM20948) CloseMPU

func (mpu *ICM20948) CloseMPU()

CloseMPU stops the driver from reading the MPU. TODO westphae: need a way to start it going again!

func (*ICM20948) EnableGyroBiasCal

func (mpu *ICM20948) EnableGyroBiasCal(enable bool) error

EnableGyroBiasCal enables or disables motion bias compensation for the gyro. For flying we generally do not want this!

func (*ICM20948) MagEnabled

func (mpu *ICM20948) MagEnabled() bool

MagEnabled returns whether or not the magnetometer is being read.

func (*ICM20948) ReadAccelBias

func (mpu *ICM20948) ReadAccelBias(sensitivityAccel int) error

ReadAccelBias reads the bias accelerometer value stored on the chip. These values are set at the factory.

func (*ICM20948) ReadGyroBias

func (mpu *ICM20948) ReadGyroBias(sensitivityGyro int) error

ReadGyroBias reads the bias gyro value stored on the chip. These values are set at the factory.

func (*ICM20948) ReadMagCalibration

func (mpu *ICM20948) ReadMagCalibration() error

ReadMagCalibration reads the magnetometer bias values stored on the chpi. These values are set at the factory.

func (*ICM20948) SampleRate

func (mpu *ICM20948) SampleRate() int

SampleRate returns the current sample rate of the ICM20948, in Hz.

func (*ICM20948) SetAccelLPF

func (mpu *ICM20948) SetAccelLPF(rate byte) (err error)

SetAccelLPF sets the low pass filter for the accelerometer.

func (*ICM20948) SetAccelSampleRate

func (mpu *ICM20948) SetAccelSampleRate(rate byte) (err error)

SetAccelSampleRate changes the sampling rate of the accelerometer on the MPU.

func (*ICM20948) SetAccelSensitivity

func (mpu *ICM20948) SetAccelSensitivity(sensitivityAccel int) error

SetAccelSensitivity sets the accelerometer sensitivity of the ICM20948; it must be one of the following values: 2, 4, 8, 16, all in G (gravity).

func (*ICM20948) SetGyroLPF

func (mpu *ICM20948) SetGyroLPF(rate byte) (err error)

SetGyroLPF sets the low pass filter for the gyro.

func (*ICM20948) SetGyroSampleRate

func (mpu *ICM20948) SetGyroSampleRate(rate byte) (err error)

SetGyroSampleRate changes the sampling rate of the gyro on the MPU.

func (*ICM20948) SetGyroSensitivity

func (mpu *ICM20948) SetGyroSensitivity(sensitivityGyro int) (err error)

SetGyroSensitivity sets the gyro sensitivity of the ICM20948; it must be one of the following values: 250, 500, 1000, 2000 (all in deg/s).

type MPUData

type MPUData struct {
	G1, G2, G3        float64
	A1, A2, A3        float64
	M1, M2, M3        float64
	Temp              float64
	GAError, MagError error
	N, NM             int
	T, TM             time.Time
	DT, DTM           time.Duration
}

MPUData contains all the values measured by an ICM20948.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto