Commit Graph

548 Commits

Author SHA1 Message Date
Randy Mackay 69bfeaf58e INS: accel offset parameter range desc to 3.5m/s/s 2015-08-10 10:30:34 -07:00
Lucas De Marchi cf1273668e AP_InertialSensor: refactor constructors to avoid leak
We were previously leaking the AP_MPU6000_BusDriver if the
~AP_InertialSensor_MPU6000::detect*() failed. In order to avoid the
leak move the repeated code in a single private _detect() member that
receives everything as argument. Then this method takes ownership of the
objects.

By a adding a destructor to AP_InertialSensor_MPU6000 it becomes easier to
free the objects it takes ownership of.
2015-08-08 14:12:22 +10:00
Lucas De Marchi c3063f0ab2 AP_InertialSensor: MPU6000: be agnostic to I2C bus/address
This decision is better made by the caller rather than polluting the
driver with board-specific details.
2015-08-08 14:12:22 +10:00
Lucas De Marchi 4d4dac867e AP_InertialSensor: pass backend instead of pointer to function
Different detect() function might need different arguments and passing a
pointer to function here is cumbersome. For example, it forces to have a
method like "detect_i2c2" rather than allowing hal.i2c2 to be passed as
parameter.
2015-08-08 14:12:22 +10:00
Gustavo Jose de Sousa d3eebdb6aa AP_InertialSensor: L3G4200D: add probe code
This driver works properly but had the initialization logic missing. Add
the support to probe it.
2015-08-08 14:12:22 +10:00
Lucas De Marchi 55279664c2 AP_InertialSensor: remove out of place ifdef
AP_InertialSensor isn't a good place to comment about board issues.
2015-08-08 14:12:21 +10:00
Lucas De Marchi 2e76d998df AP_InertialSensor: remove unused enum bus_speed
The methods actually use the enum from AP_HAL::SPIDeviceDriver, so don't
declare a new one. The I2C implementation is empty; if we actually start
to use it we'd better move the bus abstraction to HAL.
2015-08-08 14:12:21 +10:00
Lucas De Marchi f3f54157be AP_InertialSensor: fix copying wrong number of bytes
We should copy only the bytes we read, not the maximum number.
2015-08-08 14:12:21 +10:00
Lucas De Marchi 209e1924a5 AP_InertialSensor: fix whitespace usage 2015-08-08 14:12:21 +10:00
Lucas De Marchi 3851862f60 AP_InertialSensor: remove unused drivers
Nobody is using these drivers, they need to be rewritten using the
backend logic and give the false impression they are supported.
2015-08-07 20:57:49 +10:00
Andrew Tridgell 212898d02b AP_InertialSensor: don't use INT_STATUS drdy to lower SPI bus speed
as pointed out by Lucas in PR#2604 this is probably a bad idea
2015-07-30 14:05:20 +10:00
Grant Morphett e2eda97ec6 AP_InertialSensor: fix coverity warnings - param init in construct 2015-07-30 12:37:08 +10:00
Tom Pittenger 01161135d6 AP_InitialSensor_MPU6000: compiler warning - init order 2015-07-27 10:30:17 +09:00
Lucas De Marchi eda4879f3f AP_InertialSensor: use ARRAY_SIZE macro 2015-07-21 14:25:07 +09:00
Andrew Tridgell 6df33dd3f4 AP_InertialSensor: fixed MPU6000_SPI bus initialisation
we need _spi for get_semaphore()
2015-07-10 16:46:30 +10:00
Julien BERAUD 3cf952d1f8 AP_InertialSensor: add fifo support for MPU6000
And remove the use of data rdy in this case
2015-07-10 14:24:09 +10:00
Julien BERAUD 8a76ff53bd AP_InertialSensor: add i2c bus driver for MPU6050 2015-07-10 14:24:09 +10:00
Julien BERAUD 1679728730 AP_InertialSensor: Configure SPI as a generic bus for MPU6000
Add the possibility to implement an i2c bus communication for the
MPU6050 on parrot bebop
2015-07-10 14:24:09 +10:00
Lucas De Marchi efec7723ff AP_InertialSensor: reset the MPU9250 chip on startup
Now that the initialization of MPU9250 is shared between the
AP_InertialSensor and other drivers using it as a backend, we can reset
the MPU9250 in order to put it in a known state.
2015-07-06 10:48:07 +10:00
Lucas De Marchi eb4e2ac2e5 AP_InertialSensor: factor out MPU9250 initialization
Now we have the initialization code split in 2 parts:

1) Making sure the MPU9250 chip is alive and working: this is now in a
static function that may be called by other drivers that use MPU9250 as
backend.

2) The configuration of gyro and accel. Once the first part is completed
successfully the AP_InertialSensor_MPU9250 finishes the configuration of
the sensors it uses.

The only change in behavior here is that before we would try 25 time (5x
inside _hardware_init time 5x inside _init_sensor() that calls the first
function) to "boot the chip" and now we are doing "only" 5.
2015-07-06 10:48:07 +10:00
Lucas De Marchi 953bfbd3fe AP_InertialSensor: provide static methods for spi transactions
Add static methods to do the SPI transactions and provide the wrapper
methods when we have an instance of the object. This is useful so these
methods can be called from other contexts when the AP_InertialSensor
hasn't been initialized yet.
2015-07-06 10:48:07 +10:00
mirkix f82344358f AP_InertialSensor: Change BBBMINI standard orientation 2015-07-06 10:12:39 +10:00
Staroselskii Georgii d40b45c9ae AP_InertialSensor: disable reset on MPU9250
The Compass library is initialized before the InertialSensor. AK8963 with
MPU9250 as backend already takes care of resetting MPU9250. The problem with
also resetting it in the MPU9250 initialization code is that if the reset
happens during an internal I2C transaction, the AK8963 may hang. So here we
remove the reset inside MPU9250. There still a possibility that the first
MPU9250 initialization is not successful and it resets the chip, but it's not
happening in tests.
2015-07-01 20:44:09 +03:00
Andrew Tridgell ac3200fd32 AP_InertialSensor: make max_abs_offsets a single float, not a vector 2015-06-30 10:51:43 +10:00
Gustavo Jose de Sousa 0fcd98c804 AP_InertialSensor: disable debug on LSM9DS0 2015-06-30 10:28:05 +10:00
Gustavo Jose de Sousa c168e19e73 AP_InertialSensor: fix coding style with uncrustify on LSM9DS0
This commit makes backend source code for LSM9DS0 comply with the configuration
files "uncrustify_cpp.cfg" and "uncrustify_headers.cfg".
2015-06-30 10:28:02 +10:00
Gustavo Jose de Sousa 2f2a627002 AP_InertialSensor: use runtime GPIO drdy pins numbers instead C constant macros
As we intend to eventually get board related parameters from a configuration
file, this commit makes the GPIO numbers for data-ready pins be instance
variables instead of from C constant macros.

Another advantage of using instance variables in this context is the
possibility of using more than one LSM9DS0.
2015-06-30 10:27:59 +10:00
Gustavo Jose de Sousa 0ef914adac AP_InertialSensor: don't take SPI semaphore if not necessary on LSM9DS0
If the data-ready polling is done entirely on GPIO pins, it isn't necessary to
hold the semaphore before we now we have data to consume. In that case, only
take the SPI semaphore if there's new data available.

On the other hand, if at least one SPI transaction is done in order to check
for new data, then it makes sense to take the semaphore beforehand.
2015-06-30 10:27:57 +10:00
Gustavo Jose de Sousa a82ab25ed3 AP_InertialSensor: use bitfield macros instead of literal values on LSM9DS0
This commit makes accel and gyro initialization routines use bitfield macros
instead of hardcoding the literal value when wrinting on registers. That is
less prone to typos and a lot of times self-explanatory. Also, due to the
latter, the long comments explaining each register field were removed (any
detail can be checked on the datasheet).
2015-06-30 10:27:54 +10:00
Gustavo Jose de Sousa 1572324315 AP_InertialSensor: add macros for LSM9DS0 registers' bitfields 2015-06-30 10:27:51 +10:00
Gustavo Jose de Sousa 033409c629 AP_InertialSensor: set max abs calibration offset for LSM9DS0 2015-06-30 10:27:48 +10:00
Gustavo Jose de Sousa 42eb73a1d1 AP_InertialSensor: add LSM9DS0 backend
This adds the backend driver for LSM9DS0. This implementation is based on the
legacy driver coded by Víctor Mayoral Vilches (under folder LSM9DS0) and makes
some necessary adaptations and fixes in order to work properly. The legacy
driver folder was removed.
2015-06-30 10:27:46 +10:00
Gustavo Jose de Sousa c340e072f2 AP_InertialSensor: use accel instance max abs offset instead of a constant value
The calibration on LSM9DS0 was giving offsets between 4.0 and 4.2 on x-axis and
around 3.6 on y-axis. It turned out that those offsets were actually right.

The maximum absolute values of calibration offset should be a sensor
characteristic rather than a constant value for all sensors.

The constant value previously used (3.5 m/s/s for all axes) is set here as a
default maximum absolute calibration offset for every instance to keep it
working.
2015-06-30 10:27:44 +10:00
Gustavo Jose de Sousa c72dc9bd45 AP_InertialSensor: make single rotation on MPU9250
The previous implementation made some boards apply two rotations to suit
their default orientation. That was happening because there was an
unconditional rotation being done (commented as "rotate for bbone
default").

This commit makes that unconditional rotation as a default rotation
instead and adjusts the former additional rotations to be single
rotations.
2015-06-22 17:45:20 +10:00
Gustavo Jose de Sousa 3dad768e8b AP_InertialSensor: log failure to initialize after max attempts on MPU9250
This happens for example when you are trying to use an SPI speed that's
above the one supported by the sensor or the controller.
2015-06-22 17:45:20 +10:00
Gustavo Jose de Sousa 587471ab54 AP_InertialSensor: disable I2C on MPU9250
As the datasheet says: "To prevent switching into I2C mode when using
SPI, the I2C interface should be disabled by setting the I2C_IF_DIS
configuration bit."

We also reset the sensor like PX4Firmware does for initializing the
MPU6000.  See: ee1d8cd770/src/drivers/mpu6000/mpu6000.cpp (L695)
2015-06-22 17:45:20 +10:00
Andrew Tridgell 4eab27abe9 AP_InertialSensor: fixed logic bug in MPU6000 init
thanks to coverity
2015-06-20 14:53:04 +10:00
mirkix 588a16dec2 AP_InertialSensor: Add Linux support for VibTest example 2015-06-18 08:48:23 +10:00
Andrew Tridgell 4fe092fead AP_InertialSensor: panic on bad gyro or accel sample rates 2015-06-17 15:01:23 +10:00
Andrew Tridgell d3b85eb792 AP_InertialSensor: use driver supplied sample rate
this will work with a wider range of sensors
2015-06-17 14:44:19 +10:00
Andrew Tridgell e91bfdfc1c AP_InertialSensor: fixed VibTest example build 2015-06-17 14:15:58 +10:00
Andrew Tridgell bc0ae630a1 AP_InertialSensor: always provide delta_velocity and delta_angles
this makes the NavEKF code simpler
2015-06-17 13:10:26 +10:00
Andrew Tridgell f831c16238 AP_InertialSensor: use fixed sensor sample times
this uses fixed sample times for PX4 IMUs, rather than reported
timestamps. It avoids timing jitter caused by the over-sampling in
the PX4 drivers
2015-06-17 13:03:56 +10:00
Randy Mackay 9d81856580 InertialSensor: fix name of get_delta_velocity method 2015-06-17 12:46:54 +10:00
Andrew Tridgell 727be87d84 AP_InertialSensor: support HIL functions for delta_velocity and delta_angles 2015-06-16 09:53:55 +10:00
Randy Mackay 8ceccd778d InertialSensor: disable vibration checks on APM2
Also bug fix get_accel_clip_count's instance check
2015-06-12 21:36:56 +09:00
Randy Mackay 0db7acc628 InertialSensor: calc vibration and accel clipping 2015-06-12 21:36:22 +09:00
Andrew Tridgell 214b61bfc0 AP_InertialSensor: fixed example build 2015-06-01 17:35:15 +10:00
Andrew Tridgell 7f7113c1de AP_InertialSensor: convert example from .pde to .cpp 2015-06-01 17:07:04 +10:00
Andrew Tridgell 6a2c585632 AP_InertialSensor: fixed build warnings 2015-05-30 22:51:19 +10:00
Peter Barker 8be9e99fad AP_InertialSensor_PX4: 64-bit timestamps for ACCx and GYRx messages 2015-05-27 11:54:17 +10:00
Peter Barker f489f6b696 AP_InertialSensor: use 64-bit timestamps in dataflash logs 2015-05-27 11:54:17 +10:00
Lucas De Marchi 3aa46e3213 AP_InertialSensor: use functor macros
Functor is not yet being used but let's make is macro fallback to the
previous Delegate implementation for easy of transition between the two.
2015-05-26 13:46:53 +10:00
Andrew Tridgell aaa35bd1ec AP_InertialSensor: using atan2f() gives more accurate euler corrections
thanks to Jon and Paul!
2015-05-16 08:19:18 +10:00
Andrew Tridgell 9e723ef907 AP_InertialSensor: added calibrate_trim() function
used for redoing trim calculation
2015-05-16 07:56:34 +10:00
Andrew Tridgell b564ba0868 AP_InertialSensor: fixed AHRS_TRIM calculation again 2015-05-16 07:56:33 +10:00
Jonathan Challinger 159599879f AP_InertialSensor: simplify and correct AHRS_TRIM computation 2015-05-15 21:03:03 +10:00
Randy Mackay 3f8b832075 InertialSensor: fix example sketch 2015-05-13 10:13:51 +09:00
Randy Mackay 1f14eec4ea InertialSensor: accel_calibrated_all_ok replaces calibrated
This checks that the current number of accelerometers matches the number
of calibrated accels in order to catch accel failures at boot
2015-05-12 16:32:16 +09:00
Andrew Tridgell 8bf2baef70 AP_InertialSensor: fixed primary accel/gyro in replay 2015-05-11 11:19:11 +10:00
Andrew Tridgell afc9812d0b AP_InertialSensor: update VibTest after moving messages info DataFlash 2015-05-07 13:25:37 +10:00
Andrew Tridgell 7d90033a36 AP_InertialSensor: support raw accel and gyro dataflash logging 2015-05-07 12:08:30 +10:00
Andrew Tridgell f5140e25b0 AP_InertialSensor: updated VibTest for latest PX4 interfaces 2015-05-07 10:51:52 +10:00
Andrew Tridgell 089e63f987 AP_InertialSensor: fixed PSTR handling
must use PSTR on code compiled for AVR
2015-05-05 13:54:00 +10:00
Andrew Tridgell 31693e332e AP_InertialSensor: use non-PSTR printf
this is not built on AVR
2015-05-05 13:48:34 +10:00
Andrew Tridgell e6a8a6da07 AP_InertialSensor: revert AP_Math class change 2015-05-05 13:27:06 +10:00
Tom Pittenger 0e076d6dc8 AP_InertialSensor: compile warnings: format not a string literal, argument types not checked
PSTR() goofs things up when using hal.console->printf_P()
2015-05-05 13:27:02 +10:00
Tom Pittenger 9e98c68099 AP_InertialSensor: compile warnings: format not a string literal, argument types not checked
PSTR() goofs things up when using hal.console->printf_P()
2015-05-05 13:27:01 +10:00
Tom Pittenger 820199635b AP_InertialSensors: compiler warnings: apply is_zero(float) or is_equal(float) 2015-05-05 13:26:51 +10:00
Tom Pittenger 3cb2221315 AP_IntertialSensor: double to float warning 2015-05-05 13:26:50 +10:00
Andrew Tridgell ef527d9daa AP_InertialSensor: fix for HAL_SITL rename 2015-05-05 09:45:55 +10:00
Randy Mackay 6773c0b232 AP_InertialSensor: default primary accel and gyro 2015-05-01 16:37:33 +09:00
Jonathan Challinger bb88a4f8fe AP_InertialSensor: healthy() checks bounds 2015-05-01 16:37:15 +09:00
Jonathan Challinger af80f20a51 AP_InertialSensor: add get_primary_gyro, fix get_primary_accel 2015-05-01 16:37:14 +09:00
Andrew Tridgell 007b01533d AP_InertialSensor: switched to 16g accel range for MPU9250
this matches the Pixhawk, and makes us less prone to vibration. We
have seen clipping at 8g
2015-04-28 15:30:29 +10:00
Tom Pittenger a4b8575432 InertialSensor: fix compile warnings re float constants 2015-04-24 14:03:49 +09:00
mirkix 13ee34c58a AP_InertialSensor: MPU9150 fix compiler warnings 2015-04-14 11:14:48 +10:00
Lucas De Marchi b292873304 AP_InertialSensor: fix starvation in L3G4200D
The main thread would always be blocked on the semaphore to read the
data from accelerometer and gyroscope. Especially if we have a slow
update of these values in _accumulate() due to the I2C transfer function
taking too much time: the timer thread would never give up the CPU,
causing starvation on the main thread.

This fixes the issue by reducing the critical region using a flip-buffer
so _accumulate() can work on its own copy of the data. Now that the
critical region is smaller, also avoid the semaphore and use a spinlock
instead.
2015-04-14 10:01:47 +10:00
Andrew Tridgell 45e016ea5b AP_InertialSensor: check for zero delta_velocity dt 2015-04-03 15:10:47 -07:00
Jonathan Challinger b306d7a356 AP_InertialSensor: accel cal sample for 400ms instead of 1s 2015-04-03 14:54:19 -07:00
Jonathan Challinger 1e1d8efa22 AP_InertialSensor: use expected update rate for accel cal sampling 2015-04-03 14:54:17 -07:00
Jonathan Challinger bd84328440 AP_InertialSensor: hack to "reset" the accel filter before taking a cal sample 2015-04-03 14:54:15 -07:00
Jonathan Challinger b2b42e081a AP_InertialSensor: use delta_velocity/dt for calibration if available 2015-04-03 14:54:10 -07:00
Jonathan Challinger 423160eaf8 AP_InertialSensor: publish delta_velocity_dt 2015-04-03 14:54:06 -07:00
Andrew Tridgell 4147825b87 AP_InertialSensor: fixed gyro calibration bug
we must not update _gyro_offset[] until we have completed calibration
of that gyro, or we will end up using the new offsets when asking for
the raw gyro vector
2015-04-03 06:57:30 -07:00
Andrew Tridgell 23272e4013 AP_InertialSensor: added get_temperature() interface
this will allow logging of individual temperature sensors
2015-03-17 13:32:54 +11:00
ahcorde 103bb2a08d AP_InertialSensor: Fix orientation MPU6000 PXF 2015-03-16 09:50:51 +11:00
Andrew Tridgell cf2445dc97 AP_InertialSensor: prevent nested accelerometer calibration 2015-03-15 15:22:59 +11:00
Andrew Tridgell 8a99cab535 AP_InertialSensor: load only HIL backend for hil_mode 2015-03-13 22:52:55 +11:00
Andrew Tridgell 520c7c1306 AP_InertialSensor: always allow for AK8963 on MPU9250 2015-03-13 18:46:17 +11:00
Andrew Tridgell 60b8736cf1 AP_InertialSensor: use right AK8963 compass defines 2015-03-13 18:46:15 +11:00
Andrew Tridgell 808c33d0a7 AP_InertialSensor: support both MPU9250 and MPU9255
seems to be just different WHOAMI register
2015-03-13 13:26:49 +11:00
Andrew Tridgell 07fd31c724 AP_InertialSensor: change copter filters to 20Hz
with the backend filters disabled 20Hz is closer to the old default of
30Hz
2015-03-12 13:11:17 +11:00
Andrew Tridgell a1d43e39e0 AP_InertialSensor: added get_gyro_filter_hz() and get_accel_filter_hz() 2015-03-12 12:50:31 +11:00
Andrew Tridgell 3d7d46b9b0 AP_InertialSensor: replaced INS_MPU6K_FILTER with INS_ACCEL_FILTER and INS_GYRO_FILTER
this allows filtering to be set separately on accels and gyros where possible
2015-03-12 12:50:31 +11:00
Andrew Tridgell f3314791f2 AP_InertialSensor: removed INS_CALSENSFRAME
it is no longer needed as we have shifted the accel cal indexes
2015-03-12 12:50:31 +11:00
Andrew Tridgell 4bc6c8e655 AP_InertialSensor: shift to new parameter indexes for accel calibration
this allows for users to switch between development trees and previous
stable versions while retaining their accel calibration values.
2015-03-12 12:50:30 +11:00
Andrew Tridgell 5d0eb49114 AP_InertialSensor: calculate queue depth based on requested sample rate
this auto-scales the queue depth for plane, rover and copter
2015-03-12 12:50:30 +11:00
Andrew Tridgell ea49d1cd39 AP_InertialSensor: removed unused variable 2015-03-12 12:50:30 +11:00
Andrew Tridgell e6a4b9f68c AP_InertialSensor: check accel health during accel cal 2015-03-12 12:50:29 +11:00