Does RTL work if there is magnetic interference in compass?

Hi all,

I have recently bought a hexacopter and I was trying to do a flight test with it. I tried to test the Stabilize, Loiter, and RTL modes.

In stabilize mode, the copter went haywire, it was really hard to control and was not leveling itself. Then I hit the RTL button as a last resort, and luckily it landed safely, afterward I checked but could not find any problem on the field.

Then I took off again in loiter mode. Copter took off ok but after a couple of seconds it started to do the toilet bowl movement, and also yaw by itself without any RC input. Then I used RTL again and landed safely.

I checked the flight log and saw that magnetic interference is quite high

Indeed, the GPS/Compass unit is mounted near the power lines which I found weird as well (please see attached image).

I also saw that in the log the compass-motor calibration was not performed at all, i.e. COMPASS_MOT_X, Y, and Z were zero. Then, I started to think there is magnetic interference in the compass but, I am not really sure.

The one thing that I do not understand is if there is a magnetic interference with the compass, how did RTL work? I was expecting the RTL would also fail if there is a magnetic interference in the compass. Could someone please help me to understand this? If there is no problem with the compass, can someone please help me to find the problem here? I also did not understand why drone goes haywire in stabilize mode? Can magnetic interference in the compass deteriorate the flight performance in stabilize mode?

In the below link, you can find the videos during the flight and also bin log file.

https://drive.google.com/drive/folders/1S9rGMq1NJwddCc9yzczZvRJtv_PB6ts_

Best regards

yes, magnetic interference is bad and will cause all sorts of issues.
RTL uses compass, but it will still RTL fine if the interference is not very big.

Hi Amilcar,
Thanks a lot for the response, really appreciate the time and effort
I just elevated the GPS/Compass unit using a mounting mast.
I will do another test flight and update here, hopefully with a better flight.
Best regards

Ideally the GNSS unit should be up higher, which would move the compass away from the interference some more. Leave it as it is for now and we’ll try more.
I would suggest just using Stabilse mode and AltHold mode for first flights - Loiter will come after there is good stability.

Before you do anymore, what motors, props and ESCs do you have?
Is it the T-Motor Integrated power units? (ESC inside the motor mount)
From this information I can suggest changes which will help stable flight, improve the tuning, and from there you’ll be able to better calibrate the compass using Magfit - I can help you with all this.

Hi Shawn,
Thanks a lot for the response and help offer
I did first try loiter mode indeed, but then switch to stabilize. Nevertheless, the control of the drone got even worse with Stabilize mode.

Yes, they are Tmotor’s P60-X(Integrated Propulsion System).
I would really appreciate any help.

OK set all these exactly ready for the next flight:

ARMING_CHECK,1
BATT_ARM_VOLT,44.30
BATT_CRT_VOLT,42.00
BATT_FS_CRT_ACT,1
BATT_LOW_VOLT,43.20
BRD_BOOT_DELAY,3000
GPS_GNSS_MODE,5  //   or 65
INS_ACCEL_FILTER,10
INS_GYRO_FILTER,22
INS_HNTCH_BW,20
INS_HNTCH_ENABLE,1  // set this then refresh params to see the rest
INS_HNTCH_FM_RAT,0.7
INS_HNTCH_FREQ,40
INS_HNTCH_MODE,1
INS_HNTCH_REF,0.15
INS_LOG_BAT_MASK,1
INS_LOG_BAT_OPT,4
LOG_BITMASK,180222
MOT_BAT_VOLT_MAX,50.40
MOT_BAT_VOLT_MIN,39.60
MOT_SPIN_MIN,0.13
MOT_THST_EXPO,0.4
PILOT_THR_BHV,7
PSC_ACCZ_I,0.44
PSC_ACCZ_P,0.22

You appear to have a spring-centred throttle, so the PILOT_THR_BHV will take advantage of this and hover thrust should soon settle at about the same position as the centre of the throttle.
For GPS_GNSS_MODE experiment a little to see which value of 5 or 65 gives you quickest time to GPS 3D Fix and lowest HDOP. It doesn’t matter which of 5 or 65 you use right now, they will both be better than the default 0.

Just do some hovering in Stabilise and AltHold, and if that’s going OK try some gentle pitch and roll, and yaw. This flight will gather data for a bit more tuning, so dont go radical yet, just send the next .bin log file.

1 Like

Hi Shawn,

Thanks a lot for all of this.
Should I place the GPS/Compass back in the original place because I already elevated it using mounting mast or not?

Best regards

Leave it where you have it now. Higher is better for both the GPS and the compass.

Ok, Thanks a lot,
I will update this as soon as I test the copter
Best regards

Flight may not be much better than before, yet, but as I said this will gather good data, then we can make further adjustments.

I will try to fly in Stabilize mode but the copter was so aggressive during the test that is why I could not even do anything but put it on RTL otherwise it was going to hit GeoFence and trigger failsafe. Hopefully this time it will be a bit better so that I can gather decent data

Try AltHold.
Stabilise is hard to handle, and with a bit more tuning it should be OK. You will need to practice a bit in Stabilise since it will be the mode you need in an emergency.

This sounds normal for a pilot not experienced in Stabilize mode flight.

Hi Shawn,

I did the test flight again, using AltHold mode (and a bit of Loiter mode).
The flight was much better compared to last time, I did not have any hard time controlling the copter. I checked the magnetometer data and saw that the interference is quite low compared with the last time.

But I think as you said, the copter needs a bit more tuning for a better loiter mode. When I tried the copter in loiter mode, it was wobbling a bit and to be on the safe side I just changed the flight mode back to AltHold and landed. But I am not sure what is the cause of that wobble. When I checked the FFT output I can see that the filter does a good job, but there are still some noises at about 90, 180, and 270 Hz. However, I am not really an expert in that and need your help to specify the frequency that is needed to compensate for these noises If needed.
Could you please help me with that?
Also, please let me know if you see any other problems in the log.

Please find the log file below
https://drive.google.com/drive/folders/1d4bOVX2C_xFxMSXLHnBQ4B5kp4QIVOk3?usp=drive_link

Best regards

You can adjust these

INS_HNTCH_BW,27
INS_HNTCH_FREQ,45
INS_HNTCH_REF,0.12

I think you can alter these to make further improvements to the rest of the tuning

ATC_INPUT_TC,0.2
ATC_RAT_PIT_D,0.0025
ATC_RAT_PIT_I,0.10
ATC_RAT_PIT_P,0.10
ATC_RAT_RLL_D,0.0025
ATC_RAT_RLL_I,0.10
ATC_RAT_RLL_P,0.10
ATC_THR_MIX_MAN,0.5
PSC_ACCZ_I,0.32
PSC_ACCZ_P,0.16

The extra wobbling in Loiter is usually because the position controller is trying to stay in an exact location, for example, but is making demands the rest of the tuning can not yet satisfy. Loiter should come good after you are able to run Autotune.

Hi Shawn,

Thanks a lot for the suggestions.

I will test the copters with these parameters.
I can check the stabilize mode as well, I guess.

I would really appreciate if you can provide some insights about specifying these parameters because I could not fully understand it from the Wiki page.

About INS_HNTCH_FREQ, 45, is that because we saw from FFT analysis the harmonic noises were about 90, 180, and 270 Hz and putting the frequency at 45 Hz because it is a common multiple of these harmonic noises and not too large to cause delays (putting it to 90 Hz might cause delays?) but kind of large enough to reduce these noises?

I also could not understand the INS_HNTCH_REF, on the Wiki page it says this should be equal to the hover_thrust, and hover_thrust is equal to MOT_THST_HOVER if MOT_THST_LEARN is 2. In my case, I could not find the MOT_THST_LEARN but MOT_HOVER_LEARN is 2, which I assume both are similar things. Then when I checked the MOT_THST_HOVER value in the params, it is 0.2239438. I also checked the CTUN.ThH value and it sits at about 0.14. But why did you decide to put this to 0.12?

Best regards

Yes in a way that’s true. Based on my estimation your props and motors should be running about 41Hz, but that’s not exact, and clearly yours is running at 45Hz based on flight in the logs.
Usually the base frequency is not as obvious as the harmonics, so it can be easy for the novice FFT person to assume 90Hz, the first obvious peak, is the correct peak - but it’s not.

The real formula for INS_HNTCH_REF is:
INS_HNTCH_REF = hover_thrust * (min_freq / hover_freq)^2
but in reality it’s approximately
INS_HNTCH_REF = hover_thrust * 0.6 or 0.7
This relatively new parameter also helps
INS_HNTCH_FM_RAT,0.7

Hi Shawn,

Thanks a lot for the swift explanation.
I will update this after doing the test flight and hopefully, I would be able to run the autotune soon.

Best regards

Hi Shawn,

I did another flight with the updated parameters.
I tried AltHold, Stabilize, and just a little bit of Loiter.

Now, AltHold is pretty good I guess.

The stabilize mode was also fine, it just copter moves up and down, controlling the altitude was a bit tricky but this might be due to my lack of experience flying in Stabilize mode as well. This time at least, the copter levels itself pretty nice and I did not have to fight to control it.

Loiter mode was okish, the copter stays still but sometimes it reacts too strongly to the wind I guess. Hopefully, this will be resolved after Autotune as you said.

Regarding the noise, I checked the FFT plots and saw that compared to the previous one much changed in the x and y axis, but the amplitude of the noise in the z-direction seems to be lessened with the new parameters.

I feel like the copter is ready for autotune but not really sure, what do you think?

You can find the log for this flight in the below link.

Best regards

Yes, Stabilise can be very tricky to control altitude and hover. It might become easier when tuning is finished.

Set these to settle down Loiter a bit. This relaxes the position holding so Loiter wont be making so many demands that the current level of attitude control cant comply with.

PSC_POSXY_P,0.5
PSC_VELXY_D,0.25
PSC_VELXY_I,0.5
PSC_VELXY_P,1.0

It’s easy to put these back later, because they are just half of the defaults.

I’m a little unsure about MOT_THST_EXPO,0.4 since there was some instability during the only significant descent in that log, which would usually indicate MOT_THST_EXPO was too high - but I think we’d need to see more ascents and descents before we came to a conclusion. Leave this alone until we see more evidence in future logs.

There is still some unsteadiness, so hopefully Autotune doesnt give up. If you get the “failing to level” warning that doesnt automatically mean Autotune failed, it can often push on through and still work.

Temporarily set your Loiter switch position to Autotune mode, and AUTOTUNE_AXES,3

The easiest way is to takeoff and do a very short test in Althold to check the copter is OK, when ready switch to Autoune and wait…
You will see it twitching and pitching and rolling, you can reposition with the sticks as required.
Once it has stopped all movements, then just reposition and land without changing out of Autotune mode until the copter has disarmed. After a few seconds you can change to another flight mode, like Althold.

If you have some form of telemetry you’ll be able to observe Autotune progress.

Remember to set your flight mode switch back to Loiter instead of Autotune.