In our final program we need to simulate our space craft's trajectory throughout our solar system. We want to be able to plug in an initial time, \(t_0\), as well as start position, \(\vec{r}_0\), and start velocity, \(\vec{v}_0\), and get out the trajectory the space craft will have given these conditions.
The trajectory of the space craft can be described from Newton's second law of motion, \(\vec{F}=m\vec{a}\). The sum of forces on the rocket is that of all the objects in our solar system, that is:
\(m\vec{a}=\vec{F}_{g,*}+\vec{F}_{g,p}=\vec{F}_{g,*}+\sum\limits_{i=1}^NF_{g,p_i}\)
where \(\vec{F}_{g,*}\) is the gravitational force from the star, and \(\vec{F}_{g,p_i}\) is the gravitational force from planet i. When we sum up the gravitational force from each planet i, we get the total gravitational force from the planets. We have the expression for Newton's gravitational law, and use this to write out the gravitational forces from the star and planets:
\(m\ddot{\vec{r}}=-G\frac{mM_*}{|\vec{r}|^3}\vec{r}-\sum\limits_{i=1}^N\frac{GmM_i}{|\vec{r}-\vec{r}_i|^3}(\vec{r}-\vec{r}_i)\)
We have that G is the gravitational constant, \(m\) is the mass of our rocket, \(M_*\) is the mass of our star, \(M_i\) is the mass of planet i, and \(\vec{r}\)is the position vector as seen from the star while \(\vec{r}-\vec{r}_i\) is the position vector of the rocket as seen from planet i. This makes \(|\vec{r}-\vec{r}_i|\) the absolute value, and therefore the length of this vector. Recall that \(\ddot{\vec{r}}\) is the time derivative of the position twice, also known as the acceleration.
You may have noticed our use of position vectors rather than length r and the unit vector \(\hat{r}\), which has a length 1 and points in a specific direction. Previously we've written Newton's gravitational law as \(\vec{F}=-G\frac{mM}{|\vec{r}|^2}\hat{r}\). In order to get it on the form above, we've rewritten the unit vector as \(\hat{r}=\frac{\vec{r}}{|\vec{r}|}\).
In order to find the acceleration, we simply divide both sides of the equation by the mass of our space craft.
Recall how we can simulate the position of our space craft at any time when we have an expression for the acceleration? This may not pop up naturally if you aren't used to computer programming, but think on it for a second anyway.
...
Okay?
We've mentioned both the Euler-Chromer method, and the LeapFrog method previously. There are several other methods, each with their own advantages and disadvantages. Another method of integration is the Runge-Kutta method. (Methods, actually, as there are several different versions, but let's keep it simple!) It's very precise, but very slow and requires several extra steps in the integration. That is why we went with Euler-Cromer while simulating our travel plan, as we needed to check several possibilities and didn't have the time to wait for our integration every time we made an adjustment. Our intention was to implement the Runge-Kutta method when we found a somewhat reasonable plan, but (spoiler alert!) in the end we didn't manage to get close enough, and had to get some help from NASA HQ to tow our spacecraft to where we wanted to be. It's possible that Runge-Kutta would have brought us into the correct trajectory, but we're on a tight schedule, so we decided to go ahead and launch our rocket, hoping that we would be able to give our rocket some extra boosts to correct our trajectory when we were getting close. Anyways, let's talk about our plan!
When we simulate the space crafts trajectory using the initial time and position found using the Hohmann transfer (more on exactly when and where this is later), we end up with a trajectory as seen in the image to the left.
We seem to be missing our target by quite a lot, but that is no matter for now. We have a program that shows us the trajectory of our rocket, just like we wanted.
The program we just wrote can plot any trajectory given an initial time, position and velocity. It's trajectory is only affected by the forces the objects in our system exerts on the rocket, in other words, it's only affected by Newton's second law of motion. Having this program ready means we can move on to our next challenge, which is planning our journey.
We need to not simply picture any trajectory, but rather one that gets us to our destination planet. We decided our initial time and position of the launch using the Hohmann transfer method, which has given us the best time to launch, given the angle between our planets at launch time. This enables us to send our space craft to a position we know the destination planet will be at when we arrive.
If you're curious about how we decided the time and coordinates for launch, have a look at our previous post where we explain the Hohmann method. An advantage to this method is that it's very fuel efficient, but a disadvantage is that we have a large solar system that will take time to travel across, and that we have to wait for the angle between our home planet and our destination planet to be just right when we launch.
Another method we could have used is to find the place where our home planet and destination planet are at their closest. Our home planet is a bit faster than the destination planet, and as our space craft will have the speed of our home planet (when our frame of reference is with the star at the origin), we know it will travel faster than the destination planet! We would therefore know that we should leave at a time when our planet is slightly behind the destination planet, and try the simulation for a few different times and positions, eventually finding a suitable time and place for launch.
There are many ways to make an educated guess of the best time and place, and then simulate the trajectory until the best path is found, but we like the logic of the Hohmann transfer. Therefore, we decided not to let time hold us back, and went on with our original plan.
Using the Hohmann transfer, we can find out where to launch from our home planet. We want to launch tangential to our Hohmann orbit, or at least somewhat close to tangential. That means launching at a position that lies along the line where our home planet at launch, the star, and the destination planet at arrival aligns. We launch our rocket straight upwards, but as it will get a velocity tangential to the planet from the planet's rotation, we assume that our rocket will be moving at a somewhat tangential direction after launch. We will adjust our direction as we go along, but this is at least a place to start that won't put us too much off course.
Time | 104.86 years |
Position | (6854 km, 230.3\(^{\circ}\)) |
The position is given in polar coordinates around the equator, meaning we launch on the surface of the planet (6854 km from the center of the planet), at an angle of 230.3\(^{\circ}\). When finding the angle, we check the angle between the position vectors at every point in time, and utilize the least-squares method to find the angle closest to the angle we found analytically when using the Hohmann method.
When we know when and where we launch from, the second part of our plan is to decide when and where to give our rocket a boost, as well as how much boost to give.
We assume that the duration of a boost is miniscule compared to the time-scale of the journey, and therefore ignore the time spent accelerating from the boost. Instead we assume that all boosts occur instantaneously in the solar system's frame of reference. After performing a boost, the spacecraft will be given a new velocity, but remain at the same position.
Boosts use gas (we need to push something out in one direction, in order for our planet to move in a different direction), and gas is not free. (It's usually cheapest on Sunday evening or Monday morning for those of you with a car, in case you're wondering!) The price of gas means that we try to not overdo it on the boosts.
We develop our program so it can make a boost, \(\Delta\boldsymbol{v}=(v_x,v_y)\) AU/yr, at a time t. We should also know how much fuel each boost requires, so we know if we've brought enough with us. Unfortunately, our calculations from our simulation of the launch was off, as we ended up using zero fuel. We will therefore have to ignore fuel consumption in our plan. Luckily, NASA installed some fine-tuned equipment in our rocket that will let us measure our fuel consumption when we are actually travelling in space, but more on that later.
When figuring out our plan, there was a lot of trial and error. Let's take a look at all of the things that can go wrong when you are trying to launch a rocket when you are a mere second-year physics student, shall we?
We decide to have one large boost a shortly after launching, in order to slow down our rocket. We do this to prevent our rocket from speeding away from the whole system, as seen in the plot of the trajectory earlier. We do another quite large boost four years later, this time to speed up the rocket. Fasten your seat belts, because we are about to give a small boost a couple of months years later, before we gently start braking again a few weeks later.
These boosts get us very close, but how close do we need to be in order to go into orbit around our destination planet?
In an earlier post we derived an expression for l, which is the distance we need to be from our destination planet in order to perform an orbital injection maneuver:
\(l\leq|\vec{r}|\sqrt{\frac{M_p}{10M_s}}\)
where \(|\vec{r}|\) is the distance from the spacecraft to the star, \(M_p\) is our destination planet's mass and \(M_s\) is the mass of our star.
If everything goes according to plan we should be able to get sufficiently close to our destination planet so that we may be able to perform an orbital injection maneuver.
After trying and failing a bit (read: a lot), we finally simulated a trajectory where our space craft is sort of close to this distance l, but unfortunately not close enough to perform the orbital injection maneuvre:
This distance is the distance to the planet at the point we planned with the Hohmann transfer, and we have noticed that there may be points when we are closer just before this point, but were unable to simulate these values.
Ideally we would be within the limit, but we expect our rocket to be thrown a bit of course by unforeseen circumstances (more on these in the next post), and so we will have to make a few corrections on the way anyway. Our managers are breathing down our necks, and we have a much tighter schedule than most rocket launches do, so we can't plan forever.
Finally, we decide to launch at \(t=104.86\) years after the simulation began, from a position around the equator \(r=6854 \, km, \, \theta = 230.3^{\circ}\). We plan on five boosts. When giving these boosts, we choose to work with a unit vector that can be multiplied by a scalar and added to the velocity, instead of manually specifying the velocity in x- and y-direction every time. We choose to make a unit vector from the initial velocity vector:
\(\hat{v}_0 = \frac{\vec{v}_0}{|\vec{v}_0|}\)
The reason why we are doing this is because ideally we would like to only make a single boost right after launch in the opposite direction of our initial velocity. ("Boost" is a bit misleading, as we are braking rather than accelerating)
Still, we will give a few boosts in the x-direction only. It may look nonsensical, and as we are doing this by the trial and error method, it kind of is! Not using the unit vector would possibly have saved us some boosts, as it is pointing in a different direction than the direction we are heading, but we kept using it for the sake of simplicity.
- \(t_1=0.1\) years, giving \(\Delta\boldsymbol{v}=-1.67\hat{v}_0\)
- \(t_2=4.2\), giving \(\Delta\boldsymbol{v}=0.69\hat{v}_0\)
- \(t_3=4.4\) , giving \(\Delta\boldsymbol{v}=0.1 \hat{v}_0\)
- \(t_3=4.5\) , giving \(\Delta\boldsymbol{v}=-0.05\hat{v}_{0,x}\)
- \(t_4=4.6\) , giving \(\Delta\boldsymbol{v}=-0.04 \hat{v}_{0,x}\)
We expect to have to make corrections along the way, but will try to stick to the plan as best we can.
And with that, we launch:
Stay tuned, next post we'll finally get to follow our space craft on its journey, perhaps take a few pictures of our solar system from space, and see if we make it to our destination!