用户遇到了OpenMV代码运行一段时间后出现RuntimeError:Sensor Timeout错误的问题。用户提供了相关的代码,代码功能是识别不同颜色的物体并控制LED灯和引脚输出。
import sensor, image, time, math
from pyb import LED
from pyb import Pin
red_led = LED(1)
green_led = LED(2)
blue_led = LED(3)
ir_led = LED(4)
pin0 = Pin('P0', Pin.OUT_PP, Pin.PULL_DOWN)
pin1 = Pin('P1', Pin.OUT_PP, Pin.PULL_DOWN)
pin2 = Pin('P2', Pin.OUT_PP, Pin.PULL_DOWN)
thresholds = [(60, 70, 35, 60, 45, 62), #red(40, 65, 40, 85, 40, 80)
(85, 95, -60, -35, -20, 10), #green(55, 90, -85, -40, 0, 80)
(65, 80, 20, 30, 70, 85)] #yellow(58, 80, -40, 0, 40, 80)
sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False)
sensor.set_auto_whitebal(False)
sensor.set_auto_exposure(False)
clock = time.clock()
while(True):
clock.tick()
img = sensor.snapshot()
for blobr in img.find_blobs([thresholds[0]], pixels_threshold=200, area_threshold=200):
if(blobr.x()!=0):
red_led.off()
green_led.off()
blue_led.off()
ir_led.off()
r = 1
g = 0
y = 0
red_led.on()
pin0.high()
pin1.low()
pin2.low()
else:
break
img.draw_rectangle(blobr.rect())
print(r,g,y)
for blobg in img.find_blobs([thresholds[1]], pixels_threshold=200, area_threshold=200):
if(blobg.x()!=0):
red_led.off()
green_led.off()
blue_led.off()
ir_led.off()
r = 0
g = 1
y = 0
green_led.on()
pin0.low()
pin1.high()
pin2.low()
else:
break
img.draw_rectangle(blobg.rect())
print(r,g,y)
for bloby in img.find_blobs([thresholds[2]], pixels_threshold=200, area_threshold=200):
if(bloby.x()!=0):
red_led.off()
green_led.off()
blue_led.off()
ir_led.off()
r = 0
g = 0
y = 1
red_led.on()
green_led.on()
pin0.low()
pin1.low()
pin2.high()
else:
break
img.draw_rectangle(bloby.rect())
print(r,g,y)
#red_led.off()
#green_led.off()
#blue_led.off()
#ir_led.off()我复制了你的代码进行了测试,并没有报错。 你这个问题是传感器初始化的问题; 可以尝试:
①重新插拔后重新运行代码; ②将传感器螺丝拆下来,重新安装传感器后再次尝试;