Ver código fonte

Updated config.ini & c_cpp_properties.json & (Re-)started implementing the magnetic sensor calibration

wokoeck_ch 3 anos atrás
pai
commit
d28ab95aeb

+ 0 - 1
.gitignore

@@ -1,4 +1,3 @@
-.vscode/c_cpp_properties.json
 .venv
 .vscode/settings.json
 

+ 60 - 0
.vscode/c_cpp_properties.json

@@ -0,0 +1,60 @@
+//
+// !!! WARNING !!! AUTO-GENERATED FILE!
+// PLEASE DO NOT MODIFY IT AND USE "platformio.ini":
+// https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags
+//
+{
+    "configurations": [
+        {
+            "name": "PlatformIO",
+            "includePath": [
+                "/home/user/Schreibtisch/Hochschule/WPM_Projekt/lern-tracking-system/arduino/include",
+                "/home/user/Schreibtisch/Hochschule/WPM_Projekt/lern-tracking-system/arduino/src",
+                "/home/user/Schreibtisch/Hochschule/WPM_Projekt/lern-tracking-system/.pio/libdeps/uno/BMP280_DEV",
+                "/home/user/Schreibtisch/Hochschule/WPM_Projekt/lern-tracking-system/.pio/libdeps/uno/MPU9250",
+                "/home/user/.platformio/packages/framework-arduino-avr/cores/arduino",
+                "/home/user/.platformio/packages/framework-arduino-avr/variants/standard",
+                "/home/user/.platformio/packages/framework-arduino-avr/libraries/SPI/src",
+                "/home/user/.platformio/packages/framework-arduino-avr/libraries/Wire/src",
+                "/home/user/.platformio/packages/framework-arduino-avr/libraries/EEPROM/src",
+                "/home/user/.platformio/packages/framework-arduino-avr/libraries/HID/src",
+                "/home/user/.platformio/packages/framework-arduino-avr/libraries/SoftwareSerial/src",
+                ""
+            ],
+            "browse": {
+                "limitSymbolsToIncludedHeaders": true,
+                "path": [
+                    "/home/user/Schreibtisch/Hochschule/WPM_Projekt/lern-tracking-system/arduino/include",
+                    "/home/user/Schreibtisch/Hochschule/WPM_Projekt/lern-tracking-system/arduino/src",
+                    "/home/user/Schreibtisch/Hochschule/WPM_Projekt/lern-tracking-system/.pio/libdeps/uno/BMP280_DEV",
+                    "/home/user/Schreibtisch/Hochschule/WPM_Projekt/lern-tracking-system/.pio/libdeps/uno/MPU9250",
+                    "/home/user/.platformio/packages/framework-arduino-avr/cores/arduino",
+                    "/home/user/.platformio/packages/framework-arduino-avr/variants/standard",
+                    "/home/user/.platformio/packages/framework-arduino-avr/libraries/SPI/src",
+                    "/home/user/.platformio/packages/framework-arduino-avr/libraries/Wire/src",
+                    "/home/user/.platformio/packages/framework-arduino-avr/libraries/EEPROM/src",
+                    "/home/user/.platformio/packages/framework-arduino-avr/libraries/HID/src",
+                    "/home/user/.platformio/packages/framework-arduino-avr/libraries/SoftwareSerial/src",
+                    ""
+                ]
+            },
+            "defines": [
+                "PLATFORMIO=50203",
+                "ARDUINO_AVR_UNO",
+                "F_CPU=16000000L",
+                "ARDUINO_ARCH_AVR",
+                "ARDUINO=10808",
+                "__AVR_ATmega328P__",
+                ""
+            ],
+            "cStandard": "c11",
+            "cppStandard": "c++11",
+            "compilerPath": "/home/user/.platformio/packages/toolchain-atmelavr/bin/avr-gcc",
+            "compilerArgs": [
+                "-mmcu=atmega328p",
+                ""
+            ]
+        }
+    ],
+    "version": 4
+}

+ 3 - 0
raspberry-pi/config.ini

@@ -37,6 +37,9 @@
   overhead_right = 20
 
 [mag_sensor]
+measurements_gyro = 500   # amount of measurements used for the calibration of the Gyroscope
+measurements_accel = 1000 # amount of measurements used for the calibration of the Accelerometer
+
 
 [opt_sensor]
   capture_device = -1

+ 18 - 58
raspberry-pi/sensors/magneticSensor.py

@@ -1,10 +1,9 @@
 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
 import logHandler
@@ -16,74 +15,35 @@ class MagneticSensor:
   def __init__(self, conf):
     self.conf = conf
     self.queue = queue.Queue()
-<<<<<<< HEAD
-    self.calibration_state  = CalibrationStateMashine()
     self.log_handler = logHandler.get_log_handler() # neu
     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.gyro_x = []
-    self.gyro_y = []
-    self.gyro_z = []
-    self.offset_x = 0 #
-    self.offset_y = 0 #
-    self.offset_z = 0 #
->>>>>>> de61b5b54174156bc78823188e70ac7b94fdde66
-
+  
   def start(self):
     if not conn.isConnected():
       conn.open()
     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):
     #print("mag: ", conn.getMagneticField())
     #print("accel: ", conn.getAccelValues())
     print("gyro: ", conn.getGyroValues())
 
-  def calibrate(self):
+  def calibrate(self, conf):
     # 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
+    accel_x, accel_y, accel_z = conn.getAccelValues()
+
     # Magnetometer Calibration
->>>>>>> de61b5b54174156bc78823188e70ac7b94fdde66
+    magneto_x, magneto_y, magneto_z = conn.getMagneticField()
 
   def read(self):
     return conn.getMagneticField()