ROSE-HULMAN INSTITUTE OF TECHNOLOGY Department of Mechanical Engineering ME 123 Comp Apps I Mini-project 3 – Rocket landing On April 8, 2016 SpaceX made history by successfully landing their first stage rocket on an ocean platform 300 km west of their Florida launch site, while the second stage rocket delivered its resupply payload to the International Space Station. This was a significant step in their goal to reduce the costs of spaceflight by developing reusable first stage rockets. Here is a video of the successful landing:https://www.youtube.com/watch?v=RPGUQySBikQ Previous attempts were less successful, undergoing RUD (Rapid Unscheduled Disassembly): https://www.youtube.com/watch?v=JergEf21HF0 We will attempt a small, simplified version of this task. We will focus on the phase of the flight when the first stage rocket has completed its reentry burn and the aerodynamic guidance phase, and is ready for the vertical landing (see Figure 1 below). Figure 1. Floating platform recovery of the first stage Falcon 9 rocket. (https://en.wikipedia.org/wiki/Falcon_9_booster_controlled‐ descent_and_landing_tests#/media/File:Falcon_9_First_Stage_Reusability_Graphic.jpg) ROSE-HULMAN INSTITUTE OF TECHNOLOGY Department of Mechanical Engineering ME 123 Comp Apps I At this point in its trajectory the first stage is about 1 km above the ocean and falling at 250 m/s. It will reignite its engines in an attempt to land in the correct location on the barge with a velocity of less than 1 m/s. In this project, you will simulate the trajectory of a simplified rocket using Euler’s method, then adjust the rocket thrust profile to match a nominal (good, desired) trajectory that will bring the rocket in for a safe landing. To keep things simple we will assume that the rocket is already directly over the barge—we are just trying to get it to go downwards. This document explains the details of the rocket flight model, how to determine the thrust profile, and how your trajectory prediction will be tested and graded. The deliverables for the project are also discussed, and suggested steps are provided to give you some guidance. 1 — Nominal trajectory We are going to try to get our rocket to follow a nominal trajectory. If we can keep the rocket following its nominal trajectory then it will land safely. Here are the things the nominal trajectory is trying to accomplish: 1. At time 0, we have and . That is, we want to match our nominal to the initial altitude and velocity for the rocket. ( is the initial altitude and is the initial velocity for the rocket. is positive upwards, so the initial velocity will be a negative number.) , we have 0 and 0. That is, when we get to the time when 2. At time we reach the barge surface, we want to be going very slow (zero velocity). ( is the time when we reach the barge surface.) One of the easiest ways to create this profile is simply to have the altitude be a cubic function of time and figure out the four coefficients to meet these four requirements. If we do that, we find 3 2 (1) (2) ROSE-HULMAN INSTITUTE OF TECHNOLOGY Department of Mechanical Engineering ME 123 Comp Apps I with 2 2 (3) 3 (4) (5) (6) Note: The altitude and velocity after time are supposed to stay zero. You will want to pick a time limit and make the nominal altitude and velocity trajectories zero between and . We recommend that you use 20s. 2 — Simulated trajectory Once we have our nominal trajectory, we would like to simulate the flight of the rocket and see if we can create the thrust required to stay on that nominal path. The simplified equations of motion for the rocket are actually quite close to those you used in your homework for the flight of projectiles, except that this time we have a rocket thrust. Figure 2 shows the free-body diagram for the rocket. Figure 2. Free-body diagram for simplified rocket. ROSE-HULMAN INSTITUTE OF TECHNOLOGY Department of Mechanical Engineering ME 123 Comp Apps I The equations of motion we need to simulate are then dV d d d (7) (8) d d (9) where 1 2 4 (10) The definitions for the various symbols are as follows: = = = = = = = = = = = = = Mass of the empty rocket Mass of fuel Rocket velocity Time Acceleration due to gravity Drag proportionality constant Thrust fraction Maximum rocket thrust we can produce Rocket altitude Fuel consumption rate required for maximum rocket thrust Air density Rocket diameter Coefficient of drag for the rocket We also have initial conditions for all of our differential equations: 0 (11) 0 (12) 0 (13) ROSE-HULMAN INSTITUTE OF TECHNOLOGY Department of Mechanical Engineering ME 123 Comp Apps I Tables 1 and 2 give numerical values for selected variables. Table 1. Numerical values for constants. (These values will not change.) Constant Description Value with units Mass of the empty rocket 18,000 kg 9.8 m/s2 Acceleration due to gravity Maximum rocket thrust we can produce 800,000 N Fuel consumption rate required for maximum rocket thrust 130 kg/s Air density 1.2 kg/m3 Rocket diameter 3.66 m Coefficient of drag for the rocket 0.51 Table 2. Typical numerical values for initial conditions. (These values may be different on test day.) Initial condition Description Value with units Initial rocket altitude 1000 m Initial rocket velocity -250 m/s Initial fuel mass 2200 kg 3 — Controlling the thrust fraction At this point, we have a nominal trajectory and we can simulate the trajectory of the rocket for any given thrust fraction. The thrust fraction can even be different at different times, which is probably wise if we want a soft landing. The question now is, how do we choose the thrust fraction over time so that we follow the nominal trajectories? To do this we will implement a very simple control algorithm. (More about this in your sophomore and junior classes!) ROSE-HULMAN INSTITUTE OF TECHNOLOGY Department of Mechanical Engineering ME 123 Comp Apps I At every time inside your Euler simulation loop, we will find the error between the nominal trajectories and the actual trajectories. The bigger the errors are, the more thrust we will apply: (14) However, is limited to the range 0.4 to 1, and if you run out of fuel, then 0. (It is actually true that the rocket can only run in the range from 40% to 100% thrust.) and are constants that you will need to pick to obtain good performance. ( has units of m and has units of s/m.) Notice that the sign on the errors does matter, and for this to work properly you need to get the signs correct in Equation (14). Your goal for this project is to determine a set of values for , , and so that your landing velocity is between 0 and -1 m/s. There are many sets of values that will accomplish this goal, so the “optimal” solution is the one that also minimizes thrust variability. There are several constraints on the landing time and the controller constants that will affect your analysis: 1. The desired landing time cannot exceed the time limit : 0 . 2. The controller constant is positive and has an upper limit: 0 20m . 3. The controller constant is positive and has an upper limit: 0 10s/m. ROSE-HULMAN INSTITUTE OF TECHNOLOGY Department of Mechanical Engineering ME 123 Comp Apps I 4 — Thrust variability Even if we land safely, for some of the choices of the controller constants the thrust fraction over time is smooth and for others it varies wildly, as shown in Figure 3 below. Thrust Fraction Over Time Thrust Fraction Over Time 1 1 0.8 0.8 0.6 0.6 0.4 0.4 0.2 0.2 0 0 0 2 4 6 8 10 Time (s) (a) 12 14 16 18 20 0 2 4 6 8 10 12 14 16 18 20 Time (s) (b) Figure 3. Thrust fraction over time for two successful landings. The thrust profile in Figure 3b is going to be very tough on the rocket engine, while the thrust profile in Figure 3a is going to be much better (but still may not be the best you can do). We would like to quantify this intuition with a measure we will call thrust variability. The thrust variability will be the rms (root mean square) value of the rate of change of the thrust over time. If you store the thrust fraction ( ) in a vector f that has a time step size dt, then we can write the thrust variability in MATLAB in just a single line: thrust_variability = rms(diff(f)/dt); The code diff(f)/dt generates a vector which is a very simple numerical derivative of f with respect to time, and the rms function finds the root mean square value of that vector. You can find out more about these functions from the MATLAB documentation (e.g., doc diff and doc rms). Notice that thrust_variability is a scalar. The thrust variability for the profile in Figure 3a is 1.82, while the thrust variability for the profile in Figure 3b is 4.48. 5 — The test exercise ROSE-HULMAN INSTITUTE OF TECHNOLOGY Department of Mechanical Engineering ME 123 Comp Apps I During class on Thursday of Week 10 (May 19, 2016), we will hold an exercise to test the results of your program. The test exercise procedure is as follows: 1. A prediction card will be passed out to each team. 2. Your instructor will provide you with the rocket’s test-day , , and . Teams will have 20 minutes to complete Step 3. After that, no more submissions will be accepted. 3. Teams will use their MATLAB code to determine the values of , , and that yield the best trajectory, as well as the corresponding thrust variability. Teams will record these results on their prediction card. Program results must be left on the teams’ computer screens. 4. Your instructor will verify that the reported values are the ones appearing on the teams’ computer screens. 5. The , , and values predicted by each team will be tested by your instructor in a “virtual experiment” (i.e., a computer simulation). 6 — Submitting your MATLAB code By 5 pm on Friday of Week 10 (May 20, 2016), upload your team’s well-commented MATLAB code (main routine and functions) as m-files (.m) to Moodle. Upload only ONE submission per team. If your code failed to work at the test exercise, fix the code before you upload it to Moodle. 7 — Project grading Your grade for this project will be computed with the following weights: 40 pts Test exercise performance 60 pts MATLAB code (well-documented and easy to follow) 100 pts Your test exercise prediction will be scored based on the actual value of the landing velocity and the thrust variability: the closer you are to our (the ME 123 instructors’) minimum value of thrust ROSE-HULMAN INSTITUTE OF TECHNOLOGY Department of Mechanical Engineering ME 123 Comp Apps I variability, the higher your score. Your test exercise prediction score will be determined as follows: No submission , , and land the rocket with 0 1 m/s on your computer, but is out of range when we run it. , , and land the rocket with 0 1 m/s on our simulation. Score depends on the thrust variability following the rubric shown below. 0 pts 12 pts 24‐40 pts 100% percent more variable – 24 for 50% rockettestperformancescore 40 0.32 50% for0% Rocket Test Perfomance Score (pts) 40 38 36 34 32 30 28 26 24 0 10 20 30 40 50 60 70 Percent More Variable (p) 80 90 100 Figure 4. Illustration of the scoring function for your test exercise prediction. 8 — Suggested steps ROSE-HULMAN INSTITUTE OF TECHNOLOGY Department of Mechanical Engineering ME 123 Comp Apps I This is a big project, so we suggest the following steps for you to use in breaking the project down into more manageable pieces. You are not required to follow these steps, but you may find them helpful. If you do take our advice, you are free to work faster than what is suggested, but to keep from falling too far behind, you should try to keep up with this schedule. Day 1 (Friday): 1. Create a function to generate and as a function of time for a given set of , , and values. Plot those curves and verify that they seem to behave the way you think they should. You may want to label them nicely because they may be useful to you later in assessing whether you have matched the nominal trajectories. 2. Create another function to generate the simulated rocket trajectory for given initial conditions using Euler’s method. This is very similar to what you have done on your homework. We suggest that you test the function using some constant thrust fractions between 0.4 and 1 and plot the simulated trajectories on the same axes as the nominal trajectories. Day 2 (Monday): 1. Add the controller to the simulated rocket trajectory function. Test the controller with a and values. (For the suggested conditions in Table few different combinations of 2, you should get a decent landing with 12s, 1m , and 4.3s/m.) 2. Now add in the calculation of the thrust variability. Verify that your thrust profile for the case given for a decent landing looks like Figure 3a, and that the thrust variability is 1.82. Day 3 (Tuesday): You may have noticed that, when the time step for Euler’s method is small for accuracy, it takes a little while to compute even one trajectory. It could take a very long time to run through 100 different combinations of launch conditions, never mind 1000 or so. Actually, there are far more than 1000 possible combinations for this project, so we will definitely want to speed things up! We can do this by pre-allocating the solution vectors. In your code, it would not be surprising if you had something like the following structure, which is code for a ball dropping under the influence of gravity: ROSE-HULMAN INSTITUTE OF TECHNOLOGY Department of Mechanical Engineering ME 123 Comp Apps I clc clear variables g = 9.8; dt = 0.0001; maxsteps = 1e7; v(1) = 0; x(1) = 0; for i = 1:maxsteps v(i+1) = v(i) - g*dt; x(i+1) = x(i) + v(i)*dt; end When we start the for loop, the vectors v and x are only one element long, and each time we go through the loop the vectors get longer by one element. The process of making the array longer is very time consuming in MATLAB, especially when the vectors are large. This little program takes about 5 seconds to run on my machine (yours may be faster or slower). If we could tell MATLAB how big the vectors were going to get, it could make them that big to begin with and the for loop would run much more quickly. Now consider the code shown below: clc clear variables g = 9.8; dt = 0.0001; maxsteps = 1e7; v = zeros(1,maxsteps+1); % % Makes a vector v with (maxsteps + 1) zero elements x = zeros(1,maxsteps+1); % % Makes a vector x with (maxsteps + 1) zero elements v(1) = 0; x(1) = 0; % Not actually necessary now because v(1) = 0 already % Not actually necessary now because x(1) = 0 already for i = 1:maxsteps v(i+1) = v(i) - g*dt; x(i+1) = x(i) + v(i)*dt; end The two new lines are the “pre-allocation” of the vectors v and x; we set them up and then execute the for loop. Running this now takes about 0.2 seconds! We strongly encourage you to consider pre-allocating vectors for your trajectory code. ROSE-HULMAN INSTITUTE OF TECHNOLOGY Department of Mechanical Engineering ME 123 Comp Apps I The only drawback to this method is that you must estimate the length of the vectors you will need. If you guess too small, your program will slow down again; if you guess too large, you will get an “Out of Memory” error – there is not enough memory for you to use! Recall that the time it takes the rocket to land is at most ; use that knowledge and the time step you have selected to estimate how long the vectors need to be. Once you have implemented vector pre-allocation in your program, think of a way to determine the optimal combination of , , and . Of course, you may use a guess-and-check approach, but if you could automate some or all of this process, then your search will likely be much faster. This could be useful on the day of the test exercise when you have only 20 minutes to determine the optimal set of launch conditions. Remember, there are many possible solutions – let MATLAB help you find the optimal combination!