[原]JSBSim 自动驾驶(浅出)
jsbsim的脚本文件分为几大类: 系统脚本: systems? 包含通用飞机各部分功能模块组件以及自动飞行控件:Autopilot.xml? 和 自动飞行的算法控件:GNCUtilities.xml 引擎脚本: engine:包含各个飞机的发动机控件 飞机脚本: aircraft:包含各个飞机的控件、输入输出、初始化参数 控制脚本: 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> --> ?还有自动驾驶算法函数: 关于机翼滚转自动算法: 1 <!-- 2 ===================================================== 3 ROLL CHANNEL 4 ===================================================== 5 --> 6 7 <!-- Wing leveler --> 8 9 <property value="0"> simulation/input1 </property> 10 <property value="0"> simulation/input2 </property> 11 12 <channel name="Roll wing leveler"> 13 14 <sensor name="fcs/attitude/sensor/phi-rad"> 15 <input> attitude/phi-rad </input> 16 <lag> 0.5 </lag> 17 <delay> 2 </delay> 18 <noise variation="PERCENT" distribution="GAUSSIAN"> 0.05 </noise> 19 <quantization name="attitude/sensor/quantized/phi-rad"> 20 <bits> 12 </bits> 21 <min> -3.1416 </min> 22 <max> 3.1416 </max> 23 </quantization> 24 <bias> 0.001 </bias> 25 </sensor> 26 27 <switch name="simulation/test"> 28 <default value="-1"/> 29 <test value="0"> 30 simulation/input1 eq 1 31 simulation/input2 gt 2 32 </test> 33 <test value="1" logic="OR"> 34 simulation/input1 eq 3 35 simulation/input2 gt 4 36 </test> 37 <test value="2"> 38 <test logic="AND"> 39 simulation/input1 eq 4 40 simulation/input2 gt 5 41 </test> 42 <test logic="OR"> 43 simulation/input1 eq 6 44 simulation/input2 gt 7 45 </test> 46 </test> 47 <test value="3"> 48 <test logic="AND"> 49 simulation/input1 eq 8 50 simulation/input2 gt 9 51 </test> 52 <test logic="OR"> 53 simulation/input1 eq 10 54 simulation/input2 gt 11 55 </test> 56 </test> 57 </switch> 58 59 <switch name="fcs/wing-leveler-ap-on-off"> 60 <default value="-1"/> 61 <test value="0"> 62 ap/attitude_hold == 1 63 </test> 64 </switch> 65 66 <pid name="fcs/roll-ap-error-pid"> 67 <input>attitude/phi-rad</input> 68 <kp> ap/roll-pid-kp </kp> 69 <ki> ap/roll-pid-ki </ki> 70 <kd> ap/roll-pid-kd </kd> 71 <trigger> fcs/wing-leveler-ap-on-off </trigger> 72 </pid> 73 74 <switch name="fcs/roll-ap-autoswitch"> 75 <default value="0.0"/> 76 <test value="-fcs/roll-ap-error-pid"> 77 ap/attitude_hold == 1 78 </test> 79 </switch> 80 81 </channel> ? 关于偏航自动驾驶算法: 1 <!-- Heading hold --> 2 3 <channel name="Roll heading hold"> 4 <pure_gain name="fcs/heading-true-degrees"> 5 <input>attitude/heading-true-rad</input> 6 <gain>57.3</gain> <!-- convert to degrees --> 7 </pure_gain> 8 9 <summer name="fcs/heading-error"> 10 <input> -fcs/heading-true-degrees</input> 11 <input> ap/heading_setpoint </input> 12 </summer> 13 14 <switch name="fcs/heading-error-bias-switch"> 15 <default value="0.0"/> 16 <test value="360.0"> 17 fcs/heading-error lt -180 18 </test> 19 <test value="-360.0"> 20 fcs/heading-error gt 180 21 </test> 22 </switch> 23 24 <summer name="fcs/heading-corrected"> 25 <input> fcs/heading-error-bias-switch </input> 26 <input> fcs/heading-error </input> 27 <clipto> 28 <min>-30</min> 29 <max>30</max> 30 </clipto> 31 </summer> 32 33 <pure_gain name="fcs/heading-command"> 34 <input> fcs/heading-corrected </input> 35 <gain> 0.01745 </gain> 36 </pure_gain> 37 38 <lag_filter name="fcs/heading-roll-error-lag"> 39 <input> fcs/heading-command </input> 40 <c1> ap/hdg-roll-err-c1 </c1> 41 </lag_filter> 42 43 <summer name="fcs/heading-roll-error"> 44 <input> fcs/heading-roll-error-lag </input> 45 <input> -attitude/phi-rad </input> 46 </summer> 47 48 <switch name="fcs/heading-roll-error-switch"> 49 <default value="0.0"/> 50 <test value="fcs/heading-roll-error"> 51 ap/heading_hold == 1 52 </test> 53 </switch> 54 55 <pid name="fcs/heading-pi-controller"> 56 <input> fcs/heading-roll-error-switch </input> 57 <kp> 6.0 </kp> 58 <ki> 0.13 </ki> 59 <kd> 6.0 </kd> 60 </pid> 61 62 <switch name="fcs/roll-command-selector"> 63 <default value="0.0"/> 64 <test value="fcs/heading-pi-controller"> 65 ap/heading_hold == 1 66 gear/unit[2]/WOW == 0 67 </test> 68 <test value="fcs/roll-ap-autoswitch"> 69 ap/attitude_hold == 1 70 gear/unit[2]/WOW == 0 71 </test> 72 <output>ap/aileron_cmd</output> 73 </switch> 74 <!-- 75 <switch name="fcs/roll-command-selector-steering"> 76 <default value="0.0"/> 77 <test value="fcs/heading-pi-controller"> 78 ap/heading_hold == 1 79 gear/unit/WOW == 1 80 </test> 81 <output>fcs/steer-cmd-norm</output> 82 </switch> 83 --> 84 </channel> ? ? 关于高度保持自动驾驶算法: 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. 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. 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. 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. 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. 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. 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. 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) 我们这里似乎又要添加新的疑问列表了 ? 今天到此为止,困了,睡觉 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |