rambo 3 miesięcy temu
rodzic
commit
02038228cc
1 zmienionych plików z 44 dodań i 29 usunięć
  1. 44 29
      python/mcu/DeviceControl.py

+ 44 - 29
python/mcu/DeviceControl.py

@@ -47,6 +47,8 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
         self.state_camera_steering = 3
         self.state_turntable_steering = 3
         self.state_overturn_steering = 3
+        # 是否实时获取mcu状态信息
+        self.is_get_mcu_state = True
         self.state_move_turntable_steering = 3
         self.last_from_mcu_move_respond_data = None
         self.camera_motor_speed = 0
@@ -428,16 +430,21 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             data = self.send_data_queue.pop(0)
             self.serial_ins.write_cmd(data)
             self.sendSocketMessage(msg="命令发送完成", device_status=2)
-        # else:
-        #     self.t_n += 1
-        #     # 加大发送获取基础数据的时间间隔
-        #     # 默认为0.01秒一个循环,每隔1.5秒发送数据
-        #     if self.t_n > 150:
-        #         self.t_n = 0
-        #         data = [self.command["get_all_info"], 1]
-        #         self.serial_ins.write_cmd(data)
+        else:
+            # self.t_n += 1
+            # 加大发送获取基础数据的时间间隔
+            # 默认为0.01秒一个循环,每隔1.5秒发送数据
+            if self.t_n == 150:
+                # self.t_n = 0
+                self.send_get_all_info_to_mcu()
         self.lock.release()
 
+    def send_get_all_info_to_mcu(self):
+        if self.is_get_mcu_state is False:
+            return
+        data = [self.command["get_all_info"], 1]
+        self.serial_ins.write_cmd(data)
+
     def print_mcu_error_data(self, receive_data):
         # 扫码数据
         try:
@@ -1224,35 +1231,40 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             self.init_state = False
             print("关闭MCU")
             logger.info("关闭MCU")
+
     def close_lineConnect(self):
-        ''''关闭有线遥控器连接'''
+        """'关闭有线遥控器连接"""
         self.line_control.port_name = ""
         self.line_control.close_connect()
         print("关闭有线遥控器")
         logger.info("关闭有线遥控器")
+
     @property
     def mcu_move_state(self):
-        if self.m_t == 1:
-            if (
-                self.state_camera_motor == 2
-                and self.state_camera_steering == 2
-                and self.state_turntable_steering == 2
-                and self.state_overturn_steering == 2
-            ):
-                self._mcu_move_state = 2
-            else:
-                self._mcu_move_state = 1
+        if self.is_get_mcu_state is False:
+            self._mcu_move_state = 2
         else:
-            if (
-                self.state_camera_motor == 2
-                and self.state_camera_steering == 2
-                and self.state_turntable_steering == 2
-                and self.state_overturn_steering == 2
-                and self.state_move_turntable_steering == 2
-            ):
-                self._mcu_move_state = 2
+            if self.m_t == 1:
+                if (
+                    self.state_camera_motor == 2
+                    and self.state_camera_steering == 2
+                    and self.state_turntable_steering == 2
+                    and self.state_overturn_steering == 2
+                ):
+                    self._mcu_move_state = 2
+                else:
+                    self._mcu_move_state = 1
             else:
-                self._mcu_move_state = 1
+                if (
+                    self.state_camera_motor == 2
+                    and self.state_camera_steering == 2
+                    and self.state_turntable_steering == 2
+                    and self.state_overturn_steering == 2
+                    and self.state_move_turntable_steering == 2
+                ):
+                    self._mcu_move_state = 2
+                else:
+                    self._mcu_move_state = 1
 
         # self._mcu_move_state = 2
         return self._mcu_move_state
@@ -1691,7 +1703,10 @@ class DeviceControl(BaseClass, metaclass=SingletonType):
             program_item.smart_shooter = smart_shooter
             await program_item.run(3)
             self.msg_type = "mcu"
-            print("发送 run_mcu_signle消息","{} 执行完成~".format(program_item.action_name))
+            print(
+                "发送 run_mcu_signle消息",
+                "{} 执行完成~".format(program_item.action_name),
+            )
             self.sendSocketMessage(
                 code=0,
                 msg="{} 执行完成~".format(program_item.action_name),