Commit Graph

540 Commits

Author SHA1 Message Date
Lucas De Marchi 294298ea34 AP_InertialSensor: use method for downcast
Instead of just doing a static cast to the desired class, use a method
named "from". Pros:

  - When we have data shared on the parent class, the code is cleaner in
    child class when it needs to access this data. Almost all the data
    we use in AP_HAL benefits from this

  - There's a minimal type checking because now we are using a method
    that can only receive the type of the parent class
2015-09-23 09:01:29 +10:00
Randy Mackay ada26082ca InertialSensor: remove INS start style from example sketch 2015-09-21 17:06:20 +09:00
Randy Mackay ec82aa68c4 InertialSensor: add GYR_CAL to control when gyro calibration occurs 2015-09-21 17:06:16 +09:00
raspilot 1421cf600a AP_InertialSensor: added support for raspilot 2015-09-14 14:22:15 +10:00
Víctor Mayoral Vilches 6d762f62b3 AP_InertialSensor: ERLEBOARD legacy support
This config referred to the legacy Erle-Board
https://erlerobotics.com/blog/product/erle-board/
The configuration is preserved to support the
existing boards.
2015-09-09 10:31:55 +10:00
Gustavo Jose de Sousa 305ec7b08a AP_InertialSensor: MPU6000: publish sample rate
So that vibration and clipping may be calculated.
2015-09-07 11:14:43 +10:00
Gustavo Jose de Sousa eb480e959c AP_InertialSensor: MPU9250: publish sample rate
That enables the default vibration calculation.
2015-09-07 11:14:42 +10:00
Gustavo Jose de Sousa a76eb9c15f AP_InertialSensor: MPU9250: use macros for sample rate
Instead of hardcoded values.
2015-09-07 11:14:42 +10:00
Gustavo Jose de Sousa a0b1337646 AP_InertialSensor: PX4: publish sample rate
By publishing the sample rate, the vibration and clipping are magically
calculated.
2015-09-07 11:14:42 +10:00
Gustavo Jose de Sousa 77a4f10d89 AP_InertialSensor: PX4: don't call calc_vibration_and_clipping()
That calculation will be unified.
2015-09-07 11:14:42 +10:00
Gustavo Jose de Sousa 6aa973dd47 AP_InertialSensor: Backend: calculate vibration and clipping on new raw sample
This is a good way of letting each implementation easily calculate vibration
and clipping: all they need to do is publish their sample rate and they don't
need to worry about the call for calculation.
2015-09-07 11:14:42 +10:00
Gustavo Jose de Sousa e06627dfcb AP_InertialSensor: Backend: add hook for new raw accel samples
That hook will eventually do necessary things when a new accelerometer raw
sample arrives (like calculating vibration levels).
2015-09-07 11:14:42 +10:00
Gustavo Jose de Sousa 5329e63742 AP_InertialSensor: allow publishing sample rate to frontend
That information will be used for a "centralized" vibration calculation.
2015-09-07 11:14:42 +10:00
Gustavo Jose de Sousa ac3a677626 AP_InertialSensor: remove param rotate_and_correct from publish functions
Once that parameter is always false.
2015-09-07 11:14:42 +10:00
Gustavo Jose de Sousa a56c8deaee AP_InertialSensor: Oilpan: apply correction on each new sample
These changes are for enabling unified accelerometer vibration and clipping
calculation. For that, we need the values "rotated and corrected" before they
are filtered and the calculation must be called as soon as a new sample arrives
as it takes the sample rate into account.

Thus, move code that applies "corrections" to be executed as soon as accel data
arrive and call _publish_accel() passing rotate_and_correct parameter as false.
Also, do the same for gyro so we can keep it consistent.
2015-09-07 11:14:42 +10:00
Gustavo Jose de Sousa fc38691e0b AP_InertialSensor: MPU9250: apply correction on each new sample
These changes are for enabling unified accelerometer vibration and clipping
calculation. For that, we need the values "rotated and corrected" before they
are filtered and the calculation must be called as soon as a new sample arrives
as it takes the sample rate into account.

Thus, move code that applies "corrections" to be executed as soon as accel data
arrive and call _publish_accel() passing rotate_and_correct parameter as false.
Also, do the same for gyro so we can keep it consistent.
2015-09-07 11:14:42 +10:00
Gustavo Jose de Sousa b844b220c3 AP_InertialSensor: MPU9150: apply correction on each new sample
These changes are for enabling unified accelerometer vibration and clipping
calculation. For that, we need the values "rotated and corrected" before they
are filtered and the calculation must be called as soon as a new sample arrives
as it takes the sample rate into account.

Thus, move code that applies "corrections" to be executed as soon as accel data
arrive and call _publish_accel() passing rotate_and_correct parameter as false.
Also, do the same for gyro so we can keep it consistent.
2015-09-07 11:14:42 +10:00
Gustavo Jose de Sousa 487135afa2 AP_InertialSensor: MPU6000: apply correction on each new sample
These changes are for enabling unified accelerometer vibration and clipping
calculation. For that, we need the values "rotated and corrected" before they
are filtered and the calculation must be called as soon as a new sample arrives
as it takes the sample rate into account.

Thus, move code that applies "corrections" to be executed as soon as accel data
arrive and call _publish_accel() passing rotate_and_correct parameter as false.
Also, do the same for gyro so we can keep it consistent.
2015-09-07 11:14:42 +10:00
Gustavo Jose de Sousa f946f48dce AP_InertialSensor: LSM9DS0: apply correction on each new sample
These changes are for enabling unified accelerometer vibration and clipping
calculation. For that, we need the values "rotated and corrected" before they
are filtered and the calculation must be called as soon as a new sample arrives
as it takes the sample rate into account.

Thus, move code that applies "corrections" to be executed as soon as accel data
arrive and call _publish_accel() passing rotate_and_correct parameter as false.
Also, do the same for gyro so we can keep it consistent.
2015-09-07 11:14:41 +10:00
Gustavo Jose de Sousa 0963159bb8 AP_InertialSensor: Flymaple: apply correction on each new sample
These changes are for enabling unified accelerometer vibration and clipping
calculation. For that, we need the values "rotated and corrected" before they
are filtered and the calculation must be called as soon as a new sample arrives
as it takes the sample rate into account.

Thus, move code that applies "corrections" to be executed as soon as accel data
arrive and call _publish_accel() passing rotate_and_correct parameter as false.
Also, do the same for gyro so we can keep it consistent.
2015-09-07 11:14:41 +10:00
Gustavo Jose de Sousa 2ea8f1de3f AP_InertialSensor: L3G4200D: apply correction on each new sample
These changes are for enabling unified accelerometer vibration and clipping
calculation. For that, we need the values "rotated and corrected" before they
are filtered and the calculation must be called as soon as a new sample arrives
as it takes the sample rate into account.

Thus, move code that applies "corrections" to be executed as soon as accel data
arrive and call _publish_accel() passing rotate_and_correct parameter as false.
Also, do the same for gyro so we can keep it consistent.
2015-09-07 11:14:41 +10:00
Lucas De Marchi a66a201bf5 AP_Compass: HMC5843: Add support for MPU6000 auxiliary bus
Allow HMC5843 to be on MPU6000's auxiliary bus.
2015-08-28 12:39:09 +10:00
Lucas De Marchi c66800dfec AP_InertialSensor: add singleton interface
In order to allow other libraries to use the InertialSensor we need a
way to let them to get the only instance of InertialSensor. The
conventional way to do a singleton would be to let the constructor
private and force it to be instantiated from the get_instance() method.

Here however we just call panic() on the constructor if there's already
an instance alive. This allows us to let the vehicles as is. Later we
can change it so they call the get_instance() method instead.
2015-08-28 12:39:08 +10:00
Lucas De Marchi 565c18603d AP_InertialSensor: MPU6000: export auxiliary bus 2015-08-28 12:39:08 +10:00
Lucas De Marchi caae933c28 AP_InertialSensor: Add support for auxiliary buses
Add an AuxiliaryBus class that can be derived for specific
implementations in inertial sensor backends. It's an abstract
implementation so other libraries can use the auxiliary bus exported. In
order for this to succeed the backend implementation must split the
initialization of the sensor from the actual sample collecting, like is
done in MPU6000.

When AP_InertialSensor::get_auxiliary_bus() is called it will execute
following steps:
	a) Force the backends to be detected if it's the first time it's
	   being called
	b) Find the backend identified by the id
	c) call get_auxiliary_bus() on the backend so other libraries can
	   that AuxiliaryBus to initialize a slave device

Slave devices can be used by calling AuxiliaryBus::request_next_slave()
and are owned by the caller until AuxiliaryBus::register_periodic_read()
is called. From that time on the AuxiliaryBus object takes its ownership.
This way it's possible to do the necessary cleanup later without
introducing refcounts, that we don't have support to.

Between these 2 functions the caller can configure the slave device by
doing its specific initializations by calling the passthrough_*
functions. After the initial configuration and register_periodic_read()
is called only read() can be called.
2015-08-28 12:39:08 +10:00
Lucas De Marchi 3cb6f391d4 AP_InertialSensor: MPU6000: split detection and initialization 2015-08-28 12:39:08 +10:00
Lucas De Marchi 7d9579c5d8 AP_InertialSensor: identify backend with ID
Identify backend with an id, allowing other libraries to connect to
them. This is different from the _product_id member because it
identifies the sensor, not the board the sensor is in, which is
meaningless for our use case.
2015-08-28 12:39:07 +10:00
Lucas De Marchi 22c787058e AP_InertialSensor: allow to split detection and initialization
This allows backends to have a separate detection and initialization
logic. It doesn't change any backend yet and with the current code
there's no change in behavior either. This only allows
AP_InertialSensor::_detect_backend() to be called earlier so
AP_InertialSensor object can be used by other libraries. If it's not
called, later on AP_InertialSensor::init() will detect and start all
backends.
2015-08-28 12:39:07 +10:00
Lucas De Marchi f7954ee885 AP_InertialSensor: MPU6000: allow to read generic block
We were able to read only the block of registers that are part of the
data output from accelerometer/gyroscope. In order to support reading
the external sensors we need support for reading a generic block of
registers.
2015-08-28 12:39:07 +10:00
Lucas De Marchi b5da8ad61f AP_InertialSensor: MPU6000: rename method
We're reading the sensor data available in MPU6000 so name the method
accordingly, which is also the same name used in MPU9250.
2015-08-28 12:39:07 +10:00
Lucas De Marchi d9a4d3e777 AP_InertialSensor: MPU6000: fix leaking samples 2015-08-28 12:39:07 +10:00
Lucas De Marchi f18dd17377 AP_InertialSensor: fix typos
resister->register and fix copy and paste error from MPU6000 to MPU925.
2015-08-28 12:39:07 +10:00
squilter dfc35cca8b AP_InertialSensor: update severities 2015-08-28 10:04:35 +10:00
ziltoid2 0b1a997800 AP_IntertialSensor: don't require acceleration calibration in hil mode 2015-08-23 16:48:48 +10:00
Tom Pittenger 2620a57700 AP_InertialSensor: Added is_still() check
very strict check that all axis are not vibrating much at all
new param: INS_STILL_THRESH used to be a vibration threshold for different platforms
// @Description: Threshold to tolerate vibration to determine if vehicle is motionless. This depends on the frame type and if there is a constant vibration due to motors before launch or after landing. Total motionless is about 0.05. Suggested values: Planes/rover use 0.1, multirotors use 1, tradHeli uses 5
2015-08-23 10:34:17 +10:00
Tom Pittenger 220163e269 AP_InertialSensor: correct USE param storage index
USE, USE2, USE3 have 20, 21, 21 but should be 20, 21, 22
2015-08-21 11:35:37 +09:00
Randy Mackay e5615ec349 INS: add USE parameters 2015-08-19 16:44:15 +09:00
Randy Mackay affbd67c43 InertialSensor: add vibration monitoring of 2nd IMU 2015-08-19 16:44:12 +09:00
Lucas De Marchi 2c44f3e313 AP_HAL_InertialSensor: standardize inclusion of libaries headers
Do the missing header changes due to changing the code before the pr
getting accepted.
2015-08-18 17:12:52 +10:00
Andrew Tridgell dc455a5fd6 AP_InertialSensor: setup for MPU9250 support on PX4 2015-08-17 09:33:15 +10:00
Andrew Tridgell 980659d346 AP_InertialSensor: removed AVR1280 specific ifdef 2015-08-11 16:47:56 +10:00
Gustavo Jose de Sousa 7789aec85b AP_InertialSensor: standardize inclusion of libaries headers
This commit changes the way libraries headers are included in source files:

 - If the header is in the same directory the source belongs to, so the
 notation '#include ""' is used with the path relative to the directory
 containing the source.

 - If the header is outside the directory containing the source, then we use
 the notation '#include <>' with the path relative to libraries folder.

Some of the advantages of such approach:

 - Only one search path for libraries headers.

 - OSs like Windows may have a better lookup time.
2015-08-11 16:28:43 +10:00
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