[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Orekit Developers] Resetting Additional States in Event Handler



Hi,

I am trying to use an Event Handler to reset an additional state (called "A"), changing its value from -1 to +1 when the event is detected. The new state built inside the handler contains the proper value (+1), however, when the propagator goes on, it seems to ignore it and keeps its original value of "-1". Console output looks like this:

2000-01-01T00:00:00.000 A -1.0
2000-01-01T00:00:01.000 A -1.0
Additional state A set to +1
2000-01-01T00:00:02.000 A -1.0
2000-01-01T00:00:03.000 A -1.0
2000-01-01T00:00:04.000 A -1.0
2000-01-01T00:00:05.000 A -1.0

 Here is the code to reproduce the results (Orekit version is 9.1):

public static void main(String[] args) throws OrekitException {

// Load Orekit data
DataProvidersManager.getInstance()
.addProvider(new DirectoryCrawler(new File("OREKIT_DATA_LOCATION_HERE")));

// Build orbit
AbsoluteDate date0 = new AbsoluteDate(2000, 1, 1, TimeScalesFactory.getUTC());
Orbit orbit = new KeplerianOrbit(7.1E6, 0, 0, 0, 0, 0, PositionAngle.TRUE, FramesFactory.getGCRF(), date0,
Constants.WGS84_EARTH_MU);

// Build propagator
ODEIntegrator odeIntegrator = new DormandPrince853Integrator(1E-3, 1E3, 1E-6, 1E-6);
NumericalPropagator propagator = new NumericalPropagator(odeIntegrator);

// Instantiate additional states
Map<String, double[]> additionalStates = new HashMap<String, double[]>();
additionalStates.put("A", new double[] { -1 });

// Create initial state and add it to the propagator
SpacecraftState initialState = new SpacecraftState(orbit, additionalStates);

propagator.setInitialState(initialState);

// Create date detector and handler
DateDetector dateDetector = new DateDetector(date0.shiftedBy(3)).withHandler(new EventHandler<DateDetector>() {

@Override
public Action eventOccurred(SpacecraftState s, DateDetector detector, boolean increasing)
throws OrekitException {
return Action.RESET_STATE;
}

@Override
public SpacecraftState resetState(DateDetector detector, SpacecraftState oldState) {
Map<String, double[]> newAdditionalStates = new HashMap<String, double[]>();
newAdditionalStates.put("A", new double[] { +1 });

SpacecraftState newSpacecraftState = new SpacecraftState(oldState.getOrbit(), oldState.getAttitude(),
oldState.getMass(), newAdditionalStates);

System.out.println("Additional state A set to +1");
return newSpacecraftState;
}
});

propagator.addEventDetector(dateDetector);

// Set the propagator mode
propagator.setMasterMode(1, new OrekitFixedStepHandler() {

@Override
public void handleStep(SpacecraftState currentState, boolean isLast) throws OrekitException {
String line = currentState.getDate().toString();

for (Entry<String, double[]> entry : currentState.getAdditionalStates().entrySet()) {
line += " " + entry.getKey();

for (double d : entry.getValue()) {
line += " " + d;
}
}
System.out.println(line);
}
});

// Propagate
propagator.propagate(date0, date0.shiftedBy(5));
}

Any idea of whay I may be doing wrong?

Thanks in advance,

Frank