Files
Feeding_control_system/test_door_close_startup.py
2025-12-12 18:00:14 +08:00

70 lines
2.7 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/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()