Browse Source

changed calibration procedure

subDesTagesMitExtraKaese 3 years ago
parent
commit
de00e5b157

+ 7 - 7
arduino/.vscode/extensions.json

@@ -1,7 +1,7 @@
-{
-    // See http://go.microsoft.com/fwlink/?LinkId=827846
-    // for the documentation about the extensions.json format
-    "recommendations": [
-        "platformio.platformio-ide"
-    ]
-}
+{
+    // See http://go.microsoft.com/fwlink/?LinkId=827846
+    // for the documentation about the extensions.json format
+    "recommendations": [
+        "platformio.platformio-ide"
+    ]
+}

+ 5 - 3
raspberry-pi/config.ini

@@ -23,7 +23,9 @@
   right_x_offset = 0
 
   # distance to y=0 at which the calibration takes place in mm
-  calibration_y_offset = 210
+  calibration_y_offset_1 = 100
+  calibration_y_offset_2 = 395
+  calibration_x_offset   = 195
 
   # default speed of sound in mm / us (or km / s)
   # only used before calibration
@@ -31,8 +33,8 @@
 
   # default arduino timing overhead in us
   # only used before calibration
-  overhead_left  = 133
-  overhead_right = 135
+  overhead_left  = 20
+  overhead_right = 20
 
 [mag_sensor]
 

+ 2 - 2
raspberry-pi/gui/graph.py

@@ -39,8 +39,8 @@ class Graph(tk.Canvas):
     for p in range(self.scale[0], self.scale[1], 10**int(math.log10(self.scale[1]-self.scale[0]))):
       tickPosX = self.pointToCoord((p, 0))
       tickPosY = self.pointToCoord((0, p))
-      draw.line([(tickPosX[0], tickPosX[1]+self.lineWidth*3), (tickPosX[0], tickPosX[1]-self.lineWidth*3)], (60,127,127), int(self.lineWidth/2))
-      draw.line([(tickPosY[0]+self.lineWidth*3, tickPosY[1]), (tickPosY[0]-self.lineWidth*3, tickPosY[1])], (60,127,127), int(self.lineWidth/2))
+      draw.line([(tickPosX[0], tickPosX[1]+self.lineWidth*300), (tickPosX[0], tickPosX[1]-self.lineWidth*300)], (60,127,127), int(self.lineWidth/2))
+      draw.line([(tickPosY[0]+self.lineWidth*300, tickPosY[1]), (tickPosY[0]-self.lineWidth*300, tickPosY[1])], (60,127,127), int(self.lineWidth/2))
       # draw tick labels
       draw.text((tickPosX[0]+3, tickPosX[1]+self.lineWidth*4), str(p) + " mm", font=self.font)
       if p != 0:

+ 17 - 15
raspberry-pi/sensors/acusticSensor.py

@@ -21,7 +21,9 @@ class AcusticSensor:
     self.sensor_y_offset        = float(conf["ac_sensor"]["y_offset"])
     self.left_sensor_x_offset   = float(conf["ac_sensor"]["left_x_offset"])
     self.right_sensor_x_offset  = float(conf["ac_sensor"]["right_x_offset"])
-    self.calibration_y_offset   = float(conf["ac_sensor"]["calibration_y_offset"])
+    self.calibration_y_offset_1 = float(conf["ac_sensor"]["calibration_y_offset_1"])
+    self.calibration_y_offset_2 = float(conf["ac_sensor"]["calibration_y_offset_2"])
+    self.calibration_x_offset   = float(conf["ac_sensor"]["calibration_x_offset"])
     self.sensor_distance        = self.field_width - self.left_sensor_x_offset + self.right_sensor_x_offset
     self.sonic_speed            = float(conf["ac_sensor"]["sonicspeed"])
     self.overhead_left          = float(conf["ac_sensor"]["overhead_left"])
@@ -33,8 +35,8 @@ class AcusticSensor:
     # temporary calibration variables
     self.time_vals = [[],[]]
     self.cal_values = {
-      "left": [0, 0],
-      "right": [0, 0] 
+      "front": [0, 0],
+      "back": [0, 0] 
     }
     self.n = 0
 
@@ -92,8 +94,8 @@ class AcusticSensor:
       self.time_vals[1].append(value[1])
       self.calibration_state.progress = len(self.time_vals[0]) / 2
       if len(self.time_vals[0]) >= 100:
-        self.cal_values["left"][0]  = statistics.mean(self.time_vals[0])
-        self.cal_values["right"][1] = statistics.mean(self.time_vals[1])
+        self.cal_values["front"][0]  = statistics.mean(self.time_vals[0])
+        self.cal_values["front"][1] = statistics.mean(self.time_vals[1])
         self.time_vals = [[],[]]
         self.calibration_state.next_state() # signal gui to get next position
 
@@ -102,8 +104,8 @@ class AcusticSensor:
       self.time_vals[1].append(value[1])
       self.calibration_state.progress = 50 + len(self.time_vals[0]) / 2
       if len(self.time_vals[0]) >= 100:
-        self.cal_values["left"][1]  = statistics.mean(self.time_vals[0])
-        self.cal_values["right"][0] = statistics.mean(self.time_vals[1])
+        self.cal_values["back"][0]  = statistics.mean(self.time_vals[0])
+        self.cal_values["back"][1] = statistics.mean(self.time_vals[1])
 
         # all values have been captured
         self.log_handler.log_and_print("calibration measurements:", self.cal_values)
@@ -114,22 +116,22 @@ class AcusticSensor:
         #        /  | y_off + calYoff       _.-`       | y_off + calibration_y_offset
         #       /___|                     -____________|
         #       x_off                     x_off + width
-        distance_1 = math.sqrt(self.left_sensor_x_offset**2 + (self.sensor_y_offset + self.calibration_y_offset)**2 )
-        distance_2 = math.sqrt((self.left_sensor_x_offset + self.field_width)**2 + (self.sensor_y_offset + self.calibration_y_offset)**2 )
+        distance_1 = math.sqrt((self.calibration_x_offset + self.left_sensor_x_offset)**2 + (self.sensor_y_offset + self.calibration_y_offset_1)**2 )
+        distance_2 = math.sqrt((self.calibration_x_offset + self.left_sensor_x_offset)**2 + (self.sensor_y_offset + self.calibration_y_offset_2)**2 )
         distancedif = distance_2 - distance_1
-        timedif = self.cal_values["left"][1] - self.cal_values["left"][0]
+        timedif = self.cal_values["front"][0] - self.cal_values["back"][0]
         # speed of sound in mm/us
         sonicspeed_1 = distancedif / timedif
         # processing time overhead in us
-        overhead_1 = statistics.mean((self.cal_values["left"][1] - distance_1/sonicspeed_1, self.cal_values["left"][0] - distance_2/sonicspeed_1))
+        overhead_1 = statistics.mean((self.cal_values["front"][0] - distance_1/sonicspeed_1, self.cal_values["back"][0] - distance_2/sonicspeed_1))
 
         # same for the second set of values
-        distance_1 = math.sqrt(self.right_sensor_x_offset**2 + (self.sensor_y_offset + self.calibration_y_offset)**2 )
-        distance_2 = math.sqrt((self.right_sensor_x_offset + self.field_width)**2 + (self.sensor_y_offset + self.calibration_y_offset)**2 )
+        distance_1 = math.sqrt((self.right_sensor_x_offset + (self.field_width - self.calibration_x_offset))**2 + (self.sensor_y_offset + self.calibration_y_offset_1)**2 )
+        distance_2 = math.sqrt((self.right_sensor_x_offset + (self.field_width - self.calibration_x_offset))**2 + (self.sensor_y_offset + self.calibration_y_offset_2)**2 )
         distancedif = distance_2 - distance_1
-        timedif = self.cal_values["right"][1] - self.cal_values["right"][0]
+        timedif = self.cal_values["back"][1] - self.cal_values["front"][0]
         sonicspeed_2 = distancedif / timedif
-        overhead_2 = statistics.mean((self.cal_values["right"][0] - distance_1/sonicspeed_2, self.cal_values["right"][1] - distance_2/sonicspeed_2))
+        overhead_2 = statistics.mean((self.cal_values["front"][1] - distance_1/sonicspeed_2, self.cal_values["back"][1] - distance_2/sonicspeed_2))
 
         # calculate calibration results
         self.sonic_speed = statistics.mean((sonicspeed_1,sonicspeed_2))