Problem with ConstantThrustManeuver methods

Hi all,

I was trying to create a “custom” ConstantThrustManeuver class and just copied and pasted what I found on GitHub but it seems like two methods are not working and I don’t understand why… I just downloaded Orekit 10.1 and Hipparchus 1.6 and I’m taking the source code from here

Would any one be able to tell me if I’m picking the wrong version of the class?

It does not seem to like how the handler is written…

The two classes are:

/** {@inheritDoc} */
@Override
public <T extends RealFieldElement<T>> Stream<FieldEventDetector<T>> getFieldEventsDetectors(final Field<T> field) {
    // in forward propagation direction, firing must be enabled
    // at start time and disabled at end time; in backward
    // propagation direction, firing must be enabled
    // at end time and disabled at start time
    final FieldDateDetector<T> startDetector = new FieldDateDetector<>(new FieldAbsoluteDate<>(field, startDate)).
        withHandler((FieldSpacecraftState<T> state, FieldDateDetector<T> d, boolean increasing) -> {
            triggeredStart = state.getDate().toAbsoluteDate();
            return Action.RESET_DERIVATIVES;
        });
    final FieldDateDetector<T> endDetector = new FieldDateDetector<>(new FieldAbsoluteDate<>(field, endDate)).
        withHandler((FieldSpacecraftState<T> state, FieldDateDetector<T> d, boolean increasing) -> {
            triggeredEnd = state.getDate().toAbsoluteDate();
            return Action.RESET_DERIVATIVES;
        });
    return Stream.of(startDetector, endDetector);
}

/** {@inheritDoc} */
@Override
public Stream<EventDetector> getEventsDetectors() {
    // in forward propagation direction, firing must be enabled
    // at start time and disabled at end time; in backward
    // propagation direction, firing must be enabled
    // at end time and disabled at start time
    final DateDetector startDetector = new DateDetector(startDate).
        withHandler((SpacecraftState state, DateDetector d, boolean increasing) -> {
            triggeredStart = state.getDate();
            return Action.RESET_DERIVATIVES;
        });
    final DateDetector endDetector = new DateDetector(endDate).
        withHandler((SpacecraftState state, DateDetector d, boolean increasing) -> {
            triggeredEnd = state.getDate();
            return Action.RESET_DERIVATIVES;
        });
    return Stream.of(startDetector, endDetector);
}

Thank you very much!

Kind regards,

B.

Hi,

Looking at the two methods, you have picked the good version of the class.

Could you provide a back trace? A failing test case would be even more helpful in diagnosing your issue.

Regards,
Bryan

Hi Bryan,

I’m receiving the following error when trying to run my application:

Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
	Syntax error on token "SpacecraftState", ( expected after this token
	state cannot be resolved to a variable
	DateDetector cannot be resolved to a variable
	Syntax error on token "d", delete this token
	Syntax error on token "boolean", delete this token
	increasing cannot be resolved to a variable
	Syntax error on tokens, ( expected instead
	state cannot be resolved
	Syntax error, insert ")" to complete Expression
	Syntax error, insert ")" to complete Expression
	Syntax error, insert ")" to complete VariableInitializer
	Type mismatch: cannot convert from Action to Stream<EventDetector>
	Syntax error on tokens, delete these tokens
	Syntax error on token "SpacecraftState", ( expected after this token
	state cannot be resolved to a variable
	DateDetector cannot be resolved to a variable
	Syntax error on token "d", delete this token
	Syntax error on token "boolean", delete this token
	increasing cannot be resolved to a variable
	Syntax error on tokens, ( expected instead
	state cannot be resolved
	Syntax error, insert ")" to complete Expression
	Syntax error, insert ")" to complete Expression
	Syntax error, insert ")" to complete VariableInitializer
	Type mismatch: cannot convert from Action to Stream<EventDetector>
	Syntax error on tokens, delete these tokens
	Type mismatch: cannot convert from Stream<DateDetector> to Stream<EventDetector>

	at environment.CustomConstantThrustManeuver.getEventsDetectors(CustomConstantThrustManeuver.java:456)
	at org.orekit.propagation.numerical.NumericalPropagator$Main.<init>(NumericalPropagator.java:491)
	at org.orekit.propagation.numerical.NumericalPropagator.getMainStateEquations(NumericalPropagator.java:467)
	at org.orekit.propagation.integration.AbstractIntegratedPropagator.createODE(AbstractIntegratedPropagator.java:535)
	at org.orekit.propagation.integration.AbstractIntegratedPropagator.propagate(AbstractIntegratedPropagator.java:457)
	at org.orekit.propagation.integration.AbstractIntegratedPropagator.propagate(AbstractIntegratedPropagator.java:414)
	at org.orekit.propagation.integration.AbstractIntegratedPropagator.propagate(AbstractIntegratedPropagator.java:397)

Is this helpful?

Kind regards,

B.

Hi @benoist,

It is a compilation issue, you must have a missing bracket somewhere in your copied code.
Doesn’t your IDE tell you where the error is ?

Maxime

Hi,

Yes I’ve checked that but no missing bracket. I’ve even tried adding pieces by pieces to make sure each bracket had its counterpart.

When just entering this line in the getFieldEventsDetectors method:

final FieldDateDetector<T> startDetector = new FieldDateDetector<>(new FieldAbsoluteDate<>(field, startDate)).withHandler((FieldSpacecraftState<T> state, FieldDateDetector<T> d, boolean increasing)->{triggeredStart = state.getDate().toAbsoluteDate();return Action.RESET_DERIVATIVES;});

It logs errors on what is contained in withHandler() asking me to create local variables (errors on state, T, d, increasing), to change the return type of the method to Action (error on Action), and unexpected token errors (even though they’re all here).

B.

Hi again,

Hard to tell what’s happening without the code.
Can you send us your CustomConstantThrustManeuver class ?
What version of Java are you using ?

CustomConstantThrustManeuver.java (21.3 KB)

I’m using Java 8 (1.8.0_112 to be precise).

B.

Well I could not reproduce your bug sorry…

I downloaded the orekit-10.1.jar file from the link you provided and linked it in a new project in Eclipse-2019-03, wrote a small test… and everything works fine.

I can’t tell where your compilation error is coming from. Which IDE are you using ?

Hmm that’s odd… I’m using Eclipse as well but quite an old version (2013), do you think that could be it? Or my Java version is outdated?

I don’t know if it comes from there but you could definitely try upgrading Java to the latest OpenJDK 8 and Eclipse (I suggest 2019-03 for Eclipse, the latest version was buggy on my machine).

As a guess, the IDE from 2013 doesn’t probably have support for JDK8 which was released in 2014 and has many new not backward compatible features like lambdas, default methods etc.

Try newer versions of Eclipse or another (more modern) Java IDE - IntelliJ IDEA which is de-facto a “standard” IDE nowadays with support from big companies like Google (similar to how Eclipse was such an IDE 10 years ago).