-
Notifications
You must be signed in to change notification settings - Fork 2
/
payload.py
157 lines (141 loc) · 6.01 KB
/
payload.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
'''
payload.py
This file contains all software to handle whatever payload the intended satellite contains
Yearling-2 contains simply a bno085 9 DOF sensor that is being implemented in this software
Author: Nicole Maggard
'''
import time
import board
import busio
import traceback
from debugcolor import co
from adafruit_bno08x.i2c import BNO08X_I2C
import adafruit_mcp9600 #Thermocouple
class PAYLOAD:
def debug_print(self,statement):
if self.debug:
print(co("[Payload]" + statement, 'gray', 'bold'))
def Enable(self, data):
self.debug_print("Enabling the following: " + str(data))
if "acceleration" in data:
from adafruit_bno08x import BNO_REPORT_ACCELEROMETER
self.bno.enable_feature(BNO_REPORT_ACCELEROMETER)
self.acceleration=(0,0,0)
if "gyroscope" in data:
from adafruit_bno08x import BNO_REPORT_GYROSCOPE
self.bno.enable_feature(BNO_REPORT_GYROSCOPE)
self.gyroscope=(0,0,0)
if "magnetometer" in data:
from adafruit_bno08x import BNO_REPORT_MAGNETOMETER
self.bno.enable_feature(BNO_REPORT_MAGNETOMETER)
self.magnetometer=(0,0,0)
if "linear acceleration" in data:
from adafruit_bno08x import BNO_REPORT_LINEAR_ACCELERATION
self.bno.enable_feature(BNO_REPORT_LINEAR_ACCELERATION)
self.linear_acceleration=(0,0,0)
if "rotation vector" in data:
from adafruit_bno08x import BNO_REPORT_ROTATION_VECTOR
self.bno.enable_feature(BNO_REPORT_ROTATION_VECTOR)
self.rotation=(0,0,0)
if "geomagnetic rotation vector" in data:
from adafruit_bno08x import BNO_REPORT_GEOMAGNETIC_ROTATION_VECTOR
self.bno.enable_feature(BNO_REPORT_GEOMAGNETIC_ROTATION_VECTOR)
self.geomagnetic_rotation=(0,0,0)
if "game rotation vector" in data:
from adafruit_bno08x import BNO_REPORT_GAME_ROTATION_VECTOR
self.bno.enable_feature(BNO_REPORT_GAME_ROTATION_VECTOR)
self.game_rotation=(0,0,0)
if "raw acceleration" in data:
from adafruit_bno08x import BNO_REPORT_RAW_ACCELEROMETER
self.bno.enable_feature(BNO_REPORT_RAW_ACCELEROMETER)
self.raw_acceleration=(0,0,0)
if "raw gyroscope" in data:
from adafruit_bno08x import BNO_REPORT_RAW_GYROSCOPE
self.bno.enable_feature(BNO_REPORT_RAW_GYROSCOPE)
self.raw_gyroscope=(0,0,0)
if "raw magnetometer" in data:
from adafruit_bno08x import BNO_REPORT_RAW_MAGNETOMETER
self.bno.enable_feature(BNO_REPORT_RAW_MAGNETOMETER)
self.raw_magnetometer=(0,0,0)
def __init__(self, debug, i2c, data=[]):
self.debug=debug
self.data=data
self.debug_print("Initializing BNO08x...")
try:
self.bno = BNO08X_I2C(i2c)
self.debug_print("Initialization of BNO complete without error!")
except Exception as e:
self.debug_print("ERROR Initializing BNO sensor: " + ''.join(traceback.format_exception(e)))
try:
self.mcp = adafruit_mcp9600.MCP9600(i2c)
self.debug_print("Initialization of MCP complete without error!")
except Exception as e:
self.debug_print("ERROR Initializing MCP sensor: " + ''.join(traceback.format_exception(e)))
def reinit(self,data=[]):
try:
self.debug_print("Reinitializing BNO08x...")
self.Enable(self.data)
self.debug("Reinitialization of BNO complete without error!")
except Exception as e:
self.debug_print("ERROR Initializing BNO sensor: " + ''.join(traceback.format_exception(e)))
@property
def Data(self):
return self.data
def UpdateData(self, data, option="append"):
if option == "replace":
self.data=data
if option == "append":
self.data.append(data)
else:
raise TypeError("Incorrect option argument input. Please use either \"append\" or \"replace\"")
self.reinit()
@property
def Acceleration(self):
if "acceleration" in self. data:
self.acceleration=self.bno.acceleration
return self.acceleration
@property
def Gyroscope(self):
if "gyroscope" in self. data:
self.gyroscope=self.bno.gyro
return self.gyroscope
@property
def Magnetometer(self):
if "magnetometer" in self. data:
self.magnetometer=self.bno.magnetic
return self.magnetometer
@property
def Linear_Acceleration(self):
if "linear acceleration" in self. data:
self.linear_acceleration=self.bno.linear_acceleration
return self.linear_acceleration
@property
def Rotation(self):
if "rotation vector" in self. data:
self.rotation=self.bno.quaternion
return self.rotation
@property
def Geomagnetic_Rotation(self):
if "geomagnetic rotation vector" in self. data:
self.geomagnetic_rotation=self.bno.geomagnetic_quaternion
return self.geomagnetic_rotation
@property
def Game_Rotation(self):
if "game rotation vector" in self. data:
self.game_rotation=self.bno.game_quaternion
return self.game_rotation
@property
def Raw_Acceleration(self):
if "raw acceleration" in self. data:
self.raw_acceleration=self.bno.raw_acceleration
return self.raw_acceleration
@property
def Raw_Gyroscope(self):
if "raw gyroscope" in self. data:
self.raw_gyroscope=self.bno.raw_gyro
return self.raw_gyroscope
@property
def Raw_Magnetometer(self):
if "raw magnetometer" in self. data:
self.raw_magnetometer=self.bno.raw_magnetic
return self.raw_magnetometer