|
@@ -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))
|