logo

使用定时器如何实现隔一段时间与Arduino通信的功能?程序提示memory error的原因?

2019-04-04 14:03
7
浆果梦
def set_outstr(timer):
    out_str ='['
    out_str +='(%d,%d)' %(x_error,y_error)
    out_str +=']'
    uart.write(out_str)   #向arduino传递out_str字符串
    print (out_str)

while(True):

    clock.tick() # Track elapsed milliseconds between snapshots().

    img = sensor.snapshot() # Take a picture and return the image.
    
    blobs = img.find_blobs([green_threshold])

    tim=Timer(4,freq=5)
    if blobs:

        max_blob = find_max(blobs)

        x_error = max_blob[5]-img.width()/2                           #X方向偏差

        y_error = max_blob[6]-img.height()/2                          #y方向偏差

        
        print("x error: ", x_error)
        print("y_error: ", y_error)
        img.draw_rectangle(max_blob[0:4]) # rect

        img.draw_cross(max_blob[5], max_blob[6]) # cx, cy
       
        tim.callback(set_outstr)

提示错误:uncaught exception in Timer(4) interrupt handler

MemoryError:

x error: -119.0

y_error: -21.0

2019-04-04 15:22
I
网红小智智 星瞳科技

你的代码不全,无法运行。