Browse Source

Merge branch 'dev-python'

rambo 8 months ago
parent
commit
d7b97574e6

+ 2 - 3
python/config.ini

@@ -4,16 +4,15 @@ app_name=智慧拍-后端应用
 # 应用版本号
 version=1.0.0
 # 应用host地址
-host=127.0.0.1
+host=10.56.42.51
 # 应用服务启动名称
 app_run=api:app
 # 端口号
 port=7074
-debug=false
+debug=true
 env=dev
 # 线程数
 works=1
-url_mode=dev
 project=惠利玛
 [log]
 # 日志相关

+ 152 - 0
python/docs/socket命令.md

@@ -209,4 +209,156 @@ _(该命令用于单独自定义配置中某一项的单独调整测试,不进
     "msg_type": "photo_take"
 }
 ```
+
+#### 修改配置-独立操作MCU
+* data中参数释义:
+    * msg: 消息文本内容
+    * data :
+        * camera_height:相机高度
+        * after_delay:拍照后延迟
+        * camera_angle:相机角度
+        * led_switch:led开关;true:开;false:关
+        * number_focus:对焦次数;这里因为后端不控制拍照,所以无效
+        * id:固定0
+        * take_picture:固定false;这里因为后端不控制拍照,所以无效
+        * mode_type:模式类型;如:执行左脚程序
+        * turntable_position:转盘位置
+        * action_name:动作名称;如:侧视图
+        * turntable_angle:转盘角度
+        * shoe_upturn:是否翻转;true:翻转;false:不翻转
+        * action_index:固定1
+        * pre_delay:1;拍照后延迟;这里因为后端不控制拍照,所以无效
+* type:当该字段为run_mcu_single时,代表独立执行MCU设备
+##### 请求示例
+```python
+{
+    "data": {
+        "camera_height": 300,
+        "after_delay": 1,
+        "camera_angle": 20,
+        "led_switch": true,
+        "number_focus": 1,
+        "id": 0,
+        "take_picture": false,
+        "mode_type": "执行左脚程序",
+        "turntable_position": 200,
+        "action_name": "侧视图",
+        "turntable_angle": 300,
+        "shoe_upturn": false,
+        "action_index": 1,
+        "pre_delay": 1
+    },
+    "type": "run_mcu_single"
+}
+```
+##### 响应示例
+###### 当 msg_type 为run_mcu_single时,代表独立执行MCU设备完成,前端将此命令作为完成依据
+```python
+{
+    "code": 0,
+    "msg": "执行完成",
+    "status": 2,
+    "data": null,
+    "msg_type": "run_mcu_single_finish"
+}
+```
+#### 设备调平-获取
+<mark>以下操作需要连接设备且初始化<mark>
+* data:空对象或忽略,任何值无意义
+* type:当该字段为get_deviation时,代表获取调平设备信息
+##### 请求示例
+```python
+{
+    "data": {
+    },
+    "type": "get_deviation"
+}
+```
+##### 响应示例
+* data:
+    * camera_high_motor_deviation:相机高度偏移 mm
+    * camera_steering_deviation: 相机角度偏移 度
+    * turntable_steering_deviation: 转盘角度偏移 度
+    * overturn_steering_middle: 翻转舵机-中位角度
+    * overturn_steering_high: 翻转舵机-最位角度
+    * overturn_steering_up_speed: 翻转舵机-上升速度
+    * overturn_steering_down_speed: 翻转舵机-下降速度
+    * turntable_front_end_deviation: 转盘前后电机偏移度
+* type:当该字段为get_deviation_data时,代表成功获取到调平设备信息
+```python
+{
+    "code": 0,
+    "msg": "接收偏移量信息",
+    "status": 2,
+    "data": {
+        "camera_high_motor_deviation": 10,
+        "camera_steering_deviation": 0.0,
+        "turntable_steering_deviation": 0.0,
+        "overturn_steering_middle": 109.0,
+        "overturn_steering_high": 150.0,
+        "overturn_steering_up_speed": 2,
+        "overturn_steering_down_speed": 4,
+        "turntable_front_end_deviation":300
+    },
+    "msg_type": "get_deviation_data"
+}
+```
+
+
+#### 设备调平-设置
+<mark>以下操作需要连接设备且初始化<mark>
+* data:
+    * value: 偏移量值,最好传递浮点型
+    * action_name:
+        * "相机电机",  # min 0 max 400,步长1
+        * "相机舵机",  # min -40 max 40,步长0.1
+        * "转盘舵机",  # min -720 max 720,步长1
+        * "转盘前后电机",  # min 0 max 950,步长1
+        * "翻板舵机中位",  # min 0 max 180,步长0.5
+        * "翻板舵机高位",  # min 0 max 180,步长0.5
+        * "翻板舵机上升速度",  # min 1 max 10,步长1
+        * "翻板舵机下降速度",  # min 1 max 10,步长1
+    * type: 
+        * "move" 为移动
+        * "set" 为设置
+* type:
+    * 当该字段为set_deviation时,代表设置调平设备信息
+    * 当该字段为move_deviation时,代表移动调平设备偏移
+##### 请求示例
+```python
+{
+    "data": {
+        "value": 10,
+        "action_name":"相机电机",
+        "type":"move"
+    },
+    "type": "set_deviation"
+}
+```
+##### 响应示例
+* data:忽略
+* type:
+    * 当该字段为set_deviation时,代表响应调平设备设置
+    * 当该字段为move_deviation时,代表响应调平设备移动
+###### 成功状态
+```python
+{
+    "code": 0,
+    "msg": "相机电机 设置成功",
+    "status": 2,
+    "data": {},
+    "msg_type": "set_deviation"
+}
+```
+###### 失败状态
+```python
+{
+    "code": 1,
+    "msg": "设置参数有误,请检查",
+    "status": 0,
+    "data": {},
+    "msg_type": "set_deviation"
+}
+```
+
 ##### 未完待续.....

+ 160 - 19
python/mcu/DeviceControl.py

@@ -12,7 +12,7 @@ import settings
 from .ProgramItem import ProgramItem
 from .capture.module_digicam import DigiCam
 from databases import insert_photo_records
-
+from .McuDeviationSet import McuDeviationSet
 # mcu命令
 class DeviceControl(BaseClass, metaclass=SingletonType):
     lock = threading.Lock()
@@ -20,6 +20,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
     def __init__(self, websocket_manager: ConnectionManager):
         super().__init__(websocket_manager)
         self.msg_type = "mcu"
+        self.mcu_deviation_set = McuDeviationSet(self)
         self.m_t = 1
         # 0未开始  1进行中 2已结束  99异常
         self.action_state = 2
@@ -198,7 +199,8 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             )
             self.add_send_data_queue(buf)
 
-    def get_deviation(self):
+    async def get_deviation(self):
+        await asyncio.sleep(0.01)
         # 发送获取偏移量
         data = [self.command["get_deviation"], 1]
         self.add_send_data_queue(data)
@@ -206,6 +208,59 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
         #     self.serial_ins.write_cmd(data)
         print("发送获取偏移量")
 
+    def set_deviation(self, device_name, _type=0, deviation=0):
+        # turntable----0 angle_ratio   1 turntable_steering_deviation
+        # overturn ----0 middle   1 high
+        if device_name == "camera_high_motor":
+            deviation = deviation / 10  # deviation 原单位为mm
+        if device_name == "turntable_position_motor":
+            deviation = deviation / 10  # deviation 原单位为mm
+        if device_name == "camera_steering":
+            pass
+        if device_name == "turntable_steering":
+            pass
+        if device_name == "overturn_steering":
+            pass
+
+        device_id = self.device_name_dict[device_name]
+        _dir = 1 if deviation >= 0 else 0
+        deviation = int(abs(deviation * 10))
+        data = [
+            self.command["set_deviation"],
+            device_id,
+            _type,
+            _dir,
+            0xFF & deviation >> 8,
+            0xFF & deviation,
+        ]
+        self.add_send_data_queue(data)
+        # self.controlDevice(device_name, deviation)
+
+    async def set_deviation_cmd(self,value,action_name,type):
+        await asyncio.sleep(0.01)
+        name_sets = [
+            "相机电机",  # min 0 max 400,步长1
+            "相机舵机",  # min -40 max 40,步长0.1
+            "转盘舵机",  # min -720 max 720,步长1
+            "转盘前后电机",  # min 0 max 950,步长1
+            "翻板舵机中位",  # min 0 max 180,步长0.5
+            "翻板舵机高位",  # min 0 max 180,步长0.5
+            "翻板舵机上升速度",  # min 1 max 10,步长1
+            "翻板舵机下降速度",  # min 1 max 10,步长1
+        ]
+        if action_name not in name_sets:
+            self.msg_type = f"{type}_deviation"
+            self.sendSocketMessage(msg="设置参数有误,请检查", device_status=0,code=1)
+            self.msg_type = "mcu"
+            return
+        # 发送获取偏移量
+        if type == "move":
+            self.mcu_deviation_set.change_value(value, action_name)
+        elif type == "set":
+            self.mcu_deviation_set.set_deviation(action_name)
+        self.msg_type = f"{type}_deviation"
+        self.sendSocketMessage(msg=f"{action_name} 设置成功", device_status=2,code=0)
+        self.msg_type = "mcu"
     def get_other_info(self):
         # 发送获取偏移量
         data = [self.command["get_other_info"], 1]
@@ -215,7 +270,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
     def add_send_data_queue(self, data):
         self.lock.acquire()
         if self.serial_ins:
-            # print("send_data_queue  append  :{}".format(data))
+            print("send_data_queue  append  :{}".format(data))
             self.send_data_queue.append(data)
         self.lock.release()
     def send_all_cmd(self):
@@ -402,23 +457,57 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             #         },
             #     }
             # )
-            message = {
-                "_type": "get_deviation_data",
-                "plugins_mode": "mcu",
-                "data": {
-                    "camera_high_motor_deviation": camera_high_motor_deviation,
-                    "camera_steering_deviation": camera_steering_deviation,
-                    "turntable_steering_deviation": turntable_steering_deviation,
-                    "overturn_steering_middle": overturn_steering_middle,
-                    "overturn_steering_high": overturn_steering_high,
-                    "overturn_steering_up_speed": overturn_steering_up_speed,
-                    "overturn_steering_down_speed": overturn_steering_down_speed,
-                },
+            # message = {
+            #     "_type": "get_deviation_data",
+            #     "plugins_mode": "mcu",
+            #     "data": {
+            #         "camera_high_motor_deviation": camera_high_motor_deviation,
+            #         "camera_steering_deviation": camera_steering_deviation,
+            #         "turntable_steering_deviation": turntable_steering_deviation,
+            #         "overturn_steering_middle": overturn_steering_middle,
+            #         "overturn_steering_high": overturn_steering_high,
+            #         "overturn_steering_up_speed": overturn_steering_up_speed,
+            #         "overturn_steering_down_speed": overturn_steering_down_speed,
+            #     },
+            # }
+            get_deviation_data = {
+                "camera_high_motor_deviation": camera_high_motor_deviation,
+                "camera_steering_deviation": camera_steering_deviation,
+                "turntable_steering_deviation": turntable_steering_deviation,
+                "turntable_front_end_deviation": 300,
+                "overturn_steering_middle": overturn_steering_middle,
+                "overturn_steering_high": overturn_steering_high,
+                "overturn_steering_up_speed": overturn_steering_up_speed,
+                "overturn_steering_down_speed": overturn_steering_down_speed,
             }
-            self.sendSocketMessage(msg="接收偏移量信息", data=message)
+            self.initDeviationInfo(get_deviation_data)
+            self.msg_type = "get_deviation_data"
+            self.sendSocketMessage(msg="接收偏移量信息", data=get_deviation_data)
+            self.msg_type = "mcu"
             print("接收偏移量信息")
         return
 
+    def initDeviationInfo(self, get_deviation_data):
+        # 初始化偏移量信息
+        camera_high_motor_deviation = get_deviation_data["camera_high_motor_deviation"]
+        camera_steering_deviation = get_deviation_data["camera_steering_deviation"]
+        turntable_steering_deviation = get_deviation_data["turntable_steering_deviation"]
+        overturn_steering_middle=get_deviation_data["overturn_steering_middle"]
+        overturn_steering_high = get_deviation_data["overturn_steering_high"]
+        overturn_steering_up_speed = get_deviation_data["overturn_steering_up_speed"]
+        overturn_steering_down_speed = get_deviation_data["overturn_steering_down_speed"]
+        self.mcu_deviation_set.last_value["相机电机"] = camera_high_motor_deviation
+        self.mcu_deviation_set.last_value["相机舵机"] = camera_steering_deviation
+        self.mcu_deviation_set.last_value["转盘舵机"] = turntable_steering_deviation
+        self.mcu_deviation_set.last_value["翻板舵机中位"] = overturn_steering_middle
+        self.mcu_deviation_set.last_value["翻板舵机高位"] = overturn_steering_high
+        self.mcu_deviation_set.last_value["翻板舵机上升速度"] = (
+            overturn_steering_up_speed
+        )
+        self.mcu_deviation_set.last_value["翻板舵机下降速度"] = (
+            overturn_steering_down_speed
+        )
+
     # 获取其他信息
     def get_from_mcu_other_info(self, receive_data):
         is_auto_send_base_info = self.get_data_from_receive_data(
@@ -740,9 +829,9 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             self.sendSocketMessage(
                 msg="MCU连接成功", data=message_data, device_status=2
             )
-            # time.sleep(2)
-            # loop = asyncio.get_event_loop()
-            # loop.create_task(self.initDevice(), name="init_mcu")
+            time.sleep(1)
+            loop = asyncio.get_event_loop()
+            loop.create_task(self.initDevice(), name="init_mcu")
             # async def getBaseInfo():
             #     while True:
             #         await asyncio.sleep(1)
@@ -935,6 +1024,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
 
         cmd = 1
         device_id = self.device_name_dict[device_name]
+        print("正在执行",device_name)
         match device_name:
             case "camera_high_motor":
                 # value 单位毫米
@@ -1179,6 +1269,7 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                     "current_time":datetime.datetime.now(settings.TIME_ZONE).strftime("%Y-%m-%d %H:%M:%S"),
                 },
             )
+            self.controlDevice("laser_position", 0)
             self.msg_type = "mcu"
             for index, action in enumerate(config_list):
                 await asyncio.sleep(0.1)
@@ -1238,6 +1329,56 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
                 device_status=2,
             )
             self.msg_type = "mcu"
+            self.controlDevice("laser_position", 1)
+
+    async def run_mcu_config_single(self, config_info, goods_art_no):
+        '''独立拍照  仅作测试用'''
+        if self.checkDevice() == False:
+            return
+        if config_info:
+            self.action_state = 1
+            self.msg_type = "mcu"
+            await asyncio.sleep(0.1)
+            image_index = -1
+            program_item = ProgramItem(
+                    websocket_manager=self.websocket_manager,
+                    action_data=config_info,
+                    mcu=self,
+                    goods_art_no=goods_art_no,
+                    image_index=image_index,
+                )
+            print("self.action_state===>", self.action_state)
+            if self.action_state != 1:
+                # 异常终止
+                print("action异常终止")
+                return
+            self.msg_type = "photo_take"
+            # if not program_item.run_only_mcu(1):
+            #     self.sendSocketMessage(
+            #             code=1,
+            #             msg="{} 执行失败~".format(program_item.action_name),
+            #             device_status=0,
+            #         )
+            #     self.to_deal_device(device_name="buzzer", times=3)
+            #     return
+            # else:
+            program_item.run(3)
+            # self.show_info("{}执行完成~".format(action.action_name))
+            self.sendSocketMessage(
+                        code=0,
+                        msg="{} 执行完成~".format(program_item.action_name),
+                        data={"goods_art_no": goods_art_no},
+                        device_status=2,
+                    )
+            self.msg_type = "mcu"
+            self.action_state = 2
+            self.msg_type = "run_mcu_single_finish"
+            self.sendSocketMessage(
+                    code=0,
+                    msg=f"执行完成",
+                    device_status=2,
+                )
+            self.msg_type = "mcu"
 
 
 async def checkMcuConnection(device_ctrl: DeviceControl):

+ 0 - 1
python/mcu/McuDebug.py

@@ -1,5 +1,4 @@
 import time
-
 class McuDebug(object):
 
     def __init__(self, mcu, is_debug=True, is_deviation=False):

+ 72 - 56
python/mcu/McuDeviationSet.py

@@ -1,11 +1,11 @@
 from collections import defaultdict
 from .McuDebug import McuDebug
 from functools import partial
-import time
+import time, asyncio
 import settings
 
 
-class McuDeviationSet():
+class McuDeviationSet:
     # 调试处理
     # data_sign = Signal(dict)
     # info_sign = Signal(str)
@@ -164,29 +164,29 @@ class McuDeviationSet():
                 return True
 
     def change_value(self, value, name):
-        value = round(value, 2)
-        if self.last_value[name] - 1 <= value <= self.last_value[name] + 1:
-            if name == "相机电机":
-                self.mcu_debug.camera_high_motor(value=value)
-            if name == "相机舵机":
-                self.mcu_debug.camera_steering(value=value)
-            if name == "转盘舵机":
-                self.mcu_debug.turntable_steering(value=value)
-            if name == "转盘前后电机":
-                self.mcu_debug.turntable_position_motor(value=value)
-            if name == "翻板舵机中位":
-                self.mcu_debug.overturn_steering(value=value)
-            if name == "翻板舵机高位":
-                self.mcu_debug.overturn_steering(value=value)
-            if name == "翻板舵机上升速度":
-                pass
-            print(value, name)
+        value = round(float(value), 2)
+        print("change_value===>", value, name)
+        if name == "相机电机":
+            self.mcu_debug.camera_high_motor(value=value)
+        if name == "相机舵机":
+            self.mcu_debug.camera_steering(value=value)
+        if name == "转盘舵机":
+            self.mcu_debug.turntable_steering(value=value)
+        if name == "转盘前后电机":
+            self.mcu_debug.turntable_position_motor(value=value)
+        if name == "翻板舵机中位":
+            self.mcu_debug.overturn_steering(value=value)
+        if name == "翻板舵机高位":
+            self.mcu_debug.overturn_steering(value=value)
+        if name == "翻板舵机上升速度":
+            pass
+        print(value, name)
         self.last_value[name] = value
 
     def set_deviation(self, name):
         if name == "相机电机":
             # 设定相机高度偏移量 单位mm
-            camera_high_motor_deviation = int(self.doubleSpinBox.value())
+            camera_high_motor_deviation = int(self.last_value[name])
             device_name = "camera_high_motor"
             self.mcu.set_deviation(
                 device_name=device_name, _type=0, deviation=camera_high_motor_deviation
@@ -194,16 +194,16 @@ class McuDeviationSet():
 
         if name == "相机舵机":
             # 设定相机舵机偏移量
-            camera_steering_deviation = self.doubleSpinBox_2.value()
+            camera_steering_deviation = self.last_value[name]
             device_name = "camera_steering"
             self.mcu.set_deviation(
                 device_name=device_name, _type=0, deviation=camera_steering_deviation
             )
-            self.doubleSpinBox_2.setValue(0.0)
+            # self.doubleSpinBox_2.setValue(0.0)
 
         if name == "转盘舵机":
             # 设定转盘舵机偏移角度  单位 度
-            turntable_steering_deviation = self.doubleSpinBox_3.value()
+            turntable_steering_deviation = self.last_value[name]
             device_name = "turntable_steering"
             self.mcu.set_deviation(
                 device_name=device_name, _type=1, deviation=turntable_steering_deviation
@@ -211,81 +211,97 @@ class McuDeviationSet():
 
         if name == "翻板舵机中位":
             # 设定翻版舵机偏移量
-            value = self.doubleSpinBox_4.value()
+            value = self.last_value[name]
             device_name = "overturn_steering"
-            self.mcu.set_deviation(
-                device_name=device_name, _type=0, deviation=value
-            )
+            self.mcu.set_deviation(device_name=device_name, _type=0, deviation=value)
         if name == "翻板舵机高位":
             # 设定翻版舵机偏移量
-            value = self.doubleSpinBox_5.value()
+            value = self.last_value[name]
             device_name = "overturn_steering"
-            self.mcu.set_deviation(
-                device_name=device_name, _type=1, deviation=value
-            )
+            self.mcu.set_deviation(device_name=device_name, _type=1, deviation=value)
         if name == "翻板舵机上升速度":
             # 设定翻版舵机偏移量
-            value = self.doubleSpinBox_6.value()
+            value = self.last_value[name]
             device_name = "overturn_steering"
-            self.mcu.set_deviation(
-                device_name=device_name, _type=2, deviation=value
-            )
+            self.mcu.set_deviation(device_name=device_name, _type=2, deviation=value)
         if name == "翻板舵机下降速度":
             # 设定翻版舵机偏移量
-            value = self.doubleSpinBox_8.value()
+            value = self.last_value[name]
             device_name = "overturn_steering"
-            self.mcu.set_deviation(
-                device_name=device_name, _type=3, deviation=value
-            )
+            self.mcu.set_deviation(device_name=device_name, _type=3, deviation=value)
 
     def _to_init_all(self, *args):
         self.mcu.to_init_device_origin_point(device_name="mcu", is_force=True)
 
     def get_mcu_deviation(self):
-        self.mcu.get_deviation()
+        loop = asyncio.get_event_loop()
+        loop.create_task(self.mcu.get_deviation(), name="get_mcu_deviation")
 
     def get_mcu_deviation_info(self, data):
         if "_type" not in data:
             return
+        get_deviation_data = {}
         if data["_type"] == "get_deviation_data":
             data = data["data"]
             print("偏移量信息")
             # overturn_steering_up_speed  overturn_steering_down_speed
             # 相机电机 单位mm
             if "camera_high_motor_deviation" in data:
-                self.doubleSpinBox.setValue(float(data["camera_high_motor_deviation"]))
+                # self.doubleSpinBox.setValue(float(data["camera_high_motor_deviation"]))
+                get_deviation_data["camera_high_motor_deviation"] = float(
+                    data["camera_high_motor_deviation"]
+                )
             # 相机舵机
             if "camera_steering_deviation" in data:
-                self.doubleSpinBox_2.setValue(float(data["camera_steering_deviation"]))
+                # self.doubleSpinBox_2.setValue(float(data["camera_steering_deviation"]))
+                get_deviation_data["camera_steering_deviation"] = float(
+                    data["camera_steering_deviation"]
+                )
             # 转盘偏移位
             if "turntable_steering_deviation" in data:
-                self.doubleSpinBox_3.setValue(
-                    float(data["turntable_steering_deviation"])
+                # self.doubleSpinBox_3.setValue(
+                #     float(data["turntable_steering_deviation"])
+                # )
+                get_deviation_data["turntable_steering_deviation"] = float(
+                    data["turntable_steering_deviation"]
                 )
             # 翻板舵机中位
             if "overturn_steering_middle" in data:
-                self.doubleSpinBox_4.setValue(float(data["overturn_steering_middle"]))
+                # self.doubleSpinBox_4.setValue(float(data["overturn_steering_middle"]))
+                get_deviation_data["overturn_steering_middle"] = float(
+                    data["overturn_steering_middle"]
+                )
             # 翻板舵机高位
             if "overturn_steering_high" in data:
-                self.doubleSpinBox_5.setValue(float(data["overturn_steering_high"]))
+                # self.doubleSpinBox_5.setValue(float(data["overturn_steering_high"]))
+                get_deviation_data["overturn_steering_high"] = float(
+                    data["overturn_steering_high"]
+                )
 
             # 翻板舵机
             if "overturn_steering_up_speed" in data:
-                self.doubleSpinBox_6.setValue(float(data["overturn_steering_up_speed"]))
+                # self.doubleSpinBox_6.setValue(float(data["overturn_steering_up_speed"]))
+                get_deviation_data["overturn_steering_up_speed"] = float(
+                    data["overturn_steering_up_speed"]
+                )
 
             if "overturn_steering_down_speed" in data:
-                self.doubleSpinBox_8.setValue(
-                    float(data["overturn_steering_down_speed"])
+                # self.doubleSpinBox_8.setValue(
+                #     float(data["overturn_steering_down_speed"])
+                # )
+                get_deviation_data["overturn_steering_down_speed"] = float(
+                    data["overturn_steering_down_speed"]
                 )
 
             # 初始化位置
-            data = {
-                "相机电机": self.doubleSpinBox.value(),
-                "相机舵机": self.doubleSpinBox_2.value(),
-                "转盘舵机": self.doubleSpinBox_3.value(),
-                "转盘前后电机": self.doubleSpinBox_7.value(),
-            }
-            self.is_get_offset.emit(data)
+            # data = {
+            #     "相机电机": self.doubleSpinBox.value(),
+            #     "相机舵机": self.doubleSpinBox_2.value(),
+            #     "转盘舵机": self.doubleSpinBox_3.value(),
+            #     "转盘前后电机": self.doubleSpinBox_7.value(),
+            # }
+            # self.is_get_offset.emit(data)
+            print("获取初始化位置  [get_deviation_data]  ", get_deviation_data)
 
     def __del__(self):
         self.state = 2

+ 6 - 2
python/mcu/ProgramItem.py

@@ -16,6 +16,7 @@ class ProgramItem(BaseClass):
         # 1 表示等待中,2表示没有等待
         self.wait_state = 2
         self.msg_type = "mcu"
+        print("action_data====>", action_data)
         self.data = action_data
         self.capture_one = DigiCam()
         captrure_folder_path = self.capture_one.getCaptureFolderPath()
@@ -73,7 +74,9 @@ class ProgramItem(BaseClass):
     def get_value(self, data, key, default=None):
         if key not in data:
             data[key] = default
+            print("取值模式==>获取到key:{}的值为:{}".format(key, data[key]))
             return default
+        print("默认值模式==>获取到key:{}的值为:{}".format(key, data[key]))
         return data[key]
 
     def reset(self):
@@ -203,10 +206,11 @@ class ProgramItem(BaseClass):
                     device_name="turntable_steering", value=self.turntable_angle
                 )
                 time.sleep(0.1)
+            self.mcu.send_all_cmd()
 
     def do_run(self, *args):
-        if not self.goods_art_no:  # and self.action_name != "初始化位置"
-            return False
+        # if not self.goods_art_no:  # and self.action_name != "初始化位置"
+        #     return False
         start_time = time.time()
         # ============连接MCU 处理步进电机与舵机等
         if settings.IS_MCU:

+ 1 - 1
python/settings.py

@@ -161,7 +161,7 @@ STOP = _mcu_config_dict["stop"]
 
 DOMAIN = (
     "https://dev2.valimart.net"
-    if config.get("app", "url_mode") != "dev"
+    if config.get("app", "env") != "dev"
     else "https://dev2.pubdata.cn"
 )
 

+ 29 - 1
python/sockets/message_handler.py

@@ -60,7 +60,7 @@ async def handlerSend(
             device_ctrl = DeviceControl(websocket_manager=manager)
             device_ctrl.controlDevice(device_name, value)
         case "run_mcu":
-            msg_type = "mcu"
+            msg_type = "run_mcu"
             try:
                 # 判断拍照软件是否初始化
                 digicam = DigiCam()
@@ -115,12 +115,40 @@ async def handlerSend(
                 device_ctrl.run_mcu_config(action_list, goods_art_no, action_info),
                 name="run_mcu_config",
             )
+        case "run_mcu_single":
+            device_ctrl = DeviceControl(websocket_manager=manager)
+            loop.create_task(
+                device_ctrl.run_mcu_config_single(data, None),
+                name="run_mcu_single",
+            )
         case "handler_take_picture":
             blue_tooth = BlueToothMode(websocket_manager=manager)
             loop.create_task(
                 blue_tooth.remote_control_v2.handlerTakePhoto(),
                 name="run_mcu_config",
             )
+        case "get_deviation":
+            device_ctrl = DeviceControl(websocket_manager=manager)
+            loop.create_task(
+                device_ctrl.get_deviation(),
+                name="get_deviation",
+            )
+        case "set_deviation":
+            device_ctrl = DeviceControl(websocket_manager=manager)
+            value = data.get("value", None)
+            action_name = data.get("action_name", None)
+            loop.create_task(
+                device_ctrl.set_deviation_cmd(value, action_name, "set"),
+                name="set_deviation",
+            )
+        case "move_deviation":
+            device_ctrl = DeviceControl(websocket_manager=manager)
+            value = data.get("value", None)
+            action_name = data.get("action_name", None)
+            loop.create_task(
+                device_ctrl.set_deviation_cmd(value, action_name, "move"),
+                name="move_deviation",
+            )
         case _:
             data = manager.jsonMessage(code=1, msg="未知消息")
             await manager.send_personal_message(data, websocket)