tudat-team / tudatpy

A Python platform to perform astrodynamics and space research.

Home Page:https://tudat-space.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature request: termination settings when apogee is reached

gaffarelj opened this issue · comments

A new termination setting could be added to Tudat to stop a propagation when apogee is reached.

This would be particularly useful for ascent simulations and could be triggered either when the vertical velocity becomes negative, or when the vehicle starts losing altitude.

Alternatively, this could be implemented as a dependent variable that is False when apogee is not reached, and True if apogee is reached. It could even be added as a flight condition and/or dependent variable. This way, the propagation could continue, but the user could use this flight condition to trigger some change in vehicle behavior after apogee.

Hi @gaffarelj, something I pulled out from an old Slack thread might provide a good starting point, just to point out you can call on objects states in a custom termination function in Python.

The following snippet was intended for a launch segment, and was designed to terminate the simulation when the vehicles relative tangential velocity w.r.t. Earth was greater than circular orbit velocity at the vehicles current altitude. As mentioned in the thread, it was perhaps not the best solution for this design, but it worked.

Might be an easier solution, giving students more insight into custom terminations. The more we add, the more we need to maintain (e.g.. an additional dependent variable).

def custom_termination_fn(_):
    rel_state = system_of_bodies.get("Vehicle").state - system_of_bodies.get("Earth").state
    rel_r = rel_state[:3]
    rel_v = rel_state[3:]
    rel_r_mag = np.linalg.norm(rel_r)
    rel_v_t = rel_v - np.dot(rel_v, rel_r) / np.dot(rel_r, rel_r) * rel_r
    return np.linalg.norm(rel_v_t) >= sqrt(MU_EARTH / rel_r_mag)


custom_termination = propagation_setup.propagator.custom_termination(custom_termination_fn)

Good idea! Here, an important question is: what is the exact definition of apogee? The first point where dh/dt < 0? Calculating dh/dt may be cumbersome for some shape models. Alternative is the point where the angle between position and velocity vectors becomes larger than 90 degrees (flight path angle < 0 degrees?).

Hi @geoffreygarrett, thank you for the code you just shared. I actually implemented something similar in a new tudatpy rocket ascent example that I pushed yesterday here, to terminate at apogee using a custom function.

What I wanted to address in this issue is that perhaps other users would find this apogee termination useful, and it could be implemented directly in tudat?

In a first time I think I will just put what I made for my rocket ascent example as the new example for the custom_termination function in the API docs here, since the current code snippet is more of a placeholder.

@DominicDirkx good point. I think that defining it as the moment where the angle between velocity and position becomes > 90 deg would be best.

I would be cautious about using the flight path angle directly because of the whole orientation confusion, but I don't know if the orientation of the vehicle is actually used to compute the flight path angle.

We could also just offer an option to alternatively use dh/dt < 0. I do want to test both implementations anyways, so I can compare their robustness and how they differs.

I don't know if I'm missing something but is flight path angle not simply the angle between the horizon (not really horizon here, but the perpendicular from position vector in the same direction) and the velocity vector, what does the orientation confusion refer to? I think it would be a good solution. @DominicDirkx we could also add an exact termination with a root solver fairly easily for this right?

The confusion is my own: I'm still quite confused about how lots of orientations are computed and handled in tudat :)

But then indeed, if the flight path angle is computed like this, it would be perfect.

Indeed, the flight path angle does not use the body orientation, only its translational state. One possible issue is that the flight path angle becomes singular if speed is 0, which will happen at apogee.... So, using the FPA to find apogee may not be the best option. We could set it to FPA < 0, not FPA <= 0, but the angle will behave chaotically near V=0 (apogee). So, possibly not the best option.

Concerning the root finding, this is already done :) When terminating exactly on a dependent variable, the code enters a root finding algorithm.

AHH yes @DominicDirkx, I recall now it was a general implementation for any termination condition, my question was under the presupposition that it wasn't generalized to a custom one.

Regarding my previous hesitation on adding an extra dependent variable to Tudat, that came from the Zen of Python:

There should be one-- and preferably only one --obvious way to do it.

But I think in this case, it's a good addition to have as a default go-to.

I am closing this issue. It was not obvious to me at the time, but indeed using the flight path angle to determine when apogee is reached turned out to be perfect. So, no additional termination setting should be added for this. (It may still be good to describe this use case somewhere in the guide or the ascent example.)