From f8e846dda0c01646ccf5d6b99069cf2ff2a177fe Mon Sep 17 00:00:00 2001 From: ori Date: Sat, 10 Aug 2019 10:16:49 -0700 Subject: [PATCH] bug fixes for calibration module --- backend/app/handlers/SocketHandler.py | 15 ++++++++++----- backend/app/handlers/VisionHandler.py | 5 ++--- backend/settings/cams/USB Camera-B4.09.24.1.json | 2 +- chameleon-client/src/components/outputTab.vue | 10 +++++++++- 4 files changed, 22 insertions(+), 10 deletions(-) diff --git a/backend/app/handlers/SocketHandler.py b/backend/app/handlers/SocketHandler.py index 618cbb84e..bd018deb3 100644 --- a/backend/app/handlers/SocketHandler.py +++ b/backend/app/handlers/SocketHandler.py @@ -1,3 +1,5 @@ +import asyncio + import tornado.websocket import json from ..classes.Exceptions import NoCameraConnectedException @@ -14,7 +16,7 @@ def send_all_async(message): web_socket_clients.remove(ws) else: try: - ws.write_message(message) + ws.write_message(json.dumps(message)) except AssertionError as a: pass except AssertionError: @@ -47,11 +49,14 @@ class ChameleonWebSocket(tornado.websocket.WebSocketHandler): print("WebSocket opened") def on_message(self, message): - message_dic = json.loads(message) + try: + message_dic = json.loads(message) - for key in message_dic: - self.actions.get(key, self.actions["change_pipeline_values"])(message_dic) - print(message) + for key in message_dic: + self.actions.get(key, self.actions["change_pipeline_values"])(message_dic) + print(message) + except: + print("crash " + message) def on_close(self): self.settings_manager.save_settings() diff --git a/backend/app/handlers/VisionHandler.py b/backend/app/handlers/VisionHandler.py index 50c4cd51d..dc2bca4ef 100644 --- a/backend/app/handlers/VisionHandler.py +++ b/backend/app/handlers/VisionHandler.py @@ -241,7 +241,6 @@ class VisionHandler(metaclass=Singleton): return pitch def calculate_yaw(self, pixel_x, center_x, h_focal_length): - yaw = math.degrees(math.atan((pixel_x - center_x) / h_focal_length)) return yaw @@ -389,8 +388,8 @@ class VisionHandler(metaclass=Singleton): center = final_contour[0] center_x = (center[1] - curr_pipeline['B']) / curr_pipeline["M"] center_y = (center[0] * curr_pipeline["M"]) + curr_pipeline["B"] - pitch = self.calculate_pitch(pixel_y=center[1], center_y=center_x, v_focal_length=V_FOCAL_LENGTH) - yaw = self.calculate_yaw(pixel_x=center[0], center_x=center_y, h_focal_length=H_FOCAL_LENGTH) + pitch = self.calculate_pitch(pixel_y=center[1], center_y=center_y, v_focal_length=V_FOCAL_LENGTH) + yaw = self.calculate_yaw(pixel_x=center[0], center_x=center_x, h_focal_length=H_FOCAL_LENGTH) valid = True except IndexError: center = None diff --git a/backend/settings/cams/USB Camera-B4.09.24.1.json b/backend/settings/cams/USB Camera-B4.09.24.1.json index 3f4f72410..3dc902d88 100644 --- a/backend/settings/cams/USB Camera-B4.09.24.1.json +++ b/backend/settings/cams/USB Camera-B4.09.24.1.json @@ -1 +1 @@ -{"pipelines": {"pipeline0": {"exposure": 50, "brightness": 16, "orientation": "Normal", "hue": [0, 127], "saturation": [0, 138], "value": [0, 122], "erode": false, "dilate": false, "area": [20, 37], "ratio": [0, 80.5], "extent": [0, 100], "is_binary": 1, "sort_mode": "Rightmost", "target_group": "Single", "target_intersection": "Up", "M": 1, "B": 0}}, "path": "/dev/v4l/by-path/pci-0000:02:03.0-usb-0:1:1.0-video-index0", "video_mode": {"fps": 187, "width": 320, "height": 240, "pixel_format": "kYUYV"}, "resolution": 0, "FOV": 56} \ No newline at end of file +{"pipelines": {"pipeline0": {"exposure": 3, "brightness": 0, "orientation": "Normal", "hue": [85, 136], "saturation": [115, 175], "value": [190, 255], "erode": false, "dilate": false, "area": [0, 99], "ratio": [0, 94.4], "extent": [0, 100], "is_binary": 1, "sort_mode": "Largest", "target_group": "Single", "target_intersection": "Up", "M": 1, "B": 0}}, "path": "/dev/v4l/by-path/pci-0000:02:03.0-usb-0:1:1.0-video-index0", "video_mode": {"fps": 187, "width": 320, "height": 240, "pixel_format": "kYUYV"}, "resolution": 0, "FOV": 56} \ No newline at end of file diff --git a/chameleon-client/src/components/outputTab.vue b/chameleon-client/src/components/outputTab.vue index a49c1b1ae..d5469dbbd 100644 --- a/chameleon-client/src/components/outputTab.vue +++ b/chameleon-client/src/components/outputTab.vue @@ -43,11 +43,19 @@ import chrange from './ch-range.vue' if(this.pointA !== undefined && this.pointB !== undefined){ let m = (this.pointB[1] - this.pointA[1]) / (this.pointB[0] - this.pointA[0]); let b = this.pointA[1] - (m * this.pointA[0]); - this.sendSlope(m,b); + if(isNaN(m) === false && isNaN(b) === false){ + this.sendSlope(m,b); + } else{ + this.$Message.error("Point A and B are to close apart"); + } + this.pointA = undefined; + this.pointB = undefined; } }, clearPoints:function(){ this.sendSlope(1,0); + this.pointA = undefined; + this.pointB = undefined; }, sendSlope(m,b){ this.$socket.sendObj({'M':m});