例程讲解32-Modbus -> modbus_apriltag.py Modbus与ArrilTag

视频教程30 - 用RS485扩展板实现OPENMV和PLC通信:https://singtown.com/learn/50806/

import sensor, image
import time
from pyb import UART
from modbus import ModbusRTU

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA) # 如果分辨率大得多,内存就不够用了……

uart = UART(3,115200, parity=None, stop=2, timeout=1, timeout_char=4)
modbus = ModbusRTU(uart, register_num=9999)

sensor.skip_frames(time = 2000)
clock = time.clock()

while(True):
    if modbus.any():
        modbus.handle(debug=True)
    else:
        clock.tick()
        img = sensor.snapshot()
        tags = img.find_apriltags() # 如果没有给出家族,默认TAG36H11。
        modbus.clear()
        modbus.REGISTER[0] = len(tags)
        if tags:
            print(tags)
            i = 1
            for tag in tags:
                img.draw_rectangle(tag.rect(), color = 127)
                modbus.REGISTER[i] = tag.family()
                i += 1
                modbus.REGISTER[i] = tag.id()
                i += 1
                modbus.REGISTER[i] = tag.cx()
                i += 1
                modbus.REGISTER[i] = tag.cy()
                i += 1
        #print(modbus.REGISTER[0:15])
        #print(clock.fps())

results matching ""

    No results matching ""