logo

您好,如下串口通信代码,每次发一个字符?

2023-07-29 22:34
S
_6iln
while(True):
    clock.tick()  # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot()  # 从感光芯片获得一张图像
    tags = sorted(img.find_apriltags(fx=f_x, fy=f_y, cx=c_x, cy=c_y), key = lambda x: x.w() * x.h(), reverse = True)
    if tags and (tags[0].id() in valid_tag_ids):
        print_args = (tags[0].x_translation(), tags[0].y_translation(), tags[0].z_translation())
        # 位置的单位是未知的,旋转的单位是角度
        print("Tx: %f, Ty %f, Tz %f" % print_args)
        order_position='1'
        if tags[0].x_translation()>2:
            order_position='D'; #偏左需向右
        elif tags[0].x_translation()<-2:
            order_position='A'; #偏右需向左
        elif tags[0].y_translation()>2:
            order_position='S';  #偏后需向前
        elif tags[0].y_translation()<-2:
            order_position='W'; #偏前需向后
        else:
            order_position='L'; #降落
        #output_str="[%c,%c]" % (order_position[0],order_position[1]) #方式1
        print('you send:',order_position)
        uart.write(order_position+'\r\n')
S
_6iln

不好意思,没有说完,uart通信px4端,px4端代码,read(openmv_b,&data_b_r,1); //读取上位机信息,每次是读到一个字符吗?

2023-07-31 17:07
I
网红小智智 星瞳科技

你的OpenMV的代码,每次都是发送一行。

我不知道px4上的代码是怎么读取的。