LibrePilot Forum

Development => Firmware General => Topic started by: jdl on March 29, 2018, 04:05:50 pm

Title: A (maybe) serious problem with INS13 in NEXT.589!
Post by: jdl on March 29, 2018, 04:05:50 pm
I think I've encountered a serious problem with INS13 in current next.589. I currently have 3 flyable UAVs with Revo boards (a wing and two copters) running this next and they all suffer the same in different extent. I have checked in the old telemetry records and I'm sure that the wing and the copter did not have such a problem with 16.09 firmware.

Today I was tuning and testing a new 250 quadcopter with Revo (Next 589 firmware) and encountered a constant slow yaw rotation when the UAV is motionless on the ground. All sensors are calibrated, MAG is green. Horizon in PFD is correct, almost no movement, but the compass ring is rotating all the time.

This is when INS13 is selected as Fusion Algorithm. Looking in the scopes, AttitudeState.Yaw and GyroState.Z are insane (attached image BAD & UNFLYABLE_ZMR250_UAV2_INS13). AccelState and MagState are almost rock solid meanwhile.

I did not initially noticed this strange behaviour and did take off in Attitude mode. Copter got highly "unsteerable" and I crashed after 10-15 seconds, thankfully managed to drive it to a soft spot and low altutude before I cut the thrust. No damages.

I investigated the telemetry record, spotted the problem and made additional testing: switched first to Basic(Complementary), then to INS13+CF. In both cases there was not even a sign of that problem. AttitudeState and GyroState scopes show fine and plausible values (attached image OK_ZMR250_UAV2_INS13+CF).

Tested autonomous modes: PositionHold, RTB, Autoland, also basic Attitude, all they performed fine in INS13+CF.

Further, checked telemetry records from the two other UAVs I'm currently flying with next.589 and found they also have problems with YAW estimation in INS13 - not constant rotation but oscillations. (attached images BAD & FLYABLE_Z84_INS13 and BAD & FLYABLE_ZMR250_UAV1_INS13)

These oscillations are not too big and as I fly primarily in Rate, I've not noticed till now there is a problem with the INS13 in current next.589 ... But I checked older records and there were not such yaw oscillations with these UAVs when they were with 16.09 firmware.

Here are attached configuration files for all three UAVs and a short .opl log from today. Copter is on the ground, INS13 initially, then after some time I changed Fusion Algorithm to INS13+CF and Attitide.YAW and GyroState.Z immediately settled down.

I hope this information should be sufficient to reproduce the problem.

Btw, would it be safe enough to switch my UAVs to INS13+CF? I tested Complementary + MAG + GPSOutdoor and the short test flight was ok. But maybe INS13+CF is better choice?! At least until INS13 is fixed.

As I recall, Complementary + MAG + GPSOutdoor may not be a good option for a plane. But what about INS13+CF?

I've almost finished a long-range-intended Mini Talon build, with Revo as FC and OpLink for control but now I  hesitate to maiden it with next.589 and that yaw issue with INS13 I've encountered as it affects not only autonomous modes but basic level (Attitude) flight also.
Title: Re: A (maybe) serious problem with INS13 in NEXT.589!
Post by: f5soh on March 29, 2018, 07:30:59 pm
EKFSettings changed a lot between 16.09 and r589, here is current 'next' defaults to the left and your settings to the right:

(https://forum.librepilot.org/index.php?action=dlattach;topic=4206.0;attach=7342)

Try importing the UAV file attached for new default EKFSettings.

Same for AttitudeSettings -> MagKp and MagKi, your settings refers to old settings and you will expect unsafe results using Complementary+Mag+GPS even if seems ok currently.

Here is the new values:
(https://forum.librepilot.org/index.php?action=dlattach;topic=4206.0;attach=7345)
Title: Re: A (maybe) serious problem with INS13 in NEXT.589!
Post by: TheOtherCliff on March 29, 2018, 09:20:56 pm
Trying to parse to a simplified version of what this says.

From what I read, INS13 does not work well in next.589, but INS13+CF does work well.  I recall seeing that the mag has a new setting for 3D vs. 2D and the default is 2D.  Maybe all you need to run INS13 bare is to set this back to 3D so it acts like it did before.  Setting is in EKFConfiguration.

shared/uavobjectdefinition/ekfconfiguration.xml:
   <field name="MapMagnetometerToHorizontalPlane" type="enum" units="bool" elements="1"
      options="False,True" defaultvalue="True"
      description="Set to True to suppress effect of magnetometers on Roll+Pitch State estimate" />

One last thing is that mag must be well calibrated and correctly aligned on model or you get EKF oscillation and divergence.

Let us know if this setting helps your issue so I can add it to my list.  :)

If this is the cause, then it sounds like INS13 bare needs to automatically set this to 3D.
Title: Re: A (maybe) serious problem with INS13 in NEXT.589!
Post by: jdl on March 29, 2018, 10:30:07 pm
Thanks for replies.

@f5soh: I was unaware that EKF & Attitude defaults have been changed though I should have checked these defaults when updating to next.589. Sorry. Thanks for pointing me that!
I applied new (correct for next.589) defaults to all three UAVs. Cannot test wing right now but unfortunately, nothing changed for the two quads, they exhibit the same bad behaviour - light yaw oscillations for UAV1 quad (flyable) and constant yaw rotation for UAV2, being stationary on the ground. This is when INS13 is used.
If I switch them to INS13+CF, all seems perfect... Here are screenshots I made just now for UAV2 with new defaults.

As I said before, there were no such yaw oscillations for UAV1 when is was loaded with 16.09, same hardware and settings!? UAV2 was never flown with 16.09, I've finelly built it days few ago...
UAV2 flyes beautifully with INS13+CF, do you consider this algorithm safe enough or there are known dangerous issues with it?

@TheOtherCliff: I'm confident all calibrations are done thoroughly and mags are correctly aligned. Funny looking angles int "virtual rotate" you may have seen in the uav files reflect the real orientation of MAG boards. Especially for UAV2, when checking in Configutarion / Attitude / Magnitometer - all indicator bars were almost all the time at "0" position, rarely -1, and both mags are green while 3D rotating the frame in hand.

I've tested with "MapMagnetometerToHorizontalPlane = False". Nothing changed for good for UAV2, in fact I suppose that exact change made the copter unsteerable to extent that made me crash. Test flight with default "MapMagnetometerToHorizontalPlane = True" in Attitide mode at least let me land safely. So "MapMagnetometerToHorizontalPlane = True" is good, I'll continue to use it.

My previous tests with UAV1 and next.589 showed that it flies relatively well no matter of that mapping of mag to 2D, but I left it set to default "true". Yes, the yaw oscillations are there with UAV1, though they are light and practically not noticeable in Attitude mode.
 
The wing flies pretty ok with INS13 and "MapMagnetometerToHorizontalPlane = True". Yaw oscillations with it also does not seem to affect noticeably the flight.
Title: Re: A (maybe) serious problem with INS13 in NEXT.589!
Post by: TheOtherCliff on March 29, 2018, 10:50:13 pm
Just a point of reference:  It looks like I had INS13 next.r550 (December) on a quad for testing the fix for Altitude Hold.  It worked fine.

My EKF was 10,10,10,etc not the default of 25,25,25,etc.  I didn't do that on purpose, I hand converted the 16.09 UAV file to next.r550 and didn't look at the EKF values.
Title: Re: A (maybe) serious problem with INS13 in NEXT.589!
Post by: TheOtherCliff on March 29, 2018, 11:00:52 pm
I don't know if it is the technically correct thing to do, but I do fly autonomous fixed wing (4 channel), and for that I always set my yaw/rudder to manual.
Title: Re: A (maybe) serious problem with INS13 in NEXT.589!
Post by: jdl on March 29, 2018, 11:35:59 pm
I've also rebuilt Next.589 Revo firmware with the AltitudeHold Fix you published, also fixes for  ADC on output channels , tested it with UAV1 (my older ZMR250 quad), worked fine. I've flown with UAV1 and Next.589 at least several hous flight time total till now without noticing these yaw oscillations issues, though telemetry records clearly show them present before take-offs. I fly rate and only use sometimes PositionHold before landing in LOS if the terrain is difficult. Also I've engaged RTB several times when FS checking.

But with newly built ZMR250 frame (UAV2) with Next.589 and INS13 yaw is not just unstable, it rotates... It is completely unflyable in Attitide mode, PositionHold is unusable too.
Testing Basic(Complementary), Complementary+Mag+GPSOutdoor, INS13+CF - all they give very stable attitide and predictable handling. This makes me confident that the hardware of that particular revo board, AuxMag and GPS are ok.
If INS13+CF is considered safe to use, without known hidden issues, I'd like to switch all my UAVs to it.

My wing has no yaw controls, it is two elevons type (3 channel), so yaw oscillations in attitude estimation should not affect it, I guess...
Title: Re: A (maybe) serious problem with INS13 in NEXT.589!
Post by: TheOtherCliff on March 30, 2018, 01:29:19 am
I see that you are using an I2C aux mag which is normally configured with 180,0,180 or the equivalent 0,180,0

I see that you have:  <field name="BoardRotation" values="180,0,93"/>

Typically, this would be reasonable if your GPS/mag was rotated 90 degrees so that the cable came out the side and not the front/back.  I am guessing that you added 3 degrees for better alignment.  My things to check include whether you do have the GPS mounted so that the GPS cable comes out the side (not front/back) of the GPS, and whether the 93 matches the side (left/right) it actually comes out.  E.g. does it need to be -87 or 273 or ? because it comes out the other side.
Title: Re: A (maybe) serious problem with INS13 in NEXT.589!
Post by: f5soh on March 30, 2018, 06:47:49 am
Can you try to recalibrate the mags ?
Currently the AuxMag scales are something like 0.8,0.82 and 1.00 so pretty asymmetric.

(https://forum.librepilot.org/index.php?action=dlattach;topic=4206.0;attach=7354)

- Start calibration,
- Press the "Save position" button five times and move/rotate the quad around all axis to cover all the 3D space,
- Press the "Save position" button for the last step and save settings.
Title: Re: A (maybe) serious problem with INS13 in NEXT.589!
Post by: TheOtherCliff on March 30, 2018, 07:39:06 am
One last thing is that mag must be well calibrated and correctly aligned on model or you get EKF oscillation and divergence.

@TheOtherCliff: I'm confident all calibrations are done thoroughly and mags are correctly aligned.
Title: Re: A (maybe) serious problem with INS13 in NEXT.589!
Post by: jdl on March 31, 2018, 05:59:21 pm
I'm currently away from home for a few days... Will go on with tests when I'm back.

....
I see that you have:  <field name="BoardRotation" values="180,0,93"/>
....
it need to be -87 or 273 or ? because it comes out the other side.

UAV2 is built with BN-220 GPS only and HMC5883L AuxMag on standalone PCB (CJMCU-49). It is mounted between the lower carbon plates of the frame. All power lines are carefully twisted. Last flight tests show this AuxMag position is good and quite well protected from the parasitic magnetic fields.

I think the alignment is correct, I've checked it more than once. Moreover, the three bars showing differences between internal and AuxMag in GCS/Configuration/Attitude/Mags stay almost all the time at 0 - 0 - 0 for the three axles after mags are calibrated.

Here are photos of UAV1 & UAV2. UAV1 uses AuxMag from the BN-880 GPS.

It has many flawless flights with 16.09 (INS13) and after upgrading to Next.589 with the same calibrations also flies well, but there are now these slight yaw oscillations in PFD and scopes while still on the ground.

@f5soh: I've done the mags calibration using just the exact procedure you pointed. This is in the open field, away from power lines, underground communications, even away from the road. Away from any metallic objects as car, chair, laptop, phone or watch :) I've done it more than once for UAV2 and I'm confident it is done well. Asymmetric AuxMag scales are due its placement in the tiny space of the ZMR250 frame with all its surroundings, I suppose.
Same asymmetry, even worse, presents in UAV1 but it flew reliably without issues with 16.09. UAV1 flies well now with Next.589 too, but now these slight yaw oscillations are present, while they didn't existed with 16.09.

I'll make another test when back to home. I'll flash UAV2 with 16.09 with the same settings and calibrations (with 16.09 EKF defaults) and will test if the yaw rotation is present there.
Title: Re: A (maybe) serious problem with INS13 in NEXT.589!
Post by: TheOtherCliff on March 31, 2018, 10:34:41 pm
...the three bars showing differences between internal and AuxMag in GCS/Configuration/Attitude/Mags stay almost all the time at 0 - 0 - 0 for the three axles after mags are calibrated.

If it stays close to 0,0,0 no matter what bank angle the quad has then the aux mag board rotation is correct.

Did you try replacing the whole Settings.EKFConfiguration with the old version?
Title: Re: A (maybe) serious problem with INS13 in NEXT.589!
Post by: jdl on March 31, 2018, 11:32:10 pm
Yes, it was old 16.09 settings initially, I just imported old 16.09 UAV1 config file after update & erase for UAV2 Revo FC with next.589 and then checked and made manual corrections where necessary. Calibrations are done for the new Revo and Mag in UAV2, of course.

Later I followed the f5soh advice and imported new EKF defaults for 589.

Yaw rotation persists with both configurations.

I'd like to see how this build will behave when I revert it back to 16.09. I'll report back results asap.

Btw, UAV1 (older ZMR250) flies well in autonomous modes and Attitude with next.589 and EKF defaults from 16.09. Only concern I had was the drop when engaging AltitudeHold /RTB /PositionHold, but after applying your fix it works as in 16.09.
Also I noticed these light slow yaw oscillations with UAV1 stationary after updating to next.589. I do not see such ones in telemetry records from UAV1 while it was running 16.09.
Title: Re: A (maybe) serious problem with INS13 in NEXT.589!
Post by: TheOtherCliff on April 01, 2018, 12:35:21 am
Just some thoughts.

I have seen PFD oscillations like that in two cases.  Mag needing recalibration, and trying to use NMEA GPS protocol instead of Ublox protocol.  It wouldn't hurt to try recalibrating mags as all three of us discussed before.  There was a problem with mag calibration that it did not zero the bias and one the gains correctly.  That has been fixed, but if it were me, I would set all the mag calibrations to default and try mag cal again.

Are you getting any alarms in your telemetry?

Magstate showing steady but compass rotating sounds like an EKF divergence.  That can happen if the vehicle sits motionless for a while.  If all calibrations are good, it may never diverge.  With lesser calibrations it may diverge after just a couple minutes.

Mag calibration difference with onboard mag is close to 0,0,0 for all bank angles / orientations?  Say nothing bigger than a 2 or 3?

Maybe something like accel calibration was bad, or gyro calibration needs to be done again.

Have you done thermal calibration?  Gyro calibration needs to be done again after thermal calibration.
Title: Re: A (maybe) serious problem with INS13 in NEXT.589!
Post by: f5soh on April 02, 2018, 02:22:05 am
Found the issue.
https://bitbucket.org/librepilot/librepilot/pull-requests/504

Can you test the revolution firmware attached? (based on latest Next)
Title: Re: A (maybe) serious problem with INS13 in NEXT.589!
Post by: jdl on April 02, 2018, 03:09:54 pm
Tested it. I confirm the yaw rotating issue I had with my ZMR250 (UAV2) with INS13 is gone now.

Also applied the changes from https://bitbucket.org/librepilot/librepilot/pull-requests/504 (https://bitbucket.org/librepilot/librepilot/pull-requests/504) to UAV1 firmware (next.589 + ADC-on-Servo-Outputs fix + AltitudeHold fix + this INS13 fix) and the slow light yaw oscillations are not there anymore.

Thanks, Sir! :)

Btw, after confirming the new firmware solved the problem, I did accelerometers calibration for UAV1 again and noticed the new values differ in some extent from the ones from previous calibration, that I'd done very carefully an year ago. This makes me think that accererometers / gyros has some ageing and it's a good idea to re-calibrate them periodically. Am I right?

@TheOtherCliff: Your comments on EKF diverging with bad calibrated sensors helped me get a better idea of the issue, thanks! :)
After successfully testing the fix from the f5soh, I flashed back the original next.589 and the yaw rotation was there again. Then I recalibrated accelerometers only and the rotation stopped, but yaw was oscillating slowly, similar to what I was getting on UAV1 and the wing. So you was right, accelerometers calibration data was somehow inaccurate! This confuses me as I'm sure I did it very thoroughly only weeks ago, but before the thermal calibration. Should the accelerometers be recalibrated after the thermal calibration, like gyros? Or it's a matter of floating-over-time characteristics of the MEMS chip?
Title: Re: A (maybe) serious problem with INS13 in NEXT.589!
Post by: TheOtherCliff on April 02, 2018, 04:30:44 pm
The assumption I heard/used in the past is that gyros and accels don't need recalibrating, but for some reason, the mags do.  I assumed with the mags it was moving the battery around or a different type of battery, but that would probably show up most during high current flight, not during calibration.  I think too the advice came because the onboard mag environment was a difficult area to get the model built and wired correctly.

Since I have been using aux mag on GPS, I don't bother even recalibrating that and it works well (16.09).

The one thing I can say about recalibrating is that after doing a thermal calibration, you will see that the gyro noise is not centered.  Just recalibrate the gyros and save and they become centered.  My thermal calibration is over a very large range, -5C to +70C because I want to fly in cold winter and in summer I have seen +70C in telemetry when domed FC is sitting on hot ground for 15 minutes acquiring GPS almanac.
Title: Re: A (maybe) serious problem with INS13 in NEXT.589!
Post by: jdl on April 03, 2018, 10:01:56 am
I've used to follow the same assumptions. I also usually do thermal calibrations over a range of -10C to +90C as sometimes I fly in very cold or very hot (38-40C+ and the sun additionally heating the board) weather. May be a little overkill, though.

I've also made auxmag calibrations for every type of battery I use on the copter and save them (AuxMagSettings & RevoSettings) together with StabilizationSettingsBank1,2,3, SystemIdentSettings, FlightBattery Settings (for cells count and capacity), Mixer Settings (for ThrottleCurve), AltitudeHold (for ThrustLimits.Neutral) as UAV preset files for every combination of battery and props I use to fly with. I upload them to the FC before flight is necessary.

In fact I've found that mag needs recalibration if the flight zone is too far away from the calibration point (many hundreds of kilometers). I've not tested yet if the new setting of EKFConfiguration | MapMagnetometerToHorizontalPlane = "True" will help to reduce the negative effect of not doing mag recalibration in this case.

As for my observation of shifting accel calibration values, I've found that it is an issue with the calibration procedure in the firmware, it messes subsequent calibrations with previous ones and produces more and more shifted values. Easy to avoid by setting accel_bias.x,y,z=0, accel_scale.x,y,z=1 and gyro_bias.x,y,z=0 before starting the calibration.

P.S. I've just tested in real flight both quads - UAV1 & UAV2, INS13 (with the new EKF defaults and new firmware changes from f5soh) and the same mag calibrations as before - they both fly perfectly well, either in Attitide, or in autonomous modes.
Title: Re: A (maybe) serious problem with INS13 in NEXT.589!
Post by: TheOtherCliff on April 03, 2018, 04:22:10 pm
I fly an INS13 quad with an aux mag.  I fly at two sites about 37 miles apart and don't recal mags at all.  I have flown that one for a couple years now and only recal'ed when I put 1609 on it.

I do have a slightly different mag cal procedure.  Here at my latitude, north mag vector is 60 degrees down.  I click next to skip 5 times, and then on the 6th one I point (not too quickly) and wiggle each of the 6 directions (left, right, top, bottom, front, back) to point at the mag vector which is north, but 60 degrees down.  This way, the bank angle (upside down, etc.) is not important.  My thought is that this way, I guarantee that each pole of each sensor direction has a chance to clearly see the max field strength.

Find your magnetic inclination (not declination) here:
https://en.wikipedia.org/wiki/File:World_Magnetic_Inclination_2015.pdf