OPENMV定时器发送数据报错
-
import sensor, image, time from pyb import UART from pyb import millis from math import pi, isnan import time from pyb import Pin, Timer #from pid import PID #若优化在cricket_test.py修改 cricket_control.py为最终函数 def tick(timer): #print("Timer callback") output_str="[%d,%d]" % (x_now,y_now) uart.write(output_str+'\r\n') print(max_blob.cx(),max_blob.cy()) #2个 tim = Timer(4, freq=1) tim.callback(tick) sensor.reset() sensor.set_framesize(sensor.QVGA) sensor.set_pixformat(sensor.RGB565) sensor.skip_frames(time = 2000) clock = time.clock() uart = UART(3, 115200) red_threshold = ((34, 63, 27, 80, 3, 127)) x_now=y_now=0 def find_max(blobs): max_size=0 for blob in blobs: if blob[2]*blob[3] > max_size: max_blob=blob max_size = blob[2]*blob[3] return max_blob while(True): clock.tick() img = sensor.snapshot() blobs = img.find_blobs([red_threshold],roi=(55,14,225,218),pixels_threshold=2, area_threshold=2) if blobs: max_blob = find_max(blobs) img.draw_rectangle(max_blob.rect()) img.draw_cross(max_blob.cx(), max_blob.cy(),color=0) x_now=max_blob.cx() #x_now:x方向上现在的色块中心坐标位置 y_now=max_blob.cy() #y_now:y方向上现在的色块中心坐标位置![0_1563168383679_QQ图片20190715132608.png](https://fcdn.singtown.com/8931770b-b870-4152-9aef-abf70e2a2918.png)
-
我给你写一个例子。
中断函数不应该再多了。字符串拼接应该在死循环里面做。import sensor, image, time from pyb import UART from pyb import millis from math import pi, isnan import time from pyb import Pin, Timer #from pid import PID #若优化在cricket_test.py修改 cricket_control.py为最终函数 sensor.reset() sensor.set_framesize(sensor.QVGA) sensor.set_pixformat(sensor.RGB565) sensor.skip_frames(time = 2000) clock = time.clock() uart = UART(3, 115200) output_str = '' def tick(timer): #print("Timer callback") global uart global output_str uart.write(output_str) tim = Timer(4, freq=1) tim.callback(tick) red_threshold = ((34, 63, 27, 80, 3, 127)) x_now=y_now=0 def find_max(blobs): max_size=0 for blob in blobs: if blob[2]*blob[3] > max_size: max_blob=blob max_size = blob[2]*blob[3] return max_blob while(True): clock.tick() img = sensor.snapshot() blobs = img.find_blobs([red_threshold],roi=(55,14,225,218),pixels_threshold=2, area_threshold=2) if blobs: max_blob = find_max(blobs) img.draw_rectangle(max_blob.rect()) img.draw_cross(max_blob.cx(), max_blob.cy(),color=0) x_now=max_blob.cx() #x_now:x方向上现在的色块中心坐标位置 y_now=max_blob.cy() #y_now:y方向上现在的色块中心坐标位置![0_1563168383679_QQ图片20190715132608.png](https://fcdn.singtown.com/8931770b-b870-4152-9aef-abf70e2a2918.png)
-