Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mag fixes #7434

Closed
wants to merge 9 commits into from
Closed

mag fixes #7434

wants to merge 9 commits into from

Conversation

LorenzMeier
Copy link
Member

No description provided.

mhkabir and others added 9 commits June 15, 2017 08:28
A recent change removed the command forwarding required for VTOL transitions. This change brings this back.

Partially reverts #7249
Problem: _mag_device_id is used to get the correct rotation matrix for each
mag. But on POSIX, _mag_device_id was always 0, leading to invalid rotation
matrices.
This resulted in stale mag error messages (rot matrix=0 ==> mag data=0).
_mag_device_id was 0 because there are no /dev/magX devices (eg. on RPi),
thus the mag driver could not be opened.

This patch does: get the device id from the uorb topic instead. We still
need the device handle on certain platforms to apply the calibration params
and to check if the mag is internal or external.

Problem left: on POSIX, the check for external mag does not work.
With this we don't have to use the ioctl MAGIOCGEXTERNAL, which does not
work on POSIX (eg. RPi).
Because it's a baro driver, not a mag.
fixes a wrong index for _mag_device_id: previously, driver_index was used
(the CAL_MAG param index), but the correct index is the uorb topic
instance.
the 'continue' continues with the inner loop, whereas the outer loop is
responsible for opening the handle. Thus the inner loop needs to keep it
open.
@LorenzMeier
Copy link
Member Author

These are mag fixes that should go into stable.

@mhkabir
Copy link
Member

mhkabir commented Jun 17, 2017

@PX4TestFlights, please make sure you test at-least these configurations :

  1. With autopilot board rotated 180 degrees and external compass rotated 90 degrees.
  2. Autopilot board rotated 180 degrees and NO external compass.

You must recalibrate and reboot before and between these tests.

@mhkabir
Copy link
Member

mhkabir commented Jun 19, 2017

Something's not right even with these fixes. Tested on a Pixhawk 2 with 4 mags (3 internal, 1 external), and the internal/external detection seems janky. One of the internal ones is detected as external. @bkueng Do you have access to Pixhawk 2.1 hardware?

@bkueng
Copy link
Member

bkueng commented Jun 19, 2017

@bkueng Do you have access to Pixhawk 2.1 hardware?

No. I guess it's wrong in the driver then.

@mhkabir
Copy link
Member

mhkabir commented Jun 19, 2017

It used to work fine before (when I tested my last PR), so I will have to check again.

@r0gelion
Copy link
Contributor

@mhkabir Should we hold on testing?

@mhkabir
Copy link
Member

mhkabir commented Jun 20, 2017

@d3z0rian Don't let this gate testing. Please go ahead and test.

@Avysuarez
Copy link

flight with pixhawk mini (v3), flight controller rotated 180 degrees and external compass 90 degrees; good flight no issues.
http://review.px4.io/plot_app?log=308c24a0-c3ee-4103-9b6b-4e4eb60ac9d4

flight with pixracer (v4) no external compass; issues maintaining orientation; heavy drift when using position mode and AUTO/RTL"
http://review.px4.io/plot_app?log=f2e9a86b-939e-4093-a3fb-835aba0eae5b

@mhkabir
Copy link
Member

mhkabir commented Jun 20, 2017

Check out the mag params from the bad flight :

CAL_MAG0_ID, 66826
CAL_MAG0_ROT, -1
CAL_MAG0_XOFF, 0.5552833676338196
CAL_MAG0_XSCALE, 1.2924871444702148
CAL_MAG0_YOFF, 0.7929474115371704
CAL_MAG0_YSCALE, 0.792342483997345
CAL_MAG0_ZOFF, -0.24993646144866943
CAL_MAG0_ZSCALE, 1.7289966344833374
CAL_MAG1_ID, 263178
CAL_MAG1_ROT, -1
CAL_MAG1_XOFF, 0.21713092923164368
CAL_MAG1_XSCALE, 0.9173317551612854
CAL_MAG1_YOFF, 0.7974054217338562
CAL_MAG1_YSCALE, 0.766861617565155
CAL_MAG1_ZOFF, -0.038677264004945755
CAL_MAG1_ZSCALE, 1.1355003118515015
CAL_MAG2_ID, 0
CAL_MAG2_ROT, -1
CAL_MAG2_XOFF, 0.12544217705726624
CAL_MAG2_XSCALE, 1.0047169923782349
CAL_MAG2_YOFF, 0.4254632294178009
CAL_MAG2_YSCALE, 1.0015472173690796
CAL_MAG2_ZOFF, -0.013994383625686169
CAL_MAG2_ZSCALE, 0.9885672926902771
CAL_MAG3_ID, 0
CAL_MAG3_ROT, -1
CAL_MAG3_XOFF, 0.0
CAL_MAG3_XSCALE, 1.0
CAL_MAG3_YOFF, 0.0
CAL_MAG3_YSCALE, 1.0
CAL_MAG3_ZOFF, 0.0
CAL_MAG3_ZSCALE, 1.0
CAL_MAG_PRIME, 66826
CAL_MAG_SIDES, 63

The third mag (MAG2) doesn't seem to be correct. It has offsets and scaling, however no device ID. Not sure that this is the smoking gun, but it still shouldn't happen. Calibration should reset all those params.

@Avysuarez
Copy link

already recalibrate and these are the parameters;
screen shot 2017-06-20 at 12 34 23 pm

@tubeme
Copy link

tubeme commented Jun 22, 2017

Here is our Param Dump.

1 1 CAL_MAG0_ID 73225 6
1 1 CAL_MAG0_ROT -1 6
1 1 CAL_MAG0_XOFF -0.164696708321571350 9
1 1 CAL_MAG0_XSCALE 1.124019145965576172 9
1 1 CAL_MAG0_YOFF -0.073993489146232605 9
1 1 CAL_MAG0_YSCALE 0.955182909965515137 9
1 1 CAL_MAG0_ZOFF 0.185982719063758850 9
1 1 CAL_MAG0_ZSCALE 0.946247518062591553 9
1 1 CAL_MAG1_ID 73225 6
1 1 CAL_MAG1_ROT -1 6
1 1 CAL_MAG1_XOFF -0.164727285504341125 9
1 1 CAL_MAG1_XSCALE 1.124836444854736328 9
1 1 CAL_MAG1_YOFF -0.073960743844509125 9
1 1 CAL_MAG1_YSCALE 0.954893469810485840 9
1 1 CAL_MAG1_ZOFF 0.186127647757530212 9
1 1 CAL_MAG1_ZSCALE 0.945912837982177734 9
1 1 CAL_MAG2_ID 263178 6
1 1 CAL_MAG2_ROT -1 6
1 1 CAL_MAG2_XOFF -0.372631460428237915 9
1 1 CAL_MAG2_XSCALE 1.048644900321960449 9
1 1 CAL_MAG2_YOFF 0.341297119855880737 9
1 1 CAL_MAG2_YSCALE 1.025233745574951172 9
1 1 CAL_MAG2_ZOFF -0.036995410919189453 9
1 1 CAL_MAG2_ZSCALE 0.933909475803375244 9
1 1 CAL_MAG3_ID 0 6
1 1 CAL_MAG3_ROT -1 6
1 1 CAL_MAG3_XOFF 0.000000000000000000 9
1 1 CAL_MAG3_XSCALE 1.000000000000000000 9
1 1 CAL_MAG3_YOFF 0.000000000000000000 9
1 1 CAL_MAG3_YSCALE 1.000000000000000000 9
1 1 CAL_MAG3_ZOFF 0.000000000000000000 9
1 1 CAL_MAG3_ZSCALE 1.000000000000000000 9
1 1 CAL_MAG_PRIME 73225 6
1 1 CAL_MAG_SIDES 63 6

The Mag3 was not visible in the parameters in QGC. I see here it stayed empty. We made a mag calibration before the test. The hardware is AUAV X2.1. It has a 3 internal compasses in a chip. So there should be numbers after the calibration in the mag3 parameters.

We checked if the magnetometer mag0 is the main one and is working. We separated the gps from the stand and rotated only the gps+mag. As expected the arrow in the compas slowily started diverging. So everithing was ok as expected. Strangely we could not change CAL_MAG0_ROT to 4. it stayed at -1.

@mhkabir
Copy link
Member

mhkabir commented Jun 22, 2017

@Tubme A few things :

  1. MAG0 and MAG1 have the same IDs. This is causing the application of wrong offsets. This is a driver issue, but I'm not sure yet which driver it is.
  2. What exact set of sensors does the X2.1 have? I don't think anyone is actively flying this board yet, so you have issues like (1). @eyeam3 fixed a similar issue for the MPU9250 driver for Pixhawk 2 where the device ID was getting shadowed.
  3. Not sure yet why all 4 mags aren't getting detected yet. Are you sure that there are a total of 4 are connected though, and the drivers started for them?

@tubeme
Copy link

tubeme commented Jun 22, 2017

@mhkabir Thanks for the reply.

  1. I have not noticed the IDs... I will ask in a few hours what is the GPS+Mag combo used in the test. As far as I remember was the HMC5883L compass.
  2. X2.1 has a MPU9250 which includes the AK8963 3 axis magnetometer. How did the @eyeam3 fixed the problem? Is it in a separate branch or in master?
  3. We are sure there are 4 connected. The board has the MPU9250 with its 3 mags. And I told you we tried if the external mag was working. It was confirmed that on movement of the compass only the compass in the GQC reacted accordingly. But some how the mag0 was fixed as internal in the params.

@mhkabir
Copy link
Member

mhkabir commented Jun 22, 2017

We are sure there are 4 connected. The board has the MPU9250 with its 3 mags. And I told you we tried if the external mag was working. It was confirmed that on movement of the compass only the compass in the GQC reacted accordingly. But some how the mag0 was fixed as internal in the params.

This is a completely misguided line of thought. The MPU9250's AK8963 enumerates as 1 magnetometer. From a quick glance at your params, I see that MAG2 is the AK8963. So the question is - what is MAG0 and MAG1. Can you please share sensors status with the external one connected and without it connected? Make sure you reboot between unplugging the external mag.

Also @pkocmoud, would you be able to confirm what mag chips you have onboard the X2.1? The product page (which looks incomplete) suggests that the MPU9250's mag is the only one onboard the autopilot board.

@tubeme
Copy link

tubeme commented Jun 22, 2017

Here is a dump from the same GPS but with X2:

CAL_MAG0_ID 0 73225
CAL_MAG0_ROT 0 0
CAL_MAG0_XOFF 1 -0.02284376
CAL_MAG0_XSCALE 1 0.97940123
CAL_MAG0_YOFF 1 0.18024859
CAL_MAG0_YSCALE 1 1.0882009
CAL_MAG0_ZOFF 1 0.14344706
CAL_MAG0_ZSCALE 1 1.1548252
CAL_MAG1_ID 0 131594
CAL_MAG1_ROT 0 -1
CAL_MAG1_XOFF 1 0.050732274
CAL_MAG1_XSCALE 1 1.0
CAL_MAG1_YOFF 1 -0.0030052238
CAL_MAG1_YSCALE 1 1.0
CAL_MAG1_ZOFF 1 -0.07969876
CAL_MAG1_ZSCALE 1 1.0
CAL_MAG2_ID 0 0
CAL_MAG2_ROT 0 -1
CAL_MAG2_XOFF 1 0.0
CAL_MAG2_XSCALE 1 1.0
CAL_MAG2_YOFF 1 0.0
CAL_MAG2_YSCALE 1 1.0
CAL_MAG2_ZOFF 1 0.0
CAL_MAG2_ZSCALE 1 1.0
CAL_MAG_PRIME 0 73225
CAL_MAG_SIDES 0 63

So the 73225 is the ID of the external mag.

@tubeme
Copy link

tubeme commented Jun 22, 2017

The X2.1 does not have second magnetometer. It uses only the one from MPU9250. It is confirmed by Mr.Arsov.

Will confirm the sensor status later.

@tubeme
Copy link

tubeme commented Jun 22, 2017

Another pointer that might help:

Before the bootloader changes the X2.1 was recognized as ID:9. We were able to flash the regular FMUv2 firmware and then the external mag had a 90 degrees offset. We were able to correct this with CAL_MAG0_ROT = 2 (yaw 90) and we flew without a problem.

After the bootloader changed and the X2.1 is recognized as ID:33 we flash the new auav-x21_default.px4 and we have 180 degrees offset without the option to change the CAL_MAG0_ROT.

Is there some initialization dependent on the board ID? that is done once when you flash a new firmware...

@tubeme
Copy link

tubeme commented Jun 23, 2017

Status without the external magnetometer:

INFO  [ekf2] Mag sensor ID changed to 263178
INFO  [lib__ecl] EKF aligned, (pressure height, IMU buf: 17, OBS buf: 16)
WARN  [commander_tests] Not ready to fly: Sensors not set up correctly

nsh> sensors status
INFO  [sensors] gyro status:
INFO  [lib__ecl] validator: best: 0, prev best: 1, failsafe: NO (0 events)
INFO  [lib__ecl] sensor #0, prio: 100, state: OK
INFO  [lib__ecl]        val:   0.0035, lp:   0.0020 mean dev:  -0.0000 RMS:   0.0141 conf:   1.0000
INFO  [lib__ecl]        val:   0.0004, lp:   0.0004 mean dev:   0.0000 RMS:   0.0100 conf:   1.0000
INFO  [lib__ecl]        val:  -0.0003, lp:  -0.0006 mean dev:  -0.0000 RMS:   0.0020 conf:   1.0000
INFO  [lib__ecl] sensor #1, prio: 99, state: OK
INFO  [lib__ecl]        val:   0.0007, lp:  -0.0002 mean dev:  -0.0000 RMS:   0.0095 conf:   1.0000
INFO  [lib__ecl]        val:   0.0008, lp:   0.0004 mean dev:   0.0000 RMS:   0.0023 conf:   1.0000
INFO  [lib__ecl]        val:  -0.0012, lp:  -0.0014 mean dev:  -0.0000 RMS:   0.0012 conf:   1.0000
INFO  [sensors] accel status:
INFO  [lib__ecl] validator: best: 0, prev best: 1, failsafe: NO (0 events)
INFO  [lib__ecl] sensor #0, prio: 100, state: OK
INFO  [lib__ecl]        val:   0.2618, lp:   0.2616 mean dev:   0.0003 RMS:   0.0080 conf:   1.0000
INFO  [lib__ecl]        val:   0.2213, lp:   0.2090 mean dev:   0.0001 RMS:   0.0076 conf:   1.0000
INFO  [lib__ecl]        val:  -9.8718, lp:  -9.8718 mean dev:   0.0012 RMS:   0.0092 conf:   1.0000
INFO  [lib__ecl] sensor #1, prio: 99, state: OK
INFO  [lib__ecl]        val:   0.3228, lp:   0.3261 mean dev:  -0.0034 RMS:   0.0255 conf:   1.0000
INFO  [lib__ecl]        val:   0.0312, lp:   0.0301 mean dev:  -0.0033 RMS:   0.0272 conf:   1.0000
INFO  [lib__ecl]        val:  -9.7329, lp:  -9.7287 mean dev:   0.0126 RMS:   0.0968 conf:   1.0000
INFO  [sensors] mag status:
INFO  [lib__ecl] validator: best: 0, prev best: 0, failsafe: NO (0 events)
INFO  [lib__ecl] sensor #0, prio: 50, state: OK
INFO  [lib__ecl]        val:   0.0006, lp:  -0.0109 mean dev:   0.0078 RMS:   0.0380 conf:   1.0000
INFO  [lib__ecl]        val:   0.1810, lp:   0.1654 mean dev:  -0.0070 RMS:   0.0344 conf:   1.0000
INFO  [lib__ecl]        val:   0.3033, lp:   0.3002 mean dev:  -0.0007 RMS:   0.0091 conf:   1.0000
INFO  [sensors] baro status:
INFO  [lib__ecl] validator: best: 0, prev best: 0, failsafe: NO (0 events)
INFO  [lib__ecl] sensor #0, prio: 75, state: OK
INFO  [lib__ecl]        val:  20.0805, lp:  19.9974 mean dev:  -0.0250 RMS:   0.2339 conf:   1.0000
INFO  [lib__ecl]        val:   0.0000, lp:   0.0000 mean dev:   0.0000 RMS:   0.0000 conf:   1.0000
INFO  [lib__ecl]        val:   0.0000, lp:   0.0000 mean dev:   0.0000 RMS:   0.0000 conf:   1.0000
INFO  [sensors] Temperature Compensation:
INFO  [sensors]  gyro: enabled: 0
INFO  [sensors]  accel: enabled: 0
INFO  [sensors]  baro: enabled: 0
nsh>

Status WITH external magnetometer:

INFO  [ekf2] Mag sensor ID changed to 73225
INFO  [lib__ecl] EKF aligned, (pressure height, IMU buf: 17, OBS buf: 16)
WARN  [commander_tests] Not ready to fly: Sensors not set up correctly

nsh> sensors status
INFO  [sensors] gyro status:
INFO  [lib__ecl] validator: best: 0, prev best: 0, failsafe: NO (0 events)
INFO  [lib__ecl] sensor #0, prio: 100, state: OK
INFO  [lib__ecl]        val:   0.0037, lp:   0.0022 mean dev:  -0.0000 RMS:   0.0172 conf:   1.0000
INFO  [lib__ecl]        val:   0.0007, lp:   0.0004 mean dev:   0.0001 RMS:   0.0119 conf:   1.0000
INFO  [lib__ecl]        val:  -0.0002, lp:  -0.0004 mean dev:  -0.0001 RMS:   0.0024 conf:   1.0000
INFO  [lib__ecl] sensor #1, prio: 99, state: OK
INFO  [lib__ecl]        val:  -0.0001, lp:   0.0000 mean dev:  -0.0000 RMS:   0.0116 conf:   1.0000
INFO  [lib__ecl]        val:  -0.0016, lp:  -0.0002 mean dev:   0.0000 RMS:   0.0026 conf:   1.0000
INFO  [lib__ecl]        val:  -0.0010, lp:  -0.0017 mean dev:   0.0000 RMS:   0.0013 conf:   1.0000
INFO  [sensors] accel status:
INFO  [lib__ecl] validator: best: 0, prev best: 0, failsafe: NO (0 events)
INFO  [lib__ecl] sensor #0, prio: 100, state: OK
INFO  [lib__ecl]        val:   0.1434, lp:   0.1489 mean dev:   0.0012 RMS:   0.0107 conf:   1.0000
INFO  [lib__ecl]        val:  -0.1238, lp:  -0.1201 mean dev:   0.0007 RMS:   0.0087 conf:   1.0000
INFO  [lib__ecl]        val:  -9.8809, lp:  -9.8739 mean dev:   0.0019 RMS:   0.0102 conf:   1.0000
INFO  [lib__ecl] sensor #1, prio: 99, state: OK
INFO  [lib__ecl]        val:  -1.2982, lp:  -1.3087 mean dev:  -0.0015 RMS:   0.0126 conf:   1.0000
INFO  [lib__ecl]        val:  -0.1600, lp:  -0.1648 mean dev:  -0.0014 RMS:   0.0128 conf:   1.0000
INFO  [lib__ecl]        val: -19.5505, lp: -19.5638 mean dev:   0.0062 RMS:   0.0440 conf:   1.0000
INFO  [sensors] mag status:
INFO  [lib__ecl] validator: best: 0, prev best: 1, failsafe: YES (1 events)
INFO  [lib__ecl] sensor #0, prio: 100, state: OK
INFO  [lib__ecl]        val:  -0.2721, lp:  -0.2740 mean dev:   0.0007 RMS:   0.0030 conf:   1.0000
INFO  [lib__ecl]        val:   0.0643, lp:   0.0635 mean dev:   0.0005 RMS:   0.0025 conf:   1.0000
INFO  [lib__ecl]        val:   0.3341, lp:   0.3358 mean dev:  -0.0001 RMS:   0.0029 conf:   1.0000
INFO  [lib__ecl] sensor #1, prio: 100, state: OK
INFO  [lib__ecl]        val:  -0.2741, lp:  -0.2740 mean dev:   0.0002 RMS:   0.0024 conf:   1.0000
INFO  [lib__ecl]        val:   0.0620, lp:   0.0635 mean dev:   0.0002 RMS:   0.0021 conf:   1.0000
INFO  [lib__ecl]        val:   0.3369, lp:   0.3360 mean dev:  -0.0000 RMS:   0.0025 conf:   1.0000
INFO  [lib__ecl] sensor #2, prio: 50, state: OK
INFO  [lib__ecl]        val:  -0.0040, lp:   0.0038 mean dev:   0.0108 RMS:   0.0443 conf:   1.0000
INFO  [lib__ecl]        val:   0.1719, lp:   0.1822 mean dev:  -0.0092 RMS:   0.0386 conf:   1.0000
INFO  [lib__ecl]        val:   0.3036, lp:   0.3038 mean dev:  -0.0005 RMS:   0.0115 conf:   1.0000
INFO  [sensors] baro status:
INFO  [lib__ecl] validator: best: 0, prev best: 0, failsafe: NO (0 events)
INFO  [lib__ecl] sensor #0, prio: 75, state: OK
INFO  [lib__ecl]        val:  20.4975, lp:  20.3845 mean dev:   0.0120 RMS:   0.2420 conf:   1.0000
INFO  [lib__ecl]        val:   0.0000, lp:   0.0000 mean dev:   0.0000 RMS:   0.0000 conf:   1.0000
INFO  [lib__ecl]        val:   0.0000, lp:   0.0000 mean dev:   0.0000 RMS:   0.0000 conf:   1.0000
INFO  [sensors] Temperature Compensation:
INFO  [sensors]  gyro: enabled: 0
INFO  [sensors]  accel: enabled: 0
INFO  [sensors]  baro: enabled: 0

@LorenzMeier
Copy link
Member Author

Thanks! I will have a look tomorrow.

@LorenzMeier LorenzMeier self-assigned this Jun 23, 2017
@mhkabir
Copy link
Member

mhkabir commented Jun 24, 2017

#0 and #1 both seem to be from the external mag driver, and the values in the validator are exactly the same.

@LorenzMeier
Copy link
Member Author

@tubeme I suspect that the driver config for the X2 was just never finished as it looks very different from Pixhawk but supposedly is more or less the same board. @pkocmoud Could you comment on this? I don't have a board so I can't really test it, but maybe @davids5 and @pkocmoud can look at this together.

@tubeme
Copy link

tubeme commented Jun 24, 2017

@LorenzMeier @mhkabir I think it is something to do with the initialization during flash. Lorenz you mention X2, while I'm talking about X2.1. Before the bootloader changed I explained that the board was accepted as FMUv2, we flashed regular FMUv2 FW and with the same magnetometer and GPS we flew missions etc. The only thing we had done is give the CAL_MAG0_ROT = 2 (yaw 90). After the calibration the QGC asks for this offset. When the bootloader changed and we flash the AUAV X2.1 FW version after the calibration QGC did not ask us for the CAL_MAG0_ROT offset.

The hardware is performing perfectly well with the FMUv2 version. Now it is impossible to flash FMUv2. QGC does not allow this.

@LorenzMeier
Copy link
Member Author

After the boot loader change you are now flashing effectively different software and I can tell from the code that its behaving differently than FMUv2 - which makes no sense, because you said it worked with the FMUv2 software just fine. @pkocmoud Can you chime in here?

@tubeme
Copy link

tubeme commented Jun 26, 2017

@LorenzMeier I don't understand what you mean by differently but here are the specs of the two boards:

X2

STM32F427VI ARM microcontroller
STM32F100C8T6 ARM microcontroller

ST Micro L3GD20
ST Micro LSM303D
Invensense MPU 6000
MEAS MS5611 barometer

X2.1

Processors:
Main: STM32F427VIT6 ARM microcontroller - Revision 3
IO: STM32F100C8T6 ARM microcontroller

Next Generation Sensors:

Invensense MPU9250 9DOF
Invensense ICM-20608 6DOF
MEAS MS5611 barometer

By this specs it is obvious that the CPUs are the same (another revision does not mean new CPU). This in its term means that OSwise (nuttx) the boards are identical.

They have a different sensors which in its term means they have a different drivers they load during start up and that is the only difference I see.

It is a FACT that we managed to fly the board perfectly well with the FMU v2 version of the firmware with the only condition that we changed the direction of the external mag to 90deg. And it is logical because the MPU9250 drivers are in the main tree so they are loaded with the FMU v2 firmware as well. And if they are loaded then the board is working.

I don't understand what is the difference really.

We can fly the board now as well with the condition that we physically rotate the GPS 180deg.

But it is not good at all, because the external mag is registering two times as mag #0 and #1. I'm not sure what is going to happen if the external mag fails? Is it going to switch to mag #2 or is it going to stay headless?

It is for sure the board is not functioning correctly under the new bootloader with the AUAV-X2.1 version of the firmware, but it is most likely very simple thing that has to be changed in the initialization of probably the MPU9250 driver. Registering the external mag as internal in the nuttx gives me the lead towards the MPU9250 driver.

The HMC5883L is a very old device with a very old driver so I doubt there is the problem with it. We will make a test with another external compass + GPS to make sure we tried this combination as well.

@davids5
Copy link
Member

davids5 commented Jun 27, 2017

The bootloader change list the board id as that requiring FW for the auav-x21 build.

That is auav-x21_default not px4fmu-v2_default.

The auav-x21_default has a board name "AUAV_X21" So the startup is different. There may be an error in the startup script or it may have bus differences (no external) but the sensor is configured as external when it is not.

see e4afce8#diff-dc146e6fb305825fdba36bf461a3e970R64

@tubeme
Copy link

tubeme commented Jun 27, 2017

@davids5 Exactly my point.
With px4fmu-v2_default prior bootloader changes (ID 9) we were able to fly with CAL_MAG0_ROT = 2.
After the changes with auav-x21_default (ID 33) we have 180 offset to the external mag and we are not able to change CAL_MAG0_ROT = 4 to compensate.

And a little correction. The external sensor is registering as internal and not only this but it is registered 2 times as mag #0 and #1.

So it might be the script.

Here is the AUAV script:

if ver hwcmp AUAV_X21
then
# I2C bus
if hmc5883 -C -T start
then
fi

# I2C bus
if lis3mdl start
then
fi
  • Internal SPI bus ICM-20602-G is rotated 90 deg yaw

  • if mpu6000 -R 2 -T 20602 start

  • then

  • fi

  • Internal SPI bus ICM-20608-G is rotated 90 deg yaw

    if mpu6000 -R 2 -T 20608 start
    then
    fi

    Internal SPI bus mpu9250 is rotated 90 deg yaw

    if mpu9250 -R 2 start
    then
    fi
    fi

First there is no MPU6000 on this board. It is MPU9250 so the two ifs with the MPU6000 are not necessary. Also there is no other magnetometer to the X2.1 except the one in the MPU9250 that is confirmed as I mentioned above.

Second for the HMC5883 I see a substantial difference with the FMUv2 version:

FMUv2 version:

    # External I2C bus
if hmc5883 -C -T -X start
then
fi

# External I2C bus
if lis3mdl -X start
then
fi

# Internal I2C bus
if hmc5883 -C -T -I -R 4 start
then
fi

AUAVX2.1 version:

# I2C bus
if hmc5883 -C -T start
then
fi

You see for the FMUv2 version you presume there is External and Internal option for the hmc5883
while for the AUAVX2.1 there is only one option.

I presume that if you change in the AUAVX2.1 the line

    # I2C bus
if hmc5883 -C -T start
then
fi

to

    # I2C bus
if hmc5883 -C -T -X start
then
fi

it will run perfectly well like in the FMUv2 scenario we had.

@tubeme
Copy link

tubeme commented Jun 27, 2017

Something else to add. The PixRacer is accepted as FMUv4. From my knowledge it is 99% the same as X2.1 with the only difference of a mag sensor it has more than X2.1

Here is the FMUv4 script:

if ver hwcmp PX4FMU_V4
then
# External I2C bus
if hmc5883 -C -T -X start
then
fi

if lis3mdl -R 2 start
then
fi

# Internal SPI bus is rotated 90 deg yaw
if hmc5883 -C -T -S -R 2 start
then
fi

# Internal SPI bus ICM-20608-G is rotated 90 deg yaw
if mpu6000 -R 2 -T 20608 start
then
fi

# Internal SPI bus ICM-20602-G is rotated 90 deg yaw
if mpu6000 -R 2 -T 20602 start
then
fi

# Start either MPU9250 or BMI160. They are both connected to the same SPI bus and use the same
# chip select pin. There are different boards with either one of them and the WHO_AM_I register
# will prevent the incorrect driver from a successful initialization.

# Internal SPI bus mpu9250 is rotated 90 deg yaw
if mpu9250 -R 2 start
then
fi

# Internal SPI bus BMI160
if bmi160 start
then
fi

fi

and I see the exact same line I'm taliking about:

    # External I2C bus
if hmc5883 -C -T -X start
then
fi

Also I don't understand what is External and Internal I2C, when there is I2C1 and I2C2 buses on the board. From my knowledge there shouldn't be any difference between connecting devices to the C1 or C2 buses. They are interchangeable.

@mhkabir
Copy link
Member

mhkabir commented Jun 27, 2017

@tubeme @pkocmoud I have prototype fix coming for you, but you'll need to test it. It seems like no one actually properly brought up the sensors for the board, including chip rotations, etc.

#7487

@LorenzMeier
Copy link
Member Author

Superseded by fixes on master, which will come in to stable now.

@LorenzMeier LorenzMeier closed this Jul 8, 2017
@LorenzMeier LorenzMeier deleted the stable_mag_fixes branch July 8, 2017 12:30
@Avysuarez
Copy link

  1. Flight with pixhawk mini (v3), flight controller rotated 180 degrees and external compass 90 degrees; good flight no issues.
    http://review.px4.io/plot_app?log=6b84a0fa-d2e0-4cec-b609-35048afcb732
  2. Autopilot board rotated 180 degrees and NO external compass.
    Can not fly because it does not detect external mag.

screen shot 2017-07-11 at 11 18 07 am

@mhkabir
Copy link
Member

mhkabir commented Jul 11, 2017

@Avysuarez Did you recalibrate before doing the second test? I don't see how that can happen unless you don't recalibrate after disconnecting the externl mag.

@Avysuarez
Copy link

  1. Flight with pixhawk mini (V3). Autopilot board rotated 180 degrees and NO external compass.
    Good flight, no issues.
    http://review.px4.io/plot_app?log=fde3d6f8-3531-4c60-ac3d-3940de7c8cae

@mhkabir
Copy link
Member

mhkabir commented Jul 12, 2017

@Avysuarez Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants