logo

OpenMV4 H7 Plus 运行 Apriltag 追踪后 UART1 中断、绿蓝灯常亮、IDE 断连

2026-05-01 18:46
8
8vjuqt15fdoo

OpenMV4 H7 Plus 运行 Apriltag 追踪后 UART1 中断、绿蓝灯常亮、IDE 断连

故障概述

用户使用 OpenMV4 H7 Plus 追踪 Apriltag 并通过 UART1(115200 波特率)向无人机发送六轴位姿数据。初始运行正常,但持续运行一段时间后出现:绿灯与蓝灯持续闪烁、串口无响应、数据传输中断、OpenMV IDE 断连。固件版本为 4.4.4。

关键信息汇总

  • 故障类型:连接外设故障
  • 硬件型号:OpenMV4 H7 Plus
  • 固件版本:4.4.4
  • 现象细节:串口无响应、数据中断、IDE 断连,伴随绿/蓝 LED 持续闪烁
  • 参考教程:[AprilTag标记跟踪 · OpenMV中文入门教程](https://book.openmv.cc/image/apriltag.html)

附:故障代码

import sensor, time, math
from pyb import UART

# UART 初始化
uart = UART(1, 115200, timeout_char=1000)

# 摄像头初始化
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QQVGA) # 160x120
sensor.skip_frames(time=2000)
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)

clock = time.clock()

# 图像中心
IMG_W = 160
IMG_H = 120
c_x = IMG_W * 0.5
c_y = IMG_H * 0.5

# 焦距参数
f_x = (2.8 / 3.984) * IMG_W
f_y = (2.8 / 2.952) * IMG_H

def degrees(radians):
    return (180.0 * radians) / math.pi

def send_apriltag_6dof(Tx, Ty, Tz, Rx, Ry, Rz):
    uart.write("$AT,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f\r\n" % (Tx, Ty, Tz, Rx, Ry, Rz))

def send_no_tag():
    uart.write("$AT,NAN,NAN,NAN,NAN,NAN,NAN\r\n")

while True:
    clock.tick()
    img = sensor.snapshot()

    tags = img.find_apriltags(fx=f_x, fy=f_y, cx=c_x, cy=c_y)

    if tags:
        tag = tags[0]

        try:
            rect = tag.rect if not callable(tag.rect) else tag.rect()
            img.draw_rectangle(rect, color=(255, 0, 0))
        except:
            pass

        try:
            img.draw_cross(int(tag.cx()), int(tag.cy()), color=(0, 255, 0))
        except:
            pass

        try:
            Tx = tag.x_translation()
            Ty = tag.y_translation()
            Tz = tag.z_translation()

            Rx = degrees(tag.x_rotation())
            Ry = degrees(tag.y_rotation())
            Rz = degrees(tag.z_rotation())

            send_apriltag_6dof(Tx, Ty, Tz, Rx, Ry, Rz)
        except:
            send_no_tag()
    else:
        send_no_tag()

备注

用户暂未提供硬件正/反面照片,建议后续排查时检查 UART1 接线(TX/RX 是否交叉、GND 是否共地)、供电稳定性(是否使用稳压电源或大容量电容滤波)、以及是否存在长时运行导致的内存泄漏或 UART 缓冲区溢出风险。

2026-05-06 09:33
Z
星小瞳xs

更新固件后尝试