2016-01-19 21:26:31 -04:00
|
|
|
#pragma once
|
2015-05-13 19:39:03 -03:00
|
|
|
|
2015-06-29 15:03:37 -03:00
|
|
|
#define LSM9DS0_DEBUG 0
|
2015-05-13 19:39:03 -03:00
|
|
|
|
2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2016-01-20 00:09:20 -04:00
|
|
|
#include <AP_HAL/SPIDevice.h>
|
2016-01-19 21:26:31 -04:00
|
|
|
|
2015-05-13 19:39:03 -03:00
|
|
|
#include "AP_InertialSensor.h"
|
2016-01-19 21:26:31 -04:00
|
|
|
#include "AP_InertialSensor_Backend.h"
|
2021-01-08 18:24:59 -04:00
|
|
|
#include <Filter/LowPassFilter2p.h>
|
2015-05-13 19:39:03 -03:00
|
|
|
|
|
|
|
class AP_InertialSensor_LSM9DS0 : public AP_InertialSensor_Backend
|
|
|
|
{
|
|
|
|
public:
|
2016-01-20 00:09:20 -04:00
|
|
|
virtual ~AP_InertialSensor_LSM9DS0() { }
|
2016-11-03 06:17:49 -03:00
|
|
|
void start(void) override;
|
|
|
|
bool update() override;
|
2015-05-13 19:39:03 -03:00
|
|
|
|
2016-01-20 00:09:20 -04:00
|
|
|
static AP_InertialSensor_Backend *probe(AP_InertialSensor &imu,
|
2019-03-09 17:08:58 -04:00
|
|
|
AP_HAL::OwnPtr<AP_HAL::Device> dev_gyro,
|
|
|
|
AP_HAL::OwnPtr<AP_HAL::Device> dev_accel,
|
2019-08-27 05:16:15 -03:00
|
|
|
enum Rotation rotation_a,
|
|
|
|
enum Rotation rotation_g,
|
|
|
|
enum Rotation rotation_gH);
|
2016-01-20 00:09:20 -04:00
|
|
|
|
|
|
|
private:
|
|
|
|
AP_InertialSensor_LSM9DS0(AP_InertialSensor &imu,
|
2019-03-09 17:08:58 -04:00
|
|
|
AP_HAL::OwnPtr<AP_HAL::Device> dev_gyro,
|
|
|
|
AP_HAL::OwnPtr<AP_HAL::Device> dev_accel,
|
2016-11-03 06:23:55 -03:00
|
|
|
int drdy_pin_num_a, int drdy_pin_num_b,
|
2016-11-16 00:16:15 -04:00
|
|
|
enum Rotation rotation_a,
|
2017-01-29 23:49:03 -04:00
|
|
|
enum Rotation rotation_g,
|
|
|
|
enum Rotation rotation_gH);
|
2016-01-20 00:09:20 -04:00
|
|
|
|
|
|
|
struct PACKED sensor_raw_data {
|
|
|
|
int16_t x;
|
|
|
|
int16_t y;
|
|
|
|
int16_t z;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum gyro_scale {
|
2015-05-13 19:39:03 -03:00
|
|
|
G_SCALE_245DPS = 0,
|
|
|
|
G_SCALE_500DPS,
|
|
|
|
G_SCALE_2000DPS,
|
|
|
|
};
|
|
|
|
|
2016-01-20 00:09:20 -04:00
|
|
|
enum accel_scale {
|
2015-05-13 19:39:03 -03:00
|
|
|
A_SCALE_2G = 0,
|
|
|
|
A_SCALE_4G,
|
|
|
|
A_SCALE_6G,
|
|
|
|
A_SCALE_8G,
|
2016-01-20 00:09:20 -04:00
|
|
|
A_SCALE_16G,
|
2015-05-13 19:39:03 -03:00
|
|
|
};
|
|
|
|
|
2016-01-20 00:09:20 -04:00
|
|
|
bool _accel_data_ready();
|
|
|
|
bool _gyro_data_ready();
|
2015-05-13 19:39:03 -03:00
|
|
|
|
2017-01-13 15:26:14 -04:00
|
|
|
void _poll_data();
|
2015-05-13 19:39:03 -03:00
|
|
|
|
2016-01-20 00:09:20 -04:00
|
|
|
bool _init_sensor();
|
|
|
|
bool _hardware_init();
|
2015-05-13 19:39:03 -03:00
|
|
|
|
2016-01-20 00:09:20 -04:00
|
|
|
void _gyro_init();
|
|
|
|
void _accel_init();
|
|
|
|
|
2015-09-21 11:05:20 -03:00
|
|
|
void _gyro_disable_i2c();
|
|
|
|
void _accel_disable_i2c();
|
|
|
|
|
2016-01-20 00:09:20 -04:00
|
|
|
void _set_gyro_scale(gyro_scale scale);
|
|
|
|
void _set_accel_scale(accel_scale scale);
|
|
|
|
|
|
|
|
uint8_t _register_read_xm(uint8_t reg);
|
|
|
|
uint8_t _register_read_g(uint8_t reg);
|
2016-11-10 03:07:14 -04:00
|
|
|
void _register_write_xm(uint8_t reg, uint8_t val, bool checked=false);
|
|
|
|
void _register_write_g(uint8_t reg, uint8_t val, bool checked=false);
|
2015-05-13 19:39:03 -03:00
|
|
|
|
2016-01-20 00:09:20 -04:00
|
|
|
void _read_data_transaction_a();
|
|
|
|
void _read_data_transaction_g();
|
|
|
|
|
|
|
|
#if LSM9DS0_DEBUG
|
|
|
|
void _dump_registers();
|
|
|
|
#endif
|
|
|
|
|
2019-03-09 17:08:58 -04:00
|
|
|
AP_HAL::OwnPtr<AP_HAL::Device> _dev_gyro;
|
|
|
|
AP_HAL::OwnPtr<AP_HAL::Device> _dev_accel;
|
2016-01-20 00:09:20 -04:00
|
|
|
AP_HAL::Semaphore *_spi_sem;
|
2015-05-13 19:39:03 -03:00
|
|
|
|
2015-06-29 10:38:06 -03:00
|
|
|
/*
|
|
|
|
* If data-ready GPIO pins numbers are not defined (i.e. any negative
|
|
|
|
* value), the fallback approach used is to check if there's new data ready
|
|
|
|
* by reading the status register. It is *strongly* recommended to use
|
|
|
|
* data-ready GPIO pins for performance reasons.
|
|
|
|
*/
|
2016-01-20 00:09:20 -04:00
|
|
|
AP_HAL::DigitalSource * _drdy_pin_a;
|
|
|
|
AP_HAL::DigitalSource * _drdy_pin_g;
|
|
|
|
float _gyro_scale;
|
|
|
|
float _accel_scale;
|
|
|
|
int _drdy_pin_num_a;
|
|
|
|
int _drdy_pin_num_g;
|
|
|
|
uint8_t _gyro_instance;
|
|
|
|
uint8_t _accel_instance;
|
2021-01-08 18:24:59 -04:00
|
|
|
float _temperature;
|
|
|
|
uint8_t _temp_counter;
|
|
|
|
LowPassFilter2pFloat _temp_filter;
|
2016-11-03 06:23:55 -03:00
|
|
|
|
2017-01-29 23:49:03 -04:00
|
|
|
// gyro whoami
|
|
|
|
uint8_t whoami_g;
|
|
|
|
|
2016-11-16 00:16:15 -04:00
|
|
|
/*
|
|
|
|
for boards that have a separate LSM303D and L3GD20 there can be
|
|
|
|
different rotations for each
|
|
|
|
*/
|
|
|
|
enum Rotation _rotation_a;
|
2017-01-29 23:49:03 -04:00
|
|
|
enum Rotation _rotation_g; // for L3GD20
|
|
|
|
enum Rotation _rotation_gH; // for L3GD20H
|
2015-05-13 19:39:03 -03:00
|
|
|
};
|