Copter: compassmot does not work on PIXHAWK
I tried to make "compassmot" on various PIXHAWKs. It does not work.
regards Peter

Peter, Thanks for the report. Hopefully most people will move to using an external gps+compass but the built in compassmot should also work really so we will have a look at that.
Hi Randy,
all my birds have an external compass and GPS. This one too.
Peter
I can confirm the same issue on PX4
I also use external compass and its the same results when testing in CLI - test -compass: Comp Vec: nan, nan, nan
It seams the compass class (in \libraries\AP_Compass\Compass.h) is to blame as both CLI-test-compass and setup_compassmot get their bad data from these functions: compass.get_motor_compensation() and compass.get_field() (called from setup.pde)
Can someone with better code skill take a look on why those functions return "nan"?
Best Superman
I'm running Rover on a PX4 with external compass / GPS and at 2.44 I got nan for all three mag offset axes in the CLI - test - compass, and the "live calibration" gave nothing (it recorded no samples). When I updated firmware to 2.45, the live calibration worked through APM Planner (didn't try Mission Planner), then the Mission Planner CLI showed sensible values for the offsets.
I note this is a Copter issue, but it may be worth cross checking against Rover 2.45.
Thanks for your input mike. I see Rover dont have compassmot in which compass.get_motor_compensation() and compass.get_field() get used. Our mag offsets works and it may be a linking problem to the PX4 compass files, maybe with the new compass API? https://github.com/diydrones/ardupilot/commit/ffdcb715c3fb6be8a03b7e570c6de17024e9e5fc Because compassmot works on APM right?
One thing you can try on Rover is CLI test compass, and see if mag values is working.
Best Superman
Same issue observed tonight. C.f. post in arducopter user group. But anyway does it make sense to do a compassmot on pixhawk with an external compass ? thx Hugues
Hugues, this is a good point. Generally you shouldn't need compassmot if you use an external compass and place it more than 5cm or so above the power wires. I can't guarantee that 5cm is enough, it depends upon the strength of the interference, but quite often 5cm is enough. Compassmot is a software solution to the interference problem and was primarily made to help all those people who weren't using the external compass and didn't have the freedom to place the APM away from the source of interferencde.
Compassmot is a great feature that improves safety. I use it to verify quality of the assembly. 5cm is not always enough, and then, if we would use internal mag. as backup, or for another reason, - then compassmot will be very important again.
we're working on a mavlink version so it will be possible to run from the ground station instead of going into the CLI. That work is about 1/2 way done (the flight controller side is done...just the ground station side remains).
I was able to use compassmot with Pixhawk and the external GPS/Compass (I think) in V3.1.1, but after I upgraded to V3.1.2 I experienced the same NaN phenomenon. Set the gains to zero for now.
So, Compiling my own firmware for PX4, as my fix to get current sensing working isnt in main yet: https://github.com/diydrones/ardupilot/issues/653#issuecomment-35861681 My version is ArduCopter V3.2-dev (5f85e7af)
I tried your compassmot in Mission Planner and still the same NaN problem!
Here is a pic:

So I saw a recent fix to report_compass() today and compiled the latest AC, but in that you have disabled CLI and I cant download the logs... Just weird chars... How are we able to download logs when CLI is disabled?
Anyway I can test for you randy?
And is it relatively safe to compile latest main myself?
Compiled with enabled CLI and still the same prob. NaN.. ArduCopter V3.2-dev (6efc26d3)
Best Superman
your draw current never got above 3 amp.
I know, tried without props just to try, Didn't want to vacuum the room! Shouldn't be a difference tho, the compass still gives NaN.
the current draw does mater
// adjust the motor compensation to negate the impact if drawing over 3amps if( battery.current_amps() >= 3.0f )
Ok, thanx for the input. Still the same problem tho:

Seeing the same problem here. I built a fresh ArduCopter v3.1.2 for my PX4 (v1, with PX4IO) from e2ed3dd1, with https://github.com/totaltmega/PX4Firmware/commit/c08af3473325a92d3576576d1e028403776540b1 cherry-picked into my px4 tree. The CLI compassmot shows the correct throttle and current, but the other fields (mot for motor_impact and comp for motor_compensation) show all NaNs and compassmot fails. My current is going over 3A too (and this is recorded clearly in the output).
(Updated...) I looked into this a bit. The problem is that compass.get_field() is returning NaNs for roughly half of the calls made to it from setup.pde (or compassmot.pde in more recent versions). With a few debug print statements I was able to show that _count[i] is sometimes 0 in AP_Compass_PX4::read on line 95, because the rate of mag_reports being received in AP_Compass_PX4::accumulate can be lower than the 50Hz rate of calls to the read() method (called by compassmot). As a result, sometimes accumulate gets no mag_reports, and get_field() returns NaN.
Here's a quick hack that allows compassmot to work again, but glosses over the underlying problem in the compass code:
https://github.com/matthewlloyd/ardupilot/commit/670a4e179d1bd5fbe7fb4d0a820af36fb6773cad
Hi Matthew, Thanks for the patch, I've pushed it to master. I don't think there really is a deeper problem. The compassmot code is unusual in calling compass reads at such a high rate. In normal use read is called at 10Hz. This certainly was an important bug fix, thanks! Cheers, Tridge