Spaceshot Flight Software
The Illinois Space Society's Homemade Rocket Firmware
rk4.h
1 #include <array>
2 
3 #include "Atmosphere.h"
4 
5 #pragma once
6 
7 using std::array;
8 
9 class rk4 {
10  public:
11  rk4();
12 
13  array<float, 2> accel(array<float, 2> u, float rho);
14 
15  array<float, 2> rk4_step(array<float, 2> state, float dt, float rho);
16 
17  array<float, 2> sim_apogee(array<float, 2> state, float dt);
18 
19  float cd(float alt, float vel);
20  array<double, 151> poly = {
21  {0,
22  0,
23  0,
24  0,
25  0,
26  0,
27  0,
28  0,
29  0,
30  0,
31  0,
32  0,
33  0,
34  0,
35  0,
36  -0.00000000000000000000000000000000000000000000314461,
37  -0.00000000000000000000000000000000000000000001056820,
38  -0.00000000000000000000000000000000000000000003019687,
39  -0.00000000000000000000000000000000000000000007704372,
40  -0.00000000000000000000000000000000000000000017835826,
41  -0.00000000000000000000000000000000000000000037122339,
42  -0.00000000000000000000000000000000000000000066708435,
43  -0.00000000000000000000000000000000000000000089497435,
44  -0.00000000000000000000000000000000000000000018652341,
45  0.00000000000000000000000000000000000000000452923463,
46  0.00000000000000000000000000000000000000002252133750,
47  0.00000000000000000000000000000000000000007909889877,
48  0.00000000000000000000000000000000000000023785244592,
49  0.00000000000000000000000000000000000000064721946801,
50  0.00000000000000000000000000000000000000162507072012,
51  0.00000000000000000000000000000000000000378114974573,
52  0.00000000000000000000000000000000000000807938276390,
53  0.00000000000000000000000000000000000001538571557634,
54  0.00000000000000000000000000000000000002390366341662,
55  0.00000000000000000000000000000000000001998122009594,
56  -0.00000000000000000000000000000000000005154859771317,
57  -0.00000000000000000000000000000000000036836619651348,
58  -0.00000000000000000000000000000000000144815823076849,
59  -0.00000000000000000000000000000000000466809435124410,
60  -0.00000000000000000000000000000000001345404377599454,
61  -0.00000000000000000000000000000000003571811996841365,
62  -0.00000000000000000000000000000000008840263006378150,
63  -0.00000000000000000000000000000000020390013897460582,
64  -0.00000000000000000000000000000000043258491702052162,
65  -0.00000000000000000000000000000000081813928333606945,
66  -0.00000000000000000000000000000000125802360037397349,
67  -0.00000000000000000000000000000000097392013996427856,
68  0.00000000000000000000000000000000310343399515662577,
69  0.00000000000000000000000000000002096090693898106576,
70  0.00000000000000000000000000000008161370547646904257,
71  0.00000000000000000000000000000026208013237985893230,
72  0.00000000000000000000000000000075497904761522874569,
73  0.00000000000000000000000000000200552613510906557360,
74  0.00000000000000000000000000000495806281727198586581,
75  0.00000000000000000000000000001140718590815672546421,
76  0.00000000000000000000000000002401364569498200704843,
77  0.00000000000000000000000000004469664389717945228994,
78  0.00000000000000000000000000006526293292818941733661,
79  0.00000000000000000000000000003638652304169877089656,
80  -0.00000000000000000000000000023245124533032718927301,
81  -0.00000000000000000000000000134347713820037611194927,
82  -0.00000000000000000000000000501626095714016129678212,
83  -0.00000000000000000000000001573776213033828266323291,
84  -0.00000000000000000000000004442195216883345891619313,
85  -0.00000000000000000000000011527054379050515879210897,
86  -0.00000000000000000000000027651585789925042193637351,
87  -0.00000000000000000000000060818234001986655334512531,
88  -0.00000000000000000000000119393714774714749744598259,
89  -0.00000000000000000000000192556237706594247426270622,
90  -0.00000000000000000000000178227720481147558065092763,
91  0.00000000000000000000000353525901387522897914933885,
92  0.00000000000000000000002805113876116829800957642964,
93  0.00000000000000000000011254938255311482278744615665,
94  0.00000000000000000000036304497767041766747357813052,
95  0.00000000000000000000103436104702915250883910019659,
96  0.00000000000000000000267524730924664163654566364342,
97  0.00000000000000000000631564306363270396795988477970,
98  0.00000000000000000001338962145030640104106535324544,
99  0.00000000000000000002427585673368778749005334317852,
100  0.00000000000000000003189318145266884154091181847472,
101  -0.00000000000000000000065499453929852287262372393989,
102  -0.00000000000000000020338710046932609518034157968140,
103  -0.00000000000000000096729556285631687355836548672392,
104  -0.00000000000000000332109571855156827258667498502495,
105  -0.00000000000000000970372299101872130378039385879080,
106  -0.00000000000000002517585307855559328687441482435557,
107  -0.00000000000000005835112284480790588626620452450246,
108  -0.00000000000000011769890803990919198179373411484463,
109  -0.00000000000000018909604030338461769052297304105525,
110  -0.00000000000000015100623931873917890151767846966796,
111  0.00000000000000048170287264224117961023222597756432,
112  0.00000000000000323552018249589884248739919069028492,
113  0.00000000000001216963623738738987313103853453908867,
114  0.00000000000003678767112229639605527007333020961537,
115  0.00000000000009563078057860509211598401891248035354,
116  0.00000000000021516989147418571051734288101960693095,
117  0.00000000000039889817190574048477382002587654158464,
118  0.00000000000049884936905340431429917164534775057003,
119  -0.00000000000020942526189187935999093602609157489081,
120  -0.00000000000414245225601040749310738837216246902712,
121  -0.00000000001789570445050385428595199452049253983216,
122  -0.00000000005636076493535205012399175709398690525126,
123  -0.00000000014604942156233966023751932855324854251822,
124  -0.00000000031173153837571144581390551106514757301325,
125  -0.00000000049889718998833044350278879090895486903001,
126  -0.00000000028766740658974205165675336395576366238513,
127  0.00000000187736351911293997239389874556302756358761,
128  0.00000001034453300590629226677060283935694062762423,
129  0.00000003464191797877778185037238528956593519581020,
130  0.00000008938858455041137313126358441076058092278345,
131  0.00000017750172930416809520457442368029932211470623,
132  0.00000021575720769800536247432561510334325660664945,
133  -0.00000018660145789013343252785474216809413761097858,
134  -0.00000220418853725361969662010705461874238153541228,
135  -0.00000839635618679585508494344486818405925987462979,
136  -0.00002211977951115900022181076645111375000851694494,
137  -0.00004073642334724901861459783747321239388838876039,
138  -0.00003041590215202065892378772982151957648966345005,
139  0.00013507330564461257800534799144998032716102898121,
140  0.00075690839307595994892019497513047099346294999123,
141  0.00223034394552669087974372530425171134993433952332,
142  0.00411366814645865337685126661426693317480385303497,
143  0.00190727395441143109111603592964456765912473201752,
144  -0.01921304660195650992893234842995298095047473907471,
145  -0.08581277934908473903341530331090325489640235900879,
146  -0.19550984250010230991456694482621969655156135559082,
147  -0.15241962234822362121100525200745323672890663146973,
148  0.73715691704171371068099460899247787892818450927734,
149  3.49009720639244047646343460655771195888519287109375,
150  6.51769703544439504838692300836555659770965576171875,
151  -2.73789230353590840039146314666140824556350708007812,
152  -50.53373978645147701627138303592801094055175781250000,
153  -116.46571370960862168431049212813377380371093750000000,
154  51.46970637069863840906691621057689189910888671875000,
155  871.57435648196644706331426277756690979003906250000000,
156  1168.72820249389701530162710696458816528320312500000000,
157  -4221.10437662656931934179738163948059082031250000000000,
158  -10902.45880786745874502230435609817504882812500000000000,
159  26657.65176031351074925623834133148193359375000000000000,
160  53242.00177372424514032900333404541015625000000000000000,
161  -269330.56008535361615940928459167480468750000000000000000,
162  473564.28085823717992752790451049804687500000000000000000,
163  -487887.17901733302278444170951843261718750000000000000000,
164  329743.00213737942976877093315124511718750000000000000000,
165  -151774.68267442920478060841560363769531250000000000000000,
166  47859.42747184166364604607224464416503906250000000000000,
167  -10165.17644611340620031114667654037475585937500000000000,
168  1388.46553052871922773192636668682098388671875000000000,
169  -109.45988611012040792047628201544284820556640625000000,
170  3.55595509400277709488591426634229719638824462890625,
171  0.53874991700259822202667692181421443819999694824219}};
172 
173  private:
174  Atmosphere atmo_;
175  array<float, 2> y1{{0, 0}};
176  array<float, 2> y2{{0, 0}};
177  array<float, 2> y3{{0, 0}};
178  array<float, 2> y4{{0, 0}};
179  array<float, 2> rk4_kp1{{0, 0}};
180 };
Class definitions for the atmosphere model.
Definition: Atmosphere.h:19
Definition: rk4.h:9
float cd(float alt, float vel)
A function that returns the Coefficient of drag at a given altitude and velocity (based on mach numbe...
Definition: rk4.cpp:30
array< float, 2 > rk4_step(array< float, 2 > state, float dt, float rho)
A function that propagates the rk4 apogee simulation by one time step.
Definition: rk4.cpp:78
array< float, 2 > sim_apogee(array< float, 2 > state, float dt)
A function that returns the simulated apogee of the rocket from state estimates.
Definition: rk4.cpp:109
array< float, 2 > accel(array< float, 2 > u, float rho)
A function that calculates the acceleration of the rocket at a given altitude and velocity given by t...
Definition: rk4.cpp:53