|
@@ -7,7 +7,9 @@ import settings
|
|
|
import time
|
|
import time
|
|
|
from .capture.module_digicam import DigiCam
|
|
from .capture.module_digicam import DigiCam
|
|
|
from .capture.module_watch_dog import FileEventHandler
|
|
from .capture.module_watch_dog import FileEventHandler
|
|
|
|
|
+import logging
|
|
|
|
|
|
|
|
|
|
+logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
class ProgramItem(BaseClass):
|
|
class ProgramItem(BaseClass):
|
|
|
# program_sign = Signal(dict)
|
|
# program_sign = Signal(dict)
|
|
@@ -52,6 +54,7 @@ class ProgramItem(BaseClass):
|
|
|
self.is_need_confirm = self.get_value(action_data, "is_need_confirm", False)
|
|
self.is_need_confirm = self.get_value(action_data, "is_need_confirm", False)
|
|
|
self.image_index = self.get_value(action_data, "picture_index", 99)
|
|
self.image_index = self.get_value(action_data, "picture_index", 99)
|
|
|
self.camera_height = self.get_value(action_data, "camera_height", 0)
|
|
self.camera_height = self.get_value(action_data, "camera_height", 0)
|
|
|
|
|
+ self.last_camera_height = 0
|
|
|
self.camera_angle = float(self.get_value(action_data, "camera_angle", 0.0))
|
|
self.camera_angle = float(self.get_value(action_data, "camera_angle", 0.0))
|
|
|
self.af_times = self.get_value(action_data, "number_focus", 0)
|
|
self.af_times = self.get_value(action_data, "number_focus", 0)
|
|
|
self.shoe_overturn = self.get_value(action_data, "shoe_upturn", False)
|
|
self.shoe_overturn = self.get_value(action_data, "shoe_upturn", False)
|
|
@@ -73,7 +76,7 @@ class ProgramItem(BaseClass):
|
|
|
|
|
|
|
|
self.set_other()
|
|
self.set_other()
|
|
|
self.error_info_text = "" # 错误提示信息
|
|
self.error_info_text = "" # 错误提示信息
|
|
|
-
|
|
|
|
|
|
|
+ self.last_move_time = None
|
|
|
# self.setParent(parent)
|
|
# self.setParent(parent)
|
|
|
self.mcu = mcu
|
|
self.mcu = mcu
|
|
|
|
|
|
|
@@ -182,7 +185,38 @@ class ProgramItem(BaseClass):
|
|
|
print("\033[1;31m执行结束\033[0m", self.mcu.action_state)
|
|
print("\033[1;31m执行结束\033[0m", self.mcu.action_state)
|
|
|
# await asyncio.sleep(0.1)
|
|
# await asyncio.sleep(0.1)
|
|
|
# self.mcu.to_get_mcu_base_info()
|
|
# self.mcu.to_get_mcu_base_info()
|
|
|
-
|
|
|
|
|
|
|
+ async def camera_check_mcu_move_is_stop(self, re_check=False):
|
|
|
|
|
+ self.error_info_text = ""
|
|
|
|
|
+ # 发送基础数据信息
|
|
|
|
|
+ # self.mcu.to_get_mcu_base_info()
|
|
|
|
|
+ _s = time.time()
|
|
|
|
|
+ check_times = 0
|
|
|
|
|
+ await self.mcu.cleanAllReceiveData()
|
|
|
|
|
+ while 1:
|
|
|
|
|
+ if self.mcu.action_state != 1:
|
|
|
|
|
+ return False
|
|
|
|
|
+ # 发送获取设备状态消息
|
|
|
|
|
+ self.mcu.send_get_all_info_to_mcu()
|
|
|
|
|
+ await asyncio.sleep(0.5)
|
|
|
|
|
+ if all(
|
|
|
|
|
+ value == 2
|
|
|
|
|
+ for value in [
|
|
|
|
|
+ self.mcu.state_camera_motor,
|
|
|
|
|
+ self.mcu.state_camera_steering,
|
|
|
|
|
+ self.mcu.state_turntable_steering,
|
|
|
|
|
+ self.mcu.state_overturn_steering,
|
|
|
|
|
+ ]
|
|
|
|
|
+ ):
|
|
|
|
|
+ logger.info("拍照前运动检测状态[成功]")
|
|
|
|
|
+ # await asyncio.sleep(0.5)
|
|
|
|
|
+ return True
|
|
|
|
|
+ else:
|
|
|
|
|
+ check_times += 1
|
|
|
|
|
+ if check_times > 5:
|
|
|
|
|
+ logger.info("拍照前运动检测状态[失败]")
|
|
|
|
|
+ return False
|
|
|
|
|
+ # return True
|
|
|
|
|
+ print("\033[1;31m执行结束\033[0m", self.mcu.action_state)
|
|
|
async def run(self, total_len=5, *args):
|
|
async def run(self, total_len=5, *args):
|
|
|
if total_len == 1:
|
|
if total_len == 1:
|
|
|
self.mode_type = "其他配置"
|
|
self.mode_type = "其他配置"
|
|
@@ -240,6 +274,7 @@ class ProgramItem(BaseClass):
|
|
|
# if not self.goods_art_no: # and self.action_name != "初始化位置"
|
|
# if not self.goods_art_no: # and self.action_name != "初始化位置"
|
|
|
# return False
|
|
# return False
|
|
|
start_time = time.time()
|
|
start_time = time.time()
|
|
|
|
|
+ current_time = time.time()
|
|
|
self.mcu.is_get_mcu_state = self.is_get_mcu_state
|
|
self.mcu.is_get_mcu_state = self.is_get_mcu_state
|
|
|
# ============连接MCU 处理步进电机与舵机等
|
|
# ============连接MCU 处理步进电机与舵机等
|
|
|
if settings.IS_MCU:
|
|
if settings.IS_MCU:
|
|
@@ -258,30 +293,46 @@ class ProgramItem(BaseClass):
|
|
|
|
|
|
|
|
if self.shoe_overturn:
|
|
if self.shoe_overturn:
|
|
|
self.mcu.to_deal_device(device_name="overturn_steering")
|
|
self.mcu.to_deal_device(device_name="overturn_steering")
|
|
|
- # time.sleep(0.1)
|
|
|
|
|
|
|
+ await asyncio.sleep(0.01)
|
|
|
if self.camera_height is not None:
|
|
if self.camera_height is not None:
|
|
|
|
|
+ if (current_time - self.last_move_time)>110:
|
|
|
|
|
+ if self.camera_height == 0:
|
|
|
|
|
+ self.mcu.to_device_move(
|
|
|
|
|
+ device_name="camera_high_motor", value=1
|
|
|
|
|
+ )
|
|
|
|
|
+ elif self.camera_height == 400:
|
|
|
|
|
+ self.mcu.to_device_move(
|
|
|
|
|
+ device_name="camera_high_motor", value=399
|
|
|
|
|
+ )
|
|
|
|
|
+ else:
|
|
|
|
|
+ self.mcu.to_device_move(
|
|
|
|
|
+ device_name="camera_high_motor", value=self.camera_height-1
|
|
|
|
|
+ )
|
|
|
|
|
+ await asyncio.sleep(0.01)
|
|
|
|
|
+ logger.info("设备延迟执行===>,%s",time.time())
|
|
|
self.mcu.to_device_move(
|
|
self.mcu.to_device_move(
|
|
|
device_name="camera_high_motor", value=self.camera_height
|
|
device_name="camera_high_motor", value=self.camera_height
|
|
|
)
|
|
)
|
|
|
- # time.sleep(0.1)
|
|
|
|
|
|
|
+ self.last_camera_height = self.camera_height
|
|
|
|
|
+ await asyncio.sleep(0.01)
|
|
|
if self.camera_angle is not None:
|
|
if self.camera_angle is not None:
|
|
|
self.mcu.to_device_move(
|
|
self.mcu.to_device_move(
|
|
|
device_name="camera_steering", value=self.camera_angle
|
|
device_name="camera_steering", value=self.camera_angle
|
|
|
)
|
|
)
|
|
|
- # time.sleep(0.1)
|
|
|
|
|
|
|
+ await asyncio.sleep(0.01)
|
|
|
|
|
|
|
|
if self.turntable_position is not None:
|
|
if self.turntable_position is not None:
|
|
|
self.mcu.to_device_move(
|
|
self.mcu.to_device_move(
|
|
|
device_name="turntable_position_motor",
|
|
device_name="turntable_position_motor",
|
|
|
value=self.turntable_position,
|
|
value=self.turntable_position,
|
|
|
)
|
|
)
|
|
|
- # time.sleep(0.1)
|
|
|
|
|
|
|
+ await asyncio.sleep(0.01)
|
|
|
|
|
|
|
|
if self.turntable_angle is not None:
|
|
if self.turntable_angle is not None:
|
|
|
self.mcu.to_device_move(
|
|
self.mcu.to_device_move(
|
|
|
device_name="turntable_steering", value=self.turntable_angle
|
|
device_name="turntable_steering", value=self.turntable_angle
|
|
|
)
|
|
)
|
|
|
- # time.sleep(0.1)
|
|
|
|
|
|
|
+ await asyncio.sleep(0.01)
|
|
|
|
|
|
|
|
# MCU运动是否有停止检查,设定超时时间
|
|
# MCU运动是否有停止检查,设定超时时间
|
|
|
# self.mcu.send_all_cmd()
|
|
# self.mcu.send_all_cmd()
|
|
@@ -292,6 +343,7 @@ class ProgramItem(BaseClass):
|
|
|
if await self.check_mcu_move_is_stop(re_check=True) is False:
|
|
if await self.check_mcu_move_is_stop(re_check=True) is False:
|
|
|
print("MCU检测运动未停止,自动退出, 提前退出")
|
|
print("MCU检测运动未停止,自动退出, 提前退出")
|
|
|
return
|
|
return
|
|
|
|
|
+ # logger.info("设备最后一次执行时间===>,%s",current_time)
|
|
|
self.mcu.is_get_mcu_state = True
|
|
self.mcu.is_get_mcu_state = True
|
|
|
if self.delay_time:
|
|
if self.delay_time:
|
|
|
await asyncio.sleep(self.delay_time)
|
|
await asyncio.sleep(self.delay_time)
|
|
@@ -299,6 +351,10 @@ class ProgramItem(BaseClass):
|
|
|
# print("photograph==================")
|
|
# print("photograph==================")
|
|
|
self.mcu.to_deal_device(device_name="buzzer", times=1)
|
|
self.mcu.to_deal_device(device_name="buzzer", times=1)
|
|
|
# 用于临时拍照计数
|
|
# 用于临时拍照计数
|
|
|
|
|
+ if not await self.camera_check_mcu_move_is_stop(re_check=True):
|
|
|
|
|
+ logger.info("拍照前运动检测失败===>")
|
|
|
|
|
+ return
|
|
|
|
|
+ await asyncio.sleep(0.5)
|
|
|
is_af = True if self.af_times > 0 else False
|
|
is_af = True if self.af_times > 0 else False
|
|
|
if self.smart_shooter != None:
|
|
if self.smart_shooter != None:
|
|
|
# 拍照
|
|
# 拍照
|