Custom handler Java runtime exception

Hi all, I would like to implement a custom handler to get sun vector position relative to spacecraft frame. Looking in some examples I am implementing it as shown in the code below.

class SunvectorPosHandler(PythonOrekitFixedStepHandler):
    
    def __init__(self, angle):
            # set up Earth model
            self.earth = OneAxisEllipsoid(Constants.WGS84_EARTH_EQUATORIAL_RADIUS,
                                         Constants.WGS84_EARTH_FLATTENING,
                                         FramesFactory.getITRF(IERSConventions.IERS_2010, False))
            
            self.sun = CelestialBodyFactory.getSun()
            self.sunRadius = Constants.SUN_RADIUS

            self.dates = []
            self.sunXs = []
            self.sunYs = []
            self.sunZs = []
            
            # Initialize the superclass as well
            super(CorridorHandler, self).__init__()
            
    def init(self, s0:SpacecraftState, t:AbsoluteDate, step: float):
        # needs to be stated to fulfill the interface specification
        pass
    
    def handleStep(self, currentState: SpacecraftState):
        inertToSpacecraft = currentState.toTransform()
        date    = currentState.getDate()
        sunInert = self.sun.getPVCoordinates(date, currentState.getFrame()).getPosition()
        #sunSat = inertToSpacecraft.transformPosition(sunInert)
        #sunX = sunSat.getX() / sunSat.getNorm()
        #sunY = sunSat.getY() / sunSat.getNorm()
        #sunZ = sunSat.getZ() / sunSat.getNorm()
        
        #self.dates.append(date)
        #self.sunXs.append(sunX)
        #self.sunYs.append(sunY)
        #self.sunZs.append(sunZ)
    
    def finish(self, finalState: SpacecraftState):
        pass

handler = CorridorHandler(ANGULAR_OFFSET)
Propagator.cast_(propagator).setStepHandler(STEP, handler)

start = epochDate
propagator.propagate(start, start.shiftedBy(DURATION))

It throws the following:

JavaError Traceback (most recent call last) Cell In[9], [line 2]
start = epochDate 
---->propagator.propagate(start, start.shiftedBy(DURATION)) JavaError: <super: <class 

'JavaError'>, <JavaError object>> Java stacktrace: java.lang.RuntimeException: AttributeError 
at org.orekit.propagation.sampling.PythonOrekitFixedStepHandler.handleStep(Native Method)
at org.orekit.propagation.sampling.OrekitStepNormalizer.handleStep(OrekitStepNormalizer.java:111)
at org.orekit.propagation.sampling.StepHandlerMultiplexer.handleStep(StepHandlerMultiplexer.java:184)
at org.orekit.propagation.analytical.AbstractAnalyticalPropagator.acceptStep(AbstractAnalyticalPropagator.java:336)
at org.orekit.propagation.analytical.AbstractAnalyticalPropagator.propagate(AbstractAnalyticalPropagator.java:153)

If I comment the line
sunInert = self.sun.getPVCoordinates(date, currentState.getFrame()).getPosition()

Then it runs ok.

Could anyone please guide me on what could be happening here?
Thank you
Sebastian.

Hi, see:

Hi Petrus, thank you very much! That worked for that line. Now, when I uncomment the following line

sunSat = inertToSpacecraft.transformPosition(sunInert)

Now the same error. I didn’t get well the explanation in the link you shared:

I think this is true in general with the Python wrapper when you want to use a method from an interface implemented by a class: the class must be explicitely casted to the interface.

How is this applied to this new line?
And sorry for this newbie questions, I’m not a great python coder neither, but learning.

Thank you!

Hi

Think you need to cast as StaticTransform.

Cheers,
Romain

Hi Serrof,

Yes, I get more or less the idea, but can’t figure exactly the implementation for the line

sunSat = inertToSpacecraft.transformPosition(sunInert)

Sorry :pray:
And thanks in advance if you guide me more on this.

Ok, I get it. I must modify the line from:

sunSat = inertToSpacecraft.transformPosition(sunInert)

to:

sunSat = StaticTransform.cast_(currentState.toTransform()).transformPosition(sunInert)

Thanks for you guidance.