This problem could be solved by manual trying some variants and submitting the answer, i.e. without writing the code. It's OK - we'll have another task for creating automated flight controller!
In the Apogee problem we learnt how the object freely flies around the planet (or any celestial body) in circles, or rather ellipses, which we call its orbit. But we skipped very interesting process - how this object gets to the desired obrit, starting from the planet surface?
Let's try to simulate the flight of the rocket from the ground, controlling it so it reaches certain height and certain speed - we now know the obrit is defined by them - after which the engines are automatically shut and the rocket proceeds its free flight as a satellite. Free flight here means not affected by other forces than gravity.
Input data will give two values - the height of the orbit, in kilometers and the speed required at this height. Moreover the speed should be horizontal (so it is perigee point, where we turn off engines and start free flight).
Answer should contain the sequence of control commands in the simple format described further - this "flight program" should allow to reach the desired height and speed.
Tolerance for height is 20km
, for velocity 200m/s
and for direction error should be less than 1
degree.
The rocket has predetermined mass (272 tons
, with fuel, 10
when empty) and predetermined thrust force
(3 mega-Newtons
). Also the rate of fuel burning is predetermined (800 kg
per second). These values
roughly correspond to the Sputnik Rocket which delivered the
first satellite to the orbit.
We control the flight simply by changing the rocket attitude. For this "vernier thrusters" - small engines on the sides - are engaged to create some turning force. Regretfully it is not possible just to say "rocket, please magically turn to 45 degrees". You'll see this turning force creates rotational acceleration and the rocket changes its direction faster and faster. So you engage vernier thrusters on one side, wait for few seconds, then shut them and engage their counterparts on the other side, wait few seconds more for rotation to stop and then shut these too.
Acceleration of main engines and vernier thrusters is greater when rocket becomes lighter due to more and more fuel burnt out.
Engaging vernier thrusters is done by single value in the range -1 .. +1
. Positive values make rocket start
turning into direction in which we want to flow around the planet. Vernier thrusters do not waste fuel and
the force could be set to any fraction.
Two more control commands are possible:
stage
can be used once, it stops all main engines except the central one, reducing thrust (and
fuel consumption) 4
timesoff
also is used once and stops all engines, ending "controlled" part of the flightIf the off
command is not used, the controlled flight ends either with fuel going to zero (and rocket mass
becoming 10 tons
) - or with "self-destruction" which happens if the attitude gets out of the range
-45 ... 135
degrees, or flight altitude becomes negative.
You won't sit in the rocket yourself, hands on the wheel or something like this (it could be dangerous) -
instead you create a simple sequence of values, which are used by rocket computer. Sequence consists
of pairs, meaning when
and what
to do. "When" is expressed in seconds from start, e.g.
10 1 30 -0.98 50 0 200 stage 210 0.005 700 off
means engage full force on vernier thruster to start turning into direction of the orbit (right) on the
second 10
, then "start stopping" the turning on the second 30
and turn off all vernier engines on
the second 50
. Reduce thrust 4 times at second 200 (as rocket becomes much lighter then and easier to lift
and to turn). Engage turning on second 210
with very small force, so that rocket shall turn gradually
all the remaining time. Shut the engines at second 700
.
We disclose the precise algorithm of how trajectory is calculated in a form of BASIC program. You can not only study it, but you can easily test it with your own flight program!
(UPD here is a Python
version created for you by our colleague Mathias aka "gardengnome")
Copy-paste this into the "solution" area, adjust "flight program" in the first line and click "BASIC" button below. The output will be filled with tabulated data, of which three first columns (Time, X, Y) are used to plot trajectory in on a small "screen" below.
Remember however - for submission only "flight plan" in the "answer" field is important. For solution you can submit whatever you like (perhaps you'll decide to create some optimization search algorithm).
data 10, 1, 30, -0.98, 50, 0, 200, "stage", 210, 0.005, 700, "off" : rem flight program
re = 6371 * 1e3 : g = -9.81 : rem earth size and gravity
m0 = 272 * 1e3 : vm = -800 : fth = 3e6 : rem mass, fuel consumption, F thrust
dt = 1/4
att = 0 : va = 0 : fa = 0 : rem attitude (rad), speed and F turning
pi = atn(1) * 4
x = 0 : y = re : m = m0 : rem current coordinates and mass
vx = 0 : vy = 0 : t = 0 : rem current speed and time
read tc : rem next "control command" time
loop:
r = sqr(x^2 + y^2) : rem linear and turning accelerations
ag = g * (re / r)^2 : ath = fth / m
ax = ag * x/r + ath * sin(att) : ay = ag * y/r + ath * cos(att)
da = 0.001 * (m0 / m) * fa
xn = x + vx * dt : yn = y + vy * dt : rem new values for coordinates
vx = vx + ax * dt : vy = vy + ay * dt : rem new values for speed
attn = att + va * dt : va = va + da * dt : rem new attitude and its change speed
m = m + vm * dt : t = t + dt : rem reduce mass, increment time
x = xn : y = yn : att = attn : rem update coordinates and attitude
hei = sqr(x^2 + y^2) - re : rem current height
if t = int(t) then print t, int(x), int(y), int(hei), att, vx, vy
if att > pi or att < - pi/4 or hei < 0 then print "self-destroyed" : end
if m <= 10e3 then goto shutdown
if t < tc then goto loop : rem is it time to apply next command?
read cmd, tc
if cmd = "stage" then if vm <= -800 then vm = vm / 4 : fth = fth / 4 : print "staged" : goto loop
if cmd = "off" then print "shut off" : goto shutdown
fa = cmd
if fa > 1 then fa = 1
if fa < -1 then fa = -1
print "set Fa="; fa
goto loop
data 10000
shutdown:
at1 = atn(x / y) : rem at1 is attitude of X, Y vector
if vx < vy then at2 = atn(vx / vy) : rem at2 is attitude of Vx, Vy vector
if vx >= vy then at2 = atn(vy / -vx) + pi / 2 : rem we use them to find direction error
err = at1 + pi/2 - at2
print "H:", int(hei), "V:", int(sqr(vx^2 + vy^2)), "direction error:", err * 180/pi, "degrees"
This small display shows how your flight goes, according to the data in the "answer" box. Rocket starts in the bottom left corner, from the earth surface (green line) and should reach the expected height (blue line). Trajectory itself is marked with red and pink (in 15-second segments). Remember however it is necessary to "enter" the orbit with proper velocity and direction!