Launch into Orbit¶
This tutorial launches a two-stage rocket into a 150km circular orbit. The
program assumes you are using this craft file
.
The program is available in a variety of languages:
The following code connects to the server, gets the active vessel, sets up a bunch of streams to get flight telemetry then prepares the rocket for launch.
1using System;
2using System.Collections.Generic;
3using System.Net;
4using KRPC.Client;
5using KRPC.Client.Services.SpaceCenter;
6
7class LaunchIntoOrbit
8{
9 public static void Main ()
10 {
11 var conn = new Connection ("Launch into orbit");
12 var vessel = conn.SpaceCenter ().ActiveVessel;
13
14 float turnStartAltitude = 250;
15 float turnEndAltitude = 45000;
16 float targetAltitude = 150000;
17
18 // Set up streams for telemetry
19 var ut = conn.AddStream (() => conn.SpaceCenter ().UT);
20 var flight = vessel.Flight ();
21 var altitude = conn.AddStream (() => flight.MeanAltitude);
22 var apoapsis = conn.AddStream (() => vessel.Orbit.ApoapsisAltitude);
23 var stage2Resources =
24 vessel.ResourcesInDecoupleStage (stage: 2, cumulative: false);
25 var srbFuel = conn.AddStream(() => stage2Resources.Amount("SolidFuel"));
26
27 // Pre-launch setup
28 vessel.Control.SAS = false;
29 vessel.Control.RCS = false;
30 vessel.Control.Throttle = 1;
31
32 // Countdown...
33 Console.WriteLine ("3...");
34 System.Threading.Thread.Sleep (1000);
35 Console.WriteLine ("2...");
36 System.Threading.Thread.Sleep (1000);
37 Console.WriteLine ("1...");
38 System.Threading.Thread.Sleep (1000);
39 Console.WriteLine ("Launch!");
1#include <iostream>
2#include <chrono>
3#include <cmath>
4#include <thread>
5#include <krpc.hpp>
6#include <krpc/services/space_center.hpp>
7
8int main() {
9 krpc::Client conn = krpc::connect("Launch into orbit");
10 krpc::services::SpaceCenter space_center(&conn);
11 auto vessel = space_center.active_vessel();
12
13 float turn_start_altitude = 250;
14 float turn_end_altitude = 45000;
15 float target_altitude = 150000;
16
17 // Set up streams for telemetry
18 auto ut = space_center.ut_stream();
19 auto altitude = vessel.flight().mean_altitude_stream();
20 auto apoapsis = vessel.orbit().apoapsis_altitude_stream();
21 auto stage_2_resources = vessel.resources_in_decouple_stage(2, false);
22 auto srb_fuel = stage_2_resources.amount_stream("SolidFuel");
23
24 // Pre-launch setup
25 vessel.control().set_sas(false);
26 vessel.control().set_rcs(false);
27 vessel.control().set_throttle(1);
28
29 // Countdown...
30 std::cout << "3..." << std::endl;
31 std::this_thread::sleep_for(std::chrono::seconds(1));
32 std::cout << "2..." << std::endl;
33 std::this_thread::sleep_for(std::chrono::seconds(1));
34 std::cout << "1..." << std::endl;
35 std::this_thread::sleep_for(std::chrono::seconds(1));
1import krpc.client.Connection;
2import krpc.client.RPCException;
3import krpc.client.Stream;
4import krpc.client.StreamException;
5import krpc.client.services.SpaceCenter;
6import krpc.client.services.SpaceCenter.Flight;
7import krpc.client.services.SpaceCenter.Node;
8import krpc.client.services.SpaceCenter.ReferenceFrame;
9import krpc.client.services.SpaceCenter.Resources;
10
11import org.javatuples.Triplet;
12
13import java.io.IOException;
14import java.lang.Math;
15
16public class LaunchIntoOrbit {
17 public static void main(String[] args)
18 throws IOException, RPCException, InterruptedException, StreamException {
19 Connection connection = Connection.newInstance("Launch into orbit");
20 SpaceCenter spaceCenter = SpaceCenter.newInstance(connection);
21 SpaceCenter.Vessel vessel = spaceCenter.getActiveVessel();
22
23 float turnStartAltitude = 250;
24 float turnEndAltitude = 45000;
25 float targetAltitude = 150000;
26
27 // Set up streams for telemetry
28 spaceCenter.getUT();
29 Stream<Double> ut = connection.addStream(SpaceCenter.class, "getUT");
30 ReferenceFrame refFrame = vessel.getSurfaceReferenceFrame();
31 Flight flight = vessel.flight(refFrame);
32 Stream<Double> altitude = connection.addStream(flight, "getMeanAltitude");
33 Stream<Double> apoapsis =
34 connection.addStream(vessel.getOrbit(), "getApoapsisAltitude");
35 Resources stage2Resources = vessel.resourcesInDecoupleStage(2, false);
36 Stream<Float> srbFuel =
37 connection.addStream(stage2Resources, "amount", "SolidFuel");
38
39 // Pre-launch setup
40 vessel.getControl().setSAS(false);
41 vessel.getControl().setRCS(false);
42 vessel.getControl().setThrottle(1);
43
44 // Countdown...
45 System.out.println("3...");
46 Thread.sleep(1000);
47 System.out.println("2...");
48 Thread.sleep(1000);
49 System.out.println("1...");
50 Thread.sleep(1000);
1local krpc = require 'krpc'
2local platform = require 'krpc.platform'
3local math = require 'math'
4local List = require 'pl.List'
5
6local turn_start_altitude = 250
7local turn_end_altitude = 45000
8local target_altitude = 150000
9
10local conn = krpc.connect('Launch into orbit')
11local vessel = conn.space_center.active_vessel
12
13flight = vessel:flight()
14stage_2_resources = vessel:resources_in_decouple_stage(2, False)
15
16-- Pre-launch setup
17vessel.control.sas = false
18vessel.control.rcs = false
19vessel.control.throttle = 1
20
21-- Countdown...
22print('3...')
23platform.sleep(1)
24print('2...')
25platform.sleep(1)
26print('1...')
27platform.sleep(1)
28print('Launch!')
1import math
2import time
3import krpc
4
5turn_start_altitude = 250
6turn_end_altitude = 45000
7target_altitude = 150000
8
9conn = krpc.connect(name='Launch into orbit')
10vessel = conn.space_center.active_vessel
11
12# Set up streams for telemetry
13ut = conn.add_stream(getattr, conn.space_center, 'ut')
14altitude = conn.add_stream(getattr, vessel.flight(), 'mean_altitude')
15apoapsis = conn.add_stream(getattr, vessel.orbit, 'apoapsis_altitude')
16stage_2_resources = vessel.resources_in_decouple_stage(stage=2, cumulative=False)
17srb_fuel = conn.add_stream(stage_2_resources.amount, 'SolidFuel')
18
19# Pre-launch setup
20vessel.control.sas = False
21vessel.control.rcs = False
22vessel.control.throttle = 1.0
23
24# Countdown...
25print('3...')
26time.sleep(1)
27print('2...')
28time.sleep(1)
29print('1...')
30time.sleep(1)
31print('Launch!')
The next part of the program launches the rocket. The main loop continuously updates the auto-pilot heading to gradually pitch the rocket towards the horizon. It also monitors the amount of solid fuel remaining in the boosters, separating them when they run dry. The loop exits when the rockets apoapsis is close to the target apoapsis.
41 // Activate the first stage
42 vessel.Control.ActivateNextStage ();
43 vessel.AutoPilot.Engage ();
44 vessel.AutoPilot.TargetPitchAndHeading (90, 90);
45
46 // Main ascent loop
47 bool srbsSeparated = false;
48 double turnAngle = 0;
49 while (true) {
50
51 // Gravity turn
52 if (altitude.Get () > turnStartAltitude &&
53 altitude.Get () < turnEndAltitude) {
54 double frac = (altitude.Get () - turnStartAltitude)
55 / (turnEndAltitude - turnStartAltitude);
56 double newTurnAngle = frac * 90.0;
57 if (Math.Abs (newTurnAngle - turnAngle) > 0.5) {
58 turnAngle = newTurnAngle;
59 vessel.AutoPilot.TargetPitchAndHeading (
60 (float)(90 - turnAngle), 90);
61 }
62 }
63
64 // Separate SRBs when finished
65 if (!srbsSeparated) {
66 if (srbFuel.Get () < 0.1) {
67 vessel.Control.ActivateNextStage ();
68 srbsSeparated = true;
69 Console.WriteLine ("SRBs separated");
70 }
71 }
72
73 // Decrease throttle when approaching target apoapsis
74 if (apoapsis.Get () > targetAltitude * 0.9) {
75 Console.WriteLine ("Approaching target apoapsis");
76 break;
77 }
78 }
37 // Activate the first stage
38 vessel.control().activate_next_stage();
39 vessel.auto_pilot().engage();
40 vessel.auto_pilot().target_pitch_and_heading(90, 90);
41
42 // Main ascent loop
43 bool srbs_separated = false;
44 double turn_angle = 0;
45 while (true) {
46 // Gravity turn
47 if (altitude() > turn_start_altitude && altitude() < turn_end_altitude) {
48 double frac = (altitude() - turn_start_altitude)
49 / (turn_end_altitude - turn_start_altitude);
50 double new_turn_angle = frac * 90.0;
51 if (std::abs(new_turn_angle - turn_angle) > 0.5) {
52 turn_angle = new_turn_angle;
53 vessel.auto_pilot().target_pitch_and_heading(90.0 - turn_angle, 90.0);
54 }
55 }
56
57 // Separate SRBs when finished
58 if (!srbs_separated) {
59 if (srb_fuel() < 0.1) {
60 vessel.control().activate_next_stage();
61 srbs_separated = true;
62 std::cout << "SRBs separated" << std::endl;
63 }
64 }
65
66 // Decrease throttle when approaching target apoapsis
67 if (apoapsis() > target_altitude * 0.9) {
68 std::cout << "Approaching target apoapsis" << std::endl;
69 break;
70 }
52 // Activate the first stage
53 vessel.getControl().activateNextStage();
54 vessel.getAutoPilot().engage();
55 vessel.getAutoPilot().targetPitchAndHeading(90, 90);
56
57 // Main ascent loop
58 boolean srbsSeparated = false;
59 double turnAngle = 0;
60 while (true) {
61
62 // Gravity turn
63 if (altitude.get() > turnStartAltitude &&
64 altitude.get() < turnEndAltitude) {
65 double frac = (altitude.get() - turnStartAltitude)
66 / (turnEndAltitude - turnStartAltitude);
67 double newTurnAngle = frac * 90.0;
68 if (Math.abs(newTurnAngle - turnAngle) > 0.5) {
69 turnAngle = newTurnAngle;
70 vessel.getAutoPilot().targetPitchAndHeading(
71 (float)(90 - turnAngle), 90);
72 }
73 }
74
75 // Separate SRBs when finished
76 if (!srbsSeparated) {
77 if (srbFuel.get() < 0.1) {
78 vessel.getControl().activateNextStage();
79 srbsSeparated = true;
80 System.out.println("SRBs separated");
81 }
82 }
83
84 // Decrease throttle when approaching target apoapsis
85 if (apoapsis.get() > targetAltitude * 0.9) {
86 System.out.println("Approaching target apoapsis");
87 break;
88 }
30-- Activate the first stage
31vessel.control:activate_next_stage()
32vessel.auto_pilot:engage()
33vessel.auto_pilot:target_pitch_and_heading(90, 90)
34
35-- Main ascent loop
36local srbs_separated = false
37local turn_angle = 0
38while true do
39
40 -- Gravity turn
41 if flight.mean_altitude > turn_start_altitude and flight.mean_altitude < turn_end_altitude then
42 frac = (flight.mean_altitude - turn_start_altitude) / (turn_end_altitude - turn_start_altitude)
43 new_turn_angle = frac * 90
44 if math.abs(new_turn_angle - turn_angle) > 0.5 then
45 turn_angle = new_turn_angle
46 vessel.auto_pilot:target_pitch_and_heading(90-turn_angle, 90)
47 end
48 end
49
50 -- Separate SRBs when finished
51 if not srbs_separated then
52 if stage_2_resources:amount('SolidFuel') < 0.1 then
53 vessel.control:activate_next_stage()
54 srbs_separated = true
55 print('SRBs separated')
56 end
57 end
58
59 -- Decrease throttle when approaching target apoapsis
60 if vessel.orbit.apoapsis_altitude > target_altitude*0.9 then
61 print('Approaching target apoapsis')
62 break
63 end
64end
33# Activate the first stage
34vessel.control.activate_next_stage()
35vessel.auto_pilot.engage()
36vessel.auto_pilot.target_pitch_and_heading(90, 90)
37
38# Main ascent loop
39srbs_separated = False
40turn_angle = 0
41while True:
42
43 # Gravity turn
44 if altitude() > turn_start_altitude and altitude() < turn_end_altitude:
45 frac = ((altitude() - turn_start_altitude) /
46 (turn_end_altitude - turn_start_altitude))
47 new_turn_angle = frac * 90
48 if abs(new_turn_angle - turn_angle) > 0.5:
49 turn_angle = new_turn_angle
50 vessel.auto_pilot.target_pitch_and_heading(90-turn_angle, 90)
51
52 # Separate SRBs when finished
53 if not srbs_separated:
54 if srb_fuel() < 0.1:
55 vessel.control.activate_next_stage()
56 srbs_separated = True
57 print('SRBs separated')
58
59 # Decrease throttle when approaching target apoapsis
60 if apoapsis() > target_altitude*0.9:
61 print('Approaching target apoapsis')
62 break
Next, the program fine tunes the apoapsis, using 10% thrust, then waits until the rocket has left Kerbin’s atmosphere.
80 // Disable engines when target apoapsis is reached
81 vessel.Control.Throttle = 0.25f;
82 while (apoapsis.Get () < targetAltitude) {
83 }
84 Console.WriteLine ("Target apoapsis reached");
85 vessel.Control.Throttle = 0;
86
87 // Wait until out of atmosphere
88 Console.WriteLine ("Coasting out of atmosphere");
89 while (altitude.Get () < 70500) {
90 }
73 // Disable engines when target apoapsis is reached
74 vessel.control().set_throttle(0.25);
75 while (apoapsis() < target_altitude) {
76 }
77 std::cout << "Target apoapsis reached" << std::endl;
78 vessel.control().set_throttle(0);
79
80 // Wait until out of atmosphere
81 std::cout << "Coasting out of atmosphere" << std::endl;
82 while (altitude() < 70500) {
91 // Disable engines when target apoapsis is reached
92 vessel.getControl().setThrottle(0.25f);
93 while (apoapsis.get() < targetAltitude) {
94 }
95 System.out.println("Target apoapsis reached");
96 vessel.getControl().setThrottle(0);
97
98 // Wait until out of atmosphere
99 System.out.println("Coasting out of atmosphere");
100 while (altitude.get() < 70500) {
66-- Disable engines when target apoapsis is reached
67vessel.control.throttle = 0.25
68while vessel.orbit.apoapsis_altitude < target_altitude do
69end
70print('Target apoapsis reached')
71vessel.control.throttle = 0
72
73-- Wait until out of atmosphere
74print('Coasting out of atmosphere')
75while flight.mean_altitude < 70500 do
76end
64# Disable engines when target apoapsis is reached
65vessel.control.throttle = 0.25
66while apoapsis() < target_altitude:
67 pass
68print('Target apoapsis reached')
69vessel.control.throttle = 0.0
70
71# Wait until out of atmosphere
72print('Coasting out of atmosphere')
73while altitude() < 70500:
74 pass
It is now time to plan the circularization burn. First, we calculate the delta-v required to circularize the orbit using the vis-viva equation. We then calculate the burn time needed to achieve this delta-v, using the Tsiolkovsky rocket equation.
92 // Plan circularization burn (using vis-viva equation)
93 Console.WriteLine ("Planning circularization burn");
94 double mu = vessel.Orbit.Body.GravitationalParameter;
95 double r = vessel.Orbit.Apoapsis;
96 double a1 = vessel.Orbit.SemiMajorAxis;
97 double a2 = r;
98 double v1 = Math.Sqrt (mu * ((2.0 / r) - (1.0 / a1)));
99 double v2 = Math.Sqrt (mu * ((2.0 / r) - (1.0 / a2)));
100 double deltaV = v2 - v1;
101 var node = vessel.Control.AddNode (
102 ut.Get () + vessel.Orbit.TimeToApoapsis, prograde: (float)deltaV);
103
104 // Calculate burn time (using rocket equation)
105 double F = vessel.AvailableThrust;
106 double Isp = vessel.SpecificImpulse * 9.82;
107 double m0 = vessel.Mass;
108 double m1 = m0 / Math.Exp (deltaV / Isp);
109 double flowRate = F / Isp;
110 double burnTime = (m0 - m1) / flowRate;
85 // Plan circularization burn (using vis-viva equation)
86 std::cout << "Planning circularization burn" << std::endl;
87 double mu = vessel.orbit().body().gravitational_parameter();
88 double r = vessel.orbit().apoapsis();
89 double a1 = vessel.orbit().semi_major_axis();
90 double a2 = r;
91 double v1 = std::sqrt(mu * ((2.0 / r) - (1.0 / a1)));
92 double v2 = std::sqrt(mu * ((2.0 / r) - (1.0 / a2)));
93 double delta_v = v2 - v1;
94 auto node = vessel.control().add_node(
95 ut() + vessel.orbit().time_to_apoapsis(), delta_v);
96
97 // Calculate burn time (using rocket equation)
98 double F = vessel.available_thrust();
99 double Isp = vessel.specific_impulse() * 9.82;
100 double m0 = vessel.mass();
101 double m1 = m0 / std::exp(delta_v / Isp);
102 double flow_rate = F / Isp;
103 // Plan circularization burn (using vis-viva equation)
104 System.out.println("Planning circularization burn");
105 double mu = vessel.getOrbit().getBody().getGravitationalParameter();
106 double r = vessel.getOrbit().getApoapsis();
107 double a1 = vessel.getOrbit().getSemiMajorAxis();
108 double a2 = r;
109 double v1 = Math.sqrt(mu * ((2.0 / r) - (1.0 / a1)));
110 double v2 = Math.sqrt(mu * ((2.0 / r) - (1.0 / a2)));
111 double deltaV = v2 - v1;
112 Node node = vessel.getControl().addNode(
113 ut.get() + vessel.getOrbit().getTimeToApoapsis(), (float)deltaV, 0, 0);
114
115 // Calculate burn time (using rocket equation)
116 double force = vessel.getAvailableThrust();
117 double isp = vessel.getSpecificImpulse() * 9.82;
118 double m0 = vessel.getMass();
119 double m1 = m0 / Math.exp(deltaV / isp);
120 double flowRate = force / isp;
78---- Plan circularization burn (using vis-viva equation)
79print('Planning circularization burn')
80local mu = vessel.orbit.body.gravitational_parameter
81local r = vessel.orbit.apoapsis
82local a1 = vessel.orbit.semi_major_axis
83local a2 = r
84local v1 = math.sqrt(mu*((2./r)-(1./a1)))
85local v2 = math.sqrt(mu*((2./r)-(1./a2)))
86local delta_v = v2 - v1
87local node = vessel.control:add_node(conn.space_center.ut + vessel.orbit.time_to_apoapsis, delta_v, 0, 0)
88
89---- Calculate burn time (using rocket equation)
90local F = vessel.available_thrust
91local Isp = vessel.specific_impulse * 9.82
92local m0 = vessel.mass
93local m1 = m0 / math.exp(delta_v/Isp)
94local flow_rate = F / Isp
95local burn_time = (m0 - m1) / flow_rate
76# Plan circularization burn (using vis-viva equation)
77print('Planning circularization burn')
78mu = vessel.orbit.body.gravitational_parameter
79r = vessel.orbit.apoapsis
80a1 = vessel.orbit.semi_major_axis
81a2 = r
82v1 = math.sqrt(mu*((2./r)-(1./a1)))
83v2 = math.sqrt(mu*((2./r)-(1./a2)))
84delta_v = v2 - v1
85node = vessel.control.add_node(
86 ut() + vessel.orbit.time_to_apoapsis, prograde=delta_v)
87
88# Calculate burn time (using rocket equation)
89F = vessel.available_thrust
90Isp = vessel.specific_impulse * 9.82
91m0 = vessel.mass
92m1 = m0 / math.exp(delta_v/Isp)
93flow_rate = F / Isp
94burn_time = (m0 - m1) / flow_rate
Next, we need to rotate the craft and wait until the circularization burn. We orientate the ship along the y-axis of the maneuver node’s reference frame (i.e. in the direction of the burn) then time warp to 5 seconds before the burn.
112 // Orientate ship
113 Console.WriteLine ("Orientating ship for circularization burn");
114 vessel.AutoPilot.ReferenceFrame = node.ReferenceFrame;
115 vessel.AutoPilot.TargetDirection = Tuple.Create (0.0, 1.0, 0.0);
116 vessel.AutoPilot.Wait ();
117
118 // Wait until burn
119 Console.WriteLine ("Waiting until circularization burn");
120 double burnUT = ut.Get () + vessel.Orbit.TimeToApoapsis - (burnTime / 2.0);
121 double leadTime = 5;
122 conn.SpaceCenter ().WarpTo (burnUT - leadTime);
105 // Orientate ship
106 std::cout << "Orientating ship for circularization burn" << std::endl;
107 vessel.auto_pilot().set_reference_frame(node.reference_frame());
108 vessel.auto_pilot().set_target_direction(std::make_tuple(0.0, 1.0, 0.0));
109 vessel.auto_pilot().wait();
110
111 // Wait until burn
112 std::cout << "Waiting until circularization burn" << std::endl;
113 double burn_ut = ut() + vessel.orbit().time_to_apoapsis() - (burn_time / 2.0);
114 double lead_time = 5;
123 // Orientate ship
124 System.out.println("Orientating ship for circularization burn");
125 vessel.getAutoPilot().setReferenceFrame(node.getReferenceFrame());
126 vessel.getAutoPilot().setTargetDirection(
127 new Triplet<Double,Double,Double>(0.0, 1.0, 0.0));
128 vessel.getAutoPilot().wait_();
129
130 // Wait until burn
131 System.out.println("Waiting until circularization burn");
132 double burnUt =
133 ut.get() + vessel.getOrbit().getTimeToApoapsis() - (burnTime / 2.0);
134 double leadTime = 5;
97-- Orientate ship
98print('Orientating ship for circularization burn')
99vessel.auto_pilot.reference_frame = node.reference_frame
100vessel.auto_pilot.target_direction = List{0, 1, 0}
101vessel.auto_pilot:wait()
102
103-- Wait until burn
104print('Waiting until circularization burn')
105local burn_ut = conn.space_center.ut + vessel.orbit.time_to_apoapsis - (burn_time/2.)
106local lead_time = 5
107conn.space_center.warp_to(burn_ut - lead_time)
96# Orientate ship
97print('Orientating ship for circularization burn')
98vessel.auto_pilot.reference_frame = node.reference_frame
99vessel.auto_pilot.target_direction = (0, 1, 0)
100vessel.auto_pilot.wait()
101
102# Wait until burn
103print('Waiting until circularization burn')
104burn_ut = ut() + vessel.orbit.time_to_apoapsis - (burn_time/2.)
105lead_time = 5
106conn.space_center.warp_to(burn_ut - lead_time)
This next part executes the burn. It sets maximum throttle, then throttles down to 5% approximately a tenth of a second before the predicted end of the burn. It then monitors the remaining delta-v until it flips around to point retrograde (at which point the node has been executed).
124 // Execute burn
125 Console.WriteLine ("Ready to execute burn");
126 var timeToApoapsis = conn.AddStream (() => vessel.Orbit.TimeToApoapsis);
127 while (timeToApoapsis.Get () - (burnTime / 2.0) > 0) {
128 }
129 Console.WriteLine ("Executing burn");
130 vessel.Control.Throttle = 1;
131 System.Threading.Thread.Sleep ((int)((burnTime - 0.1) * 1000));
132 Console.WriteLine ("Fine tuning");
133 vessel.Control.Throttle = 0.05f;
134 var remainingBurn = conn.AddStream (
135 () => node.RemainingBurnVector (node.ReferenceFrame));
136 while (remainingBurn.Get ().Item1 > 0) {
137 }
138 vessel.Control.Throttle = 0;
139 node.Remove ();
140
141 Console.WriteLine ("Launch complete");
142 conn.Dispose();
143 }
144}
115 // Execute burn
116 std::cout << "Ready to execute burn" << std::endl;
117 auto time_to_apoapsis = vessel.orbit().time_to_apoapsis_stream();
118 while (time_to_apoapsis() - (burn_time / 2.0) > 0) {
119 }
120 std::cout << "Executing burn" << std::endl;
121 vessel.control().set_throttle(1);
122 std::this_thread::sleep_for(
123 std::chrono::milliseconds(static_cast<int>((burn_time - 0.1) * 1000)));
124 std::cout << "Fine tuning" << std::endl;
125 vessel.control().set_throttle(0.05);
126 auto remaining_burn = node.remaining_burn_vector_stream(node.reference_frame());
127 while (std::get<0>(remaining_burn()) > 0) {
128 }
129 vessel.control().set_throttle(0);
130 node.remove();
131
132 std::cout << "Launch complete" << std::endl;
133}
137 // Execute burn
138 System.out.println("Ready to execute burn");
139 Stream<Double> timeToApoapsis =
140 connection.addStream(vessel.getOrbit(), "getTimeToApoapsis");
141 while (timeToApoapsis.get() - (burnTime / 2.0) > 0) {
142 }
143 System.out.println("Executing burn");
144 vessel.getControl().setThrottle(1);
145 Thread.sleep((int)((burnTime - 0.1) * 1000));
146 System.out.println("Fine tuning");
147 vessel.getControl().setThrottle(0.05f);
148 Stream<Triplet<Double,Double,Double>> remainingBurn =
149 connection.addStream(
150 node, "remainingBurnVector", node.getReferenceFrame());
151 while (remainingBurn.get().getValue1() > 0) {
152 }
153 vessel.getControl().setThrottle(0);
154 node.remove();
155
156 System.out.println("Launch complete");
157 connection.close();
158 }
159}
109-- Execute burn
110print('Ready to execute burn')
111while vessel.orbit.time_to_apoapsis - (burn_time/2.) > 0 do
112end
113print('Executing burn')
114vessel.control.throttle = 1
115platform.sleep(burn_time - 0.1)
116print('Fine tuning')
117vessel.control.throttle = 0.05
118while node:remaining_burn_vector(node.reference_frame)[2] > 0 do
119end
120vessel.control.throttle = 0
121node:remove()
122
123print('Launch complete')
108# Execute burn
109print('Ready to execute burn')
110time_to_apoapsis = conn.add_stream(getattr, vessel.orbit, 'time_to_apoapsis')
111while time_to_apoapsis() - (burn_time/2.) > 0:
112 pass
113print('Executing burn')
114vessel.control.throttle = 1.0
115time.sleep(burn_time - 0.1)
116print('Fine tuning')
117vessel.control.throttle = 0.05
118remaining_burn = conn.add_stream(node.remaining_burn_vector, node.reference_frame)
119while remaining_burn()[1] > 0:
120 pass
121vessel.control.throttle = 0.0
122node.remove()
123
124print('Launch complete')
The rocket should now be in a circular 150km orbit above Kerbin.