SilentSys / orhelper

orhelper is a module which aims to facilitate interacting and scripting with OpenRocket from Python
GNU General Public License v2.0
16 stars 17 forks source link

Exception error #1

Closed yuriachermann closed 3 years ago

yuriachermann commented 3 years ago

Hello, Andrei!

How are you doing? I'm an aerospace engineering student and I was trying to use your version of orhelper. But for some reason it's returning an error that I'm not being able to solve. Do you have any idea of what is going on?

/home/yuri/OR/GA/venv/bin/python /home/yuri/OR/GA/examples/simple_plot.py
15:18:04.840 [main] INFO  n.s.o.s.providers.TranslatorProvider - Using default locale en_US
15:18:04.853 [main] INFO  n.s.o.s.providers.TranslatorProvider - Set up translation for locale en_US, debug.currentFile=messages.properties
15:18:04.860 [DatabaseLoadingThread] INFO  n.s.o.d.ComponentPresetDatabaseLoader - Loading component presets from datafiles/presets
15:18:04.861 [DatabaseLoadingThread] DEBUG net.sf.openrocket.util.JarUtil - Found jar file using codeSource
15:18:04.863 [DatabaseLoadingThread] INFO  n.s.o.database.MotorDatabaseLoader - Starting reading serialized motor database
15:18:04.864 [DatabaseLoadingThread] DEBUG net.sf.openrocket.util.JarUtil - Found jar file using codeSource
15:18:04.869 [DatabaseLoadingThread] DEBUG n.s.o.database.MotorDatabaseLoader - Reading motors from file datafiles/thrustcurves/thrustcurves.ser
Exception while calling OpenRocket
Traceback (most recent call last):
  File "GeneralRocketLoader.java", line 75, in net.sf.openrocket.file.GeneralRocketLoader.load
  File "FileInputStream.java", line 138, in java.io.FileInputStream.<init>
  File "FileInputStream.java", line 195, in java.io.FileInputStream.open
  File "FileInputStream.java", line -2, in java.io.FileInputStream.open0
java.io.java.io.FileNotFoundException: <unprintable java.io.FileNotFoundException object>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "GeneralRocketLoader.java", line 80, in net.sf.openrocket.file.GeneralRocketLoader.load
Exception: Java Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/yuri/OR/GA/examples/simple_plot.py", line 11, in <module>
    doc = orh.load_doc(os.path.join('examples', 'simple.ork'))
  File "/home/yuri/OR/GA/examples/_orhelper.py", line 215, in load_doc
    doc = loader.load()
net.sf.openrocket.file.net.sf.openrocket.file.RocketLoadException: <unprintable net.sf.openrocket.file.RocketLoadException object>
Traceback (most recent call last):
  File "GeneralRocketLoader.java", line 75, in net.sf.openrocket.file.GeneralRocketLoader.load
  File "FileInputStream.java", line 138, in java.io.FileInputStream.<init>
  File "FileInputStream.java", line 195, in java.io.FileInputStream.open
  File "FileInputStream.java", line -2, in java.io.FileInputStream.open0
java.io.FileNotFoundException: <exception str() failed>

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "GeneralRocketLoader.java", line 80, in net.sf.openrocket.file.GeneralRocketLoader.load
Exception: Java Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/yuri/OR/GA/examples/simple_plot.py", line 11, in <module>
    doc = orh.load_doc(os.path.join('examples', 'simple.ork'))
  File "/home/yuri/OR/GA/examples/_orhelper.py", line 215, in load_doc
    doc = loader.load()
net.sf.openrocket.file.RocketLoadException: <exception str() failed>

Process finished with exit code 1

It would be amazing if you could give me any tip! It's for my final thesis.

Best regards, -Yuri Achermann

SilentSys commented 3 years ago

Hi Yuri,

the key lines in your error are:

java.io.java.io.FileNotFoundException: <unprintable java.io.FileNotFoundException object>

and:

Traceback (most recent call last):
  File "/home/yuri/OR/GA/examples/simple_plot.py", line 11, in <module>
    doc = orh.load_doc(os.path.join('examples', 'simple.ork'))

The example script expects the simple.ork file to be in the relative path ./examples/simple.ork. My guess is that you are running the script from the examples directory, but it should be run from the root orhelper directory. Alternatively, you could just modify the following line to use whatever relative path you want:

doc = orh.load_doc(os.path.join('examples', 'simple.ork'))

Please let me know if this resolves the issue for you.

Cheers.

yuriachermann commented 3 years ago

I tried to modify the line to simply:

doc = orh.load_doc(os.path.join('simple.ork'))

But it kept running for more than half an hour

yuriachermann commented 3 years ago

When I use your directory arrangement:

|orhelper (working directory) ----|examples --------|simple_plot.py --------|simple.ork ----|orhelper --------|init.py --------|_enums.py --------|_orhelper.py

I get this error message:

Traceback (most recent call last):
  File "/home/yuri/TCC/orhelper/examples/simple_plot.py", line 3, in <module>
    import orhelper
  File "/home/yuri/TCC/orhelper/orhelper/__init__.py", line 1, in <module>
    from ._orhelper import *
  File "/home/yuri/TCC/orhelper/orhelper/_orhelper.py", line 10, in <module>
    from _enums import *
ModuleNotFoundError: No module named '_enums'
SilentSys commented 3 years ago

Currently that example will stay open until you close it when its working correctly, sorry for the confusion. But if it works, all you will see is:

16:00:23.784 [main] INFO  n.s.o.s.providers.TranslatorProvider - Using default locale en_US
16:00:23.796 [main] INFO  n.s.o.s.providers.TranslatorProvider - Set up translation for locale en_US, debug.currentFile=messages.properties
16:00:23.802 [DatabaseLoadingThread] INFO  n.s.o.d.ComponentPresetDatabaseLoader - Loading component presets from datafiles/presets
16:00:23.803 [DatabaseLoadingThread] DEBUG net.sf.openrocket.util.JarUtil - Found jar file using codeSource

and a matplotlib graph will show up in a new window. So it might be that in the first case it worked, and you just didn't see the graph for some reason.

For me it only works if run it like this:

python -m examples.simple_plot

NOT like this:

python examples/simple_plot.py

The issue here is that the examples are meant to show you how it should work if you installed orhelper through pip (not cloned with github). So it can be a bit finicky to get it to recognize where the imports are, especially if you installed if from pip AND cloned from git. Alternatively you could try copying the simple_plot.py to a whole new directory on your machine and installing orhelper with pip as shown in the readme (dont forget to copy the ork file too).

yuriachermann commented 3 years ago

It is perfectly working now, but the JVM is not shutting down to continue reading my code. I use Linux, and even with the updated package it's not working. Any tip?

Thanks for the amazing assistance!

SilentSys commented 3 years ago

Hi, yes, this is likely a bug I fixed in a recent commit. If you cloned orhelper from git, please pull in the latest changes.

For pip, I havent yet made an official release, but you can always install the latest changes using:

python -m pip install "git+https://github.com/SilentSys/orhelper.git@master#egg=orhelper"

Note that the get_events() function has changed a bit. Examples have been updated to reflect the change.

Please let me know how this works for you.

yuriachermann commented 3 years ago

Thanks a lot, it's working!

Just another thing, I'm trying to get the apogee value using this print(events.get(FlightEvent.APOGEE)) And it gives me the same value from the plot (3.51...), which make sense, but it's not the real apogee value (~50 m) Am I doing something wrong?

SilentSys commented 3 years ago

Glad to hear it's working!

Events give you the time at which they happen. To find the altitude at that time you will need to also use get_timeseries to get altitude data and then calculate it from there. Best way to calculate in my opinion is to use numpy.interp. But you can also write your own implementation. examples/simple_plot.py has a lambda function index_at which is an approximation of the same thing.

yuriachermann commented 3 years ago

Now it's working perfectly for the simple.ork, I used: np.interp(events.get(FlightEvent.APOGEE), data[FlightDataType.TYPE_TIME], data[FlightDataType.TYPE_ALTITUDE])

But for any other .ork file I get this message:

Exception while calling OpenRocket Traceback (most recent call last): File "OpenRocketDocument.java", line 247, in net.sf.openrocket.document.OpenRocketDocument.getSimulation File "ArrayList.java", line 435, in java.util.ArrayList.get File "ArrayList.java", line 659, in java.util.ArrayList.rangeCheck Exception: Java Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/home/yuri/OR/my_plot.py", line 14, in sim = doc.getSimulation(0) java.lang.java.lang.IndexOutOfBoundsException: Traceback (most recent call last): File "OpenRocketDocument.java", line 247, in net.sf.openrocket.document.OpenRocketDocument.getSimulation File "ArrayList.java", line 435, in java.util.ArrayList.get File "ArrayList.java", line 659, in java.util.ArrayList.rangeCheck Exception: Java Exception

The above exception was the direct cause of the following exception:

Traceback (most recent call last): File "/home/yuri/OR/my_plot.py", line 14, in sim = doc.getSimulation(0) java.lang.IndexOutOfBoundsException: <exception str() failed>

SilentSys commented 3 years ago

Sounds like you do not have a simulation scenario defined in your ork file. You need to have at least one: image

SilentSys commented 3 years ago

Closing this issue as I believe all the original problems have been resolved.

Feel free to open another issue if anything else comes up.

yuriachermann commented 3 years ago

I appreciate a lot your assistance! Every problem is solved Thank you for the attention