forked from JSBSim-Team/jsbsim
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
negated_crossproduct_inertia
to models with cross product inertia.
Folowing the PR JSBSim-Team#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).
- Loading branch information
Showing
16 changed files
with
74 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters