|
131 | 131 | "source": [ |
132 | 132 | "# Confirm that JSBSim is installed. If not and running on Google Colab\n", |
133 | 133 | "# then install JSBSim into the Google Colab instance.\n", |
| 134 | + "\n", |
| 135 | + "import os\n", |
| 136 | + "\n", |
134 | 137 | "try:\n", |
135 | 138 | " import jsbsim\n", |
136 | 139 | " print('JSBSim is installed')\n", |
| 140 | + " # Relative path to the directory where the flight model is stored\n", |
| 141 | + " # Note - Aircraft directory needs to be writeable in order to modify the cg\n", |
| 142 | + " PATH_TO_JSBSIM_FILES=\"../..\"\n", |
| 143 | + " print(f'Current working directory: {os.getcwd()}')\n", |
137 | 144 | "except ImportError:\n", |
138 | 145 | " import sys\n", |
139 | 146 | " if 'google.colab' in sys.modules:\n", |
140 | 147 | " print('Installing JSBSim...')\n", |
141 | | - " !git clone https://github.com/JSBSim-Team/jsbsim.git\n", |
142 | 148 | " !pip install jsbsim\n", |
143 | | - " %cd jsbsim/examples/python\n", |
144 | | - "print('Current working directory:')\n", |
145 | | - "!pwd" |
| 149 | + " # Use the standard aircraft supplied by the JSBSim Python package\n", |
| 150 | + " PATH_TO_JSBSIM_FILES=None" |
146 | 151 | ] |
147 | 152 | }, |
148 | 153 | { |
|
155 | 160 | "import jsbsim\n", |
156 | 161 | "import xml.etree.ElementTree as ET\n", |
157 | 162 | "import matplotlib.pyplot as plt\n", |
158 | | - "import os\n", |
159 | 163 | "\n", |
160 | 164 | "# Global variables that must be modified to match your particular need\n", |
161 | 165 | "# The aircraft name\n", |
162 | 166 | "# Note - It should match the exact spelling of the model file\n", |
163 | 167 | "AIRCRAFT_NAME=\"global5000\"\n", |
164 | | - "# Relative path to the directory where the flight model is stored\n", |
165 | | - "# Note - Aircraft directory needs to be writeable in order to modify the cg\n", |
166 | | - "PATH_TO_JSBSIM_FILES=\"../..\"\n", |
167 | 168 | "\n", |
168 | 169 | "# Avoid flooding the console with log messages\n", |
169 | | - "jsbsim.FGJSBBase().debug_lvl = 0\n" |
| 170 | + "jsbsim.FGJSBBase().debug_lvl = 0" |
170 | 171 | ] |
171 | 172 | }, |
172 | 173 | { |
|
211 | 212 | "\n", |
212 | 213 | "# Instantiate the FDMExec object and load the aircraft\n", |
213 | 214 | "fdm = jsbsim.FGFDMExec(PATH_TO_JSBSIM_FILES)\n", |
214 | | - "fdm.load_model(f'{AIRCRAFT_NAME}')\n", |
| 215 | + "fdm.load_model(AIRCRAFT_NAME)\n", |
215 | 216 | "\n", |
216 | 217 | "ac_xml_tree = ET.parse(os.path.join(fdm.get_root_dir(), f'aircraft/{AIRCRAFT_NAME}/{AIRCRAFT_NAME}.xml'))\n", |
217 | 218 | "ac_xml_root = ac_xml_tree.getroot()\n", |
|
290 | 291 | "dElev_deg = [d * 180 / 3.14159 for d in dElev_rad]\n", |
291 | 292 | "\n", |
292 | 293 | "# Plot AoA vs KCAS\n", |
293 | | - "ax1.plot(speed, alpha, \n", |
| 294 | + "ax1.plot(speed, alpha,\n", |
294 | 295 | " label=\"Weight {0:.0f} lb, Altitude {1:.0f} kft, CoG-x {2:.2f} in\".format(weight_0, h_ft_0/1000, x_cg_0),\n", |
295 | 296 | " marker='o', linestyle='-', color='blue')\n", |
296 | 297 | "\n", |
|
300 | 301 | "ax1.legend(loc='upper right')\n", |
301 | 302 | "\n", |
302 | 303 | "# Plot elevator deflection vs KCAS\n", |
303 | | - "ax2.plot(speed, dElev_deg, \n", |
| 304 | + "ax2.plot(speed, dElev_deg,\n", |
304 | 305 | " label=\"Weight {0:.0f} lb, Altitude {1:.0f} kft, CoG-x {2:.2f} in\".format(weight_0, h_ft_0/1000, x_cg_0),\n", |
305 | 306 | " marker='o', linestyle='-', color='red')\n", |
306 | 307 | "\n", |
|
310 | 311 | "ax2.legend(loc=\"upper right\")\n", |
311 | 312 | "\n", |
312 | 313 | "# Plot normalized elevator deflection vs KCAS\n", |
313 | | - "ax3.plot(speed, dElev_norm, \n", |
| 314 | + "ax3.plot(speed, dElev_norm,\n", |
314 | 315 | " label=\"Weight {0:.0f} lb, Altitude {1:.0f} kft, CoG-x {2:.2f} in\".format(weight_0, h_ft_0/1000, x_cg_0),\n", |
315 | 316 | " marker='o', linestyle='-', color='green')\n", |
316 | 317 | "\n", |
|
363 | 364 | } |
364 | 365 | ], |
365 | 366 | "source": [ |
366 | | - "%matplotlib inline\n", |
367 | | - "# Avoid flooding the console with log messages\n", |
368 | | - "jsbsim.FGJSBBase().debug_lvl = 0\n", |
369 | | - "\n", |
370 | 367 | "# Control whether to print results to console in addition to generating a plot\n", |
371 | 368 | "print_output = False\n", |
372 | 369 | "\n", |
|
424 | 421 | "for j in range(2):\n", |
425 | 422 | " fdm = jsbsim.FGFDMExec(PATH_TO_JSBSIM_FILES)\n", |
426 | 423 | " fdm.load_model(f'{AIRCRAFT_NAME}')\n", |
427 | | - " \n", |
| 424 | + "\n", |
428 | 425 | " # Set engines running\n", |
429 | 426 | " fdm['propulsion/set-running'] = -1\n", |
430 | | - " \n", |
| 427 | + "\n", |
431 | 428 | " # Change CoG-x in the aircraft xml\n", |
432 | 429 | " xcg_ = changeCG(fdm, xs_cg[j], False)\n", |
433 | 430 | "\n", |
|
466 | 463 | " print(\"KCAS, AoA (deg)\")\n", |
467 | 464 | " for result in results:\n", |
468 | 465 | " print(result[0], result[1])\n", |
469 | | - " \n", |
| 466 | + "\n", |
470 | 467 | " print(\"---------\")\n", |
471 | 468 | " print(\"KCAS, Elevator deflection (rad), Normalized elevator deflection (-1 to 1)\")\n", |
472 | 469 | " for result_fcs in results_fcs:\n", |
473 | 470 | " print(result_fcs[0], result_fcs[1], result_fcs[2])\n", |
474 | 471 | "\n", |
475 | 472 | " speed, alpha = zip(*results)\n", |
476 | | - " ax1.plot(speed, alpha, \n", |
| 473 | + " ax1.plot(speed, alpha,\n", |
477 | 474 | " label=\"{0} weight, {1:.0f} kft, {2:.2f} % CoG\".format(weight[i], h_ft[j]/1000, (float(xs_cg[j])/float(x_cg_Orig)-1)*100),\n", |
478 | 475 | " marker='o', linestyle='-')\n", |
479 | 476 | "\n", |
480 | 477 | " speed, dElev_rad, dElev_norm = zip(*results_fcs)\n", |
481 | 478 | " # Convert elevator deflection from radians to degrees\n", |
482 | 479 | " dElev_deg = [d * 180 / 3.14159 for d in dElev_rad]\n", |
483 | 480 | "\n", |
484 | | - " ax2.plot(speed, dElev_deg, \n", |
| 481 | + " ax2.plot(speed, dElev_deg,\n", |
485 | 482 | " label=\"{0} weight {1:.0f} kft {2:.2f} % cg\".format(weight[i], h_ft[j]/1000, (float(xs_cg[j])/float(x_cg_Orig)-1)*100),\n", |
486 | 483 | " marker='o', linestyle='-')\n", |
487 | | - " \n", |
488 | | - " ax3.plot(speed, dElev_norm, \n", |
| 484 | + "\n", |
| 485 | + " ax3.plot(speed, dElev_norm,\n", |
489 | 486 | " label=\"{0} weight {1:.0f} kft {2:.2f} % cg\".format(weight[i], h_ft[j]/1000, (float(xs_cg[j])/float(x_cg_Orig)-1)*100),\n", |
490 | 487 | " marker='o', linestyle='-')\n", |
491 | 488 | "\n", |
|
0 commit comments