-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyinzer_old.py
110 lines (78 loc) · 2.2 KB
/
yinzer_old.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import time
import math
import board
import busio
import smbus2
import adafruit_bno055
import altimeter
import picamera
from dataclasses import dataclass
RPI_BUS_NUM = 1
MULTIPLEXER_ADDR = 0x70
VID_OUTPUT = 'yinzer.h264'
I2C_CH = [1 << i for i in range(8)]
G_ACC = 9.81
TICKRATE = 10.0
ALTI_OUTPUT = 'yinzer_alti.csv'
IMU_OUTPUT = 'yinzer_imu.csv'
##############################################################
# GLOBAL VARIABLES
##############################################################
bus = smbus2.SMBus(RPI_BUS_NUM)
i2c = busio.I2C(board.SCL, board.SDA)
mux_addrs = {
'imu': 7,
'alti1': 6,
'alti2': 5,
'alti3': 4,
}
camera = picamera.PiCamera()
sensors = None
f_alti = None
f_imu = None
@dataclass
class SensorData:
timestamp: int
pass
alti = CircularBuffer(10.0 * TICKRATE)
##############################################################
# HELPER FUNCTIONS
##############################################################
def magnitude(v):
return math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z)
def get_barometer():
pass
def get_acceleration():
bus.write_byte(MULTIPLEXER_ADDR, I2C_CH[mux_addrs['imu']])
return sensors['imu'].acceleration
def noop():
pass
##############################################################
# HELPER FUNCTIONS
##############################################################
# PRE-LAUNCH
def setup():
bus.write_byte(MULTIPLEXER_ADDR, I2C_CH[mux_addrs['imu']])
sensors['imu'] = adafruit_bno055.BNO055_I2C(i2c)
for x in ['alti1', 'alti2', 'alti3']:
bus.write_byte(MULTIPLEXER_ADDR, I2C_CH[mux_addrs[x]])
sensors[x] = altimeter.Altimeter(i2c)
camera.resolution = (1280, 720)
camera.framerate = 60
camera.start_recording(VID_OUTPUT)
with open(ALTI_OUTPUT, 'w') as f:
f.write('time,altitude,pressure,temp\n')
with open(IMU_OUTPUT, 'w') as f:
f.write('time,ax,ay,az')
f_imu = open(IMU_OUTPUT, 'w')
def has_launched():
acc = get_acceleration()
return magnitude(acc) > 2 * G_ACC
# LIFT-OFF
def setup():
f_alti = open(ALTI_OUTPUT, 'a')
f_imu = open(IMU_OUTPUT, 'a')
def liftoff_loop():
f_alti.write(f'{}')
def has_reached_apogee():
pass