From 9a1b7db40cef6dd4c5c3e334d75c56e80356d6b8 Mon Sep 17 00:00:00 2001 From: Bertrand Coconnier Date: Sat, 6 Nov 2021 16:38:43 +0100 Subject: [PATCH] Add `negated_crossproduct_inertia` to models with cross product inertia. Folowing the PR #502, JSBSim now allows to specify how the sign of cross product inertia is interpreted. In order to educate users to this new parameter, all the aircraft models with cross product inertia are updated with the new parameter `negated_crossproduct_inertia` set to `true` (which is the default). --- admin/XML_mass_update.py | 59 ++++++++++++++++++++++++++++++++++ aircraft/737/737.xml | 2 +- aircraft/A320/A320.xml | 2 +- aircraft/B747/B747.xml | 2 +- aircraft/DHC6/DHC6.xml | 2 +- aircraft/SGS/SGS.xml | 2 +- aircraft/Shuttle/Shuttle.xml | 2 +- aircraft/X15/X15.xml | 2 +- aircraft/XB-70/XB-70.xml | 2 +- aircraft/f15/f15.xml | 2 +- aircraft/f16/f16.xml | 2 +- aircraft/f22/f22.xml | 2 +- aircraft/f22/yf22.xml | 2 +- aircraft/minisgs/minisgs.xml | 2 +- aircraft/t6texan2/t6texan2.xml | 2 +- aircraft/x24b/x24b.xml | 2 +- 16 files changed, 74 insertions(+), 15 deletions(-) create mode 100755 admin/XML_mass_update.py diff --git a/admin/XML_mass_update.py b/admin/XML_mass_update.py new file mode 100755 index 0000000000..0516c43df1 --- /dev/null +++ b/admin/XML_mass_update.py @@ -0,0 +1,59 @@ +#!/usr/bin/python +# +# This script adds the attribute `negated_crossproduct_inertia="true"` to +# all the aircraft models of JSBSim that have at least one non zero cross +# product inertia. + +import os +import xml.etree.ElementTree as et + +def CheckXMLFile(f, header): + # Is f an XML file ? + try: + tree = et.parse(f) + except et.ParseError: + return False + + # Check the file header + return tree.getroot().tag.upper() == header.upper() + +def recursive_scan_XML(dir_name, header): + for d in os.scandir(dir_name): + if d.is_file(): + fname = os.path.join(dir_name,d.name) + if CheckXMLFile(fname, header): + yield fname + continue + if d.is_dir(): + for f in recursive_scan_XML(os.path.join(dir_name, d.name), header): + yield f + +shift = len('mass_balance') +for fname in recursive_scan_XML('.', 'fdm_config'): + tree = et.parse(fname) + mass_balance_tag = tree.getroot().find('./mass_balance') + if mass_balance_tag is None: + continue + + # Check if there is a non zero cross product inertia + ixy_tag = mass_balance_tag.find('ixy') + if ixy_tag is None or float(ixy_tag.text) == 0.0: + ixz_tag = mass_balance_tag.find('ixz') + if ixz_tag is None or float(ixz_tag.text) == 0.0: + iyz_tag = mass_balance_tag.find('iyz') + if iyz_tag is None or float(iyz_tag.text) == 0.0: + continue + + with open(fname, 'r') as f: + lines = f.readlines() + + for i, l in enumerate(lines): + index = l.find('mass_balance') + if index == -1: + continue + index += shift + lines[i] = l[:index]+' negated_crossproduct_inertia="true"'+l[index:] + break + + with open(fname, 'w') as f: + f.writelines(lines) diff --git a/aircraft/737/737.xml b/aircraft/737/737.xml index e7b80e1b1c..4642d95ee9 100644 --- a/aircraft/737/737.xml +++ b/aircraft/737/737.xml @@ -53,7 +53,7 @@ - + 562000 1.473e+06 1.894e+06 diff --git a/aircraft/A320/A320.xml b/aircraft/A320/A320.xml index aa88e82f71..e363d4932e 100644 --- a/aircraft/A320/A320.xml +++ b/aircraft/A320/A320.xml @@ -48,7 +48,7 @@ - + 942877 2.78892e+06 3.59757e+06 diff --git a/aircraft/B747/B747.xml b/aircraft/B747/B747.xml index a86fdd604c..ad776e0067 100644 --- a/aircraft/B747/B747.xml +++ b/aircraft/B747/B747.xml @@ -52,7 +52,7 @@ - + 1.82e+07 3.31e+07 4.97e+07 diff --git a/aircraft/DHC6/DHC6.xml b/aircraft/DHC6/DHC6.xml index b1b88b8a64..6e4929bc1f 100644 --- a/aircraft/DHC6/DHC6.xml +++ b/aircraft/DHC6/DHC6.xml @@ -94,7 +94,7 @@ - + 19317 24679 35344 diff --git a/aircraft/SGS/SGS.xml b/aircraft/SGS/SGS.xml index f265a8ff0e..1daa388119 100644 --- a/aircraft/SGS/SGS.xml +++ b/aircraft/SGS/SGS.xml @@ -48,7 +48,7 @@ - + 1015 672 1663 diff --git a/aircraft/Shuttle/Shuttle.xml b/aircraft/Shuttle/Shuttle.xml index f8f0f8954f..f1c96406a5 100644 --- a/aircraft/Shuttle/Shuttle.xml +++ b/aircraft/Shuttle/Shuttle.xml @@ -52,7 +52,7 @@ - + 953159 7.46508e+06 7.74758e+06 diff --git a/aircraft/X15/X15.xml b/aircraft/X15/X15.xml index 3a6fe7b97e..3195eb4e18 100644 --- a/aircraft/X15/X15.xml +++ b/aircraft/X15/X15.xml @@ -50,7 +50,7 @@ - + 3650 80000 82000 diff --git a/aircraft/XB-70/XB-70.xml b/aircraft/XB-70/XB-70.xml index a9af1cb829..4a7b2bd173 100644 --- a/aircraft/XB-70/XB-70.xml +++ b/aircraft/XB-70/XB-70.xml @@ -53,7 +53,7 @@ - + 1.34e+06 1.6e+07 1.68e+07 diff --git a/aircraft/f15/f15.xml b/aircraft/f15/f15.xml index 7ba9f6263f..66a1e18044 100644 --- a/aircraft/f15/f15.xml +++ b/aircraft/f15/f15.xml @@ -48,7 +48,7 @@ - + 28700 165100 187900 diff --git a/aircraft/f16/f16.xml b/aircraft/f16/f16.xml index 3c3cb976ee..ed49419b16 100644 --- a/aircraft/f16/f16.xml +++ b/aircraft/f16/f16.xml @@ -59,7 +59,7 @@ - + 9496 55814 63100 diff --git a/aircraft/f22/f22.xml b/aircraft/f22/f22.xml index 0da15b8338..add609b46e 100644 --- a/aircraft/f22/f22.xml +++ b/aircraft/f22/f22.xml @@ -53,7 +53,7 @@ - + 56005 280766 354090 diff --git a/aircraft/f22/yf22.xml b/aircraft/f22/yf22.xml index a359b6bf7c..f73bed1070 100644 --- a/aircraft/f22/yf22.xml +++ b/aircraft/f22/yf22.xml @@ -53,7 +53,7 @@ - + 40843 204751 258201 diff --git a/aircraft/minisgs/minisgs.xml b/aircraft/minisgs/minisgs.xml index b769f2697a..7c923262d3 100644 --- a/aircraft/minisgs/minisgs.xml +++ b/aircraft/minisgs/minisgs.xml @@ -48,7 +48,7 @@ - + 0.4752 0.3147 0.7785 diff --git a/aircraft/t6texan2/t6texan2.xml b/aircraft/t6texan2/t6texan2.xml index 8c72b71b8c..fda4c8e3ea 100644 --- a/aircraft/t6texan2/t6texan2.xml +++ b/aircraft/t6texan2/t6texan2.xml @@ -48,7 +48,7 @@ - + 4216.3 7608 10355 diff --git a/aircraft/x24b/x24b.xml b/aircraft/x24b/x24b.xml index 270ab7e2a6..2adad94921 100644 --- a/aircraft/x24b/x24b.xml +++ b/aircraft/x24b/x24b.xml @@ -48,7 +48,7 @@ - + 2650 23710 24120