部分代码,为什么电脑接收不到圆的坐标?
-
uart = UART(3, 115200) for c in img.find_circles(threshold = 3500, x_margin = 10, y_margin = 10, r_margin = 10,r_min = 2, r_max = 100, r_step = 2): img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0)) print(c) print("FPS %f" % clock.fps()) uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters def send_data_packet(x,y,z,w): #frame=[0x2C,18,cx%0xff,int(cx/0xff),cy%0xff,int(cy/0xff),0x5B]; #data = bytearray(frame) data = ustruct.pack("<bbhhhhb", #格式为俩个字符俩个短整型(2字节) 0x2C, #帧头1 0x12, #帧头2 int(cx), # up sample by 4 #数据1 int(cy), # up sample by 4 #数据2 int(cw), # up sample by 4 #数据1 int(ch), # up sample by 4 #数据2 0x5B) uart.write(data);data_out = json.dumps(set(data)) while(True): clock.tick() date=bytearray[(1,2,3,4,5)] uart.write(data) img = sensor.snapshot() c = img.find_circles() cx=0;cy=0; if c: c = find_circles(c) cx=c.x() cy=c.y() cw=c.r() ch=c.magnitude() img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0)) FH = bytearray([0x2C,0x12,cx,cy,cw,ch,0x5B]) #sending_data(cx,cy,cw,ch) uart.write(FH) print(cx,cy,cw,ch)
请在这里粘贴代码
-
电脑端什么都没接到,还是格式错误?
-
代码就是上面那些,电脑上啥都没没收到,您看看是不是哪里写错了,新手小白,求指导。
请在这里粘贴代码
-
这个是识别到了圆,串行终端有代码输出,就是通过串口发不到电脑上
-
-
这个代码能发出来
-
uart = UART(3, 115200) uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters def send_data_packet(x,y,z,w): #frame=[0x2C,18,cx%0xff,int(cx/0xff),cy%0xff,int(cy/0xff),0x5B]; #data = bytearray(frame) data = ustruct.pack("<bbhhhhb", #格式为俩个字符俩个短整型(2字节) 0x2C, #帧头1 0x12, #帧头2 int(cx), # up sample by 4 #数据1 int(cy), # up sample by 4 #数据2 int(cw), # up sample by 4 #数据1 int(ch), # up sample by 4 #数据2 0x5B) uart.write(data);data_out = json.dumps(set(data)) while(True): clock.tick() date=bytearray[(1,2,3,4,5)] uart.write(data) time.sleep(1)
运行这个测试。