LibrePilot Forum

Users => Vehicles - Fixed Wing => Topic started by: karla on November 15, 2019, 08:04:50 am

Title: Position hold on a fixed wing - Altitude control mystery
Post by: karla on November 15, 2019, 08:04:50 am
Hi all  :)

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

(https://forum.librepilot.org/index.php?action=dlattach;topic=4769.0;attach=8337;image)

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 :) )

https://www.youtube.com/watch?v=zYGoRIEp9Sg

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).
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: TheOtherCliff 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
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: karla 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. 
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: TheOtherCliff 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.
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: karla 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.
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: jdl 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:
https://www.youtube.com/watch?v=-72J8XAqvPI (https://www.youtube.com/watch?v=-72J8XAqvPI)

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 (https://forum.librepilot.org/index.php?topic=4723.0)

Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: karla 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 :)
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: jdl 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.
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: karla 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
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: jdl 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)
https://www.youtube.com/watch?v=M-5raz3NJD0 (https://www.youtube.com/watch?v=M-5raz3NJD0)

Z-84 - RTB(and PH)
https://www.youtube.com/watch?v=IqJ-TO4beoo (https://www.youtube.com/watch?v=IqJ-TO4beoo)

MiniTalon - AutoCruise
https://www.youtube.com/watch?v=vJBrbd8WRN8 (https://www.youtube.com/watch?v=vJBrbd8WRN8)
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: karla 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.
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: karla 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?
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: jdl 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 (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.

Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: karla 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.
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: TheOtherCliff 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
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: karla on December 03, 2019, 08:53:17 am
@theothercliff
Thanks a lot, i am just not there yet, but hope to catch up and use your list.

I've later built the MiniTalon with analog airspeed sensor too.

May I ask where and how you installed the pitot tube on that wing frame?
Cant really spot it in the pictures you posted.
What considerations you went through?

Asking since I am getting a bit inspired to install one myself on a similar wing (ZOHD Talon Rebel GT, long name  ::) ).
It does have a v-tail and thus a rudder function, unlike the mako.
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: jdl on December 03, 2019, 11:03:36 am
I've installed the pitot tube on the right wing of MiniTalon, some 15-18cm away from the fuselage. I've followed the info and advices in the MT dedicated thread in rcgroups, especially these of mark_q. He also has an excellent MT dedicated site:
http://www.itsqv.com/QVM/index.php?title=X-UAV_Mini_Talon_Build_Compilation (http://www.itsqv.com/QVM/index.php?title=X-UAV_Mini_Talon_Build_Compilation)

If your pitot tube is all-metal one, you can make use of this 3d-printed mount:
https://www.thingiverse.com/thing:1887194 (https://www.thingiverse.com/thing:1887194)

Mine pitot tube was different design so I installed it with hot glue and a plastic screw for additional strength. Never had problems with it, the hot glue holds it perfectly, just had to be very cautious aligning it correctly. I'll make a close-up photo of the pitot tube on the wing later and I'll post it here...

This position of the pitot tube is considered to offer minimal disturbances in the airflow and thus minimal errors. It is safe on landings, too.

(https://static.rcgroups.net/forums/attachments/6/3/3/3/8/4/a11105872-250-23.jpg)

(https://static.rcgroups.net/forums/attachments/6/3/3/3/8/4/a11105876-62-27.jpg)

I've burried the sensor and the hoses in the foam, in the wing. Only the cable goes into the fuselage.

(https://static.rcgroups.net/forums/attachments/6/3/3/3/8/4/a11105850-119-01.Airspeed%20Sensor.jpg)

Here is the post about my MT build:

https://www.rcgroups.com/forums/showpost.php?p=39982936&postcount=13905 (https://www.rcgroups.com/forums/showpost.php?p=39982936&postcount=13905)

There are tons of useful info in the MiniTalon thread in rcgroups, worths reading it all. I guess you can find interesting ideas for your build of ZOHD Talon Rebel GT there.
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: karla on December 03, 2019, 11:37:19 am
OMG, thanks a lot for sharing all this!
Q: I notice you have a small gps unit that do not have an external mag in it, right?
So, where do you mount your external mag?
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: jdl on December 03, 2019, 12:20:06 pm
Nowhere  :)
Not using external mag at all.

On the MiniTalon I'm using Revo's internal mag, works flawlessly. There are not power lines passing too close, all cables are twisted and I get (almost) no alarms, no matter how much thrust I give. In fact, the situation is way better compated to the ZMR250 quadcopter and Z-84 plane that have auxmags installed.

I've rarely seen in the telemetry logs mag warnings, not critical reds, and the rate of their occurance is comarable or lower than the rate of the identical warnings in the logs from Z-84 (that uses external mag).
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: karla on December 03, 2019, 12:22:04 pm
sooo good to hear that!
I will take a bet the internal mag also will work on the Rebel GT.
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: jdl on December 03, 2019, 12:49:13 pm
I guess so. ZOHD Talon seems to have (looking the photos on the web) spacious internals to allow good separation betheen FC and power lines.

Even if internal mag turns to be unusable on the final build stages, you can always replace the GPS with Naza clone and use its own mag for auxmag. Weight penalty is almost insignifacant..
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: f5soh on December 03, 2019, 06:02:46 pm
You can also give a try to Complementary+GPSOutdoor, without mag.
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: TheOtherCliff on December 03, 2019, 08:17:39 pm
Cool !

Hmmm...  This is about fixed wing GPS flight modes.  I have never tried this without a mag.

So does "next" (or even 16.09??) use the "fixed wing constraint" to do GPS flight modes on fixed wing without a mag?  (It assumes that it is pointed in the direction that it is traveling?)  I have just assumed that it used mag.  I need to read code more completely.  :)
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: jdl on December 04, 2019, 02:11:06 pm
@karla
Here are some photos of how the pitot tube is mounted on my MiniTalon wing. I've measured 18.5cm from the base of the wing, so approx. 20cm from the fuselage.

Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: karla on December 05, 2019, 02:42:32 am
This sounds better and better :)

@jdl very clear, thanks.
@f5soh interesting, I will try setting Complementary+Mag+GPSOutdoor and see what it does.
@theothercliff good questions!
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: karla on December 21, 2019, 07:29:52 am
I am almost done building the new wing and preparing for some initial test flights in 2-3 weeks.
Reading up on other threads I have tried to collect the observations and settings important to position hold on a fixed wing.

(https://forum.librepilot.org/index.php?action=dlattach;topic=4769.0;attach=8385;image)

@theothercliff
If you would like to share the uav file of your bixler I can complete the setting comparison table with you @jdl and mine to better understand the outcome of the upcoming test?

Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: TheOtherCliff on December 21, 2019, 08:37:50 am
Mine was <not> pretty.  ::)  I can't publish it as it is.  The first day at the field to get it working, I set min speed = max speed and adjusted thrust limits min, neutral, and max so that it would fly about that speed with enough thrust variation to be able to climb and descend at reasonable rates, but speed wouldn't oscillate.  I didn't bother to change these since I wasn't getting the (omnidirectional) FPV video range that I wanted.

I also tweaked settings to make it turn a lot tighter in GPS flight modes (like for position hold or a very sharp waypoint turn), but the nose would drop and it would loose altitude before realizing that it needed to pull some up elevator.  So I made a code change to pull elevator that was a function of bank angle (with fixed airspeed) so it wouldn't wait till it lost altitude to pull elevator in a turn.  I think this idea might be useful.  So you see those settings won't even work well without a code change.
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: karla on December 22, 2019, 03:10:24 am
Ah yes, I see.
My mission is to see if PH RTB PP can work okay without code changes.

Another question, is there any point in playing with AltitudeHold/AltitudeVario, the non gps thrust stabilization for quads and helis? Maybe not designed/usable for fixed wings? Could possibly be easier to just tune altitude hold first...

That function uses the settings under Stabilization | Altitude Hold, right.
After getting it to work good, say flying with Attitude stab on roll and pitch, then do settings in FWPF when moving to trimming for PH, RTB and PP.
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: TheOtherCliff on December 22, 2019, 07:22:11 am
Quote
My mission is to see if PH RTB PP can work okay without code changes.
In my opinion, yes it can.  Turns are fairly big circles.  Vertical / thrust stuff probably needs to be tweaked to avoid throttle oscillation.  Use INS13 with GPS-airspeed or hardware-airspeed enabled (UseAirspeedSensor), set up and calibrated by comparing to GPS speed during normal flight on calm, no wind day.  Airspeed PID Scaling should be understood, enabled, and changed if needed, early on so that your PIDs are tuned with it enabled.  Remember SystemSettings (max and min airspeeds) need to be set too.  I should have spent more time on SafetyMargins.  I setup up Manual mode and make manual linkage adjustments to get it flying well with trims centered.  Add Rate (rate, rate, manual, manual) (tune PID).  Add Attitude (attitude, attitude, manual, manual) (tune PID).  Add PathPlanner and 2 point waypoint plan with error destination set to -1 on both waypoints and use it to get altitude / thrust oscillation fixed.

Be aware that when using a 2.4GHz RC to 433 OpLink relay box with OpLink control of aircraft, that you should never just turn the RC transmitter off because that causes the OpLink in the relay box to send full stick signals on all channels.

Configure and test both RTB and waypoint flight in "out of range mode" close to you to make sure that they do what you want them to.  RTB should come home while climbing whatever you have configured.  If I were to do long range waypoint flight, I would probably want it to continue doing the waypoints whether it was in RC range or out of RC range.

I usually make a small code change so that I can set RTB up as if it were an additional flight mode switch position that is only reachable in FC failsafe mode.  You can do the same with RC failsafe mode moving the channel farther than you can move it with the switch.

I remember the first time I tried to set up GPS flight modes on a quad.  I wondered why we have two separate vertical velocity PIDs; one in AltitudeHoldSettings and the other in VtolPfSettings.  Maybe it was to make it clear that FwPfSettings doesn't have a vertical velocity PID.

FwPfSettings as a whole has settings that can be tuned like a vertical velocity PID, but it doesn't actually have one.  It DOES has a vertical position P as opposed to velocity PID.

As suspected, a quick look at the code says that all aspects of fixed wing ignore AltitudeHoldSettings.

Oops, gotta go.
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: karla on December 24, 2019, 01:56:47 am
Yes, I feel optimistic it will work much better than last summer with the help of the recent posts by you, @jdl and @f5soh.
The issue right now it's difficult to find replacement for the full size Revo that has a weak radio link. Sparky2 and Revo mini's are available but they lack the convenient output connector pins and I already have three Sparky2 boards that don't want to work with next r782. If i can't find one i will use a revo mini and re-solder all wires.

Merry Christmas  :)
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: TheOtherCliff on December 24, 2019, 03:48:48 am
Here is a Revo for USD $36, but you have to add your own pins.  I prefer that any way.  :)  Picture shows the small X2 on the RF board, and they claim it doesn't have baro problem.  I have bought stuff from seller "porcupinerc" before.
https://www.ebay.com/itm/Openpilot-Revolution-REVO-32bit-Flight-Controller-Librepilot-compatible-FPV/172353557428

Sparky 2 may be broken in next?  :(  Any idea when it started or what all is still working?  I have more Sparky2's than Revo's by my last count.

Hmmm I guess I will buy one of those Revos since I think the ones I have are all in models.  Done.  :)
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: karla on December 24, 2019, 04:40:50 am
Ah good to know.
The last sparky2 I got was just some weeks ago since they did not have revos. That board was not recognized by gcs next r782 as a board at all.
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: TheOtherCliff on December 24, 2019, 08:30:22 am
You have other Sparky2s, so I guess you have been through the steps:
- soldering the correct jumper so the receiver port gets either 3.3V or 5V (back side of board)
- using the TauLabs bootloader that Sparky2s usually come with to install the LP bootloader updater and finally the LP firmware.

There is one Sparky2 source (xt-xinte?) that installed a 10k resistor on that receiver port power option (instead of a jumper) and that basically means that power won't flow in or out of the receiver port till you put a blob of solder over the resistor to short it out.

If the magic LP GCS code that allowed the TauLabs bootloader to be recognized was removed from next, you could try 16.09 and it would work there.  If it doesn't have a TauLabs bootloader on it, then you would need to do the DFU procedure to put the LP bootloader (at least) on it.

Where did you get this Sparky2?

I have bought several Sparky2s also from that same eBay seller "porcupinerc".  They are black and I believe they are the last of the official boards after the official source dried up.
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: jdl on December 24, 2019, 12:33:37 pm
Here is a Revo for USD $36, but you have to add your own pins.  I prefer that any way.  :)  Picture shows the small X2 on the RF board, and they claim it doesn't have baro problem.  I have bought stuff from seller "porcupinerc" before.
https://www.ebay.com/itm/Openpilot-Revolution-REVO-32bit-Flight-Controller-Librepilot-compatible-FPV/172353557428


I've recently got one from the same place ("porcupinerc"). The received Revo is fine. Arrived without header pins in the bag at all so I had to source and solder some good ones (non-magnetic pins).

This Revo has angled MMCX connector (I don't like them much) that dislodged after some plugging in and out the antenna cable. This is repairable but I had few spare straight connectors and replaced it (was a PITA though).

Anyway, the FC is working fine, data coming from mag, baro, accels and gyros seem OK. Radio module performs well, too (and it has small "X2", just as on the photo).

Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: jdl on December 24, 2019, 03:37:03 pm
I am almost done building the new wing and preparing for some initial test flights in 2-3 weeks.
Reading up on other threads I have tried to collect the observations and settings important to position hold on a fixed wing.

(https://forum.librepilot.org/index.php?action=dlattach;topic=4769.0;attach=8385;image)

@theothercliff
If you would like to share the uav file of your bixler I can complete the setting comparison table with you @jdl and mine to better understand the outcome of the upcoming test?

I think some of the values in this table are not filled correctly, especially the LP defaults. Not that important but can lead to wrong assumptions. Also, I've left in my setup the SafetyCutOffLimits for Pitch, Roll, Yaw to 25, not to 0, but I've effectively disabled them in SafetyMargins / PitchControl|RollControl to prevent cutThrust in these situations. I do also run a slightly changed code that disables the cutThrust in HighPower occasion. Original LibrePilot code does it (stops the motor) in HighPower, not conforming SafetyMargins | HighPower alarm setting. There is generally nothing wrong in this but I'm running on my MiniTalon a folding prop with brake function enabled in the ESC and I've found that cutThrust can be disastrous if it activates for only a fraction of a second. This enables some protection in the ESC and motor doesn't start again until throttle is lowered to zero for at least a second. That's why I've also chosen to disable SafetyMargins / PitchControl|RollControl.

MaxDecelerationDeltaMPS addresses the plane is too slow situation:
If airspeed drops below HorizontalVelMin*SafetyMargins.LowSpeed - MaxDecelerationDeltaMPS the motor is stopped (in autonomous modes), assuming the plane is maybe crashed...

FixedWingFlyController.cpp
Code: [Select]
        if (indicatedAirspeedState < fixedWingSettings->HorizontalVelMin * fixedWingSettings->Safetymargins.Lowspeed - fixedWingSettings->SafetyCutoffLimits.MaxDecelerationDeltaMPS) {
            cutThrust = true;
            result    = 0;
        }

For the MiniTalon I've set this threshold to 2.23m/s (8km/h). Btw, this is not a perfect solution as it does not count the possibility the pitot tube inlet to be blocked by a water drop, ice, bug, etc. If this happens, RTB will not be functional and usable anymore in critical situation...

I've once had such a situation while climbing in Attitude through fog/low clouds. Airspeed suddenly dropped to zero (apparently pitot inlet was soaked with water), PIDs instantly scaled up (because of the active ScaleToAirspeed) and I had to switch to manual and fly back to clean air until the water drop evaporated and airspeed readings regained. 

I plan to add GPS based ground speed to this check, too, or better, to write some code to detect if airspeed sensor provides implausible data and set hasAirspeed to false until valid airspeed data appears again.

Regarding ScaleToAirspeed, yes, this is the speed in m/s that PIDs were tuned for, usually the normal cruise speed for the plane. After initially tuning PIDs with ScaleToAirspeed disabled and fine-tuning airspeed sensor zero point and scale, you can set ScaleToAirspeed to your cruise speed and do any further PID tuning if necessary.

Merry Christmas!  :)
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: TheOtherCliff on December 24, 2019, 09:52:32 pm
I feel it is best to enable ScaleToAirspeed before tuning PIDs so you only have to tune once.  :)

Setting ScaleToAirspeed to a speed that is different than the actual speed you tuned at changes your effective PIDs.  It's hard to know what speed you tuned at, and you probably flew at many different speeds while tuning.

Tune PIDs once, but with ScaleToAirspeed enabled.

If you tune PIDs with ScaleToAirspeed enabled, you can test fly at all speeds without worrying about the speed you are flying.  It automatically scales it and it is either wrong at all speeds or it is right at all speeds.

Technical:

If you have PIDs set well for some middle speed and you fly a lot faster, the PIDs will cause oscillation because the faster you fly, e.g. the faster your roll rate is in degrees per second.

If you then fly a lot slower, the PIDs are not responsive enough to control the airplane very well.

It doesn't even matter much what speed you set ScaleToAirspeed to if you tune PIDs after setting it.  The effective PIDs used in flight are the same whether the PIDs are high and ScaleToAirspeed is low or whether the PIDs are low and ScaleToAirspeed is high.  Both of those are well tuned PIDs.

I think the way to tune PIDs is to:
- fly Manual mode till later
- adjust linkages and put transmitter trims back in the middle
- set up and calibrate AirspeedSettings to match GPS speed on a no wind day
- determine a reasonable cruise speed with telemetry
- set ScaleToAirspeed to a reasonable cruise speed
- always leave yaw/rudder in Manual mode
- when tuning, find upper limit of PIDs where oscillation starts to occur
- when tuning, find lower limit of PIDs where PIDs and flight is a little mushy
- set tune half way between upper and lower limits that you found
-- or maybe closer to upper end, but never oscillating
- fly Rate mode and tune rate (inner) PIDs
- fly ATtitude mode and tune aTtitude (outer) PIDs
- enable UseAirSpeedSensor before doing GPS flight modes
- tune stuff if waypoint flight has vertical / motor oscillation
-- there are several things reported to affect it, some of which I have not personally tested
-- airspeed and aLtitude are both involved
-- the main thing should be FwPfSettings.VerticalPosP ? ? ?
- test waypoint flight climbing and descending
- test RTB close by
- remember to change failsafe depending on your mission:
-- long range waypoint you may want loss of RC to continue the mission
-- long range FPV you probably want loss of RC to RTB
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: karla on December 25, 2019, 03:44:01 am
That eBay seller is actually a RC hobby online store in Hong Kong http://www.porcupinerc.com
its been around long time.
I have also ordered from them before.

I will remind them to add the header pins to my shipment!  :P

Here is a Revo for USD $36, but you have to add your own pins.  I prefer that any way.  :)  Picture shows the small X2 on the RF board, and they claim it doesn't have baro problem.  I have bought stuff from seller "porcupinerc" before.
https://www.ebay.com/itm/Openpilot-Revolution-REVO-32bit-Flight-Controller-Librepilot-compatible-FPV/172353557428


I've recently got one from the same place ("porcupinerc"). The received Revo is fine. Arrived without header pins in the bag at all so I had to source and solder some good ones (non-magnetic pins).

This Revo has angled MMCX connector (I don't like them much) that dislodged after some plugging in and out the antenna cable. This is repairable but I had few spare straight connectors and replaced it (was a PITA though).

Anyway, the FC is working fine, data coming from mag, baro, accels and gyros seem OK. Radio module performs well, too (and it has small "X2", just as on the photo).
Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: karla on December 25, 2019, 06:23:50 am
You have other Sparky2s, so I guess you have been through the steps:
- soldering the correct jumper so the receiver port gets either 3.3V or 5V (back side of board)
- using the TauLabs bootloader that Sparky2s usually come with to install the LP bootloader updater and finally the LP firmware.

Yes, pretty much thank you.
But, I had some suspicions  about this PC Win10 I am using that turned out right.
It has several versions of LP installed on it from 16.09 all the way up to next r782.

So instead, I tried use one of my Macs that has only one installation of LP and that is 16.09.
And I am very happy to now have 4 board resurrected from the grave bin :D

(https://forum.librepilot.org/index.php?action=dlattach;topic=4769.0;attach=8387;image)

. on left hand two sparky2
. on right hand one nano and one revo.

Previously they could not even be recognized on the PC gcs installation of 16.09 or next r782.
Now they are running fine on the mac on 16.09. But still, if connected with usb to the PC, any version, they don't even get recognized by the gcs.

My goal is to bring all four boards up to next r782.

The two openpilot boards can be identified when using Rescue, but non of the Sparkys can.

I have a second mac and think to install only next r782 on it and try erase and upgrade...
good idea?


Update
YES a good idea - all four boards now running fine under next r782 on that second Mac that only have LP next r782 installed.


Maybe later find out - What to do with this PC?
its my preferred machine for play/hobby.


Title: Re: Position hold on a fixed wing - Altitude control mystery
Post by: karla on December 26, 2019, 01:17:16 am
I think some of the values in this table are not filled correctly, especially the LP defaults.

Thank you for your explanations in that post, clear and very helpful.
I will have a look at the table and sort out any errors since its helpful to compare and build more understanding of the different settings for fixed wings. Need to get my PC in better order since it may have some overlapping installations of librepilot versions.