zoukankan      html  css  js  c++  java
  • 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)  #旋转寻找小球
            '''
  • 相关阅读:
    约瑟夫
    用过的ps操作
    guns框架试用笔记
    让使用WebForm的.aspx文件写的WebApi能够跨域访问
    DevExpress的GridView的行变和列变
    SSMS18.0缺少调试功能
    EF_CodeFirst框架版本问题
    微信小程序框架了解2---js的写法
    微信小程序框架了解1---总体了解
    Chrome浏览器写代码片段的地方
  • 原文地址:https://www.cnblogs.com/pengwenzheng/p/9676919.html
Copyright © 2011-2022 走看看