2021-01-06 23:34:38 -04:00
|
|
|
#pragma once
|
|
|
|
/*
|
|
|
|
driver for the invensensev3 range of IMUs
|
|
|
|
These are the ICM-4 series of IMUs
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <AP_HAL/AP_HAL.h>
|
|
|
|
#include <AP_HAL/utility/OwnPtr.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
#include <Filter/LowPassFilter2p.h>
|
|
|
|
|
|
|
|
#include "AP_InertialSensor.h"
|
|
|
|
#include "AP_InertialSensor_Backend.h"
|
|
|
|
|
|
|
|
class AP_InertialSensor_Invensensev3 : public AP_InertialSensor_Backend
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~AP_InertialSensor_Invensensev3();
|
|
|
|
|
|
|
|
static AP_InertialSensor_Backend *probe(AP_InertialSensor &imu,
|
|
|
|
AP_HAL::OwnPtr<AP_HAL::Device> dev,
|
|
|
|
enum Rotation rotation);
|
|
|
|
|
|
|
|
/* update accel and gyro state */
|
|
|
|
bool update() override;
|
|
|
|
void accumulate() override;
|
|
|
|
|
|
|
|
void start() override;
|
2022-07-20 13:47:24 -03:00
|
|
|
// get a startup banner to output to the GCS
|
|
|
|
bool get_output_banner(char* banner, uint8_t banner_len) override;
|
2021-01-06 23:34:38 -04:00
|
|
|
|
|
|
|
enum class Invensensev3_Type : uint8_t {
|
|
|
|
ICM40609 = 0,
|
|
|
|
ICM42688,
|
|
|
|
ICM42605,
|
2021-12-13 00:43:51 -04:00
|
|
|
ICM40605,
|
|
|
|
IIM42652,
|
2022-07-19 21:45:59 -03:00
|
|
|
ICM42670,
|
2022-10-25 21:35:55 -03:00
|
|
|
ICM45686
|
2021-01-06 23:34:38 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
// acclerometers on Invensense sensors will return values up to 32G
|
|
|
|
const uint16_t multiplier_accel = INT16_MAX/(32*GRAVITY_MSS);
|
|
|
|
|
|
|
|
private:
|
|
|
|
AP_InertialSensor_Invensensev3(AP_InertialSensor &imu,
|
|
|
|
AP_HAL::OwnPtr<AP_HAL::Device> dev,
|
|
|
|
enum Rotation rotation);
|
|
|
|
|
|
|
|
/* Initialize sensor*/
|
|
|
|
bool hardware_init();
|
|
|
|
bool check_whoami();
|
|
|
|
|
|
|
|
void set_filter_and_scaling(void);
|
2022-07-20 13:47:24 -03:00
|
|
|
void set_filter_and_scaling_icm42670(void);
|
2022-10-25 21:35:55 -03:00
|
|
|
void set_filter_and_scaling_icm456xy(void);
|
2021-01-06 23:34:38 -04:00
|
|
|
void fifo_reset();
|
|
|
|
|
|
|
|
/* Read samples from FIFO */
|
|
|
|
void read_fifo();
|
|
|
|
|
|
|
|
bool block_read(uint8_t reg, uint8_t *buf, uint32_t size);
|
|
|
|
uint8_t register_read(uint8_t reg);
|
|
|
|
void register_write(uint8_t reg, uint8_t val, bool checked=false);
|
|
|
|
|
2022-07-19 21:45:59 -03:00
|
|
|
uint8_t register_read_bank(uint8_t bank, uint8_t reg);
|
|
|
|
void register_write_bank(uint8_t bank, uint8_t reg, uint8_t val);
|
2022-10-25 21:35:55 -03:00
|
|
|
uint8_t register_read_bank_icm456xy(uint16_t bank_addr, uint16_t reg);
|
|
|
|
void register_write_bank_icm456xy(uint16_t bank_addr, uint16_t reg, uint8_t val);
|
|
|
|
|
2021-01-06 23:34:38 -04:00
|
|
|
bool accumulate_samples(const struct FIFOData *data, uint8_t n_samples);
|
|
|
|
|
|
|
|
// instance numbers of accel and gyro data
|
|
|
|
uint8_t gyro_instance;
|
|
|
|
uint8_t accel_instance;
|
|
|
|
|
2021-12-13 00:43:51 -04:00
|
|
|
// reset FIFO configure1 register
|
|
|
|
uint8_t fifo_config1;
|
|
|
|
|
2021-01-06 23:34:38 -04:00
|
|
|
// temp scaling for FIFO temperature
|
2021-12-13 00:43:51 -04:00
|
|
|
float temp_sensitivity;
|
2021-01-06 23:34:38 -04:00
|
|
|
const float temp_zero = 25; // degC
|
|
|
|
|
|
|
|
const enum Rotation rotation;
|
|
|
|
|
|
|
|
float accel_scale;
|
2022-07-20 13:47:24 -03:00
|
|
|
|
|
|
|
// are we doing more than 1kHz sampling?
|
|
|
|
bool fast_sampling;
|
|
|
|
|
|
|
|
// what rate are we generating samples into the backend for gyros and accels?
|
|
|
|
uint16_t backend_rate_hz;
|
2022-08-03 06:27:34 -03:00
|
|
|
// pre-calculated backend period
|
|
|
|
uint32_t backend_period_us;
|
2021-01-06 23:34:38 -04:00
|
|
|
|
|
|
|
AP_HAL::OwnPtr<AP_HAL::Device> dev;
|
2022-08-03 06:27:34 -03:00
|
|
|
AP_HAL::Device::PeriodicHandle periodic_handle;
|
2021-01-06 23:34:38 -04:00
|
|
|
|
|
|
|
// which sensor type this is
|
|
|
|
enum Invensensev3_Type inv3_type;
|
|
|
|
|
|
|
|
// buffer for fifo read
|
|
|
|
struct FIFOData *fifo_buffer;
|
|
|
|
|
|
|
|
float temp_filtered;
|
|
|
|
LowPassFilter2pFloat temp_filter;
|
|
|
|
};
|