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>