Anteworld - Outerra Game > JavaScript development

activate autopilot in new plane script

<< < (2/2)

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

andfly:
 :) :) :)

fly77:
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: ---<?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>


--- End code ---

Navigation

[0] Message Index

[*] Previous page

Go to full version