-
Notifications
You must be signed in to change notification settings - Fork 432
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
The python example has fdm.FGFDMExec twice, with different explanations #798
Comments
As an additional bug, the example tries to load |
And then as third bug, even though we won't be modifying the xml data, JSBsim tries to load the file with write permissions, which can cause problems on a properly set up Windows (running as a normal user rather than as an admin) with JSBsim installed under the standard Only admins have write access to those directories, so if a normal user runs the example script, it will error out with a PermissionError: Traceback (most recent call last):
File "C:\Users\Pomax\Documents\Git\projects\are-we-flying\api\test-jsbsim.py", line 90, in <module>
cg = changeCG(fdm, cgPos[j], False)
File "C:\Users\Pomax\Documents\Git\projects\are-we-flying\api\test-jsbsim.py", line 50, in changeCG
tree.write(os.path.join(fdm.get_root_dir(), AIRCRAFT_XML))
File "C:\Program Files\Python39\lib\xml\etree\ElementTree.py", line 732, in write
with _get_writer(file_or_filename, enc_lower) as write:
File "C:\Program Files\Python39\lib\contextlib.py", line 119, in __enter__
return next(self.gen)
File "C:\Program Files\Python39\lib\xml\etree\ElementTree.py", line 768, in _get_writer
file = open(file_or_filename, "w", encoding=encoding,
PermissionError: [Errno 13] Permission denied: 'C:/Program Files/JSBsim\\aircraft/fokker100/fokker100.xml' (The installer-default |
With JSBSim relocated to a throw-away location, and the aircraft model updated to the A320, the script runs to completion, although There are also a fair number of stderr entries, which might just be because the example was intended for a completely different aircraft, but I'll attach them here anyway: |
Well, an example is an example no more, no less. It is not meant to be successfully executed on every possible configurations that exist under the sun. More specifically, the location of the flight model data may vary from one installation to the other so, yes the example uses a constant
Granted that The example uses an algorithm that modifies the aircraft XML file to update the aircraft CG, so indeed it needs write access and it fails if you try to access data that are read only. But I would not go as far as calling that a bug. |
This one can easily be fixed. |
I just ran the example on my side with the following changes and a window opened showing the plot below. Is diff --git a/examples/python/PlotAoaVsCAS.py b/examples/python/PlotAoaVsCAS.py
index 551c554a..8ac80194 100644
--- a/examples/python/PlotAoaVsCAS.py
+++ b/examples/python/PlotAoaVsCAS.py
@@ -23,14 +23,14 @@ import os
# Change the directory to the aircraft to be studied
# Note - Moments of inertia are not updated
def changeCG(fdm, cgPos, readOnly):
- tree = ET.parse(os.path.join(fdm.get_root_dir(), 'aircraft/global5000/global5000.xml'))
+ tree = ET.parse(os.path.join(fdm.get_root_dir(), 'aircraft/A320/A320.xml'))
root = tree.getroot()
for x in root.findall('mass_balance/location'):
cg = x.find('x').text
if not readOnly:
x.find('x').text=str(cgPos)
- tree.write(os.path.join(fdm.get_root_dir(), 'aircraft/global5000/global5000.xml'))
+ tree.write(os.path.join(fdm.get_root_dir(), 'aircraft/A320/A320.xml'))
return cg
# Fuel max for Global5000
@@ -47,7 +47,7 @@ fuel=[1000,fuelmax/2,fuelmax]
weight=["light","mid","heavy"]
# Path to JSBSim files
-PATH_TO_JSBSIM_FILES="../../"
+PATH_TO_JSBSIM_FILES="../../.."
fdm = jsbsim.FGFDMExec(PATH_TO_JSBSIM_FILES)
# Get the original CG from aircraft xml |
That's fair, but the original issue is that one set of code lines tells us that # Point to the jsbsim directory and make an object
fdm = jsbsim.FGFDMExec(PATH_TO_JSBSIM_FILES) Matplotlob related, it turns out that matplotlib itself was installed correctly, but python had been installed without the TK/IDLE extensions, so matplotlib couldn't draw anything. I updated the python install to include those, and a simple tk example works, as do the examples from the matplotlib website. Rerunning the script with your diff now generates a graph, although it looks very different from yours? |
Hmm, the aircraft https://github.com/JSBSim-Team/jsbsim/tree/master/aircraft/global5000 So either you have an old installer that didn't include the aircraft but included the example script, or somehow the installer isn't including this particular aircraft? |
So I've just run Global5000Now I noticed in the diff that @bcoconni posted above that he changed 2 references to jsbsim/examples/python/PlotAoaVsCAS.py Line 67 in 36dda4f
Which means using @bcoconni's diff he's really making use of the Global5000, with cg changes to A320So @Pomax I'm guessing you must have either changed all three references to |
Oops ! I was so convinced that the global5000 was not part of the repo that I didn't bother to check 😞 |
jsbsim/examples/python/PlotAoaVsCAS.py Line 67 in 36dda4f
Well, hum, it seems I reviewed this issue too hastily. |
I installed using
Does the release maybe forget to bundle it in? Comparing the release and the repo, there's a surprising mismatch between the aircraft directories... |
Hmm, we'll need to take a look at the scripts that generate the builds to see why some aircraft are being left out. Doing a quick eyeball I see the following missing from your list compared to what is in the repo. Missing:
787-8
F450
global5000
LM |
So taking a quick look it looks like this is the file that is used by the setup program to generate the Windows installer. https://github.com/JSBSim-Team/jsbsim/blob/master/JSBSim.iss.in And in particular in terms of including the aircraft: Line 29 in 9893017
At first glance there is nothing obvious from the setup program's input file that would indicate why there are a handful of missing aircraft directories. Given the search pattern (base) C:\source\jsbsim>dir .\aircraft\737\
Directory: C:\source\jsbsim\aircraft\737
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 1/31/2022 11:01 PM 35126 737.xml
-a---- 1/1/2023 3:46 PM 504 cruise_init.xml
-a---- 2/27/2018 10:01 PM 485 cruise_steady_turn_init.xml
-a---- 2/27/2018 10:01 PM 414 INSTALL
-a---- 2/27/2018 10:01 PM 583 reset00.xml
(base) C:\source\jsbsim>dir .\aircraft\787-8\
Directory: C:\source\jsbsim\aircraft\787-8
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 1/1/2023 3:33 PM 30787 787-8.xml
-a---- 6/4/2022 9:13 PM 976 Authors.txt
-a---- 6/4/2022 9:13 PM 375 README
(base) C:\source\jsbsim>dir .\aircraft\global5000\
Directory: C:\source\jsbsim\aircraft\global5000
Mode LastWriteTime Length Name
---- ------------- ------ ----
d----- 6/30/2021 6:17 PM scripts
-a---- 6/30/2021 6:17 PM 457 airborne.xml
-a---- 12/31/2022 2:49 PM 27237 global5000.xml
-a---- 6/30/2021 6:17 PM 11649 global5000ap.xml
-a---- 6/30/2021 6:17 PM 7699 global5000apx.xml
(base) C:\source\jsbsim>dir .\aircraft\global5000\scripts\
Directory: C:\source\jsbsim\aircraft\global5000\scripts
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 6/30/2021 6:17 PM 2404 trim-cruise.xml
-a---- 6/30/2021 6:17 PM 3181 trim-cruise_ap.xml
(base) C:\source\jsbsim> |
If it helps: the source archive over on https://github.com/JSBSim-Team/jsbsim/archive/refs/tags/v1.1.13.zip also doesn't contain those aircraft, so this might not be windows-specific. |
Got it ! They are missing from the branch |
Nice! More examples are always good. For PlotAoaVsCAS, is the |
This is now fixed in the |
awesome, thank you so much! |
I'm submitting a ...
Describe the issue
The
examples/python/PlotAoaVsCAS.py
script contains the following contradictory code:and
Either
jsbsim.FGFDMExec
needs the path for the jsbsim directory, in which case the second code block is incorrect, or it needs the path for the jsbsim executable, in which case the "constant" in the first block is wrong.What is the current behavior?
We can't run this example =)
What is the motivation / use case for changing the behavior?
Projects live or die based on having good docs and working examples =)
Other information
It's also curious that
jsbsim.FGFDMExec
gets run three times, does it need to be recreated every iteration? One would assume that oncefdm
has been set up, one simply keeps using that.The text was updated successfully, but these errors were encountered: