Issue trying to implement class that is originally a Java interface

Hi Orekit community,

Nowadays, I am working with Orekit through the python wrapper.
I encounter a specific issue while trying to code class that directly implement Orekit interface. For instance, I tried to implement ThrustDirectionProvider interface as following:

class MySupaDupaThrustDirectionProvider(ThrustDirectionProvider):
    
    def __init__(self):
    	pass

    def computeThrustDirection(self,pvProv, date, frame):
    	... # Some interesting ccode
    	return directionVector

Then I create an instance of it:

attitudeProv = MySupaDupaThrustDirectionProvider()

However, when I try to use it for creating other object,

attitudeProvider = ThrustDirectionAndAttitudeProvider.buildFromDirectionInLOF(localFrame, attitudeProv, thrusterAxisInBody)

I obtain the following stack or errors:

orekit.JavaError: <super: <class 'JavaError'>, <JavaError object>>
    Java stacktrace:
org.orekit.errors.OrekitException: Le paramètre variableDirectionInFrame de ThrustDirectionAndAttitudeProvider-DIRECTION_IN_LOF est null
	at org.orekit.forces.maneuvers.propulsion.ThrustDirectionAndAttitudeProvider.checkParameterNotNull(ThrustDirectionAndAttitudeProvider.java:136)
	at org.orekit.forces.maneuvers.propulsion.ThrustDirectionAndAttitudeProvider.buildFromDirectionInLOF(ThrustDirectionAndAttitudeProvider.java:204)

Moreover, when I check on the object type in the console, I get

>>>> isinstance(attitudeProv,ThrustDirectionProvider)
True

but in the same time the variable point to null

>>>> attitudeProv
<attitudeProv: <null>>

while I expecting something like <MySupaDupaThrustDirectionProvider : MySupaDupaThrustDirectionProvider.MySupaDupaThrustDirectionProvider@xxxxxxxxxx>

My observation is that the object is clearly recognized as an implementation of the interface but it is not initialized.
In my understanding, It comes from the fact, that I try to implement in Python an class that is actually a Java interface. I try to implement other interfaces and the observations is quite the same.

I hope that the community can help me with issue

Best regards

Christophe

You’ll find that you can add some output to your computeThrustDirection method, call it as written and it will work on it’s own, but I don’t think there’s anything you can do to make it work in the attempt to buildFromDirectionInLOF

As I understand it, to subclass in python you have to work within the list of python-wrapped classes, here.

Hi @ShikaDing,
Thank you fo this recall that I missed.
So I followed yout proposition and I develop my own python AttitudeProvider subclass starting with the PythonAttitudeProvider to overcome my issue.
It seems to work rightnow with no error when a maneuver is built with my AttitudeProvider subclass. Thoroughful tests are now needed.

Hi @ShikaDing, Hi Everyone,

After few tests it seems that the workaround poposed by @ShikaDing is not suitable for my issue. But maybe something is wrong with my code.
Let start with declaring a new class that inherits from PythonAttitudeProvider:

from org.orekit.attitudes import PythonAttitudeProvider
from org.orekit.frames import FramesFactory, LOFType
from org.hipparchus.geometry.euclidean.threed import Vector3D

class MyAttitudeProvider(PythonAttitudeProvider):

    def __init__(self,params):
        self.params = params

    def getAttitude(self,pvProv, date, frame):
        # code to compute a rotation object from the input arguments
        return Attitude(date, frame, rotation.revert(), Vector3D.ZERO, Vector3D.ZERO)

Then create an instance of this class

In[1]: from MyAttitudeProvider import MyAttitudeProvider
In[2]: attProv = MyAttitudeProvider(1)

But surprisingly, the type of the instance attProv is not the one I expected

In[3]: type(attProv)
Out[3]: jcc.FinalizerProxy

At this step, I am little bit lost because of the following surprising behaviour.
In one hand, no exception is raised while constructing others objects like org.orekit.forces.maneuvers.Maneuver. On the other hand, the Maneuver.getAttitudeOverride() return a null object. Consequently, the maneuver does not provide the expected acceleration during the propagation.
Maybe @petrus.hyvonen or @ShikaDing or anyone in the community, can you help me to understand this issue and find a way to overcome this drawback.

Best regards to the community

Christophe

Hi I found a eror in my code right above. I forgot to initialize the superclass :face_with_hand_over_mouth:
the right code should be:

from org.orekit.attitudes import PythonAttitudeProvider
from org.orekit.frames import FramesFactory, LOFType
from org.hipparchus.geometry.euclidean.threed import Vector3D

class MyAttitudeProvider(PythonAttitudeProvider):

   def __init__(self,params):
       super().__init__()
       self.params = params

   def getAttitude(self,pvProv, date, frame):
       # code to compute a rotation object from the input arguments
       return Attitude(date, frame, rotation.revert(), Vector3D.ZERO, Vector3D.ZERO)

Doing so, my issue is solved:

attProv = MyAttitudeProvider(1)
<MyAttitudeProvider: org.orekit.attitudes.PythonAttitudeProvider@74f7d1d2>

Thanks to everyone.

Chris

1 Like