70 lines
2.7 KiB
Python
70 lines
2.7 KiB
Python
|
|
#!/usr/bin/env python3
|
|||
|
|
# -*- coding: utf-8 -*-
|
|||
|
|
"""
|
|||
|
|
测试脚本:模拟程序启动时门关闭的情况
|
|||
|
|
验证初始角度很小(门关闭)时的控制逻辑行为
|
|||
|
|
"""
|
|||
|
|
|
|||
|
|
import time
|
|||
|
|
from vision.visual_callback_1203 import VisualCallback
|
|||
|
|
from datetime import datetime
|
|||
|
|
|
|||
|
|
# 修改VisualCallback类,添加调试信息
|
|||
|
|
original_pulse_control = VisualCallback._pulse_control
|
|||
|
|
|
|||
|
|
# 重写_pulse_control方法,添加详细调试信息
|
|||
|
|
def debug_pulse_control(self, action, duration):
|
|||
|
|
print(f"{datetime.now().strftime('%H:%M:%S.%f')[:-3]} [DEBUG] 准备执行 {action} 脉冲,持续 {duration:.2f} 秒")
|
|||
|
|
result = original_pulse_control(self, action, duration)
|
|||
|
|
print(f"{datetime.now().strftime('%H:%M:%S.%f')[:-3]} [DEBUG] {action} 脉冲执行完成")
|
|||
|
|
return result
|
|||
|
|
|
|||
|
|
# 替换原始方法
|
|||
|
|
VisualCallback._pulse_control = debug_pulse_control
|
|||
|
|
|
|||
|
|
def test_door_close_startup():
|
|||
|
|
"""测试程序启动时门关闭的情况"""
|
|||
|
|
print("=== 测试:程序启动时门关闭的情况 ===")
|
|||
|
|
|
|||
|
|
# 创建VisualCallback实例(程序启动)
|
|||
|
|
callback = VisualCallback()
|
|||
|
|
|
|||
|
|
# 打印初始属性
|
|||
|
|
print(f"{datetime.now().strftime('%H:%M:%S.%f')[:-3]} 初始angle_mode: {callback.angle_mode}")
|
|||
|
|
print(f"{datetime.now().strftime('%H:%M:%S.%f')[:-3]} 初始overflow: {callback.overflow}")
|
|||
|
|
print(f"{datetime.now().strftime('%H:%M:%S.%f')[:-3]} 初始_last_overflow_state: {callback._last_overflow_state}")
|
|||
|
|
|
|||
|
|
# 模拟初始状态:门关闭(角度0°),无堆料
|
|||
|
|
print(f"\n{datetime.now().strftime('%H:%M:%S.%f')[:-3]} 发送状态:门关闭(角度0°),无堆料")
|
|||
|
|
callback.angle_visual_callback(0, "未堆料")
|
|||
|
|
|
|||
|
|
# 等待一段时间,观察控制行为
|
|||
|
|
for i in range(3):
|
|||
|
|
time.sleep(1)
|
|||
|
|
print(f"{datetime.now().strftime('%H:%M:%S.%f')[:-3]} 等待第{i+1}秒...")
|
|||
|
|
|
|||
|
|
# 发送角度1°,无堆料
|
|||
|
|
print(f"\n{datetime.now().strftime('%H:%M:%S.%f')[:-3]} 发送状态:角度1°,无堆料")
|
|||
|
|
callback.angle_visual_callback(1, "未堆料")
|
|||
|
|
|
|||
|
|
# 等待一段时间
|
|||
|
|
for i in range(3):
|
|||
|
|
time.sleep(1)
|
|||
|
|
print(f"{datetime.now().strftime('%H:%M:%S.%f')[:-3]} 等待第{i+1}秒...")
|
|||
|
|
|
|||
|
|
# 发送角度6°,无堆料(超过MIN_ANGLE)
|
|||
|
|
print(f"\n{datetime.now().strftime('%H:%M:%S.%f')[:-3]} 发送状态:角度6°,无堆料")
|
|||
|
|
callback.angle_visual_callback(6, "未堆料")
|
|||
|
|
|
|||
|
|
# 等待一段时间
|
|||
|
|
for i in range(3):
|
|||
|
|
time.sleep(1)
|
|||
|
|
print(f"{datetime.now().strftime('%H:%M:%S.%f')[:-3]} 等待第{i+1}秒...")
|
|||
|
|
|
|||
|
|
# 测试关闭机制
|
|||
|
|
callback.shutdown()
|
|||
|
|
print("\n=== 测试完成 ===")
|
|||
|
|
|
|||
|
|
if __name__ == "__main__":
|
|||
|
|
test_door_close_startup()
|