-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcansat.py
74 lines (65 loc) · 1.96 KB
/
cansat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
__author__ = 'prempal'
import serial
import csv
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import math
SERIAL_PORT = '/dev/ttyUSB0'
BAUD_RATE = 9600
FILE_NAME = "CANSAT2015_TLM_<TEAM_ID>.csv"
HEADER_ROW = ['TEAM_ID','MISSION_TIME','ALT_SENSOR','OUTSIDE_TEMP','INSIDE_TEMP',
'VOLTAGE','FSW_STATE','BONUS']
fig = plt.figure()
fig.canvas.set_window_title('REALTIME DATA PLOTTING')
ser = serial.Serial(SERIAL_PORT,BAUD_RATE)
myFile = open(FILE_NAME,'wb')
writer = csv.writer(myFile)
writer.writerow(HEADER_ROW)
i = 0
xar = []
out_temp, in_temp, altitude, acc_x, acc_y, acc_z = [], [], [], [], [], []
def animate(yolo):
global i, xar, out_temp, in_temp, altitude, acc_x, acc_y, acc_z
message = ser.readline()
if len(message)>5:
l = message.split(",")
print l
#remove the newline character from the end
l = l[:-1]
xyz = l[7:]
l = l[:7]
l.append(xyz)
writer.writerow(l)
xar.append(int(i))
altitude.append(float(l[2]))
out_temp.append(float(l[3]))
in_temp.append(float(l[4]))
x = int(xyz[0])
y = int(xyz[0])
z = int(xyz[0])
acc_x.append(x)
acc_y.append(y)
acc_z.append(z)
descent_angle = math.acos(math.sqrt(x*x + y*y + z*z)/math.sqrt(x*x + y*y))
print descent_angle
i = i+1
plt.subplot(3, 2, 1)
plt.plot(xar,out_temp,'yo-')
plt.xlabel('Time(s)')
plt.ylabel('Outside Temperature(deg C)')
plt.subplot(3, 2, 2)
plt.plot(xar,in_temp,'ro-')
plt.xlabel('Time(s)')
plt.ylabel('Inside Temperature(deg C)')
plt.subplot(3, 2, 3)
plt.plot(xar,altitude,'go-')
plt.xlabel('Time(s)')
plt.ylabel('Altitude(m)')
plt.subplot(3, 2, 4)
plt.plot(xar,acc_x,'bo-')
plt.plot(xar,acc_y,'go-')
plt.plot(xar,acc_z,'yo-')
plt.xlabel('Time(s)')
plt.ylabel('Acceleration(m/s^2)')
ani = animation.FuncAnimation(fig, animate, interval=1000)
plt.show()