Browse Source

Monitor system

Petra Lamborn 6 years ago
parent
commit
51e8fc15c4
4 changed files with 72 additions and 12 deletions
  1. 1
    0
      .gitignore
  2. 15
    5
      analysis.rmd
  3. 0
    7
      hover.py
  4. 56
    0
      monitor.py

+ 1
- 0
.gitignore View File

@@ -1,2 +1,3 @@
1 1
 *.swp
2 2
 *.csv
3
+*.html

+ 15
- 5
analysis.rmd View File

@@ -12,9 +12,19 @@ flight <- read.csv("flight.csv", header=T)
12 12
 
13 13
 ```{r graph}
14 14
 baseg <- ggplot(flight, aes(x=timepoint / 10)) + xlab("Time (seconds)") + theme_classic()
15
-alt <- baseg + geom_line(aes(y=current_altitude)) + ylab("Altitude (m)") + title("Altitude"
16
-spd <- baseg + geom_line(aes(y=v_speed)) + ylab("Vertical speed (m/s)") + title("Vertical speed")
17
-mass <- baseg + geom_line(aes(y=mass)) + ylab("Vessel mass (kg)") + title("Mass")
18
-fuel <- baseg + geom_line(aes(y=fuel)) + ylab("Fuel (kg)") + title("Fuel")
19
-minvia <- baseg + geom_line(aes(y=minviable)) + scale_y_continuous(labels=scales::percent) + ylab("Minimum viable thrust percentage") + title("Throttle")
15
+alt <- baseg + geom_line(aes(y=current_altitude)) + ylab("Altitude (m)") + ggtitle("Altitude")
16
+vspd <- baseg + geom_line(aes(y=v_speed)) + ylab("Vertical speed (m/s)") + ggtitle("Vertical speed")
17
+hspd <- baseg + geom_line(aes(y=h_speed)) + ylab("Horizontal speed (m/s)") + ggtitle("Horizontal speed")
18
+mass <- baseg + geom_line(aes(y=mass)) + ylab("Vessel mass (kg)") + ggtitle("Mass")
19
+fuel <- baseg + geom_line(aes(y=fuel)) + ylab("Fuel (kg)") + ggtitle("Fuel")
20
+at <- baseg + geom_line(aes(y=available_thrust)) + ylab("Available thrust (Newtons)") + ggtitle("Available thrust")
21
+```
22
+
23
+```{r drawgraphs, echo=FALSE}
24
+alt 
25
+vspd
26
+hspd
27
+mass
28
+fuel
29
+at
20 30
 ```

+ 0
- 7
hover.py View File

@@ -6,8 +6,6 @@ import krpc
6 6
 # Target altitude in meters
7 7
 target_altitude = 100
8 8
 
9
-datafile = 'flight.csv'
10
-
11 9
 # The IP of the KRPC server (if not same computer)
12 10
 remote = '192.168.1.10'
13 11
 # Make connection
@@ -31,15 +29,11 @@ vessel.auto_pilot.target_pitch_and_heading(90, 90)
31 29
 vessel.auto_pilot.engage()
32 30
 timepoint = 0
33 31
 
34
-f = open(datafile, 'w')
35
-
36
-f.write('timepoint, current_altitude, v_speed, mass, fuel, minviable\n')
37 32
 while at > 0:
38 33
     vm = vessel.mass
39 34
     minviable = (vm * grav) / at
40 35
     current_altitude = vessel.flight(r_frame).surface_altitude
41 36
     v_speed = vessel.flight(r_frame).vertical_speed
42
-    f.write('{0}, {1}, {2}, {3}, {4}, {5}\n'.format(timepoint, current_altitude, v_speed, vm, vm - dry_mass, minviable))
43 37
     if current_altitude > target_altitude:
44 38
         if v_speed < 0:
45 39
             vessel.control.throttle = minviable * 0.6
@@ -55,5 +49,4 @@ while at > 0:
55 49
     at = vessel.available_thrust
56 50
     timepoint = timepoint + 1
57 51
 
58
-f.close()
59 52
 conn.close()

+ 56
- 0
monitor.py View File

@@ -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()