|
@@ -0,0 +1,56 @@
|
|
1
|
+#! /bin/python3
|
|
2
|
+
|
|
3
|
+# Modified from the script at
|
|
4
|
+# http://krpc.github.io/krpc/tutorials/user-interface.html
|
|
5
|
+
|
|
6
|
+datafile = 'flight.csv'
|
|
7
|
+remote = '192.168.1.10'
|
|
8
|
+
|
|
9
|
+import time
|
|
10
|
+import krpc
|
|
11
|
+
|
|
12
|
+conn = krpc.connect(name='Flight monitor', address=remote)
|
|
13
|
+canvas = conn.ui.stock_canvas
|
|
14
|
+
|
|
15
|
+# Get the size of the game window in pixels
|
|
16
|
+screen_size = canvas.rect_transform.size
|
|
17
|
+
|
|
18
|
+# Add a panel to contain the UI elements
|
|
19
|
+panel = canvas.add_panel()
|
|
20
|
+
|
|
21
|
+# Position the panel on the left of the screen
|
|
22
|
+rect = panel.rect_transform
|
|
23
|
+rect.size = (200, 50)
|
|
24
|
+rect.position = (110-(screen_size[0]/2), screen_size[1]/2-75)
|
|
25
|
+
|
|
26
|
+# Add a button to set the throttle to maximum
|
|
27
|
+button = panel.add_button("Stop monitor")
|
|
28
|
+button.rect_transform.position = (0, 0)
|
|
29
|
+
|
|
30
|
+# Set up a stream to monitor the throttle button
|
|
31
|
+button_clicked = conn.add_stream(getattr, button, 'clicked')
|
|
32
|
+f = open(datafile, 'w')
|
|
33
|
+f.write('timepoint, current_altitude, v_speed, h_speed, mass, fuel, available_thrust\n')
|
|
34
|
+timepoint = 0
|
|
35
|
+
|
|
36
|
+vessel = conn.space_center.active_vessel
|
|
37
|
+body = vessel.orbit.body
|
|
38
|
+r_frame = body.reference_frame
|
|
39
|
+
|
|
40
|
+while button_clicked() == False:
|
|
41
|
+ dry_mass = vessel.dry_mass
|
|
42
|
+ vm = vessel.mass
|
|
43
|
+ at = vessel.available_thrust
|
|
44
|
+ current_altitude = vessel.flight(r_frame).surface_altitude
|
|
45
|
+ v_speed = vessel.flight(r_frame).vertical_speed
|
|
46
|
+ h_speed = vessel.flight(r_frame).horizontal_speed
|
|
47
|
+ f.write('{0}, {1}, {2}, {3}, {4}, {5}, {6}\n'.format(timepoint,
|
|
48
|
+ current_altitude,
|
|
49
|
+ v_speed, h_speed, vm, vm - dry_mass, at))
|
|
50
|
+ timepoint = timepoint + 1
|
|
51
|
+ time.sleep(0.1)
|
|
52
|
+
|
|
53
|
+f.close()
|
|
54
|
+button.remove()
|
|
55
|
+panel.remove()
|
|
56
|
+conn.close()
|