Outerra forum

Please login or register.

Login with username, password and session length
Advanced search  

News:

Download Outerra Tech Demo. Unofficial Outerra Discord server, MicroProse Discord server for OWS.

Author Topic: activate autopilot in new plane script  (Read 10052 times)

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
activate autopilot in new plane script
« on: June 25, 2019, 02:12:25 pm »

I am trying to add autopilot functionality to a plane (modding Levi's Heinkel) following the script of the cessna 172 but I can't get the autopilot functionality to work allthough I copied the lines of codes of the C172 associated with autopilot (see below). CTRL+W works on the C172 to do wingleveling but not on my Heinkel script mod. What I am missing ?
FDM folder structure is as follows..so there is a Autopilot.xml in Systems. should this be enough ?

aircraft
   Heinkel_He51
      Heinkel_He51.xml
      aerodynamics.xml
      flight_control.xml
      ground_reactions.xml
      propulsion.xml
      Systems
           Autopilot.xml
           GNCUtilities.xml
engine
   BMW_VI.xml
   prop.xml

Code: [Select]
var ap_wing_level_switch

function initialize(reload){ 
  jsb = this.jsb();
  ......
  ap_wing_level_switch = 0;
  this.register_event("air/autopilot/wing_leveler", function(v) { ap_wing_level_switch ^= 1; });
}


function update_frame(dt){
......
 jsb['ap/autopilot-roll-on']=ap_wing_level_switch;
}
« Last Edit: June 25, 2019, 02:19:16 pm by fly77 »
Logged

andfly

  • Sr. Member
  • ****
  • Posts: 347
Re: activate autopilot in new plane script
« Reply #1 on: June 26, 2019, 09:36:17 am »

I think it's sufficient to add these two lines of code in the "Heinkel_He51.xml" file

<system file = "GNCUtilities" />
<system file = "Autopilot" />


Now Heinkel should also have an autopilot and utilities.

It should be possible to recall its features with the script.

I wish you good work  :D
Logged
I do not know the English language. I use Google Translate. I hope it's all understandable.

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: activate autopilot in new plane script
« Reply #2 on: June 26, 2019, 02:02:59 pm »

Hi andfly ! nice to hear from you and thanks for the suggestion. Unfortunately there seems to be something other missing or wrong as including these two lines in the Heinkel xml form Levi didn't resolve the problem. What I did is
copy the "Systems" folder from the cessna 172 into the corresponding location of  the Heinkel (see above) so these files are the same as for the cessna. Then added the two lines of code you mention to The Heinkel xml and include the autopilot related javascript code lines (as above) from the cessna to Levi's Heinkel...still doesn't work. Heinkel xml file from Levi with the two added lines reads as below. Autopilot winglevelling works for the cessna but not for the modded Heinkel

Code: [Select]
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="http://jsbsim.sourceforge.net/JSBSim.xsl"?>
<fdm_config name="Heinkel_He51" version="2.0" release="ALPHA"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:noNamespaceSchemaLocation="http://jsbsim.sourceforge.net/JSBSim.xsd">

 <fileheader>
  <author> Levi Cires </author>
  <filecreationdate>2014-12-15</filecreationdate>
  <version>$Revision: 1.15 $</version>
  <description> Models a Heinkel_He51. </description>
 </fileheader>

<!--
  File:     Heinkel_He51.xml
  Inputs:
    name:          Heinkel_He51
    type:          light single
    max weight:    4180 lb
    wing span:     36.08333333333334 ft
    length:        27.5591 ft
    wing area:     292.6 sq-ft
    gear type:     taildragger
    retractable?:  no
    # engines:     1
    engine type:   piston
    engine layout: forward fuselage
    yaw damper?    no

  Outputs:
    wing loading:  14.29 lb/sq-ft
    payload:       349.4 lbs
    CL-alpha:      5 per radian
    CL-0:          0.25
    CL-max:        1.4
    CD-0:          0.028
    K:             0.04

-->

 <metrics>
   <wingarea  unit="FT2">  292.60 </wingarea>
   <wingspan  unit="FT" >   36.08 </wingspan>
   <wing_incidence>          2.00 </wing_incidence>
   <chord     unit="FT" >    8.11 </chord>
   <htailarea unit="FT2">   25.00 </htailarea>
   <htailarm  unit="FT" >   14.33 </htailarm>
   <vtailarea unit="FT2">   80.00 </vtailarea>
   <vtailarm  unit="FT" >   13.78 </vtailarm>
   <location name="AERORP" unit="M">
     <x>   0.00 </x>
     <y>   0.00 </y>
     <z>   0.00 </z>
   </location>
   <location name="EYEPOINT" unit="M">
     <x>  0.00 </x>
     <y>  0.00 </y>
     <z>  0.00 </z>
   </location>
   <location name="VRP" unit="M">
     <x>0</x>
     <y>0</y>
     <z>0</z>
   </location>
 </metrics>

 <mass_balance>
   <ixx unit="SLUG*FT2">      2367 </ixx>
   <iyy unit="SLUG*FT2">      2455 </iyy>
   <izz unit="SLUG*FT2">      4454 </izz>
   <emptywt unit="LBS" >      3212 </emptywt>
   <location name="CG" unit="M">
     <x>   0.00 </x>
     <y>   0.00 </y>
     <z>   0.00 </z>
   </location>
   <pointmass name="Payload">
    <description> 349 LBS + full (619 LBS) fuel should bring model up to entered max weight</description>
    <weight unit="LBS">    174.7 </weight>
    <location name="POINTMASS" unit="M">
      <x>   0.50 </x>
      <y>   0.00 </y>
      <z>   0.00 </z>
    </location>
  </pointmass>
 </mass_balance>

<ground_reactions file="ground_reactions"/>
<propulsion file="propulsion"/>
<flight_control file="flight_control"/>
<aerodynamics file="aerodynamics"/>
<system file="GNCUtilities"/>
<system file="Autopilot"/>
</fdm_config>
« Last Edit: June 26, 2019, 02:28:44 pm by fly77 »
Logged

andfly

  • Sr. Member
  • ****
  • Posts: 347
Re: activate autopilot in new plane script
« Reply #3 on: June 26, 2019, 03:01:31 pm »

Here I am denied immediately ....

I was convinced that it was all there ...

The only further advice is to insert the two new lines of code between the definitions of the propulsion and those of the flight_control because it is exactly there that they are placed in the file of the cessna (however I believe little that this is really influential)

<ground_reactions file="ground_reactions"/>
<propulsion file="propulsion"/>
<system file = "GNCUtilities" />
<system file = "Autopilot" />

<flight_control file="flight_control"/>
<aerodynamics file="aerodynamics"/>

I also noticed that at the end of the cessna script there are (disabled) lines of "log" concerning the parameters of the autopilot ...
Try enabling them to see if the autopilot is really dead or just "out of phase".

//Autopilot DEBUG
 // this.log("AP Wing Level Hold: " + ap_wing_level_switch);
 // this.log("AP Roll Cmd Norm: " + this.jsbsim['ap/roll-cmd-norm-output']);
 // this.log("AP Roll Mode: " + this.jsbsim['ap/roll-attitude-mode']);
 // this.log("AP Roll On/Off: " + this.jsbsim['ap/autopilot-roll-on']);
 // this.log("Aileron Cmd Norm: " + this.jsbsim['fcs/aileron-cmd-norm']);

(replacing this.jsbsim with jsb)

I don't know what else to tell you ...
I leave the word to the real experts of JSBSim.

Still good work and have fun!   ;)
Logged
I do not know the English language. I use Google Translate. I hope it's all understandable.

andfly

  • Sr. Member
  • ****
  • Posts: 347
Re: activate autopilot in new plane script
« Reply #4 on: June 27, 2019, 05:41:13 pm »

I discovered the mystery!

Meanwhile, I have verified that, with the added lines of code that we talked about before, the autopilot is inserted into the commands of the aircraft and works properly.
The thing that is still missing is the possibility, for Heinkel, to receive the commands of the autopilot and to implement them.

If you open the Heinkel file concerning the "flight_control" (flight_control.xlml), in particular, in the <channel name = "Roll"> you read this code:

<summer name = "Roll Trim Sum">
      <Input> FCS / aileron-cmd-norm </ input>
      <Input> FCS / roll-trim-cmd-norm </ input>
      <Clipto>
        <min> -1 </min>
        <max> 1 </max>
      </ Clipto>
   </ Summer>

               

In the corresponding Cessna file (c172r.xml), in the "flight_control" section, you will find this:

 <summer name = "Roll Trim Sum">
                <Input> ap / roll-cmd-norm-output </ input>
                <Input> FCS / aileron-cmd-norm </ input>
                <Input> FCS / roll-trim-cmd-norm </ input>
                <Clipto>
                    <Min> -1 </ min>
                    <Max> 1 </ Max>
                </ Clipto>
            </ Summer>



You will immediately notice the missing line, in the Heinkel file, which refers to the possibility of input also of the results of the autopilot calculations.
It is therefore sufficient to add this line of code and the autopilot will be able to influence the stability of the aircraft (I checked: It works!)

I no longer have much time to devote myself to Outerra, but I am happy to follow the developments of the work of the fans who publish on the forum.
I must congratulate you on the results obtained.

I wish you good work and good fun again   =D
Logged
I do not know the English language. I use Google Translate. I hope it's all understandable.

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: activate autopilot in new plane script
« Reply #5 on: June 27, 2019, 06:31:11 pm »

Great andfly ! It works also for me ! Thank you so much for your precious time and your help! Thank you also for the kind words  :) We really miss your contribution but when I have time I will study some of your older models such as the birds for instance...still there is so much to learn for me...and the more I understand the more possibilities open and the more fun outerra gets...With the Heinkel's new capabilities that I'll share soon and anti-aircraft AI guns that can be placed at will there's already enough for some real war game level challenge!  Will try to get also altitude and heading hold working again..I remember it worked before for the cessna in older outerra versions but now only the roll stabilizer seems implemented in the Cessna autopilot.xml  file..Will have to study JSBSIM as well  =|  but slowly slowly and with the some help of you users I'll get there  ;)    and share all the fun with all of you.  =D
« Last Edit: June 27, 2019, 06:36:49 pm by fly77 »
Logged

andfly

  • Sr. Member
  • ****
  • Posts: 347
Re: activate autopilot in new plane script
« Reply #6 on: June 27, 2019, 07:54:32 pm »

 :) :) :)
Logged
I do not know the English language. I use Google Translate. I hope it's all understandable.

fly77

  • Outerra Master Modder
  • Hero Member
  • *****
  • Posts: 1761
Re: activate autopilot in new plane script
« Reply #7 on: June 28, 2019, 02:17:12 pm »

wing-leveler and altitude hold autopilot in action ! Bob's autopilot flying Heinkel at 1000 m above sealevel.


Here is the Autopilot.xml file (inspired by https://flightgear-devel.narkive.com/5aIUUhwA/jsbsim-altitude-hold-autopilot-example: )
Tomorrow will implement "heading hold"  ^-^

Code: [Select]
<?xml version="1.0"?>
<system name="Autopilot"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation="http://jsbsim.sourceforge.net/JSBSimSystem.xsd">

<!-- #######################################################################

  Author:   Jon Berndt
  Date:     January 2009
  Function: Autopilot

  Description:

  This file contains general purpose autopilot functions for JSBSim aircraft.
 
  Usage
  =====
 
  This file contains algorithms that depend on parameters calculated in the
  file, GNCUtilities.xml, which should be included prior to the inclusion of
  this file, e.g.,
 
  <system file="GNCUtilities"/>

  <system file="Autopilot"/>
   
  Inputs:

    [Declared Interface Parameters]
    ap/roll-attitude-mode - This should be set to 0 for wings level or to 1
                            for roll angle hold.
    ap/autopilot-roll-on - this is either 0 (off) or 1. This turns the roll
                           autopilot on or off.

    [Overridable constants]
    guidance/roll-angle-limit = 0.524 (default value in radians)
    guidance/roll-rate-limit = 0.174 (default value in radians)

  Introduced parameters (temporary terms):

  Outputs:
    ap/roll-cmd-norm-output - roll command to the flight control roll channel
                              in a normalized range from -1 to +1.

######################################################################## -->

  <property> ap/roll-attitude-mode </property>
  <property> ap/autopilot-roll-on  </property>
  <property> ap/altitude_hold </property>
 
  <property> ap/elevator_cmd </property>
  <property> ap/altitude_setpoint </property>
 
 
  <!-- Initial constants (can be overridden in the aircraft file) -->

  <property value="0.524"> guidance/roll-angle-limit </property>
  <property value="0.174"> guidance/roll-rate-limit </property>

  <property value="0"> ap/roll-angle-saturation </property>
 
 
 
 

<!-- #################################################################### -->

    <channel name="Heading Hold">

<switch name="ap/roll-control-autopilot-on">
          <default value="0"/>
          <test value="1">
            ap/autopilot-roll-on ne 0.0
          </test>
</switch>

<switch name="ap/roll-autopilot-windup-trigger">
           <default value="1"/>
           <test value="1">
             ap/roll-angle-saturation ne 0.0
           </test>
           <test value="0">
              ap/roll-control-autopilot-on gt 0
           </test>
</switch>

<pure_gain name="ap/limited-roll-angle-rad">
          <description>
This component takes as input the angle to the target heading from
the current heading, as calculated by the Angle to Heading channel
in the GNC Utilities system file. The output of this component (stored)
in the component property "ap/limited-roll-angle-rad" is the roll
angle command, which is just the correct-sense heading error, but
nominally limited at 30 degrees (0.524 radians), though this can be
overridden.
</description>
<input> guidance/angle-to-heading-rad </input>
    <gain> guidance/angle-to-heading-sense </gain>
    <clipto>
<min> -guidance/roll-angle-limit </min>
<max>  guidance/roll-angle-limit </max>
    </clipto>
</pure_gain>

<switch name="ap/roll-attitude-selector">
<description>
This component selects whether to use a roll angle of "0" - which
is a wings-level attitude - or to use the roll angle commanded by the
ap/limited-roll-angle-rad component, above, which is used to acquire
and hold a heading.
Set ap/roll-attitude-mode to 1 for roll angle hold,
  to 0 for wings level (roll attitude of zero).
</description>
<default value="0"/>
<test value="ap/limited-roll-angle-rad">
ap/roll-attitude-mode eq 1
</test>
</switch>
   
<summer name="ap/limited-roll-angle-error">
  <description>
This component computes the error between the calculated target roll
angle and the actual roll angle. The output is interpreted as a roll
rate command.
  </description>
  <input>  ap/roll-attitude-selector </input>
  <input> -attitude/phi-rad </input>
</summer>

<pid name="ap/roll-rate-pid-control">
<input> ap/limited-roll-angle-error </input>
<kp> 30 </kp>
<ki> 0.1  </ki>
<kd> 0.1  </kd>
<trigger> ap/roll-autopilot-windup-trigger </trigger>
<clipto>
<min> -guidance/roll-rate-limit </min>
<max>  guidance/roll-rate-limit </max>
</clipto>
</pid>

<pure_gain name="ap/total-limited-roll-rate">
<input>guidance/roll-rate-limit</input>
<gain>2.0</gain>
</pure_gain>
   
<deadband name="ap/roll-rate-saturation">
<input> ap/roll-rate-pid-control </input>
<width> ap/total-limited-roll-rate </width>
</deadband>

<summer name="ap/limited-roll-rate-error">
<description>
This component computes the error between the calculated target roll
rate and the actual roll rate. The output is interpreted as an aileron
command.
</description>
<input> ap/roll-rate-pid-control </input>
<input> -velocities/p-aero-rad_sec </input>
</summer>

<pid name="ap/roll-command-pid-control">
<input> ap/limited-roll-rate-error </input>
<kp>2.5</kp>
<ki>0.0</ki>
<kd>0.0</kd>
  <trigger> ap/roll-autopilot-windup-trigger </trigger>
</pid>

<lag_filter name="ap/roll-cmd-smoother">
<input> ap/roll-command-pid-control </input>
<c1> 100.0 </c1>
</lag_filter>

       <switch name="ap/roll-cmd-norm-output">
<default value="0"/>
<test value="ap/roll-cmd-smoother">
ap/roll-control-autopilot-on ne 0.0
</test>
</switch>

       <!-- <switch name="ap/roll-command-selector-steering">
      <default value="0.0"/>
      <test value="ap/roll-cmd-norm-output">
        ap/roll-control-autopilot-on == 1
        gear/unit[0]/WOW == 1
      </test>
      <output>fcs/steer-cmd-norm</output>
      </switch> -->

</channel>


    <channel name = "Altitude Hold">

<summer name= "ap/altitude-error">  
<input> -position/h-sl-ft </input>
<input> ap/altitude_setpoint </input>
<clipto>
  <min> -100 </min>
  <max>  100 </max>
</clipto>
</summer>

<lag_filter name="ap/alt-error-lag">
<description> filter the altitude-error ...I guess to smooth it out over time interval c1 </description>
<input> ap/altitude-error </input>
<c1> 0.25 </c1>
</lag_filter>

<pure_gain name="ap/hdot-command">
<input> ap/alt-error-lag </input>
<gain> 0.1 </gain>
</pure_gain>

<summer name= "ap/hdot-error">
<description> difference between filtered altitude error and actual rate of climb </description>
<input> ap/hdot-command</input>
<input> -velocities/h-dot-fps </input>         
</summer>

<switch name="ap/ap-alt-hold-switch">
<description> either the hdot-error (climb rate error) or zero is returned depending on wether autopilot is switched on or not </description>         
<default value="0"/>  
<test logic = "AND" value = "ap/hdot-error">
ap/altitude_hold == 1
</test>
</switch>

<integrator name = "ap/integral">
<input> ap/ap-alt-hold-switch </input>
<c1> 0.0041 </c1>    
</integrator>

<pure_gain name = "ap/proportional">
<input> ap/ap-alt-hold-switch </input>
<gain> 0.035 </gain>
</pure_gain>

<summer name="ap/control-summer"> 
<description> selfmade PI(D)controller ...no derivative...just proportional and integral  </description>
<input> ap/integral </input>
<input> ap/proportional </input>
<clipto>
   <min> -1 </min>
   <max>  1 </max>
</clipto>
</summer> 

<pure_gain name="ap/elevator">
<input> ap/control-summer </input>
<gain> -1.0 </gain>
<output> ap/elevator_cmd  </output>
</pure_gain>


</channel>
 
</system>

« Last Edit: June 28, 2019, 02:19:54 pm by fly77 »
Logged