Commit Graph

105 Commits

Author SHA1 Message Date
Ricardo de Almeida Gonzaga 2e58653983 AP_Compass: Fix typos 2016-05-13 19:20:05 -03:00
Gustavo Jose de Sousa 91246ad8af AP_Compass: HMC5843: apply HMC5883L "arrow" rotation only if external
That rotation is done because of the "arrow" pointing the sensor direction in
3DR GPS+Compass kit (which isn't natural to the sensor orientation, by the
way). Thus, do that rotation only for external HMC5883L compasses.
2016-05-10 16:05:29 -03:00
Gustavo Jose de Sousa 35cddc7af0 AP_Compass: HMC5843: move hardcoded rotation to before call to rotate_field()
That rotation is set for AP_COMPASS_TYPE_HMC5883L, because it's usually
the compass from 3DR GPS+Compass kit, which has an arrow pointing the
"correct" direction. That rotation should be done before rotate_field()
as it represents the "standard" position for the kit.

This patch also makes published values consistent with respect to rotation.
Before this, raw fields used in calibration were published with a
rotation different from the filtered field when _product_id is
AP_COMPASS_TYPE_HMC5883L.
2016-05-10 15:56:38 -03:00
Gustavo Jose de Sousa 670b0071f9 AP_Compass: HMC5843: add parameter force_external to constructor
And to the detection probe() method. That way we don't need to use a board
`#ifdef` inside the class code.  Additionally, we make raspilot board use it.
2016-05-10 15:52:54 -03:00
Lucas De Marchi 20a4a42cb3 AP_Compass: don't store raw and unfiltered fields
These are not used. The only place where raw fields are used are in the
compass calibrator and we don't need to store them.

Additionally remove duplicated documentation about the meaning of the
functions to avoid them getting out of sync.
2016-03-23 17:50:38 -03:00
Lucas De Marchi 41c1209169 AP_Compass: HMC5843: improve readability
- Capitalize and rename constants
 - Make clear what gain is applied in calibration and what is the
   "normal" gain
 - Make the separation between HMC5883L and HMC5843 explicit when it
   makes sense to improve readability
 - Remove spurious delay in calibrate function
2016-03-23 17:50:38 -03:00
Lucas De Marchi 0291ad869b AP_Compass: HMC5843: use AP_HAL::I2CDevice abstraction
We still need the BusDriver (in some places called SerialBus) interface
since this driver can also be used on an AuxiliaryBus and that has a
different interface.

Besides the usual conversion some more improvements:

  - Use generic function to convert endianness
  - Minor cleanups
  - Reorder per-board ifdefs in compass instantiation: distinguish when
    there's a default compass to when it should probe other compasses
2016-03-23 17:50:38 -03:00
Caio Marcelo de Oliveira Filho 0d3fbbdd37 AP_Compass: use millis/micros/panic functions 2015-11-20 12:30:05 +09:00
Lucas De Marchi eb75d73952 AP_Compass: remove checks for HAL_BOARD_APM2 and HAL_BOARD_APM1 2015-11-04 12:14:11 +11:00
Lucas De Marchi 20c6ffc5e3 Replace use of UARTDriver::printf_P() with UARTDriver::printf()
This also starts to show warnings on places that were already using
wrong printf format strings.
2015-10-30 14:35:25 +09:00
Lucas De Marchi 2c38e31c93 Remove use of PSTR
The PSTR is already define as a NOP for all supported platforms. It's
only needed for AVR so here we remove all the uses throughout the
codebase.

This was automated with a simple python script so it also converts
places which spans to multiple lines, removing the matching parentheses.

AVR-specific places were not changed.
2015-10-30 14:35:04 +09:00
José Roberto de Souza 3888579c07 AP_Compass: HMC5843: Use the correctly spelled method 2015-10-16 10:16:24 +11:00
Gustavo Jose de Sousa 9927cf066f AP_Compass: remove use of milligauss_ratio
Now, we have all current compasses publishing their values already in
milligauss, so there's no need for that variable anymore.
2015-10-15 19:56:14 +09:00
Gustavo Jose de Sousa 256c9c06c9 AP_Compass: HMC5843: scale mag field internally
This is part of the transition to make all mag field values be used in
milligauss. Additionally the value of _gain_multiple is adapted to the new way
we're using it and corrected accordingly to the datasheets.
2015-10-15 19:56:11 +09:00
Gustavo Jose de Sousa 814442563e AP_Compass: HMC5843: fix _calibrate()
The use of _gain_multiple is not necessary because the values of
expected_{x,yz} and _mag_{x,y,z} are both in sensor raw unit (i.e., lsbs).

That wasn't fixed before in order not to make APM users to recalibrate their
compasses.
2015-10-15 19:56:10 +09:00
raspilot 19b4f5559a AP_Compass: added LSM303D driver 2015-09-14 14:22:15 +10:00
Andrew Tridgell c59bdc12df AP_Compass: fix the milligauss handling
the previous approach assumed a 1:1 mapping between compass backends
and compass instances, which isn't true on PX4.

It also only setup milligauss offsets on a set_and_save call, which is
not the only way offsets change

this adds a milligauss_ratio per instance, which is considerably
simpler
2015-09-09 14:53:11 +10:00
Staroselskii Georgii c207d8c6a8 AP_Compass: add milligauss counterparts to get_field() and get_offsets()
From now on there's a pair get_field_milligauss() and
get_offsets_milligauss() that can make the transition to the common
units across all compasses easier.
2015-09-09 10:38:16 +10:00
Siddharth Bharat Purohit 75829f5533 AP_Compass: remove extra compass field correction 2015-09-03 16:59:14 +10:00
Siddharth Bharat Purohit cdd8bae6ac AP_Compass: publish raw and unfiltered field for HMC5843 compass 2015-09-03 16:59:13 +10:00
Jonathan Challinger ade39abc7f AP_Compass_HMC5843: use new compass backend interface 2015-09-03 16:59:09 +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 628e446e3e AP_Compass: HMC5843: use a struct for raw value
Like is done in AK8963, declare a raw_value struct.
2015-08-28 12:39:09 +10:00
Lucas De Marchi 9ecd1daf81 AP_Compass: HMC5843: remove useless delay
There's no need to add a delay after suspending timer in the
initialization. Also initialize _bus_sem earlier, like is done in
AK8963.
2015-08-28 12:39:09 +10:00
Lucas De Marchi c66c9c41f2 AP_Compass: HMC5843: be agnostic to I2C bus
Like was done to inertial AK8963 and inertial sensor move the decision
regarding the I2C bus to the caller. We don't allow changing the address
because apparently HMC5843 doesn't support different addresses.

Changing only the bus could be more easily done but this prepares the
ground for using HMC5843 on an AuxiliarBus.

The need for a more generic abstraction is evidenced by this commit: a
"SerialBus" in AP_HAL would be a nice addition rather than letting each
driver to provide its own. However the methods are a little bit
different from what we have in AK8963. It's safer to do the simple
conversion now and later on to add the abstraction changing everybody to
use it.
2015-08-28 12:39:09 +10:00
Staroselskii Georgii 3eb6be64c9 AP_Compass: ignore first two readings in a clearer way
This way we don't mix two different conditionals: settling and data validation.
2015-08-28 12:39:09 +10:00
Staroselskii Georgii 633330db14 AP_Compass: rename calibration array in HMC
I think naming the variable "scaling" makes more sense.
2015-08-28 12:39:09 +10:00
Staroselskii Georgii d8bddcbf3a AP_Compass: fix indentation in HMC's driver 2015-08-28 12:39:09 +10:00
Staroselskii Georgii 79ffddc6db AP_Compass: add a macro for checking calibration values in HMC 2015-08-28 12:39:08 +10:00
Lucas De Marchi f61386ae43 AP_Compass: HMC5843: release the lock before read
read() calls accumulate() which takes the lock by itself so we must
release it like we were doing before 669ae26 ("AP_Compass: encapsulated
calibration in HMC").
2015-08-28 12:39:08 +10:00
Staroselskii Georgii a9e8c1c464 AP_Compass: encapsulated calibration in HMC 2015-08-28 12:39:08 +10:00
Staroselskii Georgii 0fbc295d97 AP_Compass: encapsulated version detection in HMC driver 2015-08-28 12:39:08 +10:00
Gustavo Jose de Sousa 58f300e78e AP_Compass: 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:42 +10:00
Randy Mackay 66469d7529 Compass_HMC5843: remove unnecessary i2c semaphore give 2015-08-07 15:50:36 +09:00
Randy Mackay d192b3ccea Compass: set device id for ak8963 and hmc5843 2015-07-06 21:04:46 +09:00
Tom Pittenger 16e71ec1ce Compass: fix compile warning re member init order 2015-04-24 14:15:00 +09:00
Tom Pittenger bf1d128d70 Compass: fix compile warnings re float constants
Also fix example sketch
2015-04-24 12:29:07 +09:00
Andrew Tridgell 1962706a33 AP_Compass: fixed last_update, using last_update_usec()
this broke use of compass in the EKF
2015-03-14 12:31:23 +11:00
Andrew Tridgell 7b51c907f5 AP_Compass: zero some more variables in constructor and init 2015-03-13 19:22:11 +11:00
Andrew Tridgell 0efd3bacea AP_Compass: make new backend match old PX4 behaviour
when a compass is internal only apply board orientation, not user
specified rotation
2015-03-13 18:46:15 +11:00
Andrew Tridgell a871c87cad AP_Compass: use state array for compass variables 2015-03-13 18:46:15 +11:00
Víctor Mayoral Vilches 13f0aa5ecd AP_Compass: Separate common code into backend
_copy_to_frontend function takes care of abstracting
this code from the driver. For now the function takes
care of the offset and rotation that is common.
2015-03-13 18:46:15 +11:00
Víctor Mayoral Vilches d3b76cd8d3 AP_Compass: split compass into frontend/backend 2015-03-13 18:46:15 +11:00
Staroselskii Georgii 7f00dd413f AP_Compass: fixed HMC5883's initialisation code 2014-11-14 10:21:04 +11:00
Jonathan Challinger 9054dd3f9a AP_Compass: use apply_correction_function to eliminate duplication 2014-10-19 17:02:45 +11:00
Randy Mackay 86aac4f40c Compass_HMC5843: use instance specific orient and external 2014-10-01 13:02:03 +10:00
Andrew Tridgell 54562b0b9a AP_Compass: prevent bad initial values from affecting HMC5883 calibration
the first couple of values after we enter strap mode may be low, but
just above our 0.7 threshold. We now discard the first two values to
prevent these affecting the average.

Also added some commented out debug code and a comment on the scaling
of the calibration code
2014-01-22 17:15:34 +11:00
Andrew Tridgell 61f564d7c9 AP_Compass: support motor compensation for multiple compasses
Pair-Programmed-With: Randy Mackay <rmackay9@yahoo.com>
2013-12-09 19:45:31 +11:00
Andrew Tridgell c538816825 AP_Compass: support compass health status on multiple compasses 2013-12-09 17:46:41 +11:00
Andrew Tridgell bde89fd4e2 AP_Compass: added compass offsets for 2nd compass 2013-12-09 17:34:07 +11:00