| 1 |
## |
| 2 |
# Century IIB Autopilot System |
| 3 |
# Models behavior of the Century IIB autopilot |
| 4 |
# one axis. |
| 5 |
# |
| 6 |
# One would also need the autopilot configuration file |
| 7 |
# CENTURYIIB.xml (in pa24-250/Systems) and the animation and panel |
| 8 |
# and .ac files in pa24-250/Models/Century-IIB. |
| 9 |
# |
| 10 |
# |
| 11 |
# Written by Dave Perry to match functionality described in |
| 12 |
# |
| 13 |
# CENTURY IIB |
| 14 |
# AUTOPILOT FLIGHT SYSTEM |
| 15 |
# PILOT'S OPERATING HANDBOOK |
| 16 |
# MARCH 1981 68S75 |
| 17 |
# |
| 18 |
# Draws heavily from the kap140 system written by Vegard Ovesen |
| 19 |
## |
| 20 |
|
| 21 |
# Properties |
| 22 |
|
| 23 |
var locks = "/autopilot/CENTURYIIB/locks"; |
| 24 |
var settings = "/autopilot/CENTURYIIB/settings"; |
| 25 |
var internal = "/autopilot/internal"; |
| 26 |
var flightControls = "/controls/flight"; |
| 27 |
var autopilotControls = "/autopilot/CENTURYIIB/controls"; |
| 28 |
|
| 29 |
# locks |
| 30 |
var propLocks = props.globals.getNode(locks, 1); |
| 31 |
|
| 32 |
var lockAprHold = propLocks.getNode("apr-hold", 1); |
| 33 |
var lockHdgHold = propLocks.getNode("hdg-hold", 1); |
| 34 |
var lockNavHold = propLocks.getNode("nav-hold", 1); |
| 35 |
var lockOmniHold = propLocks.getNode("omni-hold", 1); |
| 36 |
var lockRevHold = propLocks.getNode("rev-hold", 1); |
| 37 |
var lockRollAxis = propLocks.getNode("roll-axis", 1); |
| 38 |
var lockRollMode = propLocks.getNode("roll-mode", 1); |
| 39 |
var lockRollArm = propLocks.getNode("roll-arm", 1); |
| 40 |
|
| 41 |
|
| 42 |
var rollModes = { "OFF" : 0, "ROL" : 1, "HDG" : 2, "OMNI" : 3, "NAV" : 4, "REV" : 5, "APR" : 6 }; |
| 43 |
var rollArmModes = { "OFF" : 0, "NAV" : 1, "OMNI" : 2, "APR" : 3, "REV" : 4 }; |
| 44 |
|
| 45 |
# settings |
| 46 |
var propSettings = props.globals.getNode(settings, 1); |
| 47 |
|
| 48 |
var settingTargetInterceptAngle = propSettings.getNode("target-intercept-angle", 1); |
| 49 |
var settingTargetRollDeg = propSettings.getNode("target-roll-deg", 1); |
| 50 |
var settingRollKnobDeg = propSettings.getNode("roll-knob-deg", 1); |
| 51 |
|
| 52 |
#Flight controls |
| 53 |
var propFlightControls = props.globals.getNode(flightControls, 1); |
| 54 |
|
| 55 |
var elevatorControl = propFlightControls.getNode("elevator", 1); |
| 56 |
var elevatorTrimControl = propFlightControls.getNode("elevator-trim", 1); |
| 57 |
|
| 58 |
#Autopilot controls |
| 59 |
var propAutopilotControls = props.globals.getNode(autopilotControls, 1); |
| 60 |
|
| 61 |
var rollControl = propAutopilotControls.getNode("roll", 1); |
| 62 |
# values 0 (A/P switch off) and 1 (A/P switch on) |
| 63 |
var hdgControl = propAutopilotControls.getNode("hdg", 1); |
| 64 |
# values 0 (hdg switch off) and 1 (hdg switch on) |
| 65 |
var modeControl = propAutopilotControls.getNode("mode", 1); |
| 66 |
# values 0 NAV, 1 OMNI, 2 HDG, 3 LOC, 4 LOC REV |
| 67 |
|
| 68 |
var headingNeedleDeflection = "/instrumentation/nav/heading-needle-deflection"; |
| 69 |
var power="/systems/electrical/outputs/autopilot"; |
| 70 |
var filteredHeadingNeedleDeflection = "/autopilot/internal/filtered-heading-needle-deflection"; |
| 71 |
|
| 72 |
# Initialize Variables |
| 73 |
var valueTest = 0; |
| 74 |
var lastValue = 0; |
| 75 |
var newValue = 0; |
| 76 |
var minVoltageLimit = 8.0; |
| 77 |
var newMode = 2; |
| 78 |
var oldMode = 2; |
| 79 |
var deviation = 0; |
| 80 |
rollControl.setDoubleValue(0.0); |
| 81 |
hdgControl.setDoubleValue(0.0); |
| 82 |
modeControl.setDoubleValue(2.0); |
| 83 |
|
| 84 |
var apInit = func { |
| 85 |
##print("ap init"); |
| 86 |
|
| 87 |
## |
| 88 |
# Initialises the autopilot. |
| 89 |
## |
| 90 |
|
| 91 |
lockAprHold.setBoolValue(0); |
| 92 |
lockHdgHold.setBoolValue(0); |
| 93 |
lockNavHold.setBoolValue(0); |
| 94 |
lockOmniHold.setBoolValue(0); |
| 95 |
lockRevHold.setBoolValue(0); |
| 96 |
lockRollAxis.setBoolValue(0); |
| 97 |
lockRollMode.setIntValue(rollModes["OFF"]); |
| 98 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 99 |
# Reset the memory for power down or power up |
| 100 |
settingTargetInterceptAngle.setDoubleValue(0.0); |
| 101 |
settingTargetRollDeg.setDoubleValue(0.0); |
| 102 |
settingRollKnobDeg.setDoubleValue(0.0); |
| 103 |
} |
| 104 |
|
| 105 |
var apPower = func { |
| 106 |
|
| 107 |
## Monitor autopilot power |
| 108 |
## Call apInit if the power is too low |
| 109 |
|
| 110 |
if (getprop(power) < minVoltageLimit) { |
| 111 |
newValue = 0; |
| 112 |
} else { |
| 113 |
newValue = 1; |
| 114 |
} |
| 115 |
|
| 116 |
valueTest = newValue - lastValue; |
| 117 |
# print("v_test = ", v_test); |
| 118 |
if (valueTest > 0.5) { |
| 119 |
# autopilot just powered up |
| 120 |
logprint(3, "CENTURY IIB power up"); |
| 121 |
apInit(); |
| 122 |
} elsif (valueTest < -0.5) { |
| 123 |
# autopilot just lost power |
| 124 |
logprint(3, "CENTURY IIB power lost"); |
| 125 |
apInit(); |
| 126 |
# note: all button and knobs disabled in functions below |
| 127 |
} |
| 128 |
lastValue = newValue; |
| 129 |
var inrange0 = getprop("/instrumentation/nav[0]/in-range"); |
| 130 |
# Shut off autopilot if HDG switch on and mode != 2 when NAV flag is on |
| 131 |
if ( !inrange0 ) { |
| 132 |
if ( hdgControl.getValue() and (modeControl.getValue() != 2)) { |
| 133 |
rollControl.setDoubleValue(0.0); |
| 134 |
apRollControl(); |
| 135 |
} |
| 136 |
} |
| 137 |
settimer(apPower, 0.5); |
| 138 |
} |
| 139 |
|
| 140 |
var apRollControl = func { |
| 141 |
|
| 142 |
if (rollControl.getValue() ) { |
| 143 |
if (hdgControl.getValue() ) { |
| 144 |
## |
| 145 |
# hdg switch already on so check which roll mode is set |
| 146 |
## |
| 147 |
apModeControlsSet(); |
| 148 |
} else { |
| 149 |
## |
| 150 |
# roll switch on and hdg switch off |
| 151 |
## |
| 152 |
rollButton(1); |
| 153 |
} |
| 154 |
} else { |
| 155 |
# A/P on/off switch was turned off, so turn off other AP switches |
| 156 |
hdgControl.setDoubleValue(0.0); #hdgButton(0); |
| 157 |
# rollButton(0); |
| 158 |
apInit(); |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
var apHdgControl = func { |
| 164 |
|
| 165 |
if (hdgControl.getValue() ) { |
| 166 |
## |
| 167 |
# hdg switch is on so if roll switch is also on, check which roll mode is set |
| 168 |
## |
| 169 |
if (rollControl.getValue() ) { |
| 170 |
apModeControlsSet(); |
| 171 |
} |
| 172 |
} else { |
| 173 |
# hdg switch turned off |
| 174 |
hdgControl.setDoubleValue(0.0); hdgButton(0); |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
|
| 179 |
var rollKnobUpdate = func { |
| 180 |
if ( rollControl.getValue() and !hdgControl.getValue() ) { |
| 181 |
settingTargetRollDeg.setDoubleValue( settingRollKnobDeg.getValue() ); |
| 182 |
} |
| 183 |
} |
| 184 |
|
| 185 |
|
| 186 |
var apModeControlsChange = func { |
| 187 |
## |
| 188 |
# Delay mode change to allow time for multi-mode rotation |
| 189 |
## |
| 190 |
settimer(apModeControlsSet, 2); |
| 191 |
} |
| 192 |
|
| 193 |
var apModeControlsSet = func { |
| 194 |
newMode = modeControl.getValue(); |
| 195 |
|
| 196 |
oldMode = newMode; |
| 197 |
|
| 198 |
#All modes entered from hdg mode |
| 199 |
if ( hdgControl.getValue() ) { |
| 200 |
hdgButton(1); |
| 201 |
if (newMode == 0 ){ |
| 202 |
navButton(); |
| 203 |
} elsif (newMode == 1 ) { |
| 204 |
omniButton(); |
| 205 |
} elsif (newMode == 3 ) { |
| 206 |
aprButton(); |
| 207 |
} elsif(newMode == 4 ) { |
| 208 |
revButton(); |
| 209 |
} |
| 210 |
} else { |
| 211 |
return; |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
var rollButton = func(switch_on) { |
| 217 |
##print("rollButton"); |
| 218 |
# Disable button if too little power |
| 219 |
if (getprop(power) < minVoltageLimit) { return; } |
| 220 |
|
| 221 |
if ( switch_on ) { |
| 222 |
## |
| 223 |
# Engage the autopilot in Wings level mode (ROL) and set the turn rate |
| 224 |
# from the "ROLL Knob". |
| 225 |
## |
| 226 |
|
| 227 |
lockAprHold.setBoolValue(0); |
| 228 |
lockHdgHold.setBoolValue(0); |
| 229 |
lockNavHold.setBoolValue(0); |
| 230 |
lockOmniHold.setBoolValue(0); |
| 231 |
lockRevHold.setBoolValue(0); |
| 232 |
lockRollAxis.setBoolValue(1); |
| 233 |
lockRollMode.setIntValue(rollModes["ROL"]); |
| 234 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 235 |
} else { |
| 236 |
lockAprHold.setBoolValue(0); |
| 237 |
lockHdgHold.setBoolValue(0); |
| 238 |
lockNavHold.setBoolValue(0); |
| 239 |
lockOmniHold.setBoolValue(0); |
| 240 |
lockRevHold.setBoolValue(0); |
| 241 |
lockRollAxis.setBoolValue(0); |
| 242 |
lockRollMode.setIntValue(rollModes["OFF"]); |
| 243 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 244 |
} |
| 245 |
} |
| 246 |
|
| 247 |
|
| 248 |
var hdgButton = func(switch_on) { |
| 249 |
##print("hdgButton"); |
| 250 |
# Disable button if too little power |
| 251 |
if (getprop(power) < minVoltageLimit) { return; } |
| 252 |
|
| 253 |
if (switch_on) { |
| 254 |
## |
| 255 |
# Engage the heading mode (HDG). |
| 256 |
## |
| 257 |
lockAprHold.setBoolValue(0); |
| 258 |
lockRevHold.setBoolValue(0); |
| 259 |
lockHdgHold.setBoolValue(1); |
| 260 |
lockNavHold.setBoolValue(0); |
| 261 |
lockOmniHold.setBoolValue(0); |
| 262 |
lockRollAxis.setBoolValue(1); |
| 263 |
lockRollMode.setIntValue(rollModes["HDG"]); |
| 264 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 265 |
|
| 266 |
settingTargetInterceptAngle.setDoubleValue(0.0); |
| 267 |
|
| 268 |
} else { |
| 269 |
lockHdgHold.setBoolValue(0); |
| 270 |
rollKnobUpdate(); |
| 271 |
if ( rollControl.getValue() ) { |
| 272 |
lockRollMode.setIntValue(rollModes["ROL"]); |
| 273 |
} else { |
| 274 |
lockRollMode.setIntValue(rollModes["OFF"]); |
| 275 |
} |
| 276 |
} |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
var navButton = func { |
| 281 |
##print("navButton"); |
| 282 |
# Disable button if too little power |
| 283 |
if (getprop(power) < minVoltageLimit) { return; } |
| 284 |
|
| 285 |
## |
| 286 |
# The Mode Selector and DG Course Selector should be set before switching the HDG |
| 287 |
# rocker switch to "on". The DG Course Selector should be set to the OBS "to" or |
| 288 |
# "from" bearing. |
| 289 |
# Set up NAV mode and switch to the 45 degree angle intercept NAV mode |
| 290 |
## |
| 291 |
lockAprHold.setBoolValue(0); |
| 292 |
lockRevHold.setBoolValue(0); |
| 293 |
lockHdgHold.setBoolValue(1); |
| 294 |
lockNavHold.setBoolValue(0); |
| 295 |
lockOmniHold.setBoolValue(0); |
| 296 |
lockRollAxis.setBoolValue(1); |
| 297 |
lockRollArm.setIntValue(rollArmModes["NAV"]); |
| 298 |
lockRollMode.setIntValue(rollModes["NAV"]); |
| 299 |
|
| 300 |
navArmFromHdg(); |
| 301 |
} |
| 302 |
|
| 303 |
var navArmFromHdg = func |
| 304 |
{ |
| 305 |
## |
| 306 |
# Abort the NAV-ARM mode if something has changed the arm mode to something |
| 307 |
# else than NAV-ARM. |
| 308 |
## |
| 309 |
if (lockRollArm.getValue() != rollArmModes["NAV"]) |
| 310 |
{ |
| 311 |
return; |
| 312 |
} |
| 313 |
|
| 314 |
## |
| 315 |
# Activate the nav-hold controller and check the needle deviation. |
| 316 |
## |
| 317 |
lockNavHold.setBoolValue(1); |
| 318 |
deviation = getprop(headingNeedleDeflection); |
| 319 |
## |
| 320 |
# If the deflection is more than 9.95 degrees wait 5 seconds and check again. |
| 321 |
## |
| 322 |
if (abs(deviation) > 9.95) |
| 323 |
{ |
| 324 |
#print("deviation"); |
| 325 |
settimer(navArmFromHdg, 5); |
| 326 |
return; |
| 327 |
} |
| 328 |
## |
| 329 |
# If the deviation is less than 10 degrees turn off the NAV-ARM. End of NAV-ARM sequence. |
| 330 |
## |
| 331 |
elsif (abs(deviation) < 10.0) |
| 332 |
{ |
| 333 |
#print("capture"); |
| 334 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 335 |
} |
| 336 |
} |
| 337 |
|
| 338 |
|
| 339 |
var omniButton = func { |
| 340 |
##print("navButton"); |
| 341 |
# Disable button if too little power |
| 342 |
if (getprop(power) < minVoltageLimit) { return; } |
| 343 |
|
| 344 |
## |
| 345 |
# The Mode Selector and DG Course Selector should be set before switching the HDG |
| 346 |
# rocker switch to "on". The DG Course Selector should be set to the OBS "to" or |
| 347 |
# "from" bearing. |
| 348 |
# Set up OMNI mode and switch to the 45 degree angle intercept OMNI mode |
| 349 |
## |
| 350 |
lockAprHold.setBoolValue(0); |
| 351 |
lockRevHold.setBoolValue(0); |
| 352 |
lockHdgHold.setBoolValue(1); |
| 353 |
lockNavHold.setBoolValue(0); |
| 354 |
lockOmniHold.setBoolValue(0); |
| 355 |
lockRollAxis.setBoolValue(1); |
| 356 |
lockRollArm.setIntValue(rollArmModes["OMNI"]); |
| 357 |
lockRollMode.setIntValue(rollModes["OMNI"]); |
| 358 |
|
| 359 |
omniArmFromHdg(); |
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
var omniArmFromHdg = func |
| 364 |
{ |
| 365 |
## |
| 366 |
# Abort the OMNI-ARM mode if something has changed the arm mode to something |
| 367 |
# else than OMNI-ARM. |
| 368 |
## |
| 369 |
if (lockRollArm.getValue() != rollArmModes["OMNI"]) |
| 370 |
{ |
| 371 |
return; |
| 372 |
} |
| 373 |
|
| 374 |
## |
| 375 |
# Activate the omni-hold controller and check the needle deviation. |
| 376 |
## |
| 377 |
lockOmniHold.setBoolValue(1); |
| 378 |
deviation = getprop(filteredHeadingNeedleDeflection); |
| 379 |
## |
| 380 |
# If the deflection is more than 9.95 degrees wait 5 seconds and check again. |
| 381 |
## |
| 382 |
if (abs(deviation) > 9.95) |
| 383 |
{ |
| 384 |
#print("deviation"); |
| 385 |
settimer(omniArmFromHdg, 5); |
| 386 |
return; |
| 387 |
} |
| 388 |
## |
| 389 |
# If the deviation is less than 10 degrees turn off the OMNI-ARM. End of OMNI-ARM sequence. |
| 390 |
## |
| 391 |
elsif (abs(deviation) < 10.0) |
| 392 |
{ |
| 393 |
#print("capture"); |
| 394 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 395 |
} |
| 396 |
} |
| 397 |
|
| 398 |
var aprButton = func { |
| 399 |
##print("aprButton"); |
| 400 |
# Disable button if too little power |
| 401 |
if (getprop(power) < minVoltageLimit) { return; } |
| 402 |
|
| 403 |
## |
| 404 |
# The Mode Selector and DG Course Selector should be set before switching the HDG |
| 405 |
# rocker switch to "on". Set the DG Course Selector to the LOC inbound heading. |
| 406 |
# Set up APR mode and switch to the 45 degree angle intercept APR mode |
| 407 |
## |
| 408 |
lockAprHold.setBoolValue(1); |
| 409 |
lockRevHold.setBoolValue(0); |
| 410 |
lockHdgHold.setBoolValue(1); |
| 411 |
lockNavHold.setBoolValue(0); |
| 412 |
lockOmniHold.setBoolValue(0); |
| 413 |
lockRollAxis.setBoolValue(1); |
| 414 |
lockRollArm.setIntValue(rollArmModes["APR"]); |
| 415 |
lockRollMode.setIntValue(rollModes["APR"]); |
| 416 |
|
| 417 |
aprArmFromHdg(); |
| 418 |
} |
| 419 |
|
| 420 |
var aprArmFromHdg = func |
| 421 |
{ |
| 422 |
## |
| 423 |
# Abort the APR-ARM mode if something has changed the arm mode to something |
| 424 |
# else than APR-ARM. |
| 425 |
## |
| 426 |
if (lockRollArm.getValue() != rollArmModes["APR"]) |
| 427 |
{ |
| 428 |
return; |
| 429 |
} |
| 430 |
|
| 431 |
## |
| 432 |
# Activate the apr-hold controller and check the needle deviation. |
| 433 |
## |
| 434 |
lockAprHold.setBoolValue(1); |
| 435 |
deviation = getprop(headingNeedleDeflection); |
| 436 |
## |
| 437 |
# If the deflection is more than 2.5 degrees wait 5 seconds and check again. |
| 438 |
## |
| 439 |
if (abs(deviation) > 2.495) |
| 440 |
{ |
| 441 |
#print("deviation"); |
| 442 |
settimer(aprArmFromHdg, 5); |
| 443 |
return; |
| 444 |
} |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
var revButton = func { |
| 449 |
##print("revButton"); |
| 450 |
# Disable button if too little power |
| 451 |
if (getprop(power) < minVoltageLimit) { return; } |
| 452 |
|
| 453 |
## |
| 454 |
# The Mode Selector and DG Course Selector should be set before switching the HDG |
| 455 |
# rocker switch to "on". Set the DG Course Selector to the LOC outbound |
| 456 |
# (or reverse) heading. |
| 457 |
# Set up REV mode and switch to the 45 degree angle intercept REV mode |
| 458 |
## |
| 459 |
lockAprHold.setBoolValue(0); |
| 460 |
lockRevHold.setBoolValue(0); |
| 461 |
lockHdgHold.setBoolValue(1); |
| 462 |
lockNavHold.setBoolValue(0); |
| 463 |
lockOmniHold.setBoolValue(0); |
| 464 |
lockRollAxis.setBoolValue(1); |
| 465 |
lockRollArm.setIntValue(rollArmModes["REV"]); |
| 466 |
|
| 467 |
revArmFromHdg(); |
| 468 |
} |
| 469 |
|
| 470 |
|
| 471 |
var revArmFromHdg = func |
| 472 |
{ |
| 473 |
## |
| 474 |
# Abort the REV-ARM mode if something has changed the arm mode to something |
| 475 |
# else than REV-ARM. |
| 476 |
## |
| 477 |
if (lockRollArm.getValue() != rollArmModes["REV"]) |
| 478 |
{ |
| 479 |
return; |
| 480 |
} |
| 481 |
|
| 482 |
## |
| 483 |
# Activate the rev-hold controller and check the needle deviation. |
| 484 |
## |
| 485 |
lockRevHold.setBoolValue(1); |
| 486 |
deviation = getprop(headingNeedleDeflection); |
| 487 |
## |
| 488 |
# If the deflection is more than 2.5 degrees wait 5 seconds and check again. |
| 489 |
## |
| 490 |
if (abs(deviation) > 2.495) |
| 491 |
{ |
| 492 |
#print("deviation"); |
| 493 |
settimer(revArmFromHdg, 5); |
| 494 |
return; |
| 495 |
} |
| 496 |
## |
| 497 |
# If the deviation is less than 2.5 - End of REV-ARM sequence. |
| 498 |
## |
| 499 |
elsif (abs(deviation) < 2.5) |
| 500 |
{ |
| 501 |
#print("capture"); |
| 502 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 503 |
lockAprHold.setBoolValue(0); |
| 504 |
lockRevHold.setBoolValue(1); |
| 505 |
lockHdgHold.setBoolValue(1); |
| 506 |
lockNavHold.setBoolValue(0); |
| 507 |
lockOmniHold.setBoolValue(0); |
| 508 |
lockRollAxis.setBoolValue(1); |
| 509 |
lockRollMode.setIntValue(rollModes["REV"]); |
| 510 |
lockRollArm.setIntValue(rollArmModes["OFF"]); |
| 511 |
} |
| 512 |
} |
| 513 |
|
| 514 |
var touchPower = func{ |
| 515 |
setprop(power,apVolts); |
| 516 |
} |
| 517 |
|
| 518 |
var apVolts = getprop(power); |
| 519 |
|
| 520 |
if ( apVolts == nil or apVolts < minVoltageLimit ) { |
| 521 |
# Wait for autopilot to be powered up |
| 522 |
var L = setlistener(power, func { |
| 523 |
apPower(); |
| 524 |
removelistener(L); |
| 525 |
}); |
| 526 |
} else { |
| 527 |
# Skip the setlistener since autopilot is already powered up |
| 528 |
settimer(touchPower ,10); |
| 529 |
apPower(); |
| 530 |
} |
| 531 |
|
| 532 |
|