# Code to generate Sun-Earth L2 halo orbits for given epoch?

I am working on a GMAT script out of personal interest (not part of a job) that involves a spacecraft orbiting the Sun-Earth L2 point. I have found some orbital state vectors for the spacecraft that allow a stable halo orbit with minimal delta V correction if I run a stationkeeping script. However, this only works for specific epochs, with the orbits becoming unstable eventually even with stationkeeping (I know halo orbits are not perfectly stable in the short-term, hence the need for stationkeeping, but this seems to be something else relating to the motion of the Sun, Earth and Moon over time. L2 is colinear, so the shifting barycenters due to the motion of the Moon perhaps?).

I want to find the optimal epoch for an L2-Mars transfer, and I want the halo orbit to last for a specific amount of time, so I need to be able to vary the date the spacecraft enters the halo orbit. Therefore, I have been looking for an algorithm or code that can generate state vectors for viable halo orbits in specific dates. I have found some sources of code that appear to do that: Matlab scripts provided J.D. Mireles James, the code in the appendix of this report by Ethan Geipel, this unvalidated code by Christopher Rabotin, and the code at the end of this question, which is a code version of the algorithm described in Kathleen Connor Howell's "Three-Dimensional, Periodic 'Halo' Orbits" paper.

These collections of code appear to do what I'm looking for, but they seem to focus on visualizing the orbits rather than outputting state vectors spacecraft must have to orbit them. I'm also still a complete beginner in understanding trajectories involving Lagrange points, so I'm not completely sure what "computing halo orbits" means in the first place. Therefore my question is twofold: do these scripts indeed do what I think they do, and if yes then how I can use them to acquire the orbital state vectors a spacecraft must have in a specific date to be able to enter a halo orbit?

Sorry for the very beginner question, I'm an amateur and this is my first time ever doing anything with Lagrange points and halo orbits. This is the main reason why I'm looking for a "simple" solution, I have just started educating myself on the topic by reading Robert Farquhar's important papers.

• – uhoh
Commented Feb 25, 2022 at 0:55

This is a very partial answer that is too long to post as a comment.

I'm not completely sure what "computing halo orbits" means in the first place.

It means using a search procedure to find an initial state vector that results in the trajectory returning to the same state vector over and over again periodically, or at least very nearly so. That would be called a closed, periodic orbit.

It means some kind of trial and error procedure where you pick some initial state vectors and propagate them and see which ones seem like they are somewhat close to being closed, then keep tweaking the initial state vectors iteratively until the become closer and closer to being closed. You stop when it's close enough for you (e.g. within meters and millimeters per second of the initial state vector)

Since you are searching a 6-dimensional space, there are several tricks to speeding this up beyond a blind search of a zillion possible initial states.

1. If this is a pure circular restricted three-body problem (e.g. Earth's eccentricity is zero) then you chose your starting point at the top of the orbit, out of plane and directly above the Sun-Earth line. That makes one of your spatial coordinates zero, and one of your velocity coordinates zero also. Now you are only searching 4-dimensional space.
2. Use the state transition matrix to speed up your search. After you try an initial state vector, it helps you to choose which one to try next to get closer to a closed orbit so you can converge more quickly. See answers to How to best think of the State Transition Matrix, and how to use it to find periodic Halo orbits?
3. If you want to model a realistic halo orbit with Earth in a slightly eccentric orbit instead of a circular one, you first solve for a family of nearby closed, periodic halo orbits in the circular approximation and use those state vectors to start propagating in a realistic problem, propagating Earth's actual trajectory (and probably the Moon's as well) along with propagating your desired trajectory.

do these scripts indeed do what I think they do,

It will be infinitely rewarding for you if you start by writing a short, simple circular restricted three body orbit propagator yourself first. You don't need a sophisticated method for converging on a closed periodic orbit, just something that when given known solutions (say those in Howells 1984 paper) confirms that yes, after one period T the state vector returns to very nearly the same value; it's closed to within some small tolerance.

Once you can confirm closure, then try a bunch of different but nearby state vectors, propagate them for one (or ten!) times the nominal period and see in amazement how they diverge exponentially from the nominal orbit. You've now witnessed instability, the thing people always talk about when they say "Halo orbits are always unstable" or Are some Halo Orbits actually Stable? (stable orbits about unstable Lagrange points)

and if yes then how I can use them to acquire the orbital state vectors a spacecraft must have in a specific date to be able to enter a halo orbit?

Halo orbits proper exist only in the circular restricted three body problem and so are timeless (i.e. dateless). There are two things that will lead to specific dates:

1. You have moved to a realistic solar system with Earth and Moon trajectories, so you need a starting date to define their initial state vectors as well
2. You want Mars to be there when you pass its orbit, and you also might want to be at a point in the halo orbit where you have maximum prograde velocity in the non-rotating frame (i.e. at the "top" or "bottom" of the orbit, depending on if it's the northern or southern halo solution, since they are tilted, halos come in nearly-identical pairs)