karla

  • *****
  • 629
Position hold on a fixed wing - Altitude control mystery
« on: November 15, 2019, 08:04:50 am »
Hi all  :)

last summer I had some great weeks flying my mako fixed wings.



One has a Revolution board and the other a Revo Nano and both controlled via OPLINK from ground tx.

I first upgraded to the official 'latest' Librepilot version 16.09 +r782
https://forum.librepilot.org/index.php?topic=4580.0
This version finally feels like a mature code when it comes to the magnetometer calibration and using the Attitude Estimation Algorithm set to GPS navigation (INS 13).
I found it stable and predictable on my fixed wings (finally :) )



So far so good.
I made many flights to try out Position hold under INS13.
I have some experience and some questions.

It seems when the altitude is getting low, then the fc will try to increase it, but only by increasing the rpm of the motor.
Is that correct?
One could have thought that adding a bit pitch would be included in the code, but it does not seem that way.

Would be great if anyone (cliff :) ?) could confirm this.


I can upload other videos of what happens in good wind conditions (no wind, and some 15 min of successful pos hold) and another (more than one) what happens if trying to increase altitude just by using rpm increase when going down-wind (doesn't do the job unless you are at very high altitude).
« Last Edit: November 15, 2019, 08:20:32 am by karla »

Re: Position hold on a fixed wing - Altitude control mystery
« Reply #1 on: November 15, 2019, 07:01:56 pm »
What mode were you flying in that video?  Especially takeoff and landing.  Attitude mode takeoffs are usually a problem because of PID windup.

Fixed wing hasn't received the love it should.  Indeed, the coded way to increase altitude is to add power and as I recall, the coded way to decrease speed is to climb.  So e.g. when following a waypoint course, it adds power, and after a while it starts to climb.

There are some "cross feeds" that are designed (my understanding) to make this work more quickly.  I haven't played with them.  The units in System->Settings->FWPF are what you have to try to figure out how you might change them.  FWPF setup is not intuitive for a model pilot.  :)

One reason I can imagine for doing it this way is that you won't ever stall by asking it to climb too quickly or by asking it to climb with a dead or failing motor.

This algorithm seems to also fit well where you trim a commercial aircraft for best fuel economy and want to keep it trimmed that way.  Also, commercial aircraft change attitude / altitude slowly as compared to models.

I've made several comments about this over the years, among them that:
- If you determine that you need to increase altitude quickly, this is not effective.
- If you want to make a terrain following aircraft, it will crash when flying toward a hill if you give it a normal climb command.
- The way the physics works, it seems to me much better to instantly climb with elevator which causes a gradual slowdown that can be offset by adding power. Conversely, if you only climb by adding power and then because increased speed causes the code to pull up elevator, then, well the aircraft doesn't come to full speed instantly and the climb is delayed.
- The statement was made back in the OP days, that all airplanes climb when you add power, but that isn't true.  It may be true that the design of full sized aircraft works this way, but many models are designed so that adding power neither climbs nor descends and if your aircraft is built (e.g. tail heavy or motor in a pod over wing) so that adding power forces the nose down, then some aircraft even descend when adding power.

One of the things on my wish list of things I would like to do is a different FWPF that uses elevator to climb.

Some related threads:
https://forum.librepilot.org/index.php?topic=4644.0
https://forum.librepilot.org/index.php?topic=3518.0
« Last Edit: November 15, 2019, 07:22:21 pm by TheOtherCliff »

karla

  • *****
  • 629
Re: Position hold on a fixed wing - Altitude control mystery
« Reply #2 on: November 16, 2019, 08:15:04 am »
Thanks a lot Cliff for clear confimation.
plus all extra resources and experience on what can possibly be done about it.

Start and landings always in attitude mode. Before, when ins13 was not reliable and also during setup of servos I did fly rate so I know all is nicely centered. Now attitude is very convenient to use at most times.
No real problem with pid windup here, maybe because I reboot and arm very shortly before I take off generally. After getting a good altitude I have experimented mostly with Position hold and RTB.

Since its been taking a long time and effort to get to point I am today and now learning there seems to be no proven solution for getting a mako to do position hold when there is wind, I am seriously considering to migrate over to another platform for these wings. To control altitude is crucial for trying waypoints and complete missions. 
« Last Edit: November 17, 2019, 02:20:14 am by karla »

Re: Position hold on a fixed wing - Altitude control mystery
« Reply #3 on: November 16, 2019, 09:29:38 am »
I've got several fixed wings that do waypoint (including altitude changes) and RTB, but I did several changes and hacks to get it working:
- The altitude and throttle was oscillating.  It would go from stopped motor to 100% throttle, especially during Position Hold.  I should have spent more time trying to get the PID adjusted, but I set FWPF min and max thrust to some values that tamed this down and set Min and max airspeed to the same number which was a reasonable cruise speed.  There are different alarms for FWPF min/max airspeed and for SystemSettings min/max arispeed.  (settings hacks)
- I increased the max bank angle so that it would stay closer when doing Position Hold.  (settings change)
- Especially with the increased bank angle, in a turn it would drop the nose and loose altitude before adding elevator.  I added a code change that starts off with a reasonable amount of elevator, so it does more of a normal turn, rather than bank, drop the nose, finally add some elevator.  (code change)
- Waypoint flight would never get past the first waypoint or 2 without returning to the first waypoint.  This is because of the various airspeed alarms that were happening (partly because of my airspeed and thrust settings hacks).  I set Error Destination to -1 on each waypoint to get it to ignore this, and waypoints worked fine.  (settings hack)

Certainly a lot of hacks that I need to clean up.  :(  Fixed wing GPS flight needs a detailed set of instructions that can guarantee good GPS flight if you start with an airplane that flies good.  It should be possible to set up both a 3 channel high dihedral powered glider and a 3D stunt airplane.

Figuring out and writing a good complete set of setup instructions for fixed wing GPS flight is at the top of my wish list.  The code change to add elevator as soon as it banks would help too.

karla

  • *****
  • 629
Re: Position hold on a fixed wing - Altitude control mystery
« Reply #4 on: November 17, 2019, 03:31:17 am »
Indeed that would be very nice to have but surely be a considerable effort.

Meanwhile, the wing that is intended for FPV flight will be fine to use.

Just wanted to share a video to illustrate the position hold, starts at ~2:30 and all the way to close before landing at ~13:30 something. I think i might have switched over to attitude mode once in the middle of that since i got scared it got too low altitude and then went back to pos hold.
I only have the low resolution fpv version of the flight.

https://drive.google.com/file/d/1KITYJ8vshnRfQO6ptpx4_oon-ler1yqi

There is just a weak wind of like 2 knots (1m/s) coming from the sea.
It behaves surprisingly well (what i am used to) and is interesting and entertaining to see what the fc will do.
Mostly it flies in counter clockwise circles but not always. It will rise and run at pretty low speed going towards the sea but increase speed and sink going away from it (with the wind). It picks up altitude again after it starts to make a turn to left or right. I noticed on the flight logs that there are very often autopilot warnings during pos hold, but not always. I don't know the reasons but assume it could be crossing some limits for speed, banking etc etc.

Anyway, the season for wing flying is over for this year for me - it was a good one.

jdl

  • ***
  • 246
Re: Position hold on a fixed wing - Altitude control mystery
« Reply #5 on: November 18, 2019, 12:31:42 pm »
I'd like to add few words about my own experience. I'm currently flying two wings with Revolution FC and Librepilot Next r735/r782 that proved fully capable of autonomous flight (PH, RTB, AC, PP). WingWing Z-84 (elevon type, like Mako) and MiniTalon (V-tail).

The key features (along with some hacks that TheOtherCliff mentioned above) that allow for stable and reliable autonomous flight are:

1. Use of a real airspeed sensor (pitot tube & MPXV7002DP) instead of GroundSpeedBasedEstimation. I guess it is not intended to properly work on planes without rudder control (Z-84). Anyway, nothing replaces true airspeed sensor when flying in gusty winds and/or looking for efficiency. I've carefully calibrated the sensor (Scale & Zero Point). I'm also checking ZeroPoint before every flight, just for peace of mind.

2. Planes are trimmed to (slowly) gain altitude when throttle is above ThrustLimits.Neutral. I recall I did it on Z-84 by mechanically trimming elevons just a hair "up".

Also tweaked settings for BoardRotation (TheOtherCliff has also discussed this some time ago) to fool the flight controller to keep the nose slightly up when FC board is level in Attitude mode.

AttitudeSettings / BoardRotation / Pitch = -2
AuxMagSettings / BoardRotation / Pitch = -2 (if using external mag sensor)

It may also be beneficial to raise a little
FixedWingPathFollowerSettings / PitchLimit Min, Neutral & Max values. I've added 7 degrees there in Z-84 setup but left the default values for MiniTalon as it seems to not need changes there.

For the last two years I've flown hundreds of kilometers with both planes in autonomous mode (PathPlan & AutoCruise) without single altitude control issue. I'm also using PH / RTB after each takeoff to test autopilot and failsafe behavior.
Edited video from a MiniTalon fully autonomous flight (40+km predefined flight plan), except takeoff and landing (attitude) here:


Btw, I've found the FWPF handles well motor/esc failures (when no thrust is available). I've had a situation the ESC on MT stopped and did not start again the motor during PH in a VERY windy occasion(HighPower alarm causing CutThrust in fixedwingflycontroller.cpp) (ESC issue/protective feature? with ESC brake enabled and throttle command going to zero and up again for too short pulse). The plane kept well airspeed while gradually descending instead of pitching up (if trying to maintain altitude by adding up elevator) and stalling.

PIDs windup can really be an issue on takeoff in Attitude, I've had few scary launches with Z-84 when being too slow (when waiting for more than 3-4sec before throwing plane after arming, switching from manual to attitude and applying throttle). Here is a related thread about a possible solution/workaround:
https://forum.librepilot.org/index.php?topic=4723.0


karla

  • *****
  • 629
Re: Position hold on a fixed wing - Altitude control mystery
« Reply #6 on: November 19, 2019, 04:39:39 am »
Okay! this was encouraging.
Thank you.
To install an airspeed tube and tweak the settings of board rotation etc is doable for me, but the code fixing is not.
I think I might give it another try for next season and see how far that will go.
You think it can be enough or code must be changed?

p.s. that is one lovely video :)
« Last Edit: November 19, 2019, 06:25:25 am by karla »

jdl

  • ***
  • 246
Re: Position hold on a fixed wing - Altitude control mystery
« Reply #7 on: November 19, 2019, 11:34:20 am »
Thanks!  :)

I don't think I can do the supposed general code changes myself, either. Lack of enough background knowledge and free time, at least.

So far I'm OK with current FWPF implementation. My planes had their Revo FCs loaded with standard next r735/r782 firmwares for long enough time.

Indeed, I've recently installed in my planes a custom firmware (r735/r782 based) with some minor code changes in order to disable CutThrust on HighPower alarm condition, so I can safely use ESC brake function on the MiniTalon with folding prop. Also added few lines of code to rapidly apply throttle in case of sudden, dangerously low airspeed, until airspeed raises over predefined threshold.

Anyway, these code changes are not really important and FWPF works fine without them.
I can upload here the current settings (.uav) for my Wing Z-84 and MiniTalon, as a working example, if you think it could be useful.

karla

  • *****
  • 629
Re: Position hold on a fixed wing - Altitude control mystery
« Reply #8 on: November 20, 2019, 07:33:38 am »
lets see If I understand you

. code does not really have to change, the settings will be enough?
. you are willing to upload your settings for your two fixed wings here!

If okay, please upload  :)  :D  ;D

jdl

  • ***
  • 246
Re: Position hold on a fixed wing - Altitude control mystery
« Reply #9 on: November 20, 2019, 11:12:08 pm »
I cannot say code does not have to change  ;)

But, my expirience with these two planes makes me confident that current code handles reliably basic autonomous flight modes, incl. PH. It just requires the plane to be set up to climb on high throttle. Either mechanically (elevator trim, thrust vector, etc.) or the the FC settings. Maybe easiest way to do is by adjusting AttitudeSettings / BoardRotation / Pitch. Then, as a test, while cruising in Attitude, more throttle applied should cause the plane to slightly climb.

Here are the current uav files for both planes, I'd be glad if useful to you!  :)

---
Samples from recent flights:

MiniTalon - RTB(and PH)


Z-84 - RTB(and PH)


MiniTalon - AutoCruise
« Last Edit: November 21, 2019, 12:31:51 am by jdl »

karla

  • *****
  • 629
Re: Position hold on a fixed wing - Altitude control mystery
« Reply #10 on: November 21, 2019, 07:11:20 am »
That's good enough for me to try.

Thanks a lot!
The results will not be around until next August though when back in that field.

karla

  • *****
  • 629
Re: Position hold on a fixed wing - Altitude control mystery
« Reply #11 on: November 23, 2019, 05:58:56 am »
jdl,
I have got a couple of these analog tube wind speed instruments.
I can install it, but is that really needed to get the basic autonomous flight modes to work?
Does it bring some other benefits?
I don't feel detecting stall speed has ever been a problem, maybe some other benefits?

jdl

  • ***
  • 246
Re: Position hold on a fixed wing - Altitude control mystery
« Reply #12 on: November 23, 2019, 02:28:19 pm »
I've made attempts to get a reliable autonomous flight without airspeed sensor on Wing Z-84 only.
The results were encouraging but never 100% satisfying. I've achieved a very nice PH and (almost) reliable RTB, but had issues with thrust occasionally going to max preset limit on longer legs in PP mode. It might be related to GroundSpeedBasedWindEstimation not reliable on planes without ridder control (just a guess).
Cliff already pointed to the thread:

https://forum.librepilot.org/index.php?topic=3518.0

Playing with settings, acceptable results can be achieved even without real airspeed measurement. But this is not an energy efficient autonomous flight as you have to set airspeed limits rather high as an insurance against stronger wind gusts.

Once I've installed the airspeed sensor on Z-84, I've never looked back. I've later built the MiniTalon with analog airspeed sensor too. Of course, this adds one more preflight check (it's always a good idea to check if the zeropoint of the sensor is correct).

I do always keep an eye at the airspeed, especially when flying in manual mode. The winds in my area are quite often gusty and unpredictable. Here is a snapshot of an occasion few months ago when I was hit by a sudden and long lasting wind from behind and had to add a lot of throttle to keep the plane well above stall speed (84km/h ground speed vs 37km/h airspeed. MiniTalon stalls at 28-32km/h).
Without a real airspeed measurement I would not have an idea of the situation until losing control.


karla

  • *****
  • 629
Re: Position hold on a fixed wing - Altitude control mystery
« Reply #13 on: November 25, 2019, 06:44:02 am »
Thank you!

That were some good reasons why install an airspeed sensor :)

Reading up on the previous threads - there are soo many things think about.

But Cliff started a setup check list for fixed wings
It would be nice to have a step by step setup and tuning guide, fixing alarms, etc. for fixed wing.
build balance align
fly in manual mode and adjust trims mechanically so that transmitter trims are centered
fly in rate mode (yaw manual) and adjust Stabilization page PIDs for maximum response without oscillation
fly in attitude mode (yaw manual) and adjust for max response
(fixed wing needs to zero the integral when in manual mode so that a switch to stabilized doesn't go crazy for a few seconds, yes you can zero the throttle, switch to stabilized, increase throttle to work around this)
enable GPS airspeed sensor in two places
determine airspeed and set fwpf speeds and throttles
adjust fwpf horizontal PIDs etc to tighten up loiter
crossfeeds and other stuff ???

b t w
It seems I have been using your method to avoid the PID windup in manual without being aware of it.
I have my 'manual' mode set up as stabilized1 and then manual as stab method on all axis. Until today I had not noticed there even is a Manual option :) Lucky in a way.

One of the reasons I like LP is the flexibility and control you have to set your flight modes and stab methods. I think that and OPlink.

Re: Position hold on a fixed wing - Altitude control mystery
« Reply #14 on: November 25, 2019, 08:26:26 am »
That was just off the top of my head at the time.  That list is certainly not complete.

I would ADD (again, off the top of my head) that you can/should:
- Fly around manually and get good info about how to trim your Rotate Virtual from looking at the roll and pitch angle telemetry in normal flight.  Trim it in Rotate Virtual (put those numbers into RV) and it will work for Attitude mode and GPS flight modes.  Thus trim FWPF PitchLimit closer to -15,0,15 or so?
- Fly in calm conditions and get info about min and max airspeed from GPS telemetry groundspeed, and set min/max airspeed in both places (FWPF and SystemSettings).
- Enable an Airspeed sensor, even if it is only the GPS one.
- Per JDL you can tune the AirspeedSettings.LowPassPeriod12 to get your GPS mode airspeed working without oscillation
- Understand, enable, set up ScaleToAirspeed to automatically scale the RPY PIDs based on airspeed.  Maybe retune the RPY PIDs after enabling this, or at least understand how to set it up to be basically using your unscaled PIDs at the airspeed that you tested those PIDs.
- Test it with a waypoint course where there is significant altitude change.  Adjust to get it working the best it can.
- Understand and adjust the PIDs, SafetyMargins, and SafetyCutoffLimits so that GPS flight doesn't throw alarms (which will abort your waypoint flights and by default send you back to the first waypoint over and over).

Things to consider:
- Remember that you can set waypoint flight Error Destinations to -1 to get waypoint flight to ignore alarms (like overspeed, underspeed) for testing.
- Reduce the Rate PID ILimit to reduce PID windup during Attitude mode hand launch.  Note that the windup looks like it occurs in the Rate section since the Attitude section has a zero I term by default.  Fly along in Manual mode for a while, then switch to Attitude mode.  It will go crazy for a few seconds.  This is what you are trying to fix.
- Tweak crossfeeds