|
@@ -1,10 +1,9 @@
|
|
import queue
|
|
import queue
|
|
-import time
|
|
|
|
-<<<<<<< HEAD
|
|
|
|
-import threading
|
|
|
|
-import random
|
|
|
|
-=======
|
|
|
|
->>>>>>> de61b5b54174156bc78823188e70ac7b94fdde66
|
|
|
|
|
|
+from struct import calcsize
|
|
|
|
+import numpy
|
|
|
|
+#import time
|
|
|
|
+import threading # ?
|
|
|
|
+import random # ?
|
|
|
|
|
|
from sensors.connection import globalArduinoSlave
|
|
from sensors.connection import globalArduinoSlave
|
|
import logHandler
|
|
import logHandler
|
|
@@ -16,74 +15,35 @@ class MagneticSensor:
|
|
def __init__(self, conf):
|
|
def __init__(self, conf):
|
|
self.conf = conf
|
|
self.conf = conf
|
|
self.queue = queue.Queue()
|
|
self.queue = queue.Queue()
|
|
-<<<<<<< HEAD
|
|
|
|
- self.calibration_state = CalibrationStateMashine()
|
|
|
|
self.log_handler = logHandler.get_log_handler() # neu
|
|
self.log_handler = logHandler.get_log_handler() # neu
|
|
self.success = False
|
|
self.success = False
|
|
-
|
|
|
|
- self.field_height = float(conf["field"]["y"])
|
|
|
|
- self.field_width = float(conf["field"]["x"])
|
|
|
|
-
|
|
|
|
- self.n = 0
|
|
|
|
-
|
|
|
|
- #pass
|
|
|
|
-=======
|
|
|
|
|
|
+ self.mpu_array = []
|
|
|
|
+ self.mpu_gyro_offsets = []
|
|
self.log_handler = logHandler.get_log_handler()
|
|
self.log_handler = logHandler.get_log_handler()
|
|
- self.gyro_x = []
|
|
|
|
- self.gyro_y = []
|
|
|
|
- self.gyro_z = []
|
|
|
|
- self.offset_x = 0 #
|
|
|
|
- self.offset_y = 0 #
|
|
|
|
- self.offset_z = 0 #
|
|
|
|
->>>>>>> de61b5b54174156bc78823188e70ac7b94fdde66
|
|
|
|
-
|
|
|
|
|
|
+
|
|
def start(self):
|
|
def start(self):
|
|
if not conn.isConnected():
|
|
if not conn.isConnected():
|
|
conn.open()
|
|
conn.open()
|
|
conn.addRecvCallback(self._readCb)
|
|
conn.addRecvCallback(self._readCb)
|
|
-<<<<<<< HEAD
|
|
|
|
- self.dummyActive = True
|
|
|
|
- dummyThread = threading.Thread(target=self._readCb_dummy)
|
|
|
|
- dummyThread.start()
|
|
|
|
-
|
|
|
|
- def _readCb(self, raw):
|
|
|
|
- print("mag: ", conn.getMagneticField())
|
|
|
|
-
|
|
|
|
- def _readCb_dummy(self):
|
|
|
|
- self.log_handler.log_and_print("acoustic sensor: generating test values")
|
|
|
|
- while self.dummyActive:
|
|
|
|
- dummyValue = 250
|
|
|
|
- position = 20
|
|
|
|
-
|
|
|
|
- self.pass_to_gui(position + dummyValue)
|
|
|
|
-
|
|
|
|
- def calibrate(self, x, y):
|
|
|
|
- pass
|
|
|
|
-=======
|
|
|
|
- self.calibrate() #
|
|
|
|
|
|
+ #self.dummyActive = True
|
|
|
|
+ #dummyThread = threading.Thread(target=self._readCb_dummy)
|
|
|
|
+ #dummyThread.start()
|
|
|
|
|
|
def _readCb(self, raw):
|
|
def _readCb(self, raw):
|
|
#print("mag: ", conn.getMagneticField())
|
|
#print("mag: ", conn.getMagneticField())
|
|
#print("accel: ", conn.getAccelValues())
|
|
#print("accel: ", conn.getAccelValues())
|
|
print("gyro: ", conn.getGyroValues())
|
|
print("gyro: ", conn.getGyroValues())
|
|
|
|
|
|
- def calibrate(self):
|
|
|
|
|
|
+ def calibrate(self, conf):
|
|
# Gyroscope Calibration
|
|
# Gyroscope Calibration
|
|
- i = 0
|
|
|
|
- while i < 500:
|
|
|
|
- self.gyro_x.append(conn.getGyroValues()) #
|
|
|
|
- self.gyro_y.append(conn.getGyroValues()) #
|
|
|
|
- self.gyro_z.append(conn.getGyroValues()) #
|
|
|
|
- print("gyro_x: %d", self.gyro_x)
|
|
|
|
- i += 1
|
|
|
|
- if i == 500:
|
|
|
|
- self.offset_x = sum(self.gyro_x) / len(self.gyro_x)
|
|
|
|
- self.offset_y = sum(self.gyro_y) / len(self.gyro_y)
|
|
|
|
- self.offset_z = sum(self.gyro_z) / len(self.gyro_z)
|
|
|
|
- #pass
|
|
|
|
|
|
+ gyro_x, gyro_y, gyro_z = conn.getGyroValues()
|
|
|
|
+ self.mpu_array.append([gyro_x,gyro_y,gyro_z])
|
|
|
|
+
|
|
# Accelerometer Calibration
|
|
# Accelerometer Calibration
|
|
|
|
+ accel_x, accel_y, accel_z = conn.getAccelValues()
|
|
|
|
+
|
|
# Magnetometer Calibration
|
|
# Magnetometer Calibration
|
|
->>>>>>> de61b5b54174156bc78823188e70ac7b94fdde66
|
|
|
|
|
|
+ magneto_x, magneto_y, magneto_z = conn.getMagneticField()
|
|
|
|
|
|
def read(self):
|
|
def read(self):
|
|
return conn.getMagneticField()
|
|
return conn.getMagneticField()
|