[原]JSBSim 自动驾驶(浅出)

jsbsim的脚本文件分为几大类:

1.系统脚本:

systems  包含通用飞机各部分功能模块组件以及自动飞行控件:Autopilot.xml  和 自动飞行的算法控件:GNCUtilities.xml

2.引擎脚本:

engine:包含各个飞机的发动机控件

3.飞机脚本:

aircraft:包含各个飞机的控件、输入输出、初始化参数

4.控制脚本:

scripts:一次飞行模拟的全过程

现在来分析一次自动驾驶飞行所使用的部分脚本,以及脚本中的参数意义。

分析:C172的自动驾驶飞行

脚本文件scripts中找到c1722.xml文件

 1   <use aircraft="c172x" initialize="reset01"/>
 2   <run start="0.0" end="200" dt="0.00833333">
 3     
 4     <event name="Engine start">
 5       <condition>simulation/sim-time-sec  ge  0.25</condition>
 6       <set name="fcs/throttle-cmd-norm" value="0.65"/>
 7       <set name="fcs/mixture-cmd-norm" value="0.87"/>
 8       <set name="propulsion/magneto_cmd" value="3"/>
 9       <set name="propulsion/starter_cmd" value="1"/>
10       <set name="ap/heading_hold" value="0"/>
11       <notify>
12         <property>velocities/vc-kts</property>
13         <property>position/h-agl-ft</property>
14       </notify>
15     </event>
16     
17     <event name="Trim">
18       <condition>simulation/sim-time-sec  ge  0.50</condition>
19       <set name="simulation/do_simple_trim" value="0"/>
20       <notify>
21         <property>velocities/vc-kts</property>
22         <property>position/h-agl-ft</property>
23       </notify>
24     </event>
25 
26     <event name="Set roll autopilot">
27       <condition>simulation/sim-time-sec  ge  5.0</condition>
28       <set name="ap/attitude_hold" value="1"/>
29       <notify>
30         <property>velocities/vc-kts</property>
31         <property>position/h-agl-ft</property>
32       </notify>
33     </event>
34 
35   </run>

第一行:可以看到飞机文件用的是c172x.xml  初始化文件用的是:reset01.xml

第二行:表示执行的过程,0到200秒,间隔帧数是0.008秒

第四行:event代表事件处理:

    遇到condition的条件成立就执行后面的set步骤

以上是整体框架。

下面开启我们的疑问列表

  1.飞机文件c172x.xml是干什么的?初始化文件又初始化哪些东西?

  2.第五行中的  sim-time-sec是什么意思?表达式是完成什么条件?

  3.哪些和自动飞行控制有关?

   。。。。。。

1.飞机文件c172x.xml是干什么的?初始化文件又初始化哪些东西?

答1:飞机文件c172x.xml是在“飞机脚本aircraft”文件夹下的c172x文件夹中,

初始化文件reset01.xml也在这个文件夹中。

初始化文件很简单:

<initialize name="reset00">
  <vt unit="KTS">        100.0  </vt>
  <latitude unit="DEG">   28.0  </latitude>
  <longitude unit="DEG"> -90.0  </longitude>
  <psi unit="DEG">       200.0  </psi>
  <altitude unit="FT">   4000.0  </altitude>
  <running>                0    </running>
</initialize>

初始化了飞机的位置,姿态等信息

飞机定义文件c172x.xml包含了很多东西,但我们只关心部分代码:

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

    <system file="Autopilot">
      <property value="0.523"> guidance/roll-angle-limit </property>
      <property value="0.174"> guidance/roll-rate-limit </property>
    </system>
    
    <autopilot file="c172ap"/>

    <flight_control name="c172">
        <channel name="Pitch">
            <summer name="fcs/pitch-trim-sum">
                <input>ap/elevator_cmd</input>
                <input>fcs/elevator-cmd-norm</input>
                <input>fcs/pitch-trim-cmd-norm</input>
                <clipto>
                    <min>-1</min>
                    <max> 1</max>
                </clipto>
            </summer>

            <aerosurface_scale name="fcs/elevator-control">
                <input>fcs/pitch-trim-sum</input>
                <range>
                    <min>-28</min>
                    <max> 23</max>
                </range>
                <gain>0.01745</gain>
            </aerosurface_scale>

            <actuator name="fcs/elevator-actuator">
              <input> fcs/elevator-control </input>
              <lag> 60 </lag>
              <bias> 0.002 </bias>
              <hysteresis_width> 0.05 </hysteresis_width>
              <clipto>
                <!-- +/- 20 degrees -->
                <min> -0.34 </min>
                <max>  0.34 </max>
              </clipto>
              <output>fcs/elevator-pos-rad</output>
            </actuator>

        </channel>
  。。。

这里我们看到:飞机文件引用了两个和自动飞行相关的系统文件:GNCUtilities和 Autopilot

这个两个文件提供通用的自动飞行算法和组件

接着我们又看到这个c172飞机自定义了一个自动飞行的文件:c172ap

我们的问题列表又多了一个问题:4.自定义自动飞行文件c172ap做了哪些事情?

问题保留,我们接着看这个飞机文件:

飞机脚本文件提供了自己的飞行控制组件

<flight_control name="c172">

这个里面又分成很多部分,我们只看一个通道:Pitch

里面有一个加法器定义一个属性值 <summer name="fcs/pitch-trim-sum">

这个值由三方输入参数构成:

1.ap/elevator_cmd

2.fcs/elevator-cmd-norm

3.fcs/pitch-trim-cmd-norm

其中的2和3都是在jsbsim中有明确绑定的 “成员变量”

只有1我们没见过

我们的问题列表又多了一个问题:5.输入参数ap/elevator_cmd在哪里定义?由什么提供输入?

似乎问题总在加多,但其实都在抽丝剥茧中变少变得更加具体,继续把Pitch通道看完:

我们看到这个加法器属性值fcs/pitch-trim-sum又作为输入参数被下一个算法使用,得到值fcs/elevator-control

这个值fcs/elevator-control又被fcs/elevator-actuator继续输入使用算出最终的输出fcs/elevator-pos-rad

这个通道Pitch就此结束。

这个通道是干什么的?为了计算飞机一个姿态参数的!(此文仅讨论自动驾驶部分)

先跳过其他问题,我们看4.自定义自动飞行文件c172ap做了哪些事情?

答4 这个是一个自定义的c172自动驾驶脚本 用来定义便于自动驾驶计算的一些值和自动驾驶算法 (飞机自动驾驶算法举例)

打开c172ap.xml文件发现自定义输出输出的地方:答5

<!-- INTERFACE PROPERTIES -->

  <property>ap/attitude_hold</property>
  <property>ap/altitude_hold</property>
  <property>ap/heading_hold</property>
  <property>ap/altitude_setpoint</property>
  <property>ap/heading_setpoint</property>
  <property>ap/aileron_cmd</property>
  <property>ap/elevator_cmd</property>
  <property>ap/airspeed_setpoint</property>
  <property>ap/airspeed_hold</property>
  <property>ap/throttle-cmd-norm</property>

<!-- INITIAL GAIN VALUES -->
  
  <property value="0.5"> ap/hdg-roll-err-c1 </property>
  <property value="50.0"> ap/roll-pid-kp </property>
  <property value="5.0"> ap/roll-pid-ki </property>
  <property value="17.0"> ap/roll-pid-kd </property>

  <!--  <property>attitude/sensor/phi-rad</property> -->

 还有自动驾驶算法函数:

关于c172机翼滚转自动算法 和 偏航自动驾驶算法:(统一为roll通道提供算法,暂时忽略

  1 <!--
  2 =====================================================
  3 ROLL CHANNEL
  4 =====================================================
  5 -->
  6 
  7 <!-- Wing leveler -->
  8 
  9 <channel name="Roll wing leveler">
 10 
 11   <sensor name="fcs/attitude/sensor/phi-rad">
 12     <input> attitude/phi-rad </input>
 13     <lag> 0.5 </lag>
 14     <delay> 2 </delay>
 15     <noise variation="PERCENT" distribution="GAUSSIAN"> 0.05 </noise>
 16     <quantization name="attitude/sensor/quantized/phi-rad">
 17       <bits> 12 </bits>
 18       <min> -3.1416 </min>
 19       <max>  3.1416 </max>
 20     </quantization>
 21     <bias> 0.001 </bias>
 22   </sensor>
 23 
 24   <switch name="fcs/wing-leveler-ap-on-off">
 25     <default value="-1"/>
 26     <test value="0">
 27       ap/attitude_hold == 1
 28     </test>
 29   </switch>
 30 
 31   <pid name="fcs/roll-ap-error-pid">
 32     <input>attitude/phi-rad</input>
 33     <kp> ap/roll-pid-kp </kp>
 34     <ki> ap/roll-pid-ki </ki>
 35     <kd> ap/roll-pid-kd </kd>
 36     <trigger> fcs/wing-leveler-ap-on-off </trigger>
 37   </pid>
 38 
 39   <switch name="fcs/roll-ap-autoswitch">
 40     <default value="0.0"/>
 41     <test value="-fcs/roll-ap-error-pid">
 42       ap/attitude_hold == 1
 43     </test>
 44   </switch>
 45 
 46 </channel>
 47 
 48 <!-- Heading hold -->
 49 
 50 <channel name="Roll heading hold">
 51   <pure_gain name="fcs/heading-true-degrees">
 52     <input>attitude/heading-true-rad</input>
 53     <gain>57.3</gain> <!-- convert to degrees -->
 54   </pure_gain>
 55 
 56   <summer name="fcs/heading-error">
 57     <input> -fcs/heading-true-degrees</input>
 58     <input> ap/heading_setpoint </input>
 59   </summer>
 60 
 61   <switch name="fcs/heading-error-bias-switch">
 62     <default value="0.0"/>
 63     <test value="360.0">
 64       fcs/heading-error lt -180
 65     </test>
 66     <test value="-360.0">
 67       fcs/heading-error gt 180
 68     </test>
 69   </switch>
 70 
 71   <summer name="fcs/heading-corrected">
 72     <input> fcs/heading-error-bias-switch </input>
 73     <input> fcs/heading-error </input>
 74     <clipto>
 75       <min>-30</min>
 76       <max>30</max>
 77     </clipto>
 78   </summer>
 79 
 80   <pure_gain name="fcs/heading-command">
 81     <input> fcs/heading-corrected </input>
 82     <gain> 0.01745 </gain>
 83   </pure_gain>
 84 
 85   <lag_filter name="fcs/heading-roll-error-lag">
 86     <input> fcs/heading-command </input>
 87     <c1> ap/hdg-roll-err-c1 </c1>
 88   </lag_filter>
 89 
 90   <summer name="fcs/heading-roll-error">
 91     <input> fcs/heading-roll-error-lag </input>
 92     <input> -attitude/phi-rad </input>
 93   </summer>
 94 
 95   <switch name="fcs/heading-roll-error-switch">
 96     <default value="0.0"/>
 97     <test value="fcs/heading-roll-error">
 98       ap/heading_hold == 1
 99     </test>
100   </switch>
101 
102   <pid name="fcs/heading-pi-controller">
103     <input> fcs/heading-roll-error-switch </input>
104     <kp> 6.0 </kp>
105     <ki> 0.13 </ki>
106     <kd> 6.0 </kd>
107   </pid>
108 
109   <switch name="fcs/roll-command-selector">
110     <default value="0.0"/>
111     <test value="fcs/heading-pi-controller">
112       ap/heading_hold == 1
113       gear/unit[2]/WOW == 0
114     </test>
115     <test value="fcs/roll-ap-autoswitch">
116       ap/attitude_hold == 1
117       gear/unit[2]/WOW == 0
118     </test>
119     <output>ap/aileron_cmd</output>
120   </switch>
121 <!--
122   <switch name="fcs/roll-command-selector-steering">
123     <default value="0.0"/>
124     <test value="fcs/heading-pi-controller">
125       ap/heading_hold == 1
126       gear/unit/WOW == 1
127     </test>
128     <output>fcs/steer-cmd-norm</output>
129   </switch>
130 -->
131 </channel>
View Code

关于c172高度保持自动驾驶算法:(为pitch通道提供算法,开始分析

  1 <!--
  2 =====================================================
  3 PITCH CHANNEL
  4 =====================================================
  5 -->
  6 
  7 <!-- Altitude hold -->
  8 
  9 <!-- The Altitude Error component below computes the altitude error, subtracting
 10      the desired altitude (altitude_setpoint) from the actual altitude above sea
 11      level (_not_ Above Ground Level).  This error signal is interpreted as an
 12      hdot command (hdot is time rate of change of altitude, or rate of climb). As
 13      such it is limited to a maximum absolute value of 12 fps here (720 fpm). The
 14      maximum achievable climb rate depends on altitude. The commanded climb rate
 15      is scheduled in the HDot Command component, below. For the given altitude
 16      (left column in the table), the commanded maaximum climb rate divided by 100
 17      is given in the right column.
    下方的“高度误差”组件计算高度误差,从海平面以上的实际高度(_not_高于地面高度)减去所需的高度(altitude_setpoint)。
    该错误信号被解释为hdot命令(hdot是高度变化的时间速率或爬升速率)。 因此,这里限制为最大绝对值12 fps(720 fpm)。
    可达到的最大爬升率取决于高度。 命令爬升率安排在下面的HDot Command组件中。
    对于给定的高度(表中的左栏),在右栏中给出了命令的最大爬升率除以100。
18 --> 19 20 <channel name="Pitch altitude hold"> 21 22 <!-- 23 The difference between the desired altitude and the actual altitude 24 is determined, and limited to 100. The output from this component is 25 the desired climb rate in percent of maximum.
    确定所需高度与实际高度之间的差异,并将其限制为100.此组件的输出是所需的爬升率,以最大百分比表示
26 --> 27 <summer name="fcs/altitude-error"> 28 <input> ap/altitude_setpoint </input> 29 <input> -position/h-agl-ft </input> 30 <clipto> 31 <min>-100</min> 32 <max> 100</max> 33 </clipto> 34 </summer> 35 36 <!-- 37 The desired climb rate is lagged slightly for stability.
    为了稳定性,所需的爬升率略有滞后
38 --> 39 <lag_filter name="fcs/alt-error-lag"> 40 <input> fcs/altitude-error </input> 41 <c1> 1 </c1> 42 </lag_filter> 43 44 <!-- 45 Dependent on altitude, the lagged (and limited) altitude error is multipled 46 by the scheduled gain determined from the table, below. The output from this 47 component is the absolute climb rate in feet/second. For example, if the desired 48 climb rate is 100 percent of maximum and the current altitude is 1000.0 ft., then 49 the output from this component would be 11 ft. sec.
    取决于高度,滞后(和有限)高度误差乘以从下表中确定的预定增益。 该组件的输出是以英尺/秒为单位的绝对爬升率。
    例如,如果所需爬升率为最大值的100%且当前海拔高度为1000.0英尺,则此组件的输出将为11英尺/秒。
50 --> 51 <scheduled_gain name="fcs/hdot-command"> 52 <input> fcs/alt-error-lag </input> 53 <table> 54 <independentVar>position/h-sl-ft</independentVar> 55 <tableData> 56 0.0 0.12 57 1000.0 0.11 58 2000.0 0.10 59 3000.0 0.096 60 4000.0 0.093 61 5000.0 0.086 62 6000.0 0.078 63 7000.0 0.069 64 8000.0 0.061 65 9000.0 0.053 66 10000.0 0.045 67 11000.0 0.037 68 12000.0 0.028 69 </tableData> 70 </table> 71 </scheduled_gain> 72 73 <!-- 74 This component calculates the climb rate error, taking the difference between 75 the commanded climb rate (from the previous component) and actual climb rate 76 in ft./sec.
    该组件计算爬升率误差,取命令爬升率(来自前一个组件)与实际爬升率之间的差值,单位为英尺/秒。
77 --> 78 <summer name="fcs/hdot-error"> 79 <input> fcs/hdot-command </input> 80 <input> -velocities/h-dot-fps </input> 81 </summer> 82 83 <!-- 84 If the altitude hold autopilot command is ON, then this switch component will 85 pass through the climb rate error (from the previous component). Otherwise, it 86 will pass zero.
    如果高度保持自动驾驶仪命令为ON,则此开关组件将通过爬升率误差(来自前一个组件)。 否则,它将传递零
87 --> 88 <switch name="fcs/ap-alt-hold-switch"> 89 <default value="0.0"/> 90 <test value="fcs/hdot-error"> 91 ap/altitude_hold == 1 92 </test> 93 </switch> 94 95 <!-- 96 The windup trigger below assumes the elevator will travel +/-23 degrees. The 97 elevator, however, does not travel symmetrically. This will need to be addressed 98 in a fix to the deadband component.
    下面的饱和触发器假定电梯将行驶+/- 23度。 然而,电梯不对称地行进。 这需要通过修复死区组件来解决
99 --> 100 <deadband name="fcs/windup-trigger"> 101 <input> fcs/elevator-pos-deg </input> 102 <width>46.0</width> 103 </deadband> 104 105 <!-- 106 The integrator integrates the hdot error (when the switch component passes that 107 signal through above when the altitude hold is selected ON). In the situation 108 where the elevator becomes saturated, the integrator ceases to integrate. The 109 windup protection is indicated below, with the windup-trigger property being 110 the trigger to halt integration. When the windup trigger is non-zero (when the 111 elevator position falls outside the range +/- 23 degrees - a deadband of 46 112 degrees) then the deadband passes a non-zero value, triggering the anti-windup 113 logic in the integrator. 114 115 The proportional component multiplies the error signal by a constant, providing 116 the proportional control action of this PI altitude hold controller. 117 118 The pid component combines the proportional and integral control 119 signals. It clips the sum to +/- 1.0.
    积分器集成了hdot错误(当选择高度保持为ON时,当开关组件通过上面的信号时)。
    在电梯变得饱和的情况下,积分器停止积分。 饱和保护如下所示,其中windup-trigger属性是停止积分的触发器。
    当卷绕触发器非零时(当电梯位置落在+/- 23度范围之外 - 死区为46度时),死区通过非零值,触发积分器中的抗饱和逻辑。     比例分量将误差信号乘以常数,提供该PI高度保持控制器的比例控制动作。     pid组件结合了比例和积分控制信号。 它将总和剪辑为+/- 1.0。
120 --> 121 122 <pid name="fcs/altitude-hold-pid"> 123 <input> fcs/ap-alt-hold-switch </input> 124 <kp> 0.01 </kp> 125 <ki> 0.00015 </ki> 126 <kd> 0.0003 </kd> 127 <trigger> fcs/windup-trigger </trigger> 128 <clipto> <min>-1.0</min> 129 <max> 1.0</max> </clipto> 130 </pid> 131 132 <!-- 133 The elevator component flips the sign on the output of the control summer 134 above and sets the ap/elevator_command property.
    电梯组件翻转上面控制夏季输出上的标志并设置ap / elevator_command属性
135 --> 136 <pure_gain name="fcs/elevator"> 137 <input> fcs/altitude-hold-pid </input> 138 <gain> -1.0 </gain> 139 <output> ap/elevator_cmd </output> 140 </pure_gain> 141 </channel>

这个高度保持最后输出就是,之前在飞机文件里使用的参数ap/elevator_cmd (答5)

我们这里似乎又要添加新的疑问列表了:

6.可以计算出ap/elevator_cmd的输入参数ap/altitude_setpoint,从哪里设置?

 答6:我在另外一个脚本文件c1723.xml中找到了ap/altitude_setpoint的输入。

于是我发现c1722.xml的脚本文件并没有用到自动驾驶的pitch通道。

于是,我重新比对c1723.xml和c1722.xml中关于自动驾驶的使用,可以回答问题3和问题2

答2 sim-time-sec是仿真的时间,限定条件是到达某个设定时间坐某事event

答3:c1722.xml没有使用很多自动驾驶功能,只有其中ap/heading_hold和ap/attitude_hold是和自动驾驶有关的。

ap/heading_hold 和 ap/attitude_hold 是在在c172ap.xml自定义文件中的自定义属性值

用来参与自定义的自动驾驶计算,算出的值,例如:ap/elevator_cmd

ap/elevator_cmd将会送入自定义的飞机文件中,作为飞控的某一个通道的输入参数使用。

至此1到6所有疑问都已解答,并了解了自动驾驶的简单使用过程。

下面我们尽量深入分析自动驾驶,来看脚本文件:c1723.xml

 1     。。。
 2 <event name="engine start">
 3       <description>Start the engine and set roll control to heading hold启动发动机并将滚动控制设置为航向保持</description>
 4       <condition> sim-time-sec >= 0.25 </condition>
 5       <set name="fcs/throttle-cmd-norm" value="1.0" action="FG_RAMP" tc ="0.5"/>
 6       <set name="fcs/mixture-cmd-norm" value="1.00" action="FG_RAMP" tc ="0.5"/>
 7       <set name="propulsion/magneto_cmd" value="3"/>
 8       <set name="propulsion/starter_cmd" value="1"/>
 9       <set name="ap/roll-attitude-mode" value="1"/>
10       <set name="ap/autopilot-roll-on" value="1"/>
11       <notify>
12         <property>simulation/run_id</property>
13         <property>ap/hdg-roll-err-c1</property>
14       </notify>
15     </event>
16 
17     <event name="Begin roll">
18       <description>Release brakes and get rolling with flaps at 10 degrees.松开制动器,襟翼滚动10度 </description>
19       <condition> sim-time-sec >= 2.0 </condition>
20       <set name="fcs/left-brake-cmd-norm" value="0"/>
21       <set name="fcs/right-brake-cmd-norm" value="0"/>
22       <set name="fcs/center-brake-cmd-norm" value="0"/>
23       <set name="fcs/flap-cmd-norm" value="0.33"/>
24     </event>
25 
26     <event name="Rotate">
27       <description>Set Autopilot for 400 ft and rotate at 49 keas.当空速达到49 节时,,将自动驾驶目标高度设置为400英尺</description>
28       <notify/>
29       <condition> velocities/vc-kts >= 49 </condition>
30       <set name="ap/altitude_setpoint" value="400.0"/>
31       <set name="ap/altitude_hold" value="1"/>
32       <set name="ap/roll-attitude-mode" value="1"/>
33     </event>
34 
35     <event name="Set autopilot for 6000 ft.">
36       <description>Set Autopilot for 6000 ft after a five second delay. 当空速达到49 节时,5秒延迟后将自动驾驶目标高度设置为6000英尺</description>
37       <notify/>
38       <condition> velocities/vc-kts >= 49 </condition>
39       <delay>5.0</delay>
40       <set name="ap/altitude_setpoint" value="6000.0"/>
41     </event>
42 
43     。。。

就看其中的四个事件,简要分析

1."engine start"            启动发动机并将滚动控制设置为航向保持

    <set name="ap/roll-attitude-mode" value="1"/>

    <set name="ap/autopilot-roll-on" value="1"/>

2."Begin roll"             松开制动器,襟翼滚动10度

3."Rotate"               当空速达到49 节时,,将自动驾驶目标高度设置为400英尺

    <set name="ap/altitude_setpoint" value="400.0"/>
    <set name="ap/altitude_hold" value="1"/>
    <set name="ap/roll-attitude-mode" value="1"/>

4."Set autopilot for 6000 ft."      当空速达到49 节时,5秒延迟后将自动驾驶目标高度设置为6000英尺

     <set name="ap/altitude_setpoint" value="6000.0"/>

这里用了几个自定义的自动驾驶的参数:

ap/roll-attitude-mode      在系统systems的Autopilot.xml文件中定义  0机翼控制    1滚转角保持

ap/autopilot-roll-on    在系统systems的Autopilot.xml文件中定义  0 关闭   1 打开   自动驾驶系统  

ap/altitude_setpoint        在自定义文件c172ap.xml中文件中定义  需要脚本输入的目标高度  单位:英尺(FT)

ap/altitude_hold      在自定义文件c172ap.xml中文件中定义  需要脚本输入控制 高度保持是否开启  0关闭  1开启

原文地址:https://www.cnblogs.com/lyggqm/p/10285526.html