Board index FlightGear Development Nasal

Setting maximum bank angle

Nasal is the scripting language of FlightGear.

Setting maximum bank angle

Postby jamesBG » Mon May 07, 2018 7:31 am

Hi,

I am writing an autopilot to follow certain patterns. Currently I am trying to get the plane to fly in a square (squarish), but it seems to have a maximum bank angle of 20 degrees. This means that even at very low speeds it takes too long to turn 90 degrees. Is there a way to allow the autopilot to change to a greater bank angle?
jamesBG
 
Posts: 9
Joined: Fri May 04, 2018 7:37 am

Re: Setting maximum bank angle

Postby curt » Mon May 07, 2018 12:01 pm

Each autopilot component can have a u_min and u_max value that clamps the output range. If your aircraft has it's own autopilot config, you can adjust these limits to whatever you like. I would recommend making small changes and then testing carefully. Airplanes fly in a delicate balance. Steeper banks will require more elevator to keep the plane level and also require a bit more power. Depending on how well the other axes are tuned for your aircraft, you may need to make some PID gain adjustments.

For whatever it's worth, I've been playing around with a TECS (total energy control system) that blends altitude and speed errors together to decide throttle and elevator position. For small UAV's at least, it seems to work quite a bit better than separating the altitude and speed holds and picking which control (throttle vs. elevator) affects speed vs. altitude. One nice thing about the TECS system is you can establish energy error limits that correspond to speed range limits and the system will then never over or under speed your aircraft in climbs and descents. This is currently written for my UAS autopilot system which has diverged from the flightgear system, but it wouldn't be too much work for someone who understands modern C++ to port this back to FlightGear.

https://github.com/AuraUAS/aura-core/bl ... l/tecs.cxx
Aerospace Engineering and Mechanics
University of Minnesota
curt
Administrator
 
Posts: 1174
Joined: Thu Jan 01, 1970 12:00 am
Location: Minneapolis, MN

Re: Setting maximum bank angle

Postby Alant » Mon May 07, 2018 1:26 pm

As you are writing your own autopilot in nasal and we have not seen your code, it is a bit difficult to guess what is wrong.

Alan
Alant
 
Posts: 904
Joined: Wed Jun 23, 2010 5:58 am
Location: Portugal
Callsign: Tarnish99
Version: from Git
OS: Windows 10

Re: Setting maximum bank angle

Postby curt » Mon May 07, 2018 2:13 pm

I do notice that the generic autopilot target roll component has u_min/u_max set to +/- 20 degrees. I'm guessing that is probably what the original poster has encountered. But you are right, without more details we are just guessing, hopefully our guesses help a little bit.
Aerospace Engineering and Mechanics
University of Minnesota
curt
Administrator
 
Posts: 1174
Joined: Thu Jan 01, 1970 12:00 am
Location: Minneapolis, MN

Re: Setting maximum bank angle

Postby jamesBG » Tue May 08, 2018 4:43 am

Thanks for your help. It's probably more accurate to say that I am writing an AI for the autopilot than writing the autopilot itself, so I didn't think code was necessary. At the moment I'm just modifying the value for "/autopilot/settings/heading-bug-deg" every thirty seconds.

The aircraft I'm using doesn't have it's own autopilot config, is it possible to write one to just update u_min/u_max? Or would you recommend using a plane which already has one?
jamesBG
 
Posts: 9
Joined: Fri May 04, 2018 7:37 am

Re: Setting maximum bank angle

Postby curt » Tue May 08, 2018 2:19 pm

You could always start with a copy the generic autopilot and make a custom autopilot for your aircraft. Honestly, the generic autopilot was not intended/expected to work well for most airplanes. It is more by luck that it does anything useful. Every airplane is different, so realistically the autopilot should be tuned for each airplane specifically to achieve optimal performance. In that context, I don't think it's a bad thing to grab a copy of the generic autopilot and make specific adjustments for your aircraft and for your performance objectives. There is also a lot of subjectivity that can go into autopilot tuning ... at least in the sense of what you wish to optimize ... do you want the fastest/tightest convergence with the target values? Do you want to minimize overshoot? Do you want to give the passengers a smooth ride? Maybe you want to hold airspeed really carefully, but can be more flexible with altitude (or visa versa.) In your case, you probably just want to increase the roll limits, so you could modify your installed version of the generic autopilot in fgdata, or you could make a copy for your specific aircraft, in your aircraft config point to your version, and then make modifications there. Lots of options and choices! You might be able to even adjust some of the limits and gains on-the-fly from a nasal script or external telnet interface.
Aerospace Engineering and Mechanics
University of Minnesota
curt
Administrator
 
Posts: 1174
Joined: Thu Jan 01, 1970 12:00 am
Location: Minneapolis, MN

Re: Setting maximum bank angle

Postby jamesBG » Wed May 09, 2018 2:34 am

Thanks for your help Curt.

For ease I decided to try a different plane (Honda Jet) and modify its autopilot, I changed the u_max and u_min for Heading Bug Hold to -40 and 40 degrees (To see what would happen), I found that it made no difference to the 20 degree target bank angle. Is there something else I should be looking at?
This is the xml, the original angle is commented out. Strangely it is set to 22 but the plane still banks at 20, like with my change.

Code: Select all
<pid-controller>
    <name>Heading Bug Hold (DG based) Stage 1</name>
    <debug>false</debug>
    <enable>
      <prop>/autopilot/locks/roll</prop>
      <value>dg-heading-hold</value>
    </enable>
    <input>
      <prop>/autopilot/internal/heading-bug-error-deg</prop>
    </input>
    <reference>
      <value>0.0</value>
    </reference>
    <output>
      <prop>/autopilot/internal/target-roll-deg</prop>
    </output>
    <config>
      <Kp>-1.0</Kp>
      <beta>1.0</beta>
      <alpha>0.1</alpha>
      <gamma>0.0</gamma>
      <Ti>10.0</Ti>
      <Td>0.00001</Td>
      <u_min>-40.0</u_min>  <!-- -22.0</u_min> -->
      <u_max>40.0</u_max>   <!-- 22.0</u_max> -->
    </config>
  </pid-controller>
jamesBG
 
Posts: 9
Joined: Fri May 04, 2018 7:37 am

Re: Setting maximum bank angle

Postby curt » Wed May 09, 2018 2:56 am

I probably can't touch the honda jet myself because of a promise I made to the lawyers from a certain company that shall remain nameless, but I'd check that you really loaded the autopilot config you thought you loaded.

I guess I'm rusty, I can't find if the autopilot config is loaded anywhere in the property tree? Or maybe the autopilot module just loads a temporary copy to build the c++ classes and the discards the config after that? If it is somewhere in the property tree you could inspect the values and make sure they are the ones you expected (and possibly even change them on the fly ... Torsten: I thought we used to be able to do this, but I'm not seeing it now.)

It's possible something else is also clamping the values? It might be worth editing some ghastly values into the autopilot config just to make very sure you are editing the right file. And then if you still aren't getting any positive result, start greping to see if you can find any other code or config in the aircraft setup that could be doing this.

Curt.
Aerospace Engineering and Mechanics
University of Minnesota
curt
Administrator
 
Posts: 1174
Joined: Thu Jan 01, 1970 12:00 am
Location: Minneapolis, MN

Re: Setting maximum bank angle

Postby Thorsten » Wed May 09, 2018 4:37 am

I can't find if the autopilot config is loaded anywhere in the property tree?


AP/property rules essentially works like JSBSim - the output of each tag is a property written to the location you specify. Of course it also needs to be picked up by the plane...
Thorsten
 
Posts: 10820
Joined: Mon Nov 02, 2009 8:33 am

Re: Setting maximum bank angle

Postby Alant » Wed May 09, 2018 10:36 am

Don´t tell Curt but I have a copy of the banned Honda on an old archive disc and am looking at the file zkv1000\Systems\autopilot.xml.

I would look at the /autopilot/internal/heading-bug-error-deg, /autopilot/internal/target-roll-deg, and any other properties that are in the flow between your initial heading command and /controls/flight/aileron.
Also check that the correct condition i.e. /autopilot/locks/roll</prop> = dg-heading-hold
is being set to enable heading bug mode.

You also need to make sure that this file (zkv1000\Systems\autopilot.xml.) is being loaded at start. The zkv1000 system does this with nasal in the init_afcs section of zkv1000\Systems\autopilot.xml.Nasal\afcs.nas:-
if (getprop("/sim/systems/autopilot/path") == "Aircraft/Generic/generic-autopilot.xml") {
setprop("/sim/systems/autopilot/path", "Aircraft/xxxxJet/zkv1000/Systems/autopilot.xml");

You can also do it the more conventional way by putting
<systems>
<autopilot>
<path>Aircraft/xxxxJet/zkv1000/Systems/autopilot.xm</path>
</autopilot>
</systems>

in your xxxxjet-set.xml file.

Alan
Alant
 
Posts: 904
Joined: Wed Jun 23, 2010 5:58 am
Location: Portugal
Callsign: Tarnish99
Version: from Git
OS: Windows 10

Re: Setting maximum bank angle

Postby jamesBG » Fri May 11, 2018 6:07 am

I tried both the changes to xxxxjet-set and the afcs.nas file already has "if (getprop("/sim/systems/autopilot/path") == "Aircraft/Generic/generic-autopilot.xml") { setprop("/sim/systems/autopilot/path", "Aircraft/xxxxJet/zkv1000/Systems/autopilot.xml");" set.
The autopilot path is set correctly when looking at the property tree (in flight) but the angle won't move from 20 degrees.

As Curt suggested I checked each file (using a bash script) within the xxxxjet folder to look for something that might be holding this to 20 degrees, but I can't seem to find anything. Could it potentially be something to do with something outside the xxxxjet?

@Alant I'm not quite sure what I am looking for between the heading command and /controls/flight/aileron (I am quite new to flightgear). /controls/flight/aileron does appear twice in the code, I'm not sure if this means anything? I have posted the autopilot.xml for roll below. Where can I look to find out what Kp, beta, alpha, gamma, Ti and Td are?

Should I be avoiding the xxxxjet if there are legal issues? I am using flightgear as a simulator for a thesis.

Code: Select all
<pid-controller>
    <name>Wing Leveler (Turn Coordinator based)</name>
    <debug>false</debug>
    <enable>
      <condition>
        <and>
          <equals>
            <property>/autopilot/locks/roll</property>
            <value>wing-leveler</value>
          </equals>
          <not>
            <property>/autopilot/locks/passive-mode</property>
          </not>
        </and>
      </condition>
    </enable>
    <input>
      <prop>/instrumentation/turn-indicator/indicated-turn-rate</prop>
    </input>
    <reference>
      <value>0.0</value>
    </reference>
    <output>
      <prop>/controls/flight/aileron</prop>
    </output>
    <config>
      <Kp>0.5</Kp>
      <beta>1.0</beta>
      <alpha>0.1</alpha>
      <gamma>0.0</gamma>
      <Ti>10.0</Ti>
      <Td>0.00001</Td>
      <u_min>-1.0</u_min>
      <u_max>1.0</u_max>
    </config>
  </pid-controller>

  <pid-controller>
    <name>Heading Bug Hold (DG based) Stage 1</name>
    <debug>false</debug>
    <enable>
      <prop>/autopilot/locks/roll</prop>
      <value>dg-heading-hold</value>
    </enable>
    <input>
      <prop>/autopilot/internal/heading-bug-error-deg</prop>
    </input>
    <reference>
      <value>0.0</value>
    </reference>
    <output>
      <prop>/autopilot/internal/target-roll-deg</prop>
    </output>
    <config>
      <Kp>-1.0</Kp>
      <beta>1.0</beta>
      <alpha>0.1</alpha>
      <gamma>0.0</gamma>
      <Ti>10.0</Ti>
      <Td>0.00001</Td>
      <u_min>-40.0</u_min>  <!-- -22.0</u_min> -->
      <u_max>40.0</u_max>   <!-- 22.0</u_max> -->
    </config>
  </pid-controller>

  <pid-controller>
    <name>NAV Hold Stage 1</name>
    <debug>false</debug>
    <enable>
      <prop>/autopilot/locks/roll</prop>
      <value>nav1-hold</value>
    </enable>
    <input>
      <prop>/instrumentation/zkv1000/cdi/course-deflection</prop>
    </input>
    <reference>
      <value>0.0</value>
    </reference>
    <output>
      <prop>/autopilot/internal/target-roll-deg</prop>
    </output>
    <config>
      <Kp>-1.0</Kp>
      <beta>1.0</beta>
      <alpha>0.1</alpha>
      <gamma>0.0</gamma>
      <Ti>10.0</Ti>
      <Td>0.00001</Td>
      <u_min>-40.0</u_min>  <!-- -22.0</u_min> -->
      <u_max>40.0</u_max>   <!-- 22.0</u_max> -->
    </config>
  </pid-controller>

  <pid-controller>
    <name>Approach mode Stage 1</name>
    <debug>false</debug>
    <enable>
      <prop>/autopilot/locks/roll</prop>
      <value>APR</value>
    </enable>
    <input>
      <prop>/instrumentation/zkv1000/cdi/course-deflection</prop>
    </input>
    <reference>
      <value>0.0</value>
    </reference>
    <output>
      <prop>/autopilot/internal/target-roll-deg</prop>
    </output>
    <config>
      <Kp>-1.0</Kp>
      <beta>1.0</beta>
      <alpha>0.1</alpha>
      <gamma>0.0</gamma>
      <Ti>10.0</Ti>
      <Td>0.00001</Td>
      <u_min>-40.0</u_min>  <!-- -22.0</u_min> -->
      <u_max>40.0</u_max>   <!-- 22.0</u_max> -->
    </config>
  </pid-controller>

  <pid-controller>
    <name>Ailerons control</name>
    <debug>false</debug>
    <enable>
      <condition>
        <and>
          <not-equals>
            <property>/autopilot/locks/roll</property>
            <value>wing-leveler</value>
          </not-equals>
          <not>
            <property>/autopilot/locks/passive-mode</property>
          </not>
        </and>
      </condition> 
      <honor-passive>true</honor-passive>
    </enable>
    <input>
      <prop>/orientation/roll-deg</prop>
    </input>
    <reference>
      <prop>/autopilot/internal/target-roll-deg</prop>
    </reference>
    <output>
      <prop>/controls/flight/aileron</prop>
    </output>
    <config>
      <Kp>0.1</Kp>
      <beta>1.0</beta>
      <alpha>0.1</alpha>
      <gamma>0.0</gamma>
      <Ti>10.0</Ti>
      <Td>0.00001</Td>
      <u_min>-1.0</u_min>
      <u_max>1.0</u_max>
    </config>
  </pid-controller>
jamesBG
 
Posts: 9
Joined: Fri May 04, 2018 7:37 am

Re: Setting maximum bank angle

Postby Thorsten » Fri May 11, 2018 8:18 am

I tried both the changes to xxxxjet-set and the afcs.nas file already has "if (getprop("/sim/systems/autopilot/path") == "Aircraft/Generic/generic-autopilot.xml") { setprop("/sim/systems/autopilot/path", "Aircraft/xxxxJet/zkv1000/Systems/autopilot.xml");" set.
The autopilot path is set correctly when looking at the property tree (in flight) but the angle won't move from 20 degrees.


I'd be surprised if that would work, because according to my understanding FDM/AP/property rules are set up at FG init time and Nasal is initialized somewhat later - so by the time you set the path property the value is no longer read.

I'm not sure what exactly you're trying to do - there's dozens of planes which come with their own APs - why can't you simply start with one of them and study how it's done?

Also, I'm not sure what exactly you're looking for, but if it's for a thesis, a JSBSim plane with the AP also implemented on the JSBSim level might give you much more flexibility in its ability to run it in standalone mode - if you're using the FG-side AP/property rules, you always have to deal with the (at times weird) interaction between two separate modules.

I can point you at APs I've implemented in JSBSim (or with high level Nasal decisionmaking code) - a simple example is the Alouette-III helicopter which has both a 'true' AP for level flight and heading bug and a more sophisticated AP simulating the co-pilot being able to take off and hover the helicopter.

Possibly the most complex example of an AP in FG is the Space Shuttle, it can basically do everything the real thing can (launch, entry, launch abort trajectories, low energy entries, contingency Nz holding entries, orbital attitude management, orbital correction burns, atmospheric flight,...) This is an example of a high-level decisionmaking layer written in Nasal combined with a low-level JSBSim system to hold attitude targets and transit between the various control modes.

Should I be avoiding the xxxxjet if there are legal issues? I am using flightgear as a simulator for a thesis.


The simple answer is - probably yes. Honda claimed that using the model is a copyright infringement, that wasn't contested by Curt and the model was removed instead, if you now dig up and use the plane and even publish something with it, chances are you might get a nice letter from Honda lawyers and find yourself arguing how far the freedom of research gets you (or you might not) - basically any other plane you can choose has no such history.
Thorsten
 
Posts: 10820
Joined: Mon Nov 02, 2009 8:33 am

Re: Setting maximum bank angle

Postby curt » Fri May 11, 2018 11:25 am

Typically you would specify the autopilot config file to load in the <aircraft>-set.xml file. As Thorsten commented, changing the path via nasal is probably going to happen too late. Maybe it would work if you called for an ap reinit after changing the path (?) but I've never tried to do it that way so I don't know.

If there is a question about which file is actually being loaded, you could even go so far as to put an obvious syntax error in the file (temporarily of course!) and see if flightgear barfs or not. Sometimes you have to work backwards a couple steps and verify some basic things before working forward to debug a specific issue. At my day job we were hung up on trying to figure out why a config value in some firmware was getting corrupted after it was set. Turns out that section of code wasn't even getting run due to a json parse error earlier in the function -- and the error checking logic wasn't all quite nested properly, so the unset value was just inheriting whatever was randomly in the memory slot from something earlier. Mine was a totally different issue of course, but the point being that sometimes it's worth backing up a couple levels just to make sure you are working with the thing you think you are working with.
Aerospace Engineering and Mechanics
University of Minnesota
curt
Administrator
 
Posts: 1174
Joined: Thu Jan 01, 1970 12:00 am
Location: Minneapolis, MN

Re: Setting maximum bank angle

Postby Thorsten » Fri May 11, 2018 12:57 pm

but the point being that sometimes it's worth backing up a couple levels just to make sure you are working with the thing you think you are working with


Amen... The number of hours I've wasted trying to figure out why a change in a file that wasn't even loaded didn't affect what I see is too high to state it in public.
Thorsten
 
Posts: 10820
Joined: Mon Nov 02, 2009 8:33 am


Return to Nasal

Who is online

Users browsing this forum: No registered users and 3 guests