logo

循环读串口,但是运行一段时间,好像openMV就会断开连接,这是什么原因?

2018-12-06 10:24
1
sunnyjack236

# Single Color RGB565 Blob Tracking Example

#

# This example shows off single color RGB565 tracking using the OpenMV Cam.

import sensor, image, time, pyb

from pyb import UART

#4种灯

red_led = pyb.LED(1)

green_led = pyb.LED(2)

blue_led = pyb.LED(3)

infrared_led = pyb.LED(4)

#串口设置

uart = UART(3, 115200)

uart.init(115200, bits=8, parity=None, stop=1, timeout_char=1000 ,read_buf_len=64)

# Color Tracking Thresholds (L Min, L Max, A Min, A Max, B Min, B Max)

# The below thresholds track in general red/green/blue things. You may wish to tune them...

thresholds = [(6, 100, -64, -8, -32, 32), # day_generic_green_thresholds

(6, 100, -64, -8, -32, 32), # night_generic_green_thresholds

(0, 30, 0, 64, -128, 0)] # generic_blue_thresholds

sensor.reset()

sensor.set_pixformat(sensor.RGB565)

sensor.set_framesize(sensor.QVGA)

sensor.skip_frames(time = 200)

sensor.set_auto_gain(False) # must be turned off for color tracking

sensor.set_auto_whitebal(False) # must be turned off for color tracking

clock = time.clock()

# Only blobs that with more pixels than "pixel_threshold" and more area than "area_threshold" are

# returned by "find_blobs" below. Change "pixels_threshold" and "area_threshold" if you change the

# camera resolution. "merge=True" merges all overlapping blobs in the image.

day_flag = True

Uart_Rcv0 = 70

Uart_Rcv1 = 0

Igrcnt = 0

while(True):

UartRcv1 = uart.readchar()

if(UartRcv1 == 70 or UartRcv1 == 69):

Uart_Rcv0 = UartRcv1

elif(UartRcv1 == 72 or UartRcv1 == 71):

Uart_Rcv1 = UartRcv1

print("Uart_Rcv0=",Uart_Rcv0)

if(Uart_Rcv0 == 70):

print("from_night_to_day")

uart.write('F')

day_flag = True

time.sleep(50)

elif(Uart_Rcv0 == 69):

print("from_day_to_night")

infrared_led.on()

uart.write('E')

day_flag = False

time.sleep(50)

if((Uart_Rcv0 == 69 or Uart_Rcv0 == 70) and Uart_Rcv1 == 72): #下位机会一直给openMV串口发送70,只有触发条件满足时才会发72,

clock.tick()

blue_led.on()

img = sensor.snapshot()

if(day_flag):

for blob in img.find_blobs([thresholds[0]], pixels_threshold=200, area_threshold=3000, merge=True, margin=1):

img.draw_rectangle(blob.rect())

img.draw_cross(blob.cx(), blob.cy())

print("blob.area()=",blob.area())

if (blob.area() >= 5000):

uart.write('A')

Igrcnt = 0

Uart_Rcv1 = 0

else:

for blob in img.find_blobs([thresholds[1]], pixels_threshold=200, area_threshold=3000, margin=1):

img.draw_rectangle(blob.rect())

img.draw_cross(blob.cx(), blob.cy())

print("blob.area()=",blob.area())

if (blob.area() >= 5000):

uart.write('A')

Igrcnt = 0

Uart_Rcv1 = 0

Igrcnt += 1

if(Igrcnt >= 4):

Igrcnt = 0

uart.write('B')

Uart_Rcv1 = 0

blue_led.off()

#print(clock.fps())

2018-12-06 10:47
I
网红小智智 星瞳科技

什么叫做断开连接,说具体的现象

2018-12-06 14:09
1
sunnyjack236

就好像烧录进openMV板子里的程序没有在一直运行一样,openMV板子如果没有在运行会有什么现象吗?

2018-12-06 14:26
I
网红小智智 星瞳科技

说具体的现象...

I
网红小智智 星瞳科技

我又不知道你说的“烧录进openMV板子里的程序没有在一直运行一样”是什么现象。。。

2018-12-06 21:09
1
sunnyjack236

找到原因了,是内存溢出了