trust

  • ****
  • 299
Position hold not working
« on: October 31, 2019, 12:14:34 am »
I have a 450 size quad with a mini Revo FC and a GPS without mag. I have the attitude estimation set for GPS Navigation ins13.
I can fly the quad fine in attitude mode with axislock on the yaw and it hovers and holds yaw fine.
It does take a few minutes before arming, I assume acquiring enough satellites - I've checked and the GPS seems fine.
But when I switch to position hold, it heads off in one direction or another - not holding position at all. It doen't seem to be consistent which way it heads.
Is this set right? Have I missed something? Thanks

Re: Position hold not working
« Reply #1 on: October 31, 2019, 06:02:03 am »
Are you using 16.09 or next?

Attitude mode with plain "GPS Navigation (INS13)", works great, right?  New AttiEstAlgos in next act differently to original INS13.

PositionHold, not VelocityRoam, with "GPS Navigation (INS13)" is what fails, right?  If VR it is your transmitter trims.

In PH, does it fly away scary fast (faster than you can run) or drift slowly away (say a walking speed).  A small amount of GPS drift is normal under some conditions.  If fairly slow, have you let it go for a while to see if it stops drifting?  Scary fast is usually caused by a different issue than "slow drift that doesn't ever go very far".

Is it actually an east-west oscillation that reverses about every 4 seconds; that gets worse and worse, not a constant drift?  That is a known issue, but usually for DJI/Naza GPS, although I recreated it with normal Ublox GPS by tweaking settings.

Do you have telemetry?  Does the mag health stay green when flying?  Red mag can cause fly away in GPS modes.  Even always yellow mag health when flying is worrisome.

Did you tweak something not specifically in the instructions?  There are things you can mess up while thinking you are making it better.

Does Attitude mode wander when climbing?  That would imply that different power levels might have different mag issues.

How many GPS satellites does it usually get?  7 is min to start with and if you are flying with a small number of sats and you are adding or subtracting sats during flight, then that is probably your issue.  Does GPS health stay green during a flight that is drifting?

What type (web link to buy it) of GPS is it?  Some are suspected to have poor reception.

Did you twist all your motor power wiring from battery all the way out to motor?  You must do this for good GPS flight mode usage.

What kind of power distribution board do you have (link to buy one) as bad ones can cause mag issues?

Are your props well balanced?

Are you flying in an area with a lot of magnetic interference?  Like with a lot of cars (junk yard or parking lot) or high power power lines?  I have personally flown right around medium power lines that feed a subdivision and not had problems, but larger than that may have issues.

Did you move your transmitter trims since you ran the transmitter wizard?  Put them back where they were (to verify, use Input page, flight battery plugged in and transmitter on, make sure roll and pitch are at Neutral value).
and then use Attitude->RotateVirtual to adjust Attitude mode drift.
-> if it is drifting forward you subtract from pitch
-> if it is drifting left you subtract from roll
but the drift direction from these issues would always be the same direction.

The only things I can think of that match exactly what you describe are:
- bad mag calibration
- flying indoors or close to buildings so that you have a poor GPS signal, a bounced GPS signal, or no clear view of most of the sky; maybe made worse by using a poor quality GPS.
- really bad mag issues that happens to affect the compass heading a lot, but does not affect the level much
- lots and lots of metal in the area

Post your settings, so we can look for issues.

I have built an Alien 500 quad without aux mag, for a friend, and it flies fine, but I was careful about twisting all motor power cables.
« Last Edit: October 31, 2019, 09:31:02 am by TheOtherCliff »

trust

  • ****
  • 299
Re: Position hold not working
« Reply #2 on: October 31, 2019, 06:50:43 pm »
Enclosed are settings.
Yes on 16.09
It flies away almost scary fast - faster than a drift. I get it back by returning to normal flight mode.
Its a Ublk GPS this one:
https://www.ebay.com/itm/For-Arduino-NEO-6M-GPS-Module-with-MWC-IMU-APM2-GPS-Flight-Control-EE/
No telemetry
I have a 5.8Mhz video xmtr, but not on for this test.
I did not notice anything unusual about the attitude mode. I flew in abt a 10mph wind, so had to tilt into it some, but it seemed to hold fine in manual control mode. No yaw drift.
Not sure on the satellites - I'm not bringing a computer out with me to check this in the field. But at my office, maybe 12 satellites?
But that could be an issue - I flew as soon as it would let me, which takes a few minutes.
No metal close by or power lines.
Power distribution is a fairly short bundled cable out to the ESCs, on each arm of the quad. I haven't had any power or glitch problems or balance problems with the motors/props.
Not on xmtr trims - they never get moved.

One item - the GPS antenna is sitting about 3/8" above the battery, though equally spaced between quad arms half way out to get some space separation. Perhaps I should check GPS reception when running, but have to hold the thing down.

Re: Position hold not working
« Reply #3 on: November 01, 2019, 08:03:19 pm »
All the facts point to there being a problem with the mag (compass) sensor.  The mag health must be green for Atti/Stab to go green and then you can arm it.  That leaves the most likely thing being that the mag health goes red once the motors are running.  That is a very common problem.  You see, there is no electromagnetic field (OK, very very small field) when the motors are stopped, but once the high current starts to flow, that is when you get an electromagnet effect and the mag sensor goes crazy.

I don't see anything wrong in your settings file.  You could try a new mag calibration.  That might help, but I would not bet on it.

At this point, a good guess is that you have your FC mounted right on top of your PDB and as soon as the motors run, a bad PDB design causes huge magnetic field right through the FC.  With that I would expect some Attitude mode trim issues when using INS13 though.

You don't have telemetry.  If you have a 3 meter usb cable and a laptop, you can make a 30 second Attitude Mode test flight with cable attached.  Make a log of the flight.  Watch for red mag while flying or while playing back the flight log.  Are you confident enough that you can do this with a 3m cable attached?  Another option (also using USB and laptop, and getting a flight log) would be to tie it down, like to the planks in a wooden porch; arm it and give it flight power.  Again, look for red mag.

Consider getting an OpLink for about USD $18 on eBay.  The telemetry comes in handy for things like this.  I am guessing that 433MHz may be a problem in your country though...  Also, I guess you would need an "OpLink Air" if you are using a Revo mini.  Probably the best way for Europe is to replace the RFM22B boards on Revo / OpLinkAir and on Oplink with a version that works with a frequency you can use locally.  You would then want to upgrade from 16.09 to next which has support for these frequencies.
https://www.ebay.com/itm/Openpilot-OPLink-Mini-Ground-Station-433MHz-Rdaio-LibrePilot-Compatible-FPV/172353558651

It's also possible to simply buy serial telemetry links on your frequency and connect them to Flexiport/Mainport in the air and USB on the ground.

One other thing you can do is verify that mag sensor is working correctly.  Look at some parts of instructions in Aux Mag GPS wiki and everywhere use MagSensor instead of AuxMagSensor.
https://librepilot.atlassian.net/wiki/spaces/LPDOC/pages/18382863/Aux+Mag+Setup+and+Calibration

In the section titled "Viewing AuxMagSensor to check if your mag is working", start at line "Default for these numbers is 'report to GCS every 10 seconds'  ".  You really could permanently leave it set to 1000ms if you want, no problem.

Then in the section titled "Set and verify AuxMagSettings.BoardRotation" start at the line "Look up (Google) 'magnetic inclination' for your location." to verify that your mag sensor data seems sane.  End at "Same for Bottom side pointing north"

Watching the MagSensor x,y,z you should be able to zero in on exactly where the magnetic field north direction is.  Is it where you expect and do the numbers act like they should?  For example, when pointing the nose north and 60 degrees (magnetic inclination/dip) down, "x" should be a large positive number and with small motions, you should be able to get "y" and "z" to be close to zero.

If sensor numbers check out, and mag health goes red with motor power, then you must fix the red mag health that happens with motors running.  All thick wire cables including battery, cables to PDB, cables to ESC, cables to motor must be twisted into ropes and routed as far away from the mag sensor (Revo FC in this case) as possible.

We need a picture of your power distribution board (some kinds are horrible for mag sensors) and another of the whole quad with battery installed and plugged in for flight.  These will help determine if you have an electromagnetic wiring problem.

One more question and that is whether you have any magnets (besides in the motors) on the quad?  The standard "1-8S LiPo alarm" actually has magnets in it and must be mounted far away (say at least 25cm) from any mag sensor.
« Last Edit: November 01, 2019, 08:47:55 pm by TheOtherCliff »

trust

  • ****
  • 299
Re: Position hold not working
« Reply #4 on: November 02, 2019, 06:40:58 pm »
Yes, looks like the problem is in the magnetometer. I hooked up my laptop outside on a long cable - at first I had trouble getting the attitude to turn on, but after several plug in/out and moving the quad around, it went green.
GPS went green after several minutes, and after the few plugin/out sessions, it would go green quickly.
But the magnetometer never went off red. I looked at the mag settings page, which seems to show a box with some percentage value and coloring on the box. The percent value ranged from 20-40% - and would occasionally go green if I tilted and moved the quad around by hand. But it would not stay green.
Once ATTI and STAB were green, I could fly the quad - but MAG never went green, so I presume these features won't work until it is.
I ordered one of the combo GPS/mag units you mentioned worked for you, so will try that when it arrives.
I could try recalibrating the MAG again. Can you give any insight into what the percent values might mean?
FYI - pix enclosed of system

Re: Position hold not working
« Reply #5 on: November 03, 2019, 03:58:26 am »
Mag calibration should really be done outdoors where you fly it, away from metal (LP gas tanks, cars, metal buildings, ... and done via telemetry...

I have successfully calibrated with a long USB cable, but I made sure that the USB cable connector was not magnetized, by temporarily using a second cable and moving the first cable connector around the FC while watching MagSensor x,y,z.  Also, during calibration, I powered the quad with a flight battery even though it was not necessary.  I also made sure that my ESC BEC was putting out more voltage than the USB cable so that it would draw power from the battery, not the USB cable.  All this to make sure that it was drawing power via the same path it would use during flight, not via the USB.

If you find that your USB connector is magnetized, you might be able to demagnetize it.  I have a big soldering gun that puts out a big magnetic field (you can feel the humming field if you hold a nail close to it) and I demagnetize things by holding the thing close to it, and then farther and farther away.

Remember during mag calibration:
- once you start, it is always gathering data, not just when you press the button 6 times
- once you start, you can't set it down on the ground or anything metal
- be careful of wood that has nails in it?  I basically don't set it down on anything.

The way I calibrate mags is that I estimate my north magnetic field lines (for me it's north and 60 degrees down) and then for each of the 6 button presses that should be a strange position, I just point a different one of front, rear, right, left, bottom, top in the north field line direction and wiggle it around a little, say 10 degrees in other directions, in case I am not pointing it accurately enough.  No other fact is important then.  When pointing the nose at it, it doesn't matter if it is upside down or whatever.  You can also (while holding the quad away from things) just click the button 5 times, then do all 6 positions on the 6th time, and finally press the button the 6th time...  That, and pointing along the magnetic north field line is the easiest for me to remember and do, without even reading all those positions.

I would try another mag calibration and see if you can get it behaving better when watching mag via GCS.  If you hold it off the ground, mag should usually be green with only occasional yellow (orange) and no red.  At least that is what I strive for.  To be honest though, half green and half yellow/orange may be more typical.

I'd worry about whether the power distribution board was designed with mag sensors in mind given that it looks like you have the FC mounted very close to it.  I'd also twist all those power cables.

By default mag health is: 0-5% is green, 5-15% is yellow(orange), 15%+ is red.
« Last Edit: November 03, 2019, 10:35:12 pm by TheOtherCliff »

trust

  • ****
  • 299
Re: Position hold not working
« Reply #6 on: November 05, 2019, 01:55:31 am »
OK! Success! I recalibrated the magnetometer outside as far from metal as was reasonable, and this time holding it up and moving it around the magnetometer stayed in the green, and was always 0-3%, mostly under 1%. Watching the simulated quad on the laptop it followed the movements of the real craft.

I test flew in normal mode - interestingly, it seemed MUCH more stable and would even try to stay in place - with a 10mph headwind - even when NOT in position hold mode. I'm using attitude mode on pitch and roll, and axislock on yaw. Nice!

I switched to what I thought was position hold mode (but was actually return to base) - it drifted back over my head, yawing as it went, and climbing. I assumed something was wrong, but when I came back and checked the switch positions I realized they were backwards - so I think it WAS actually heading back to a position over takeoff - at some altitude - what is it set for - 30meters? That would make sense - it had to climb to get there.
Is it normal to yaw a lot when doing RTB?

For some reason, I am having a hard time getting it to initialize. ATTI and STAB stay red a long time -usually stay red for many minutes. I have to unplug and replug several times before it finally goes green.
Any idea why this should be? GPS goes green before the ATTI and STAB go green. It is on level ground - or seems to be. Does the quad have to be level when plugged in and not move, or can it plug in and move slightly for a second while I set it back down?

I tested with the 5.8Mhz xmt & gopro on also - functions worked the same, so don't think there is any interference issues. The rcvr always comes on right away with no problem. I can check that as there is a camera tilt function.

Re: Position hold not working
« Reply #7 on: November 05, 2019, 06:45:20 am »
Attitude mode should not stay in place in a 10mph wind.  It should drift with the wind.  So sounds like you were in PH.

By default, RTB does not change the yaw when engaged.  The compass heading should remain what it was.  You can actually move the yaw with the stick if I remember correctly.  I suggest that you make sure your sticks are really sitting at Neutral on the Input page.

Mag and GPS must both be green for Atti/Stab to go green.  You say that Mag is green, so I ask if GPS is not green yet.

RTB climbs to configured height (default 10 meters), returns to base (default is arming place), and holds position (default) or lands (option), so it sounds like it was doing what RTB should do, except for the yaw and the default height is 10 meters.
« Last Edit: November 05, 2019, 04:53:32 pm by TheOtherCliff »

trust

  • ****
  • 299
Re: Position hold not working
« Reply #8 on: November 05, 2019, 07:31:15 pm »
Fail. So I switched the two positions on the function switch, and took it out to test again, and this time took a laptop so I could see what was going on. It wouldn't initialize, and the magnetometer stayed in the red again. So I did another calibration, which got it back to green.
Now when I lifted off in attitude mode, it had a tilt forward. I landed and double checked and everything looked fine, so I tried it again. Again it had a forward tilt - I compensated and flew it up to about 30' then switched to position hold. It stayed at the same altitude but slowly yawed and moved fairly quickly to the southeast - right into the sun. Fortunately I switched back to normal mode and flew it back but by this time it had gone pretty far away. I didn't even try RTB.
I'm certain all the controls on the xmtr are set to mid point - no trim adjustments.
To me this looks like the onboard magnetometer is just not reliable. I guess I'll just wait for the combo GPS/mag to arrive and try that instead, unless you can suggest something I've missed to try.

Re: Position hold not working
« Reply #9 on: November 05, 2019, 09:18:37 pm »
Quote
To me this looks like the onboard magnetometer is just not reliable.
If the FC (mag sensor) is mounted right over a strong source of mag interference (e.g. a PDB design not designed with mag sensors in mind), it will not work well enough to fly.  The strongest signal from the PDB comes out perpendicular to the board, so it is shooting it's strongest signal straight at the FC mounted above it.  Moving the PDB and FC away from each other helps a little.

Untwisted motor power wire sets cause the same issue.  The mag field of a pair of wires is proportional to both the area between the wires (imagine the number of square millimeters of a single film of soap bubble between the wires), and the current passing through them.  Twisting the wires does two things, it keep the wires as close together as possible (reduces the area of the "soap bubble" between the wires), and each time the wires cross it changes the direction of the field, which helps it cancel out.  Even the battery cable needs to be twisted.  Just putting your battery or battery cable in differently from one flight to another can cause flight differences if the wiring harness and battery placement weren't considered when putting it together.  All of this is why it is just easier to use an external mag sensor (built into a GPS) mounted up on a pole (hint hint).  All of my GPS quads have the GPS/mag mounted on a pole.

INS13 uses the whole 3D set of data from the mag sensor, so it actually gets leveling data as well as compass heading.  In Attitude mode a bad mag signal will make it tilt and fly in some direction.

In addition to the simple tilt of Attitude mode, in GPS modes, it will think it is flying in the correct direction, but the heading is wrong, so it is flying in the wrong direction so it gets farther and farther away from where it should be and tries harder and harder to fly faster and faster in what it thinks is the correct direction, so within a few seconds, it is flying at maximum bank angle, really fast.

trust

  • ****
  • 299
Re: Position hold not working
« Reply #10 on: November 06, 2019, 08:52:02 pm »
Unlike some quads, there is no power distribution board on this. The ESCs wires go underneath and are bundled together into the XT60 connector. I reran the power wires, twisted them, and tried a tethered test. I taped the quad to a brick and hooked up the laptop to monitor the magnetometer health readings. Without power it was in the <1%-2% range. As I increased power it stayed in the green till I got to well over half power (it hovers at less than half power), then it would occasionally go yellow - but the values stayed in the <10% range, usually much lower. It never went red even at full power.
Should this be good enough or does it need to stay green?

trust

  • ****
  • 299
Re: Position hold not working
« Reply #11 on: November 06, 2019, 10:31:55 pm »
I tested it in the field. Normal hover was the same. Switching to position hold it tilted sharply and moved away - direction random - I tried it twice. For yucks I tried RTB also - it tilted and yawed and moved away.
Both fail.

Re: Position hold not working
« Reply #12 on: November 07, 2019, 07:45:29 am »
You've got your Arming set to "Always Armed".  This says to set TakeoffLocation as soon as the CPU starts running which is going to be before the GPS has a fix, so RTB will go to 0,0 or bad,bad or previous,previous depending on GPS type.  Set Arming to something reasonable like "Yaw Right" for instance, and obey it.  If it won't arm, there is a reason, like GPS or mag.  Watch your health to understand why.  I also notice that your TakeOffLocation is "Valid" which implies you were armed when you made that uav file.  Make sure it goes back to InValid if you save a uav when it is disarmed just after power on (before arming it the first time on that battery).  I don't recall if there is code to manage that automatically if it is actually stored as Valid in settings.

LEDs on GPS can tell you some, but they do not have all the information.  They do not know about PDOP for instance.

The LEDs (orange and blue if I recall correctly) on the FC go from long orange, long blue when it is not ready to arm to long orange short blue when it is ready to arm and then to short and short after you have armed it.

You can also add WS2811 / WS2812 LEDs (search wiki) for something brighter and to mount where it is easy to see.

A WS2811/WS2812 LED will tell you why it won't arm, like "mag warning".
https://librepilot.atlassian.net/wiki/spaces/LPDOC/pages/12812390/Setup+WS281x+Led

Quote
One other thing you can do is verify that mag sensor is working correctly.  Look at some parts of instructions in Aux Mag GPS wiki and everywhere use MagSensor instead of AuxMagSensor.
https://librepilot.atlassian.net/wiki/spaces/LPDOC/pages/18382863/Aux+Mag+Setup+and+Calibration

In the section titled "Viewing AuxMagSensor to check if your mag is working", start at line "Default for these numbers is 'report to GCS every 10 seconds'  ".  You really could permanently leave it set to 1000ms if you want, no problem.

Then in the section titled "Set and verify AuxMagSettings.BoardRotation" start at the line "Look up (Google) 'magnetic inclination' for your location." to verify that your mag sensor data seems sane.  End at "Same for Bottom side pointing north"

Watching the MagSensor x,y,z you should be able to zero in on exactly where the magnetic field north direction is.  Is it where you expect and do the numbers act like they should?  For example, when pointing the nose north and 60 degrees (magnetic inclination/dip) down, "x" should be a large positive number and with small motions, you should be able to get "y" and "z" to be close to zero.

Just to be complete, you are always using INS13 AttiEstAlgo, correct?  Even when flying Attitude mode?

I recall that you did have some success or at least differences where for instance it was drifting even in Attitude mode.  What is different now?

Unlike some quads, there is no power distribution board on this. The ESCs wires go underneath and are bundled together into the XT60 connector.
Try this: Make sure that your XT-60 hangs vertically like this:
0
0
rather than horizontally like this:
0 0
and as far away from the FC as possible.  That has more of the field going sideways rather than straight at the FC.  Maybe try mounting your battery below the quad a few inches.  These are all trying to move the magnetic field away from the FC.

Without power it was in the <1%-2% range. As I increased power it stayed in the green till I got to well over half power (it hovers at less than half power), then it would occasionally go yellow - but the values stayed in the <10% range, usually much lower. It never went red even at full power.

Should this be good enough or does it need to stay green?
That sounds reasonable.  I would expect that to work.

I tested it in the field. Normal hover was the same. Switching to position hold it tilted sharply and moved away - direction random - I tried it twice. For yucks I tried RTB also - it tilted and yawed and moved away.
Both fail.
Random direction may give a clue.  Is it always the same direction till you change the battery?  Is it always the same compass heading that it moves off?  If it is truly random, that again points to mag alignment issues.

Watch the GCS GPS map, zoomed in to say level 22 (almost max) when the quad is sitting still on the ground, armed and ready to fly.  How much does the GPS position on the map move over the course of a couple minutes?  It may drift, but should be slow, less than walking speed.  That speed is the speed of drift you should see when flying.  Is the map location correct for where you are?  Is the compass heading on the FlightData page correct?  Does the map show you moving north when you carry the quad and laptop in a northern direction?  Maybe take a screen capture of System->DataObjects->GPSPositionSensor as you walk the whole setup north at a fast walk, and post it here.

Your new GPS/mag put up on a pole to get it away from mag sources should help if it is a mag issue.  It must be mounted with the arrow pointing forward, some settings need to be changed, and you need to recalibrate the mags so it can do the new aux mag.

There was some question about your mode switch.  Have you addressed that so that you know what mode you are in for sure?

I never bother to use PositionHold since there is a mode called VelocityRoam.  If all sticks (including throttle) are in the middle, VR is exactly PH.  But you can move the sticks and it for instance holding left roll makes it fly at constant speed to the left.  It may be useful to know if you can correct for it using VR.

Watch the gyrostate and accelstate scopes in GCS as you run it up to 3/4 power however you did before.  Look for vibration in the scope picture.  Do a screen capture and post it here.  Also, with this method, is the compass heading on the FlightData page correct and does it change just because you are adding power?
« Last Edit: November 07, 2019, 08:19:29 am by TheOtherCliff »

trust

  • ****
  • 299
Re: Position hold not working
« Reply #13 on: November 07, 2019, 06:51:16 pm »
Good point about arming - that could explain RTB not working. I've switched it to yaw left. It may explain other issues too, like the tilt. So I'll try that first. Also changed PH to VelocityRoam - that seems more useful. Yes, I did double check the switch positions after having them backwards before.
Also yes on INS13 AttiEstAlgo
On moving battery- I'll have to think on that - the current layout allows it to sit flat on the short legs on each arm - the battery is off to the side, and I did try twisting the battery cable as well.
I could move the FC higher by a few inches.
Yes, the direction of motion after switching to PH seemed random, though I did not try it more than a few times.
I'll try the tethered tests you suggested.
The new GPS/mag should be here any day now - I'll try it when it gets here.

trust

  • ****
  • 299
Re: Position hold not working
« Reply #14 on: November 07, 2019, 07:48:37 pm »
Just did a short test to see if I could arm it outside - I have been having trouble getting it to arm when the USB cable is not connected. And I found that I needed to have the USB cable plugged in to arm it - even if the cable was not connected to anything! Looks like it has something magnetic in the plug. That may be why things go haywire - the mag settings completely change once the cable is removed.
I don't have soldering guns anymore, just irons. I'll poke around for other USB cables.