extra500-autopilot.xml 94.6 KB
Newer Older
Eric van den Berg's avatar
Eric van den Berg committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
<?xml version="1.0" encoding="utf-8" ?>
	
<!--
    This file is part of extra500

    The extra500 is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 2 of the License, or
    (at your option) any later version.

    The extra500 is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with extra500.  If not, see <http://www.gnu.org/licenses/>.

      Author: Eric van den Berg
      Date: 2013-05-23

22
      Last change:      Eric van den Berg
23
      Date:             2015-04-26
Eric van den Berg's avatar
Eric van den Berg committed
24 25 26 27
-->

<autopilot name="STEC55X">

28 29
<!--**************************************AP COMPUTER ACCELERATION SENSOR********************************************************-->

Eric van den Berg's avatar
Eric van den Berg committed
30
<!--this the acceleration sensor in the AP computer (in the glareshield). It is used to dampen the pitch motion-->
Eric van den Berg's avatar
Eric van den Berg committed
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
	<channel name="accelsensor">
		<accelerometer name="/autopilot/accsens-channel/ap-z-accelsensor">
			<location unit="M">
				<x>1.1</x>
				<y>0.0</y>
				<z>0.0</z>
			</location>
  			<orientation unit="DEG">
    				<pitch>0.0</pitch>
    				<roll>0.0</roll>
    				<yaw>0.0</yaw>
  			</orientation>
			<axis>Z</axis>
			<gain>0.0310809970784</gain>	<!--1/32.174 -->
			<output>/autopilot/accsens-channel/ap-z-accel</output>
		</accelerometer>

	</channel>

50
<!--*****************************************ALTITUDE SENSOR*****************************************************************-->
Eric van den Berg's avatar
Eric van den Berg committed
51

Eric van den Berg's avatar
Eric van den Berg committed
52 53
	<channel name="altitudesensor">
<!-- this is the dedicated AP altitude sensor (with its own static system) ,located in the tail cone. It is used to mnge vertical speed and altitude hold-->
54
		<fcs_function name="/autopilot/altsensor/vs-fpm-unfiltered">
Eric van den Berg's avatar
Eric van den Berg committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
			<function>
				<product>
					<value>60.0</value>		
					<sum>
						<property>/instrumentation/altimeter-AP/indicated-altitude-ft</property>
						<property>/autopilot/altsensor/alt-old</property>
					</sum>
					<pow>
						<max>
							<value>0.0001</value>	
							<property>sim-dt-sec</property>
						</max>
						<value>-1.0</value>	
					</pow>
				</product>
			</function>
		</fcs_function>

73 74 75 76 77 78 79
		<lead_lag_filter name="/autopilot/altsensor/vs-fpm">
			<input>/autopilot/altsensor/vs-fpm-unfiltered</input>
			<c1>/autopilot/altsensor/c1</c1>
			<c2>/autopilot/altsensor/c2</c2>
			<c3>/autopilot/altsensor/c3</c3>
			<c4>/autopilot/altsensor/c4</c4>
		</lead_lag_filter>
Eric van den Berg's avatar
Eric van den Berg committed
80 81 82 83 84 85 86 87 88 89 90

		<fcs_function name="/autopilot/altsensor/alt-old">
			<function>
				<product>
					<value>-1.0</value>				
					<property>/instrumentation/altimeter-AP/indicated-altitude-ft</property>
				</product>	
			</function>
		</fcs_function>
	</channel>

91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
<!--***************************************BLINKER**********************************************************************-->

	<channel name="timer">

<!-- indication timer -->
		<fcs_function name="/autopilot/indication/timer-sec">
			<function>
				<product>
					<property>/extra500/light/strobe/reset</property>
					<sum>
						<property>/autopilot/indication/timer-sec</property>
						<property>sim-dt-sec</property> 
					</sum>
				</product>
			</function>
		</fcs_function>

<!-- timer reset -->
		<switch name="/autopilot/indication/reset">
			<default value="1"/>
			<test logic="OR" value="0">
				/autopilot/indication/timer-sec gt 2.0
			</test>
		</switch>

<!-- on/off -->
		<switch name="/autopilot/indication/timer-on">
			<default value="0"/>
			<test logic="AND" value="1">
				/autopilot/indication/timer-sec ge 0.0
				/autopilot/indication/timer-sec lt 1
			</test>
		</switch>

	</channel>

127
<!--***************************************HEADING**********************************************************************-->
Eric van den Berg's avatar
Eric van den Berg committed
128 129

	<channel name="heading">
130
<!-- this is the heading channel. when the hdg mode is active, the hdg bug of the LH IFD is followed-->
Eric van den Berg's avatar
Eric van den Berg committed
131

132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
<!-- heading fail used for indication-->
		<switch name="hdgfail">
			<default value="0"/>
			<test value="1">
				/instrumentation/heading-indicator-IFD-LH/serviceable eq 0
				/instrumentation/heading-indicator-IFD-RH/serviceable eq 0
			</test>
			<output>/autopilot/hdg-channel/fail</output>
		</switch>

		<switch name="hdgind">
			<default value="/autopilot/mode/heading"/>
			<test value="/autopilot/indication/timer-on">
				/autopilot/hdg-channel/fail eq 1
				/autopilot/mode/heading eq 1
			</test>
			<output>/autopilot/indication/heading</output>
		</switch>

151 152 153 154 155 156 157 158 159
<!-- heading source is selected -->
		<switch name="hdgselect">
			<default value="/instrumentation/heading-indicator-IFD-LH/heading-bug-error-deg"/>
			<test value="/instrumentation/heading-indicator-IFD-RH/heading-bug-error-deg">
				/instrumentation/hdg-source eq 1
			</test>
			<output>/autopilot/hdg-channel/heading-bug-error-deg</output>
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
160
<!--the heading error is clipped to -20 to 20 deg -->
Eric van den Berg's avatar
Eric van den Berg committed
161
		<pure_gain name="/autopilot/hdg-channel/lmd-hdg-error">
162
			<input>/autopilot/hdg-channel/heading-bug-error-deg</input>
Eric van den Berg's avatar
Eric van den Berg committed
163 164 165 166 167 168 169
			<gain>1.0</gain>
			<clipto>
				<min>-20</min>
				<max>20</max>
			</clipto>
		</pure_gain>

Eric van den Berg's avatar
Eric van den Berg committed
170
<!--determining the target turn rate using the hdg error. Note that kp and the clipped hdg error determines the maximum turnrate-->
Eric van den Berg's avatar
Eric van den Berg committed
171 172
		<pid name="/autopilot/hdg-channel/target-turn-rate">
			<input>/autopilot/hdg-channel/lmd-hdg-error</input>
173
			<kp>/autopilot/hdg-channel/lmd-hdg-error-kp</kp>							<!--180deg/min devided by 20deg -->
Eric van den Berg's avatar
Eric van den Berg committed
174 175 176 177
			<ki>/autopilot/hdg-channel/lmd-hdg-error-ki</ki>
			<kd>/autopilot/hdg-channel/lmd-hdg-error-kd</kd>
		</pid>
		
178
<!-- the turn rate (inverted) as measured by the turn coordinator in deg/min (RH panel) -->
Eric van den Berg's avatar
Eric van den Berg committed
179 180 181 182
		<fcs_function name="/autopilot/hdg-channel/turn-rate-inv">
			<function>
				<product>
					<value>-180.0</value>
183
					<property>/instrumentation/turn-indicator/indicated-turn-rate</property>  <!--pos right (1 corresponds to 3deg/sec)-->
Eric van den Berg's avatar
Eric van den Berg committed
184 185 186 187
				</product>
			</function>
		</fcs_function>

Eric van den Berg's avatar
Eric van den Berg committed
188
<!-- the turn rate error -->
Eric van den Berg's avatar
Eric van den Berg committed
189 190 191 192 193 194 195 196 197
		<fcs_function name="/autopilot/hdg-channel/turn-rate-error">
			<function>
				<sum>
					<property>/autopilot/hdg-channel/target-turn-rate</property>	
					<property>/autopilot/hdg-channel/turn-rate-inv</property>
				</sum>
			</function>
		</fcs_function>

198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
<!-- the flight director bank angle (relative to AC position/turnrate) -->
		<fcs_function name="/autopilot/hdg-channel/fld-bank-deg">
			<function>
				<product>
					<property>/autopilot/hdg-channel/turn-rate-error</property>	
					<property>/autopilot/fms-channel/indicated-ground-speed-kt</property>
					<property>/extra500/const/NM2METER</property>
					<property>/extra500/const/SEC2MIN</property>
					<property>/extra500/const/SEC2MIN</property>
					<property>/extra500/const/SEC2MIN</property>
					<pow>	
						<property>/extra500/const/G0</property>
						<value>-1</value>
					</pow>
				</product>
			</function>
		</fcs_function>

Eric van den Berg's avatar
Eric van den Berg committed
216
<!-- the commanded aileron position change using the turn rate error -->
Eric van den Berg's avatar
Eric van den Berg committed
217 218 219 220 221 222 223
		<pid name="/autopilot/hdg-channel/cmd-ail-change">
			<input>/autopilot/hdg-channel/turn-rate-error</input>
			<kp>/autopilot/hdg-channel/turn-rate-error-kp</kp>							
			<ki>/autopilot/hdg-channel/turn-rate-error-ki</ki>
			<kd>/autopilot/hdg-channel/turn-rate-error-kd</kd>
		</pid>

Eric van den Berg's avatar
Eric van den Berg committed
224
<!-- calculating the new aileron position-->
Eric van den Berg's avatar
Eric van den Berg committed
225 226 227 228 229
		<fcs_function name="/autopilot/hdg-channel/cmd-ap-ail-pos-norm-raw">
			<function>
				<sum>
					<property>fcs/aileron-cmd-tot</property>	
					<product>
230
                                  	<property>/autopilot/mode/heading</property>
Eric van den Berg's avatar
Eric van den Berg committed
231 232 233 234 235 236 237 238
						<value>1.0</value>
						<property>/autopilot/hdg-channel/cmd-ail-change</property>
						<property>sim-dt-sec</property>
					</product>
				</sum>
			</function>
			<output>/autopilot/hdg-channel/cmd-ap-ail-pos-norm-raw</output>
		</fcs_function>
Eric van den Berg's avatar
Eric van den Berg committed
239 240

<!-- making sure the aileron servo is not going to fast-->	
Eric van den Berg's avatar
Eric van den Berg committed
241 242 243 244 245 246 247 248 249 250
		<actuator name="/autopilot/hdg-channel/ail-servo">
			<input>/autopilot/hdg-channel/cmd-ap-ail-pos-norm-raw</input>
			<rate_limit>0.2</rate_limit>
			<clipto>
				<min>-1</min>
				<max>1</max>
			</clipto>
			<output>/autopilot/hdg-channel/cmd-ap-ail-pos-norm</output>
		</actuator>

251 252 253
<!--this makes the aileron pilot input to move along, so when the hdg mode is disconnected, the ailerons are in the correct position-->
		<switch name="headingon">
			<default value="/controls/flight/aileron"/>
254
			<test logic="AND" value="/autopilot/hdg-channel/cmd-ap-ail-pos-norm">
255
				/autopilot/mode/heading eq 1
256
				/autopilot/settings/ap eq 1
257 258 259 260
			</test>
			<output>/controls/flight/aileron</output>
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
261 262 263

	</channel>

264 265 266 267 268
<!--***************************************RADIO NAVIGATION**********************************************************************-->

	<channel name="radionav">
<!-- this is the radionav channel. when the nav mode is active, the ap will intercept the selected radial of a VOR or the selected LOC-->

269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
<!-- radio nav mode fail used for indication -->
		<switch name="radnavfail">
			<default value="0"/>
			<test logic="OR" value="1">
				<test logic="AND">
					<test logic="AND">
						/instrumentation/nav-source eq 0
					</test>
					<test logic="OR">
						/instrumentation/nav[0]/operable eq 0 
						/instrumentation/nav[0]/in-range eq 0
					</test>
				</test>
				<test logic="AND">
					<test logic="AND">
						/instrumentation/nav-source eq 1
					</test>
					<test logic="OR">
						/instrumentation/nav[1]/operable eq 0 
						/instrumentation/nav[1]/in-range eq 0
					</test>
				</test>
			</test>
			<output>/autopilot/radionav-channel/fail</output>
		</switch>
294 295

<!-- selection of nav unit based on /instrumentation/nav-source property -->
Eric van den Berg's avatar
Eric van den Berg committed
296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320
		<switch name="navdistanceselect">
			<default value="/instrumentation/nav[0]/nav-distance"/>
			<test value="/instrumentation/nav[1]/nav-distance">
				/instrumentation/nav-source eq 1
			</test>
			<output>/autopilot/radionav-channel/nav-distance-m</output>
		</switch>

		<fcs_function name="/autopilot/radionav-channel/nav-distance-nm">
			<function>
				<product>
					<property>/autopilot/radionav-channel/nav-distance-m</property>
					<property>/extra500/const/METER2NM</property> 
				</product>
			</function>
		</fcs_function>

		<switch name="navradialselect">
			<default value="/instrumentation/nav[0]/radials/reciprocal-radial-deg"/>
			<test value="/instrumentation/nav[1]/radials/reciprocal-radial-deg">
				/instrumentation/nav-source eq 1
			</test>
			<output>/autopilot/radionav-channel/radials/reciprocal-radial</output>
		</switch>

321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
		<switch name="navfromflagselect">
			<default value="/instrumentation/nav[0]/from-flag"/>
			<test value="/instrumentation/nav[1]/from-flag">
				/instrumentation/nav-source eq 1
			</test>
			<output>/autopilot/radionav-channel/from-flag</output>
		</switch>

		<switch name="navtoflagselect">
			<default value="/instrumentation/nav[0]/to-flag"/>
			<test value="/instrumentation/nav[1]/to-flag">
				/instrumentation/nav-source eq 1
			</test>
			<output>/autopilot/radionav-channel/to-flag</output>
		</switch>

337
		<switch name="navselect">
338 339
			<default value="/instrumentation/nav[0]/heading-needle-deflection-norm"/>
			<test value="/instrumentation/nav[1]/heading-needle-deflection-norm">
340 341
				/instrumentation/nav-source eq 1
			</test>
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403
			<output>/autopilot/radionav-channel/heading-needle-deflection-norm-nlmd</output>
		</switch>

		<pure_gain name="/autopilot/radionav-channel/heading-needle-deflection-norm-lmd">
			<input>/autopilot/radionav-channel/heading-needle-deflection-norm-nlmd</input>
			<gain>1</gain>
			<clipto>
				<min>-0.1</min>
				<max>0.1</max>		
			</clipto>
		</pure_gain>

<!-- in soft mode, neglect large needle deflections -->
		<switch name="needle-deflect-gt-half">
			<default value="0"/>
			<test logic="OR" value="1">
				/autopilot/radionav-channel/heading-needle-deflection-norm-nlmd gt 0.5
				/autopilot/radionav-channel/heading-needle-deflection-norm-nlmd lt -0.5
			</test>
			<output>/autopilot/radionav-channel/needle-defl-gt-half</output>
		</switch>

		<fcs_function name="/autopilot/radionav-channel/timer-soft-lnd">
			<function>
				<product>
					<property>/autopilot/radionav-channel/needle-defl-gt-half</property>
					<sum> 
						<property>/autopilot/radionav-channel/timer-soft-lnd</property> 
						<property>sim-dt-sec</property>
					</sum>
				</product>
			</function>
		</fcs_function>

		<switch name="needle-deflect-full">
			<default value="0"/>
			<test logic="OR" value="1">
				/autopilot/radionav-channel/heading-needle-deflection-norm-nlmd gt 0.99
				/autopilot/radionav-channel/heading-needle-deflection-norm-nlmd lt -0.99
			</test>
			<output>/autopilot/radionav-channel/needle-defl-full</output>
		</switch>

		<fcs_function name="/autopilot/radionav-channel/timer-full-defl">
			<function>
				<product>
					<property>/autopilot/radionav-channel/needle-defl-full</property>
					<sum> 
						<property>/autopilot/radionav-channel/timer-full-defl</property> 
						<property>sim-dt-sec</property>
					</sum>
				</product>
			</function>
		</fcs_function>

		<switch name="needle-deflect-s">
			<default value="/autopilot/radionav-channel/heading-needle-deflection-norm-nlmd"/>
			<test logic="AND" value="/autopilot/radionav-channel/heading-needle-deflection-norm-lmd">
				/autopilot/radionav-channel/gain-mode eq 3
				/autopilot/radionav-channel/timer-soft-lnd lt 60
				/autopilot/radionav-channel/timer-full-defl lt 3
			</test>
404 405 406
			<output>/autopilot/radionav-channel/heading-needle-deflection-norm</output>
		</switch>

407
<!-- getting the "in range" property from the selected nav unit -->
408
		<switch name="inrange">
409 410
			<default value="/instrumentation/nav[0]/in-range"/>
			<test value="/instrumentation/nav[1]/in-range">
411 412 413 414 415
				/instrumentation/nav-source eq 1
			</test>
			<output>/autopilot/radionav-channel/in-range</output>
		</switch>

416 417 418 419 420 421 422 423 424
<!-- getting the "is-localizer-frequency" property from the selected nav unit -->
		<switch name="locselect">
			<default value="/instrumentation/nav[0]/frequencies/is-localizer-frequency"/>
			<test value="/instrumentation/nav[1]/frequencies/is-localizer-frequency">
				/instrumentation/nav-source eq 1
			</test>
			<output>/autopilot/radionav-channel/is-localizer-frequency</output>
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449
<!--switching REV mode off when not a localizer freq -->
		<switch name="revmodeautodisc">
			<default value="/autopilot/mode/rev"/>
			<test value="0">
				/autopilot/radionav-channel/is-localizer-frequency eq 0
			</test>
			<output>/autopilot/mode/rev</output>
		</switch>

		<switch name="revmodeautodisc2">
			<default value="/instrumentation/nav[0]/back-course-btn"/>
			<test value="0">
				/autopilot/mode/rev eq 0
			</test>
			<output>/instrumentation/nav[0]/back-course-btn</output>
		</switch>

		<switch name="revmodeautodisc3">
			<default value="/instrumentation/nav[1]/back-course-btn"/>
			<test value="0">
				/autopilot/mode/rev eq 0
			</test>
			<output>/instrumentation/nav[1]/back-course-btn</output>
		</switch>

450
<!--logic for cap and soft modes -->
Eric van den Berg's avatar
Eric van den Berg committed
451
<!-- NOTE: gain-mode is changed to 0,1,2 or 3 all the time, do not use this property outside this channel!!! -->
452 453 454
		<switch name="gainmode1">
			<default value="0"/>
			<test logic="AND" value="1">
Eric van den Berg's avatar
Eric van den Berg committed
455 456 457 458 459 460 461 462 463
				<test logic="AND" value="1">
					/autopilot/radionav-channel/in-range eq 1
					/autopilot/mode/nav eq 1
					/autopilot/radionav-channel/heading-needle-deflection-norm lt 0.15
					/autopilot/radionav-channel/heading-needle-deflection-norm gt -0.15
				</test>
				<test logic="AND" value="1">
					/autopilot/radionav-channel/radials/diff lt 10
				</test>
464 465 466 467
			</test>
			<output>/autopilot/radionav-channel/gain-mode</output>
		</switch>

468
		<fcs_function name="/autopilot/radionav-channel/timer-cap">
469 470 471 472
			<function>
				<product>
					<property>/autopilot/radionav-channel/gain-mode</property>
					<sum> 
473
						<property>/autopilot/radionav-channel/timer-cap</property> 
474 475 476 477 478 479 480 481 482
						<property>sim-dt-sec</property>
					</sum>
				</product>
			</function>
		</fcs_function>

		<switch name="gainmode2">
			<default value="/autopilot/radionav-channel/gain-mode"/>
			<test logic="AND" value="2">
483
				/autopilot/radionav-channel/timer-cap gt 15
484 485 486 487 488 489 490
			</test>
			<output>/autopilot/radionav-channel/gain-mode</output>
		</switch>

		<switch name="gainmode3">
			<default value="/autopilot/radionav-channel/gain-mode"/>
			<test logic="AND" value="3">
491
				/autopilot/radionav-channel/timer-cap gt 75
492 493 494 495
			</test>
			<output>/autopilot/radionav-channel/gain-mode</output>
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
496 497 498
<!--when in APR mode, set gain mode to 2 -->
		<switch name="gainmode2b">
			<default value="/autopilot/radionav-channel/gain-mode"/>
Eric van den Berg's avatar
Eric van den Berg committed
499
			<test logic="OR" value="2">
Eric van den Berg's avatar
Eric van den Berg committed
500
				/autopilot/mode/apr eq 1
Eric van den Berg's avatar
Eric van den Berg committed
501
				/autopilot/mode/apr-rev eq 1
Eric van den Berg's avatar
Eric van den Berg committed
502 503 504 505 506
			</test>
			<output>/autopilot/radionav-channel/gain-mode</output>
		</switch>

<!-- indication -->
507 508
		<switch name="cap">
			<default value="0"/>
509 510 511 512 513
			<test logic="AND" value="1">
				<test logic="OR" value="1">
					/autopilot/radionav-channel/gain-mode eq 1
					/autopilot/radionav-channel/gain-mode eq 2
				</test>
Eric van den Berg's avatar
Eric van den Berg committed
514
				<test  logic="OR" value="1">
515 516
					/autopilot/radionav-channel/is-localizer-frequency eq 0
				</test>
517 518 519 520
				<test logic="OR" value="1">
					/instrumentation/nav-source eq 0
					/instrumentation/nav-source eq 1
				</test>
521 522 523 524 525 526
			</test>
			<output>/autopilot/mode/cap</output>
		</switch>

		<switch name="soft">
			<default value="0"/>
527 528 529 530 531
			<test logic="AND" value="1">
				<test logic="OR" value="1">
					/autopilot/radionav-channel/gain-mode eq 2
					/autopilot/radionav-channel/gain-mode eq 3
				</test>
Eric van den Berg's avatar
Eric van den Berg committed
532
				<test  logic="OR" value="1">
533 534
					/autopilot/radionav-channel/is-localizer-frequency eq 0
				</test>
535 536 537 538
				<test logic="OR" value="1">
					/instrumentation/nav-source eq 0
					/instrumentation/nav-source eq 1
				</test>
539 540 541 542
			</test>
			<output>/autopilot/mode/soft</output>
		</switch>

543 544
<!-- setting gains and max turnrates for CAP, CAP-SOFT and SOFT -->

545 546 547
		<switch name="gains/gain-c">
			<default value="/autopilot/radionav-channel/gains/gain-n"/>
			<test value="/autopilot/radionav-channel/gains/gain-c">
548 549 550 551 552
				/autopilot/radionav-channel/gain-mode eq 1
			</test>
			<output>/autopilot/radionav-channel/gain</output>
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
553
<!-- also for APR -->
554
		<switch name="gains/gain-cs">
555
			<default value="/autopilot/radionav-channel/gain"/>
556
			<test value="/autopilot/radionav-channel/gains/gain-cs">
557 558 559 560 561
				/autopilot/radionav-channel/gain-mode eq 2
			</test>
			<output>/autopilot/radionav-channel/gain</output>
		</switch>

562
		<switch name="gains/gain-s">
563
			<default value="/autopilot/radionav-channel/gain"/>
564
			<test value="/autopilot/radionav-channel/gains/gain-s">
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585
				/autopilot/radionav-channel/gain-mode eq 3
			</test>
			<output>/autopilot/radionav-channel/gain</output>
		</switch>

		<switch name="turnrate-cs">
			<default value="/autopilot/radionav-channel/lmd-hdg-error-kp-n"/>
			<test value="/autopilot/radionav-channel/lmd-hdg-error-kp-cs">
				/autopilot/radionav-channel/gain-mode eq 2
			</test>
			<output>/autopilot/radionav-channel/lmd-hdg-error-kp</output>
		</switch>

		<switch name="turnrate-s">
			<default value="/autopilot/radionav-channel/lmd-hdg-error-kp"/>
			<test value="/autopilot/radionav-channel/lmd-hdg-error-kp-s">
				/autopilot/radionav-channel/gain-mode eq 3
			</test>
			<output>/autopilot/radionav-channel/lmd-hdg-error-kp</output>
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602
		<fcs_function name="/autopilot/radionav-channel/tgt-hdg-kd-rev">
			<function>
				<product>
					<property>/autopilot/radionav-channel/tgt-hdg-kd-n</property>
					<value>-1</value>
				</product>
			</function>
		</fcs_function>

		<switch name="tgt-hdg-kd for rev">
			<default value="/autopilot/radionav-channel/tgt-hdg-kd-n"/>
			<test value="/autopilot/radionav-channel/tgt-hdg-kd-rev">
				/autopilot/mode/rev eq 1
			</test>
			<output>/autopilot/radionav-channel/tgt-hdg-kd</output>
		</switch>

603
<!--calculating the target heading to intercept the radial-->
604
		<pid name="/autopilot/radionav-channel/relative-diff-heading-target-deg">
605 606 607 608
			<input>/autopilot/radionav-channel/heading-needle-deflection-norm</input>
			<kp>/autopilot/radionav-channel/tgt-hdg-kp</kp>							
			<ki>/autopilot/radionav-channel/tgt-hdg-ki</ki>
			<kd>/autopilot/radionav-channel/tgt-hdg-kd</kd>
609
			<output>/autopilot/radionav-channel/relative-d-heading-target-deg</output>
610 611
		</pid>

612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638
		<fcs_function name="/autopilot/radionav-channel/p-gain">
			<function>
				<product>
					<property>/autopilot/radionav-channel/gain</property>
					<pow> 
						<max>
							<abs>
								<property>/autopilot/radionav-channel/relative-d-heading-target-deg</property> 
							</abs>
							<value>0.000001</value>
						</max>
						<value>-1</value>
					</pow>
				</product>
			</function>
		</fcs_function>

		<pure_gain name="/autopilot/radionav-channel/p-gain-lmd">
			<input>/autopilot/radionav-channel/p-gain</input>
			<gain>1</gain>
			<clipto>
				<min>0</min>
				<max>225</max>		<!-- making sure it starts to turns at min needle defl of |0.2| --> 
			</clipto>
		</pure_gain>

		<pure_gain name="/autopilot/radionav-channel/relative-heading-target-deg">
639
			<input>/autopilot/radionav-channel/heading-needle-deflection-norm</input>
640
			<gain>/autopilot/radionav-channel/p-gain-lmd</gain>
641
			<clipto>
642 643
				<min>/autopilot/radionav-channel/rel-hdg-min</min>
				<max>/autopilot/radionav-channel/rel-hdg-max</max>
644 645 646
			</clipto>
		</pure_gain>

647
		<switch name="navselect2">
648 649
			<default value="/instrumentation/nav[0]/radials/selected-deg"/>
			<test value="/instrumentation/nav[1]/radials/selected-deg">
650 651 652 653 654
				/instrumentation/nav-source eq 1
			</test>
			<output>/autopilot/radionav-channel/radial-deg</output>
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671
		<fcs_function name="/autopilot/radionav-channel/radials/diff">
			<function>
				<abs>
					<difference>
						<property>/autopilot/radionav-channel/radial-deg</property> 
						<property>/autopilot/radionav-channel/radials/old-radial</property>
					</difference>
				</abs>
			</function>
		</fcs_function>

		<fcs_function name="/autopilot/radionav-channel/radials/old-radial">
			<function>
				<property>/autopilot/radionav-channel/radial-deg</property> 
			</function>
		</fcs_function>

Eric van den Berg's avatar
Eric van den Berg committed
672 673
<!--normal target heading -->
		<fcs_function name="/autopilot/radionav-channel/hdgtarget/heading-target-n-deg">
674 675 676 677 678 679 680 681
			<function>
				<sum>
					<property>/autopilot/radionav-channel/radial-deg</property> 
					<property>/autopilot/radionav-channel/relative-heading-target-deg</property> 
				</sum>
			</function>
		</fcs_function>

Eric van den Berg's avatar
Eric van den Berg committed
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716
<!--target heading for rev mode -->
		<fcs_function name="/autopilot/radionav-channel/hdgtarget/heading-target-revpos-deg">
			<function>
				<sum>
					<property>/autopilot/radionav-channel/hdgtarget/heading-target-n-deg</property> 
					<value>180</value> 
				</sum>
			</function>
		</fcs_function>

		<fcs_function name="/autopilot/radionav-channel/hdgtarget/heading-target-revneg-deg">
			<function>
				<difference>
					<property>/autopilot/radionav-channel/hdgtarget/heading-target-n-deg</property> 
					<value>180</value> 
				</difference>
			</function>
		</fcs_function>

		<switch name="hdgtargetselect">
			<default value="/autopilot/radionav-channel/hdgtarget/heading-target-revneg-deg"/>
			<test value="/autopilot/radionav-channel/hdgtarget/heading-target-revpos-deg">
				/autopilot/radionav-channel/hdgtarget/heading-target-revneg-deg le 0
			</test>
			<output>/autopilot/radionav-channel/hdgtarget/heading-target-rev-deg</output>
		</switch>

		<switch name="revhdgselect">
			<default value="/autopilot/radionav-channel/hdgtarget/heading-target-n-deg"/>
			<test value="/autopilot/radionav-channel/hdgtarget/heading-target-rev-deg">
				/autopilot/mode/rev eq 1
			</test>
			<output>/autopilot/radionav-channel/heading-target-deg</output>
		</switch>

717
		<switch name="hdgselect2">
718 719 720 721 722 723 724
			<default value="/instrumentation/heading-indicator-IFD-LH/indicated-heading-deg"/>
			<test value="/instrumentation/heading-indicator-IFD-RH/indicated-heading-deg">
				/instrumentation/hdg-source eq 1
			</test>
			<output>/autopilot/radionav-channel/heading-deg</output>
		</switch>

725
		<fcs_function name="/autopilot/radionav-channel/hdg-error/heading-1-error-deg">
726 727 728 729 730 731 732 733
			<function>
				<difference>
					<property>/autopilot/radionav-channel/heading-target-deg</property> 
					<property>/autopilot/radionav-channel/heading-deg</property> 
				</difference>
			</function>
		</fcs_function>

734
		<fcs_function name="/autopilot/radionav-channel/hdg-error/heading-2-error-deg">
735 736
			<function>
				<sum>
737
					<property>/autopilot/radionav-channel/hdg-error/heading-1-error-deg</property> 
738 739 740 741 742
					<value>360</value> 
				</sum>
			</function>
		</fcs_function>

743
		<fcs_function name="/autopilot/radionav-channel/hdg-error/heading-3-error-deg">
744 745
			<function>
				<difference>
746
					<property>/autopilot/radionav-channel/hdg-error/heading-1-error-deg</property> 
747 748 749 750 751 752
					<value>360</value> 
				</difference>
			</function>
		</fcs_function>

		<switch name="hdgdirection">
753 754 755
			<default value="/autopilot/radionav-channel/hdg-error/heading-1-error-deg"/>
			<test value="/autopilot/radionav-channel/hdg-error/heading-2-error-deg">
				/autopilot/radionav-channel/hdg-error/heading-1-error-deg lt -180
756
			</test>
757
			<output>/autopilot/radionav-channel/hdg-error/heading-4-error-deg</output>
758 759 760
		</switch>

		<switch name="hdgdirection2">
761 762 763
			<default value="/autopilot/radionav-channel/hdg-error/heading-4-error-deg"/>
			<test value="/autopilot/radionav-channel/hdg-error/heading-3-error-deg">
				/autopilot/radionav-channel/hdg-error/heading-1-error-deg gt 180
764 765 766 767
			</test>
			<output>/autopilot/radionav-channel/heading-error-deg</output>
		</switch>

768 769 770 771 772 773 774 775 776
		<switch name="validdata">
			<default value="/autopilot/radionav-channel/heading-error-deg"/>
			<test value="0">
				/autopilot/radionav-channel/in-range eq 0
			</test>
			<output>/autopilot/radionav-channel/heading-error-deg</output>
		</switch>


777

778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
<!--the heading error is clipped to -20 to 20 deg -->
		<pure_gain name="/autopilot/radionav-channel/lmd-hdg-error">
			<input>/autopilot/radionav-channel/heading-error-deg</input>
			<gain>1.0</gain>
			<clipto>
				<min>-20</min>
				<max>20</max>
			</clipto>
		</pure_gain>

<!--determining the target turn rate using the hdg error. Note that kp and the clipped hdg error determines the maximum turnrate-->
		<pid name="/autopilot/radionav-channel/target-turn-rate">
			<input>/autopilot/radionav-channel/lmd-hdg-error</input>
			<kp>/autopilot/radionav-channel/lmd-hdg-error-kp</kp>							<!--180deg/min devided by 20deg -->
			<ki>/autopilot/radionav-channel/lmd-hdg-error-ki</ki>
			<kd>/autopilot/radionav-channel/lmd-hdg-error-kd</kd>
		</pid>
		
<!-- the turn rate (inverted) as measured by the turn coordinator in deg/s (RH panel) -->
		<fcs_function name="/autopilot/radionav-channel/turn-rate-inv">
			<function>
				<product>
					<value>-180.0</value>
					<property>/instrumentation/turn-indicator/indicated-turn-rate</property>  <!--pos right-->
				</product>
			</function>
		</fcs_function>

<!-- the turn rate error -->
		<fcs_function name="/autopilot/radionav-channel/turn-rate-error">
			<function>
				<sum>
					<property>/autopilot/radionav-channel/target-turn-rate</property>	
					<property>/autopilot/radionav-channel/turn-rate-inv</property>
				</sum>
			</function>
		</fcs_function>

816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
<!-- the flight director bank angle (relative to AC position/turnrate) -->
		<fcs_function name="/autopilot/radionav-channel/fld-bank-deg">
			<function>
				<product>
					<property>/autopilot/radionav-channel/turn-rate-error</property>	
					<property>/autopilot/fms-channel/indicated-ground-speed-kt</property>
					<property>/extra500/const/NM2METER</property>
					<property>/extra500/const/SEC2MIN</property>
					<property>/extra500/const/SEC2MIN</property>
					<property>/extra500/const/SEC2MIN</property>
					<pow>	
						<property>/extra500/const/G0</property>
						<value>-1</value>
					</pow>
				</product>
			</function>
		</fcs_function>


835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
<!-- the commanded aileron position change using the turn rate error -->
		<pid name="/autopilot/radionav-channel/cmd-ail-change">
			<input>/autopilot/radionav-channel/turn-rate-error</input>
			<kp>/autopilot/radionav-channel/turn-rate-error-kp</kp>							
			<ki>/autopilot/radionav-channel/turn-rate-error-ki</ki>
			<kd>/autopilot/radionav-channel/turn-rate-error-kd</kd>
		</pid>

<!-- calculating the new aileron position-->
		<fcs_function name="/autopilot/radionav-channel/cmd-ap-ail-pos-norm-raw">
			<function>
				<sum>
					<property>fcs/aileron-cmd-tot</property>	
					<product>
                                  		<property>/autopilot/mode/nav</property>
						<value>1.0</value>
						<property>/autopilot/radionav-channel/cmd-ail-change</property>
						<property>sim-dt-sec</property>
					</product>
				</sum>
			</function>
			<output>/autopilot/radionav-channel/cmd-ap-ail-pos-norm-raw</output>
		</fcs_function>

<!-- making sure the aileron servo is not going to fast-->	
		<actuator name="/autopilot/radionav-channel/ail-servo">
			<input>/autopilot/radionav-channel/cmd-ap-ail-pos-norm-raw</input>
862
			<rate_limit>0.05</rate_limit>
863 864 865 866 867 868 869
			<clipto>
				<min>-1</min>
				<max>1</max>
			</clipto>
			<output>/autopilot/radionav-channel/cmd-ap-ail-pos-norm</output>
		</actuator>

870
<!--this makes the aileron pilot input to move along, so when the nav mode is disconnected, the ailerons are in the correct position-->
871 872
		<switch name="radionavon">
			<default value="/controls/flight/aileron"/>
873
			<test logic="AND" value="/autopilot/radionav-channel/cmd-ap-ail-pos-norm">
874
				<test logic="AND" value="1">
875
					/autopilot/mode/nav eq 1
876
					/autopilot/settings/ap eq 1
877 878 879 880 881
				</test>
				<test logic="OR" value="1">
					/instrumentation/nav-source eq 0
					/instrumentation/nav-source eq 1
				</test>
882 883 884 885
			</test>
			<output>/controls/flight/aileron</output>
		</switch>

886
<!-- switch off HDG mode (for HDG+NAV mode)-->
Eric van den Berg's avatar
Eric van den Berg committed
887 888 889
		<switch name="hdgoff">
			<default value="/autopilot/mode/heading"/>
			<test logic="AND" value="0">
Eric van den Berg's avatar
Eric van den Berg committed
890 891 892 893 894 895 896 897 898 899 900 901 902 903
				<test logic="AND" value="1">
					/autopilot/mode/nav eq 1
					/autopilot/radionav-channel/needle-defl-full eq 0
				</test>
				<test logic="OR" value="1">
					<test logic="AND" value="1">
						/autopilot/radionav-channel/heading-needle-deflection-norm gt 0
						/autopilot/radionav-channel/heading-error-deg lt 0
					</test>
					<test logic="AND" value="1">
						/autopilot/radionav-channel/heading-needle-deflection-norm lt 0
						/autopilot/radionav-channel/heading-error-deg gt 0
					</test>
				</test>
Eric van den Berg's avatar
Eric van den Berg committed
904 905 906 907
			</test>
			<output>/autopilot/mode/heading</output>
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
908 909 910 911
<!-- setting APR mode ON automatically-->
		<switch name="APRmodeon">
			<default value="/autopilot/mode/apr"/>
			<test logic="AND" value="1">
912 913 914 915 916 917
				<test logic="OR" value="1">
					/instrumentation/nav-source eq 0
					/instrumentation/nav-source eq 1
				</test>
				<test logic="AND" value="1">
					/autopilot/mode/nav eq 1
Eric van den Berg's avatar
Eric van den Berg committed
918
					/autopilot/mode/rev eq 0
919 920 921
					/autopilot/radionav-channel/is-localizer-frequency eq 1
					/autopilot/radionav-channel/timer-cap gt 5
				</test>
Eric van den Berg's avatar
Eric van den Berg committed
922 923 924 925
			</test>
			<output>/autopilot/mode/apr</output>
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
<!-- setting APR-REV mode ON automatically-->
		<switch name="APRREVmodeon">
			<default value="/autopilot/mode/apr-rev"/>
			<test logic="AND" value="1">
				<test logic="OR" value="1">
					/instrumentation/nav-source eq 0
					/instrumentation/nav-source eq 1
				</test>
				<test logic="AND" value="1">
					/autopilot/mode/nav eq 1
					/autopilot/mode/rev eq 1
					/autopilot/radionav-channel/is-localizer-frequency eq 1
					/autopilot/radionav-channel/timer-cap gt 5
				</test>
			</test>
			<output>/autopilot/mode/apr-rev</output>
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
944
<!-- switching APR mode off when nav mode is not on, on FMS, not tuned to localizer freq, CDI needle defl more then 1 (less then -1)-->
Eric van den Berg's avatar
Eric van den Berg committed
945 946 947 948
		<switch name="APRmodeoff">
			<default value="/autopilot/mode/apr"/>
			<test logic="OR" value="0">
				/autopilot/mode/nav eq 0
Eric van den Berg's avatar
Eric van den Berg committed
949
				/instrumentation/nav-source eq 2
Eric van den Berg's avatar
Eric van den Berg committed
950 951 952 953 954 955
				/autopilot/radionav-channel/is-localizer-frequency eq 0
				/autopilot/radionav-channel/timer-full-defl eq 1
			</test>
			<output>/autopilot/mode/apr</output>
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
956 957 958 959 960 961 962 963 964 965 966 967
<!-- same for rev-apr-->
		<switch name="APRREVmodeoff">
			<default value="/autopilot/mode/apr-rev"/>
			<test logic="OR" value="0">
				/autopilot/mode/nav eq 0
				/instrumentation/nav-source eq 2
				/autopilot/radionav-channel/is-localizer-frequency eq 0
				/autopilot/radionav-channel/timer-full-defl eq 1
			</test>
			<output>/autopilot/mode/apr-rev</output>
		</switch>

968 969
	</channel>

Eric van den Berg's avatar
Eric van den Berg committed
970
<!-- ********************* GLIDESLOPE ********************-->
971
	<channel name="glideslope">
972 973

<!-- gs fail used for indication -->
974
		<!--switch name="gsnavfail">
975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
			<default value="0"/>
			<test logic="OR" value="1">
				<test logic="AND">
					<test logic="AND">
						/instrumentation/nav-source eq 0
					</test>
					<test logic="OR">
						/instrumentation/nav[0]/operable eq 0
						/instrumentation/nav[0]/gs-in-range eq 0
					</test>
				</test>
				<test logic="AND">
					<test logic="AND">
						/instrumentation/nav-source eq 1
					</test>
					<test logic="OR">
						/instrumentation/nav[1]/operable eq 0
						/instrumentation/nav[1]/gs-in-range eq 0
					</test>
				</test>
			</test>
			<output>/autopilot/gs-channel/fail</output>
		</switch>

		<switch name="gsind">
			<default value="/autopilot/mode/gs"/>
			<test value="/autopilot/indication/timer-on">
				/autopilot/gs-channel/fail eq 1
				/autopilot/mode/gs eq 1
			</test>
			<output>/autopilot/indication/gs</output>
1006
		</switch-->
1007

1008
	
Eric van den Berg's avatar
Eric van den Berg committed
1009
	<!-- selecting GS properties from active nav -->
1010 1011 1012 1013 1014
		<switch name="gsselect">
			<default value="/instrumentation/nav[0]/gs-in-range"/>
			<test value="/instrumentation/nav[1]/gs-in-range">
				/instrumentation/nav-source eq 1
			</test>
1015
			<output>/autopilot/gs-channel/gs-in-range</output>
1016 1017
		</switch>

1018 1019 1020 1021 1022
		<switch name="gsselect2">
			<default value="/instrumentation/nav[0]/has-gs"/>
			<test value="/instrumentation/nav[1]/has-gs">
				/instrumentation/nav-source eq 1
			</test>
1023
			<output>/autopilot/gs-channel/has-gs</output>
1024 1025 1026
		</switch>

		<switch name="gsselect3">
1027 1028 1029 1030
			<default value="/instrumentation/nav[0]/gs-needle-deflection-norm"/>
			<test value="/instrumentation/nav[1]/gs-needle-deflection-norm">
				/instrumentation/nav-source eq 1
			</test>
1031
			<output>/autopilot/gs-channel/gs-needle-deflection-norm</output>
1032 1033
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
1034
	<!-- arming GS -->
1035
		<switch name="armgs">
1036
			<default value="/autopilot/mode/gs-armed"/>
1037 1038 1039
			<test logic="AND" value="1">
				/autopilot/mode/nav eq 1
				/autopilot/mode/apr eq 1
Eric van den Berg's avatar
Eric van den Berg committed
1040
				/autopilot/mode/rev eq 0
1041
				/autopilot/mode/alt eq 1
1042
				/autopilot/mode/vs eq 0
1043
				/autopilot/gs-channel/gs-in-range eq 1
1044 1045
				/autopilot/radionav-channel/is-localizer-frequency eq 1
				/autopilot/radionav-channel/needle-defl-gt-half eq 0
1046 1047 1048 1049 1050 1051
				/autopilot/gs-channel/gs-needle-deflection-norm lt 0.1
				/autopilot/mode/gs-disable eq 0
			</test>
			<output>/autopilot/mode/gs-armed</output>
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
1052
	<!-- follow gs signal -->
1053 1054 1055 1056 1057 1058 1059 1060 1061
		<switch name="gs-follow">
			<default value="/autopilot/mode/gs-follow"/>
			<test logic="AND" value="1">
				/autopilot/gs-channel/gs-needle-deflection-norm lt 0.05	
				/autopilot/mode/gs-armed eq 1
			</test>
			<output>/autopilot/mode/gs-follow</output>
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
1062
	<!-- setting the GS indication (armed or following) -->
1063 1064 1065 1066 1067
		<switch name="gs-ind">
			<default value="0"/>
			<test logic="OR" value="1">
				/autopilot/mode/gs-follow eq 1		
				/autopilot/mode/gs-armed eq 1
1068 1069 1070 1071
			</test>
			<output>/autopilot/mode/gs</output>
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
1072
	<!-- automatic ALT mode off when GS(-follow) is active  -->
1073 1074 1075 1076 1077 1078 1079 1080
		<switch name="altoff">
			<default value="/autopilot/mode/alt"/>
			<test logic="AND" value="0">
				/autopilot/mode/gs-follow eq 1	
			</test>
			<output>/autopilot/mode/alt</output>
		</switch>

1081 1082 1083 1084 1085 1086 1087 1088
<!-- the gs-needle deflection differential part -->
		<pid name="/autopilot/gs-channel/gs-needle-deflection-pid">
			<input>/autopilot/gs-channel/gs-needle-deflection-norm</input>
			<kp>0</kp>							
			<ki>0</ki>
			<kd>/autopilot/gs-channel/gs-ndefl-gain-kd</kd>
			<output>/autopilot/gs-channel/gs-needle-deflection-diff</output>
		</pid>
Eric van den Berg's avatar
Eric van den Berg committed
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099

<!-- pitch error accel sensor damper-->
		<fcs_function name="/autopilot/gs-channel/accel-rate-damp">
			<function>
				<product>	
					<property>/autopilot/gs-channel/accel-rate-gain</property>
					<property>/autopilot/accsens-channel/ap-z-accel</property>
				</product>
			</function>
		</fcs_function>

Eric van den Berg's avatar
Eric van den Berg committed
1100 1101 1102 1103 1104 1105 1106
	
<!-- pitch error (NOT in deg) using the glideslope deflection, dampened by the accel sensor inthe AP computer-->
		<fcs_function name="/autopilot/gs-channel/pitch-error">
			<function>
				<product>
					<property>/autopilot/mode/gs-follow</property>
					<property>/autopilot/gs-channel/pitch-error-gain</property>
1107 1108
					<sum>
						<property>/autopilot/gs-channel/gs-needle-deflection-norm</property>
1109
						<property>/autopilot/gs-channel/gs-needle-deflection-diff</property>
Eric van den Berg's avatar
Eric van den Berg committed
1110
						<property>/autopilot/gs-channel/accel-rate-damp</property>
1111
					</sum>
Eric van den Berg's avatar
Eric van den Berg committed
1112 1113 1114 1115
				</product>
			</function>
		</fcs_function>

1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126
		<fcs_function name="/autopilot/gs-channel/fld-pitch-deg">
			<function>
				<product>
					<property>/autopilot/gs-channel/gs-needle-deflection-norm</property>
					<property>/autopilot/gs-channel/fd-gain</property>
				</product>
			</function>
		</fcs_function>



Eric van den Berg's avatar
Eric van den Berg committed
1127 1128 1129 1130 1131 1132
<!-- moving the elevator -->
		<fcs_function name="/autopilot/gs-channel/cmd-ap-elev-pos-norm-raw">
			<function>
				<sum>
					<property>fcs/elevator-cmd-tot</property>	
					<product>
1133
                                  	<property>/autopilot/mode/gs-follow</property>
Eric van den Berg's avatar
Eric van den Berg committed
1134 1135 1136 1137 1138 1139 1140 1141
						<value>1.0</value>
						<property>/autopilot/gs-channel/pitch-error</property>
						<property>sim-dt-sec</property>
					</product>
				</sum>
			</function>
			<output>/autopilot/gs-channel/cmd-ap-elev-pos-norm-raw</output>
		</fcs_function>
1142

Eric van den Berg's avatar
Eric van den Berg committed
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153
<!-- limiting the elevator movement speed -->
		<actuator name="/autopilot/gs-channel/pitch-servo">
			<input>/autopilot/gs-channel/cmd-ap-elev-pos-norm-raw</input>
			<rate_limit>0.2</rate_limit>
			<clipto>
				<min>-1</min>
				<max>1</max>
			</clipto>
			<output>/autopilot/gs-channel/cmd-ap-elev-pos-norm</output>
		</actuator>

1154
<!--this makes the elevator pilot input to move along, so when the gs mode is disconnected, the elevator is in the correct position-->
Eric van den Berg's avatar
Eric van den Berg committed
1155 1156
		<switch name="gson">
			<default value="/controls/flight/elevator"/>
1157
			<test logic="AND" value="/autopilot/gs-channel/cmd-ap-elev-pos-norm">
Eric van den Berg's avatar
Eric van den Berg committed
1158
				/autopilot/mode/gs-follow eq 1
1159
				/autopilot/settings/ap eq 1
Eric van den Berg's avatar
Eric van den Berg committed
1160 1161 1162
			</test>
			<output>/controls/flight/elevator</output>
		</switch>
1163 1164 1165

	</channel>

1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182
<!--***************************************FMS (GPS) NAVIGATION**********************************************************************-->

	<channel name="fmsnav">

<!-- 	/instrumentation/gps/wp/leg-true-course-deg
	/instrumentation/gps/wp/leg-distance-nm
	/instrumentation/gps/wp/wp[1]/distance-nm
	/instrumentation/gps/wp/wp[1]/bearing-true-deg (direct to next waypoint, wp[1])
	/instrumentation/gps/wp/wp[1]/course-error-nm (left of leg =pos) = /instrumentation/nav[2]/crosstrack-error-m
	/instrumentation/gps/cdi-deflection = /instrumentation/nav[2]/heading-needle-deflection-norm = (dependent on /instrumentation/gps/config/cdi-max-deflection-nm
	/instrumentation/gps/indicated-ground-speed-kt
	/instrumentation/gps/indicated-track-true-deg (aircraft track)
	/instrumentation/gps/serviceable
	/instrumentation/gps/raim (should be 1)

-->

1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219
<!-- fms fail used for indication -->
		<switch name="fmsnavfail">
			<default value="0"/>
				<test logic="OR" value="1">
					<test logic="AND" value="1">
						/instrumentation/nav-source eq 2
						/instrumentation/gps/serviceable eq 0
						/instrumentation/gps[1]/serviceable eq 0
						/autopilot/route-manager/current-wp eq -1
					</test>
					<test logic="OR" value="1">
						/instrumentation/gps/raim eq 0
					</test>
				</test>
			<output>/autopilot/fms-channel/fail</output>
		</switch>

		<switch name="fmsnav">
			<default value="/autopilot/mode/nav"/>
			<test logic="AND" value="/autopilot/indication/timer-on">
				<test logic="AND" value="1">
					/autopilot/mode/nav eq 1
				</test>
				<test logic="OR" value="1">
					<test logic="AND" value="1">
						/instrumentation/nav-source eq 2
						/autopilot/fms-channel/fail eq 1
					</test>
					<test logic="AND" value="1">
						/instrumentation/nav-source ne 2
						/autopilot/radionav-channel/fail eq 1
					</test>
				</test>
			</test>
			<output>/autopilot/indication/nav</output>
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233
	<!-- determining if fms is "servicable" -->
		<switch name="fmsservicable">
			<default value="0"/>
			<test logic="AND" value="1">
				<test logic="AND" value="1">
					/instrumentation/gps/raim eq 1
				</test>
				<test logic="OR" value="1">
					/instrumentation/gps/serviceable eq 1
					/instrumentation/gps[1]/serviceable eq 1
				</test>
			</test>
			<output>/autopilot/fms-channel/serviceable</output>
		</switch>
1234

1235
	<!-- selecting GPS properties from gps1 or 2 depending on "serviceable" -->
1236 1237 1238
		<switch name="gpsselect1">
			<default value="/instrumentation/gps/wp/leg-true-course-deg"/>
			<test value="/instrumentation/gps[1]/wp/leg-true-course-deg">
Eric van den Berg's avatar
Eric van den Berg committed
1239
				/instrumentation/gps/serviceable eq 0
1240 1241 1242 1243
			</test>
			<output>/autopilot/fms-channel/leg-true-course-deg</output>
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
1244 1245 1246 1247 1248 1249 1250 1251
		<switch name="gpsselect1b">
			<default value="/instrumentation/gps/wp/leg-mag-course-deg"/>
			<test value="/instrumentation/gps[1]/wp/leg-mag-course-deg">
				/instrumentation/gps/serviceable eq 0
			</test>
			<output>/autopilot/fms-channel/leg-mag-course-deg</output>
		</switch>

1252
		<switch name="gpsselect2">
1253 1254 1255 1256 1257 1258 1259 1260
			<default value="/instrumentation/gps/wp/wp[1]/bearing-true-deg"/>
			<test value="/instrumentation/gps[1]/wp/wp[1]/bearing-true-deg">
				/instrumentation/gps/serviceable eq 0
			</test>
			<output>/autopilot/fms-channel/dto/true-course-deg</output>
		</switch>

		<switch name="gpsselect3">
1261 1262
			<default value="/instrumentation/gps/wp/wp[1]/course-error-nm"/>
			<test value="/instrumentation/gps[1]/wp/wp[1]/course-error-nm">
Eric van den Berg's avatar
Eric van den Berg committed
1263
				/instrumentation/gps/serviceable eq 0
1264 1265 1266 1267
			</test>
			<output>/autopilot/fms-channel/course-error-nm</output>
		</switch>

1268 1269 1270 1271 1272 1273 1274 1275 1276
		<pure_gain name="/autopilot/fms-channel/course-error-norm">
			<input>/autopilot/fms-channel/course-error-nm</input>
			<gain>0.3333333</gain>
			<clipto>
				<min>-1</min>
				<max>1</max>
			</clipto>
		</pure_gain>

1277
		<switch name="gpsselect4">
1278 1279
			<default value="/instrumentation/gps/cdi-deflection"/>
			<test value="/instrumentation/gps[1]/cdi-deflection">
Eric van den Berg's avatar
Eric van den Berg committed
1280
				/instrumentation/gps/serviceable eq 0
1281 1282 1283 1284
			</test>
			<output>/autopilot/fms-channel/cdi-deflection</output>
		</switch>

1285
		<switch name="gpsselect5">
1286 1287
			<default value="/instrumentation/gps/indicated-track-true-deg"/>
			<test value="/instrumentation/gps[1]/indicated-track-true-deg">
Eric van den Berg's avatar
Eric van den Berg committed
1288
				/instrumentation/gps/serviceable eq 0
1289 1290 1291 1292
			</test>
			<output>/autopilot/fms-channel/indicated-track-true-deg</output>
		</switch>

1293
		<switch name="gpsselect6">
1294 1295
			<default value="/instrumentation/gps/wp/leg-distance-nm"/>
			<test value="/instrumentation/gps[1]/wp/leg-distance-nm">
Eric van den Berg's avatar
Eric van den Berg committed
1296
				/instrumentation/gps/serviceable eq 0
1297 1298 1299 1300
			</test>
			<output>/autopilot/fms-channel/leg-distance</output>
		</switch>

1301
		<switch name="gpsselect7">
Eric van den Berg's avatar
Eric van den Berg committed
1302 1303
			<default value="/instrumentation/gps/indicated-ground-speed-kt"/>
			<test value="/instrumentation/gps[1]/indicated-ground-speed-kt">
Eric van den Berg's avatar
Eric van den Berg committed
1304
				/instrumentation/gps/serviceable eq 0
Eric van den Berg's avatar
Eric van den Berg committed
1305 1306 1307 1308
			</test>
			<output>/autopilot/fms-channel/indicated-ground-speed-kt</output>
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
1309 1310 1311 1312 1313 1314 1315 1316
		<switch name="gpsselect8">
			<default value="/instrumentation/gps/wp/wp[1]/distance-nm"/>
			<test value="/instrumentation/gps[1]/wp/wp[1]/distance-nm">
				/instrumentation/gps/serviceable eq 0
			</test>
			<output>/autopilot/fms-channel/gpss/distance-nm</output>
		</switch>

1317 1318 1319 1320 1321 1322 1323 1324
		<switch name="gpsselect9">
			<default value="/instrumentation/gps/desired-course-deg"/>
			<test value="/instrumentation/gps[1]/desired-course-deg">
				/instrumentation/gps/serviceable eq 0
			</test>
			<output>/autopilot/fms-channel/obs/desired-course-deg</output>
		</switch>

1325
<!-- AUTOTUNING -->
1326
<!-- see also /nasal/AvidyneEntregra9/fms.nas; _onCurrentWaypointChange -->
Eric van den Berg's avatar
Eric van den Berg committed
1327 1328 1329
<!-- setting the course of nav1 automatically when fms active and selected -->
		<switch name="courseNav1set">
			<default value="/instrumentation/nav/radials/selected-deg"/>
Eric van den Berg's avatar
Eric van den Berg committed
1330
			<test logic="AND" value="/autopilot/fms-channel/leg-mag-course-deg">
Eric van den Berg's avatar
Eric van den Berg committed
1331 1332
				/autopilot/route-manager/current-wp gt -1
				/instrumentation/nav-source eq 2
1333
				/autopilot/fms-channel/autotuning/approach eq 0
Eric van den Berg's avatar
Eric van den Berg committed
1334 1335 1336 1337
			</test>
			<output>/instrumentation/nav/radials/selected-deg</output>
		</switch>

1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381
		<fcs_function name="/autopilot/fms-channel/autotuning/d-psi-deg-1">
			<function>
				<difference> 
						<property>/instrumentation/nav/radials/selected-deg</property> 
						<property>/autopilot/radionav-channel/heading-deg</property> 
				</difference>
			</function>
		</fcs_function>

		<fcs_function name="/autopilot/fms-channel/autotuning/d-psi-deg-2">
			<function>
				<sum>
					<property>/autopilot/fms-channel/autotuning/d-psi-deg-1</property> 
					<value>360</value> 
				</sum>
			</function>
		</fcs_function>

		<fcs_function name="/autopilot/fms-channel/autotuning/d-psi-deg-3">
			<function>
				<difference>
					<property>/autopilot/fms-channel/autotuning/d-psi-deg-1</property> 
					<value>360</value> 
				</difference>
			</function>
		</fcs_function>

		<switch name="headingerror1">
			<default value="/autopilot/fms-channel/autotuning/d-psi-deg-1"/>
			<test value="/autopilot/fms-channel/autotuning/d-psi-deg-2">
				/autopilot/fms-channel/autotuning/d-psi-deg-1 le -180
			</test>
			<output>/autopilot/fms-channel/autotuning/d-psi-deg-4</output>
		</switch>

		<switch name="headingerror2">
			<default value="/autopilot/fms-channel/autotuning//d-psi-deg-4"/>
			<test value="/autopilot/fms-channel/autotuning/d-psi-deg-3">
				/autopilot/fms-channel/autotuning/d-psi-deg-1 ge 180
			</test>
			<output>/autopilot/fms-channel/autotuning/d-psi-deg</output>
		</switch>

<!--switching from FMS to Nav1 on approach -->
1382 1383 1384 1385 1386 1387
		<switch name="AutoSwitchNav1">
			<default value="/instrumentation/nav-source"/>
			<test logic="AND" value="0">
				/extra500/instrumentation/IFD-LH/settings/autonav1 eq 1
				/autopilot/fms-channel/autotuning/approach eq 1
				/instrumentation/nav-source eq 2
1388 1389 1390 1391 1392 1393
				/autopilot/settings/dto-leg ne 1 
				/autopilot/settings/obs-mode ne 1 
				/autopilot/settings/fly-vector ne 1
				/instrumentation/nav/nav-distance lt 33336
				/autopilot/fms-channel/autotuning/d-psi-deg lt 15
				/autopilot/fms-channel/autotuning/d-psi-deg gt -15
1394 1395 1396 1397 1398
				/autopilot/radionav-channel/timer-cap gt 10
			</test>
			<output>/instrumentation/nav-source</output>
		</switch>

Eric van den Berg's avatar
Eric van den Berg committed
1399
<!-- GPSS calcs -->
1400 1401
<!-- the course change at next waypoint -->
		<fcs_function name="/autopilot/fms-channel/gpss/angle/d-psi-deg-1">
Eric van den Berg's avatar
Eric van den Berg committed
1402
			<function>
1403
				<difference> 
1404
<!-- /autopilot/fms-channel/gpss/next-bearing-deg set in /nasal/AvidyneEntregra9/fms.nas; __nextGpssBearing -->
Eric van den Berg's avatar
Eric van den Berg committed
1405 1406
						<property>/autopilot/fms-channel/gpss/next-bearing-deg</property> 
						<property>/autopilot/fms-channel/indicated-track-true-deg</property> 
1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431
				</difference>
			</function>
		</fcs_function>

		<fcs_function name="/autopilot/fms-channel/gpss/angle/d-psi-deg-2">
			<function>
				<sum>
					<property>/autopilot/fms-channel/gpss/angle/d-psi-deg-1</property> 
					<value>360</value> 
				</sum>
			</function>
		</fcs_function>

		<fcs_function name="/autopilot/fms-channel/gpss/angle/d-psi-deg-3">
			<function>
				<difference>
					<property>/autopilot/fms-channel/gpss/angle/d-psi-deg-1</property> 
					<value>360</value> 
				</difference>
			</function>
		</fcs_function>

		<switch name="gpssangle">
			<default value="/autopilot/fms-channel/gpss/angle/d-psi-deg-1"/>
			<test value="/autopilot/fms-channel/gpss/angle/d-psi-deg-2">
1432
				/autopilot/fms-channel/gpss/angle/d-psi-deg-1 le -180
1433 1434 1435 1436 1437 1438 1439
			</test>
			<output>/autopilot/fms-channel/gpss/angle/d-psi-deg-4</output>
		</switch>

		<switch name="gpssangle2">
			<default value="/autopilot/fms-channel/gpss/angle/d-psi-deg-4"/>
			<test value="/autopilot/fms-channel/gpss/angle/d-psi-deg-3">
1440
				/autopilot/fms-channel/gpss/angle/d-psi-deg-1 ge 180
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472
			</test>
			<output>/autopilot/fms-channel/gpss/angle/d-psi-deg</output>
		</switch>

<!-- target turn rate in GPSS turn dependent on course change -->
		<fcs_function name="/autopilot/fms-channel/gpss/gpss-turn-rate-nc">
			<function>
				<product>
					<property>/autopilot/fms-channel/gpss/gpss-turn-rate-p</property> 
					<property>/autopilot/fms-channel/gpss/angle/d-psi-deg</property> 
				</product>
			</function>
		</fcs_function>

<!-- limiting the target turn rate to standard turn (188.49162 rad/h) -->
		<pure_gain name="/autopilot/fms-channel/gpss/gpss-turn-rate">
			<input>/autopilot/fms-channel/gpss/gpss-turn-rate-nc</input>
			<gain>1.0</gain>
			<clipto>
				<min>-188.49162</min>
				<max>188.49162</max>
			</clipto>
		</pure_gain>

<!-- lead in time dependent on target turn rate -->
		<fcs_function name="/autopilot/fms-channel/gpss/time-lead-in-h">
			<function>
				<product>
					<abs>
						<property>/autopilot/fms-channel/gpss/gpss-turn-rate</property>
					</abs> 
					<property>/autopilot/fms-channel/gpss/time-lead-in-p</property> 
Eric van den Berg's avatar
Eric van den Berg committed
1473 1474 1475 1476 1477
				</product>
			</function>
		</fcs_function>

<!-- when next waypoint distance less than this number: start to turn -->
Eric van den Berg's avatar
Eric van den Berg committed
1478
		<fcs_function name="/autopilot/fms-channel/gpss/distance-to-turn-raw">
Eric van den Berg's avatar
Eric van den Berg committed
1479
			<function>
1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493
			<product>
				<sum>
					<product>
						<property>/autopilot/fms-channel/indicated-ground-speed-kt</property> 
						<pow>
							<max>
								<abs>
									<property>/autopilot/fms-channel/gpss/gpss-turn-rate</property>
								</abs>
								<value>1</value> <!--just to prevent seg fault -->
							</max>
							<value>-1</value>
						</pow>
						<tan> 
1494
							<abs>
1495 1496 1497 1498 1499
								<product>
									<value>0.5</value>
									<property>/extra500/const/DEG2RAD</property>
									<property>/autopilot/fms-channel/gpss/angle/d-psi-deg</property> 
								</product>
1500
							</abs>
1501 1502 1503 1504 1505 1506 1507
						</tan>
					</product>
					<product>
						<property>/autopilot/fms-channel/gpss/time-lead-in-h</property> 
						<max>
							<property>/autopilot/fms-channel/indicated-ground-speed-kt</property>
							<value>60</value>
1508
						</max>
1509 1510 1511
					</product>
				</sum>
			</product>
Eric van den Berg's avatar
Eric van den Berg committed
1512 1513 1514
			</function>
		</fcs_function>

Eric van den Berg's avatar
Eric van den Berg committed
1515 1516 1517 1518 1519 1520
<!-- limiting the distance-to-turn to 5 nm (needed for some direct-to cases, maybe a better dto-off can be devised?)-->
		<pure_gain name="/autopilot/fms-channel/gpss/distance-to-turn">
			<input>/autopilot/fms-channel/gpss/distance-to-turn-raw</input>
			<gain>1.0</gain>
			<clipto>
				<max>5</max>
Eric van den Berg's avatar
Eric van den Berg committed
1521
				<min>0.05</min>
Eric van den Berg's avatar
Eric van den Berg committed
1522 1523 1524
			</clipto>
		</pure_gain>

1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543

<!--calculating the target heading to intercept the leg-->
		<pid name="/autopilot/fms-channel/relative-diff-heading-target-deg">
			<input>/autopilot/fms-channel/course-error-nm</input>
			<kp>/autopilot/fms-channel/tgt-hdg-kp</kp>							
			<ki>/autopilot/fms-channel/tgt-hdg-ki</ki>
			<kd>/autopilot/fms-channel/tgt-hdg-kd</kd>
			<output>/autopilot/fms-channel/relative-d-heading-target-deg</output>
		</pid>

		<fcs_function name="/autopilot/fms-channel/p-gain">
			<function>
				<product>
					<property>/autopilot/fms-channel/gain</property>
					<pow> 
						<max>
							<abs>
								<property>/autopilot/fms-channel/relative-d-heading-target-deg</property> 
							</abs>
1544
							<value>0.000001</value>  <!--just to prevent seg fault -->
1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570
						</max>
						<value>-1</value>
					</pow>
				</product>
			</function>
		</fcs_function>

		<pure_gain name="/autopilot/fms-channel/p-gain-lmd">
			<input>/autopilot/fms-channel/p-gain</input>
			<gain>1</gain>
			<clipto>
				<min>0</min>
				<max>225</max>		<!-- making sure it starts to turns at min needle defl of |0.2| --> 
			</clipto>
		</pure_gain>

		<pure_gain name="/autopilot/fms-channel/relative-course-target-deg">
			<input>/autopilot/fms-channel/course-error-nm</input>
			<gain>/autopilot/fms-channel/p-gain-lmd</gain>
			<clipto>
				<min>/autopilot/fms-channel/rel-hdg-min</min>
				<max>/autopilot/fms-channel/rel-hdg-max</max>
			</clipto>
		</pure_gain>

<!--target course -->
1571
		<fcs_function name="/autopilot/fms-channel/course-target1-deg">
1572 1573 1574 1575 1576 1577 1578
			<function>
				<sum>
					<property>/autopilot/fms-channel/leg-true-course-deg</property> 
					<property>/autopilot/fms-channel/relative-course-target-deg</property> 
				</sum>
			</function>
		</fcs_function>
1579 1580 1581 1582 1583 1584 1585
	
	<!-- switching target course between normal fms and Direct To course -->
		<switch name="dtoselect">
			<default value="/autopilot/fms-channel/course-target1-deg"/>
			<test value="/autopilot/fms-channel/dto/true-course-deg">
				/autopilot/settings/dto-leg eq 1
			</test>
1586 1587 1588 1589 1590 1591 1592
			<output>/autopilot/fms-channel/course-target2-deg</output>
		</switch>

		<fcs_function name="/autopilot/fms-channel/course-target3-deg">
			<function>
				<sum>
					<property>/autopilot/fms-channel/obs/desired-course-deg</property> 
1593
					<property>/environment/magnetic-variation-deg</property>  <!--converting to true course -->
1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604
					<property>/autopilot/fms-channel/relative-course-target-deg</property> 
				</sum>
			</function>
		</fcs_function>

	<!-- switching target course between normal fms/Direct To  and OBS course -->
		<switch name="obsselect">
			<default value="/autopilot/fms-channel/course-target2-deg"/>
			<test value="/autopilot/fms-channel/course-target3-deg">
				/autopilot/settings/obs-mode eq 1
			</test>
1605 1606
			<output>/autopilot/fms-channel/course-target-deg</output>
		</switch>
1607

Eric van den Berg's avatar
Eric van den Berg committed
1608
		<fcs_function name="course-target-mag-deg">
1609 1610 1611 1612 1613 1614 1615 1616 1617 1618
			<function>
				<difference>
					<property>/autopilot/fms-channel/course-target-deg</property> 
					<property>/environment/magnetic-variation-deg</property>  
				</difference>
			</function>
			<output>/autopilot/fms-channel/course-target-mag-deg</output>
		</fcs_function>


1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645
		<fcs_function name="/autopilot/fms-channel/crs-error/course-1-error-deg">
			<function>
				<difference>
					<property>/autopilot/fms-channel/course-target-deg</property> 
					<property>/autopilot/fms-channel/indicated-track-true-deg</property> 
				</difference>
			</function>
		</fcs_function>

		<fcs_function name="/autopilot/fms-channel/crs-error/course-2-error-deg">
			<function>
				<sum>
					<property>/autopilot/fms-channel/crs-error/course-1-error-deg</property> 
					<value>360</value> 
				</sum>
			</function>
		</fcs_function>

		<fcs_function name="/autopilot/fms-channel/crs-error/course-3-error-deg">
			<function>
				<difference>
					<property>/autopilot/fms-channel/crs-error/course-1-error-deg</property> 
					<value>360</value> 
				</difference>
			</function>
		</fcs_function>

Eric van den Berg's avatar
Eric van den Berg committed
1646
		<switch name="crsdirection1">
1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658
			<default value="/autopilot/fms-channel/crs-error/course-1-error-deg"/>
			<test value="/autopilot/fms-channel/crs-error/course-2-error-deg">
				/autopilot/fms-channel/crs-error/course-1-error-deg lt -180
			</test>
			<output>/autopilot/fms-channel/crs-error/course-4-error-deg</output>
		</switch>

		<switch name="crsdirection2">
			<default value="/autopilot/fms-channel/crs-error/course-4-error-deg"/>
			<test value="/autopilot/fms-channel/crs-error/course-3-error-deg">
				/autopilot/fms-channel/crs-error/course-1-error-deg gt 180
			</test>
Eric van den Berg's avatar
Eric van den Berg committed
1659 1660 1661 1662 1663 1664 1665 1666
			<output>/autopilot/fms-channel/crs-error/course-5-error-deg</output>
		</switch>

		<switch name="crsdirection3">
			<default value="/autopilot/fms-channel/crs-error/course-5-error-deg"/>
			<test value="/autopilot/hdg-channel/heading-bug-error-deg">
				/autopilot/settings/fly-vector eq 1
			</test>
1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681
			<output>/autopilot/fms-channel/crs-error/course-error-deg</output>
		</switch>

<!--the course error is clipped to -20 to 20 deg -->
		<pure_gain name="/autopilot/fms-channel/lmd-crs-error-clp">
			<input>/autopilot/fms-channel/crs-error/course-error-deg</input>
			<gain>1.0</gain>
			<clipto>
				<min>-20</min>
				<max>20</max>
			</clipto>
		</pure_gain>

		<switch name="crserrorendofflp">
			<default value="/autopilot/fms-channel/lmd-crs-error-clp"/>
Eric van den Berg's avatar
Eric van den Berg committed
1682
			<test logic="OR" value="0">
1683 1684 1685 1686 1687 1688 1689
				<test logic="AND" value="0">
					/autopilot/fms-channel/leg-distance lt 0.0		<!-- end of flightplan -->
					/autopilot/settings/obs-mode eq 0				<!-- (not) in OBS mode: in OBS mode, leg-distance is lt 0! -->
				</test>
				<test logic="AND" value="0">
					/autopilot/fms-channel/serviceable eq 0			<!-- gps not working (both units or no satellites), no position -->
				</test>
1690 1691 1692 1693 1694
			</test>
			<output>/autopilot/fms-channel/lmd-crs-error</output>
		</switch>

<!--determining the target turn rate using the crs error. Note that kp and the clipped crs error determines the maximum turnrate-->
Eric van den Berg's avatar
Eric van den Berg committed
1695
		<pid name="/autopilot/fms-channel/target-turn-rate-pid">
1696 1697 1698 1699
			<input>/autopilot/fms-channel/lmd-crs-error</input>
			<kp>/autopilot/fms-channel/lmd-hdg-error-kp</kp>							<!--180deg/min devided by 20deg -->
			<ki>/autopilot/fms-channel/lmd-hdg-error-ki</ki>
			<kd>/autopilot/fms-channel/lmd-hdg-error-kd</kd>
Eric van den Berg's avatar
Eric van den Berg committed
1700
			<output>/autopilot/fms-channel/target-turn-rate-n</output>
1701
		</pid>
Eric van den Berg's avatar
Eric van den Berg committed
1702

1703
<!-- current waypointno + 1 -->
1704 1705 1706 1707 1708 1709 1710 1711 1712
		<fcs_function name="/autopilot/route-manager/current-wp-plus">
			<function>
				<sum>
					<property>/autopilot/route-manager/current-wp</property>
					<value>1</value> 
				</sum>
			</function>
		</fcs_function>

1713 1714 1715
		<switch name="dtooff">
			<default value="/autopilot/settings/dto-leg"/>
			<test logic="AND" value="0">
Eric van den Berg's avatar
Eric van den Berg committed
1716
				/autopilot/fms-channel/gpss/distance-to-turn gt /autopilot/fms-channel/gpss/distance-nm
1717 1718 1719 1720
			</test>
			<output>/autopilot/settings/dto-leg</output>
		</switch>

1721
<!-- switching the gpss turn on (and off), with latching function (by in-turn2)-->
1722
	<!-- also the next waypoint may not be the last to prevent "double next wp"-->
Eric van den Berg's avatar
Eric van den Berg committed
1723
		<switch name="gpsson">
1724 1725
			<default value="0"/>
			<test logic="AND" value="1">
1726 1727
				<test logic="AND" value="1">
					/autopilot/settings/dto-leg ne 1 <!-- this is needed for some reason; else when pressing Direct To, it will do into turn -->
1728
					/autopilot/settings/obs-mode ne 1 
Eric van den Berg's avatar
Eric van den Berg committed
1729
					/autopilot/settings/fly-vector ne 1
1730
					/autopilot/mode/gpss eq 1
1731
					/autopilot/route-manager/current-wp-plus ne /autopilot/route-manager/route/num
1732 1733
				</test>
				<test logic="OR" value="1">
Eric van den Berg's avatar
Eric van den Berg committed
1734
					/autopilot/fms-channel/gpss/distance-to-turn gt /autopilot/fms-channel/gpss/distance-nm
1735 1736
					/autopilot/fms-channel/gpss/in-turn2 eq 1
				</test>
Eric van den Berg's avatar
Eric van den Berg committed
1737
			</test>
1738
			<output>/autopilot/fms-channel/gpss/in-turn</output>
Eric van den Berg's avatar
Eric van den Berg committed
1739
		</switch>
1740

1741
<!-- setting the turn rate accordingly-->
1742
		<switch name="gpsson2">
1743 1744 1745
			<default value="/autopilot/fms-channel/target-turn-rate-n"/>
			<test logic="AND" value="/autopilot/fms-channel/gpss/gpss-turn-rate">
				/autopilot/fms-channel/gpss/in-turn eq 1
1746
			</test>
1747
			<output>/autopilot/fms-channel/target-turn-rate</output>
1748 1749
		</switch>

1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776
<!-- turn time  (assuming lead-out = lead-in time)-->
		<fcs_function name="/autopilot/fms-channel/gpss/turn-time-raw-s">
			<function>
				<product>
					<value>3600</value>
					<sum>
						<property>/autopilot/fms-channel/gpss/time-lead-in-h</property>
						<product>					
							<property>/extra500/const/DEG2RAD</property>
							<abs>
								<property>/autopilot/fms-channel/gpss/angle/d-psi-deg</property>
							</abs>
							<pow>
								<max>
									<abs>
										<property>/autopilot/fms-channel/gpss/gpss-turn-rate</property>
									</abs>
									<value>1</value> 
								</max>
								<value>-1</value>
							</pow> 
						</product>
					</sum>
				</product>
			</function>
		</fcs_function>

Eric van den Berg's avatar
Eric van den Berg committed