• openmv第一次调试


    2018-09-19  20:14:51

    import sensor, image, time
    import car
    import json
    import time
    from pyb import UART
    from pid import PID
    
    sensor.reset() # Initialize the camera sensor.
    sensor.set_pixformat(sensor.RGB565) # use RGB565.
    sensor.set_framesize(sensor.QQVGA) # use QQVGA for speed.
    sensor.skip_frames(30) # Let new settings take affect.
    sensor.set_auto_whitebal(False) # 追踪颜色需要关闭白平衡
    sensor.set_auto_gain(False)#扫码需要关闭自动增益
    clock = time.clock() # Tracks FPS.
    red_threshold  = (13, 49, 18, 61, 6, 47)  #红色阈值
    size_threshold = 2000
    x_pid = PID(p=0.5, i=1, imax=100)
    h_pid = PID(p=0.05, i=0.1, imax=50)
    uart = UART(3, 115200)
    ma_flag = 0
    ma = []
    '''
    #串口通信:
    测试json数据    {(1,22),(-3,33),(22222,0),(9999,12),(0,0)}
    data=[]
    data_out = json.dumps(set(data))
    uart.write(data_out +'
    ')
    uart.write("Hello World!
    ")
    '''
    ######################
    '''
    #扫码反馈信息
    img.lens_corr(1.8) # 缩小视野
        for code in img.find_qrcodes():
            print(code)
    
    '''
    def find_ma():
        global ma_flag
        if ma_flag :
            print("已完成扫码。")
        else :
            ma = img.find_qrcodes()
            if ma:
                print("发现二维码即将停车进行扫码")
                saoma()
                ma_flag = 1
            else:
                print("正在寻找二维码。。。")
    
    def saoma():
        img.lens_corr(1.8) # strength of 1.8 is good for the 2.8mm lens.
        for code in img.find_qrcodes():
            print(code)
    
    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() # Track elapsed milliseconds between snapshots().
        img = sensor.snapshot()
        find_ma()
    
    
        '''
        blobs = img.find_blobs([red_threshold])
        if blobs:
            max_blob = find_max(blobs)
            x_error = max_blob[5]-img.width()/2
            h_error = max_blob[2]*max_blob[3]-size_threshold
            # print("x error: ", x_error)
            print("测试与arduino通信")
            ###下面代码为测试与arduino通信发送坐标####
            data=[]
            for b in blobs:
                # Draw a rect around the blob.
                img.draw_rectangle(b[0:4]) # rect
                img.draw_cross(b[5], b[6]) # cx, cy
                data.append((b.cx(),b.cy()))
                data_out = json.dumps(set(data))
                uart.write(data_out +'
    ')
            ###################################
            img.draw_rectangle(max_blob[0:4]) # rect
            img.draw_cross(max_blob[5], max_blob[6]) # cx, cy
            x_output=x_pid.get_pid(x_error,1)
            h_output=h_pid.get_pid(h_error,1)
            print("h_output",h_output)
            car.run(-h_output-x_output,-h_output+x_output)
        else:
            car.run(10,-10)  #旋转寻找小球
            '''
  • 相关阅读:
    iTOP-4412开发板低功耗高性能的开源硬件平台——上手评测
    迅为三星Exynos 4412开发板四核Cortex-A9ARM安卓linux开发板
    体验更低功耗的开源硬件平台-迅为4412开发板
    【分享】iTOP-4412开发板使用之初体验[多图]
    【嵌入式开发板】大家都在玩儿的4412开发板
    [POJ] 2965.The Pilots Brothers' refrigerator
    [POJ] 1753.Flip Game
    [HDOJ] 1753.大明A+B (大数加法)
    C++ Primer 第五版 一些遇到的注意点记录。
    [HDOJ] 1172.猜数字
  • 原文地址:https://www.cnblogs.com/pengwenzheng/p/9676919.html
Copyright © 2020-2023  润新知