|
@@ -111,27 +111,28 @@ class AcusticSensor:
|
|
|
self.log_handler.log_and_print("calibration measurements:", self.cal_values)
|
|
|
|
|
|
# calculate distances from config
|
|
|
- # /| _.-|
|
|
|
- # d1 / | d2 _.-` |
|
|
|
- # / | y_off + calYoff _.-` | y_off + calibration_y_offset
|
|
|
- # /___| -____________|
|
|
|
- # x_off x_off + width
|
|
|
+ # /|\
|
|
|
+ # d1 d2 d3 / | \ d4
|
|
|
+ # _..'|'.._y_off + calYoff_2 / | \y_off + calYoff_2
|
|
|
+ # /____|____\ /___|___\
|
|
|
+ # x_off x_off
|
|
|
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["front"][0] - self.cal_values["back"][0]
|
|
|
+ timedif = self.cal_values["back"][0] - self.cal_values["front"][0]
|
|
|
# speed of sound in mm/us
|
|
|
sonicspeed_1 = distancedif / timedif
|
|
|
- # processing time overhead in us
|
|
|
- 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 + (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["back"][1] - self.cal_values["front"][0]
|
|
|
+ distance_3 = 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_4 = 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_4 - distance_3
|
|
|
+ timedif = self.cal_values["back"][1] - self.cal_values["front"][1]
|
|
|
sonicspeed_2 = distancedif / timedif
|
|
|
- overhead_2 = statistics.mean((self.cal_values["front"][1] - distance_1/sonicspeed_2, self.cal_values["back"][1] - distance_2/sonicspeed_2))
|
|
|
+
|
|
|
+ # processing time overhead in us
|
|
|
+ overhead_1 = statistics.mean((self.cal_values["front"][0] - distance_1/sonicspeed_1, self.cal_values["back"][0] - distance_2/sonicspeed_1))
|
|
|
+ overhead_2 = statistics.mean((self.cal_values["front"][1] - distance_3/sonicspeed_2, self.cal_values["back"][1] - distance_4/sonicspeed_2))
|
|
|
|
|
|
# calculate calibration results
|
|
|
self.sonic_speed = statistics.mean((sonicspeed_1,sonicspeed_2))
|