工程训练大赛物流小车项目

这是一个基于OpenMV的物流小车项目,通过识别二维码和不同颜色的色块及色环,实现定位和顺序识别。程序稳定,适合初学者学习。主要涉及二维码读取、颜色识别和串口通信技术。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

工程训练大赛物流小车项目
参赛视频:https://www.bilibili.com/video/BV1Ny4y1J7Bg/
采用openmv与下位机通信进行二维码读取,色块位置、色环位置识别与色块顺序识别。该程序可以稳定运行,对于大佬来说可能并没有什么意义,但是对于刚刚参赛同学来说可以拿来学习和使用。


from machine import I2C
from vl53l1x import VL53L1X
import sensor, image, time,json
from pyb import UART
import json
import struct ,pyb
#1:red 2:green 3:blue```


def find_max(blobs):#return the max blob
    max_size=0
    for blob in blobs:
        if blob.pixels() > max_size:
            max_blob=blob
            max_size = blob.pixels()
    return max_blob
def send_data_packet(x, y):#串口发送函数定义
    temp = struct.pack("<bbii",                #格式为俩个字符俩个整型
                   0xAA,                       #帧头1
                   0xAE,                       #帧头2
                   int(x), # up sample by 4    #数据1
                   int(y)) # up sample by 4    #数据2
    uart.write(temp)                           #串口发送
    print(x,y)

def compareBlob(blob1,blob2):#比较色块后返回最大值
    tmp = blob1.pixels() - blob2.pixels()
    if tmp == 0:
        return 0;
    elif tmp > 0:
        return 1;
    else:
        return -1;

threshold_index = 0


#红绿蓝色环阈值

objthresholds=[(42, 76, 5, 35, -3, 88),


                (53, 66, -23, -5, 17, -5),
                
                (49, 61, -12, 18, -27, -3)]
                
graythreshold=[(100,255)]#二值化阈值

sensor.reset()

sensor.set_pixformat(sensor.RGB565)

sensor.set_framesize(sensor.QVGA)

sensor.skip_frames(time = 1000)

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()

A=7 #串口接收执行代码初始值

i= 1 #二维码发送触发代码值初始值

r=0

red_threshold_01 = (29, 47, 50, 72, 34, 57)#红色色块阈值

green_threshold_01=(18, 72, -60, -26, 16, 43)#绿色色块阈值

blue_threshold_01=(8, 58, -17, 23, -54, -16) #蓝色色块阈值

uart =UART(3,115200)

while(True):

    clock.tick()
    
    img = sensor.snapshot()
    
    if( uart.any() ):
    
        print("range: mm ")
        
        r=uart.readline()
        
        
        print(r)
        
        if r==b'1':

            A=1
            print('A=1')
        if r==b'2':
            A=2
            print('A=2')
        if r==b'3':

            A=3
            print('A=3')

        if r==b'4':
            A=4
            print('A=4')

        if r==b'5':
            A=5
            print('A=5')

        if r==b'6':
            A=6
            print('A=6')
        if r==b'7':
            A=7
            print('A=6')
        #else:
           # A=0

    if i==1:#二维码识别
         img.lens_corr(1.8) # strength of 1.8 is good for the 2.8mm lens.
         for code in img.find_qrcodes():
            print(code.payload())
            led = pyb.LED(1)
            led.on()
            output_str=code.payload()
            uart.write(output_str+'\r\n')
            #print('send:',output_str)
            led.off()
            i=1
    if(A==1):#红色色块识别

        blobs1= img.find_blobs([red_threshold_01],area_threshold=150)
        if blobs1:
        #如果找到了目标颜色
            led = pyb.LED(1)
            led.on()
            max_blob=find_max(blobs1)
            print('sum :', len(blobs1))
            img.draw_rectangle(max_blob.rect())
            img.draw_cross(max_blob.cx(), max_blob.cy())
            send_data_packet(max_blob.cx()-120,max_blob.cy()-160)

            led.off()
            #output_str=json.dumps([max_blob.cx(),max_blob.cy()]) #方式2
            print('send red blob')
            #uart.write(output_str+'\r\n')

    if(A==2):#绿色色块识别

        blobs2=img.find_blobs([green_threshold_01],area_threshold=150)
        if blobs2:
            led = pyb.LED(2)
            led.on()
            #如果找到了目标颜色
            max_blob=find_max(blobs2)
            print('sum :', len(blobs2))
            img.draw_rectangle(max_blob.rect())
            img.draw_cross(max_blob.cx(), max_blob.cy())
            send_data_packet(max_blob.cx()-120,max_blob.cy()-160)

            led.off()
            #output_str=json.dumps([max_blob.cx(),max_blob.cy()]) #方式2
            print('send green blob')




    if(A==3):#蓝色色块识别

        blobs3=img.find_blobs([blue_threshold_01],area_threshold=150)
        if blobs3:

            led = pyb.LED(3)
            led.on()
        #如果找到了目标颜色
            max_blob=find_max(blobs3)
            #print('sum :', len(blobs3))
            img.draw_rectangle(max_blob.rect())
            img.draw_cross(max_blob.cx(), max_blob.cy())
            send_data_packet(max_blob.cx()-120,max_blob.cy()-160)

            led.off()
            #output_str=json.dumps([max_blob.cx(),max_blob.cy()]) #方式2
            print('send blue blob')



    if(A==4):#红色色环识别
        img.binary([objthresholds[0]])
        img.dilate(2)

        blobs=img.find_blobs(graythreshold,pixels_threshold=2525,area_threashold=1600,merge=True)
        if blobs:
            led = pyb.LED(1)
            led.on()
            bigBlob=blobs[0]
            #print('1')
            for blob in blobs:
                if compareBlob(bigBlob,blob) == -1:
                    bigBlob=blob
                img.draw_rectangle(bigBlob.rect())
                #print(bigBlob.cx(),bigBlob.cy())
                #output_str="[%d,%d]" % (bigBlob.cx(),bigBlob.cy())
                #output_str=json.dumps([judge(bigBlob.cx()),judge(bigBlob.cy()),bigBlob.cx(),bigBlob.cy()])
                #uart.write(output_str+'\r\n')
                send_data_packet(bigBlob.cx()-120,bigBlob.cy()-160)

                led.off()
                #print('you send:',bigBlob.cx()-120)
            #uart.write(data_out)

    if(A==5):#绿色色环识别
        img.binary([objthresholds[1]])
        img.bilateral(2, color_sigma=0.1, space_sigma=1)
        img.dilate(3)

        blobs=img.find_blobs(graythreshold,pixels_threshold=2025,area_threashold=1600,merge=True)
        if len(blobs)==1:
            led = pyb.LED(2)
            led.on()
            bigBlob=blobs[0]
            for blob in blobs:
                if compareBlob(bigBlob,blob)==-1:
                    bigBlob=blob
                img.draw_rectangle(bigBlob.rect())
                #output_str=json.dumps([judge(bigBlob.cx()),judge(bigBlob.cy()),bigBlob.cx(),bigBlob.cy()])
                send_data_packet(bigBlob.cx()-120,bigBlob.cy()-160)

                led.off()
           # uart.write(data_out)
            #print(data_out)

    if(A==6):#蓝色色环识别
        img.binary([objthresholds[2]])
        img.bilateral(2, color_sigma=0.1, space_sigma=1)
        img.dilate(3)

        blobs=img.find_blobs(graythreshold,pixels_threshold=2025,area_threashold=1600,merge=True)
        if len(blobs)==1:
            led = pyb.LED(2)
            led.on()
            bigBlob=blobs[0]
            for blob in blobs:
                if compareBlob(bigBlob,blob)==-1:
                    bigBlob=blob
                img.draw_rectangle(bigBlob.rect())
                #output_str=json.dumps([judge(bigBlob.cx()),judge(bigBlob.cy()),bigBlob.cx(),bigBlob.cy()])
                send_data_packet(bigBlob.cx()-120,bigBlob.cy()-160)

                led.off()
           # uart.write(data_out)
            #print(data_out)

    if(A==7):#红绿蓝三色块顺序识别
         blobs1= img.find_blobs([red_threshold_01],area_threshold=150)
         blobs2=img.find_blobs([green_threshold_01],area_threshold=150)
         blobs3=img.find_blobs([blue_threshold_01],area_threshold=150)
         #if max_blob1.cx()< max_blob2.cx() < max_blob3.cx():
            #print('sadf')
         if blobs1 and blobs2 and blobs3:
            max_blob1=find_max(blobs1)
            img.draw_cross(max_blob1.cx(), max_blob1.cy())
            max_blob2=find_max(blobs2)
            img.draw_cross(max_blob2.cx(), max_blob2.cy())
            max_blob3=find_max(blobs3)
            img.draw_cross(max_blob3.cx(), max_blob3.cy())
            led = pyb.LED(3)
            led.on()
            if max_blob1.cx()< max_blob2.cx() < max_blob3.cx():

                output_str="[%d]" % (123) #方式1
                uart.write(output_str+'\r\n')

            if max_blob1.cx() < max_blob3.cx() < max_blob2.cx():
                output_str="[%d]" % (132) #方式1
                #uart.write('132')
                uart.write(output_str+'\r\n')

            if max_blob2.cx() < max_blob1.cx() < max_blob3.cx():
                output_str="[%d]" % (213) #方式1
                #uart.write('213')
                uart.write(output_str+'\r\n')

            if max_blob2.cx()< max_blob3.cx() < max_blob1.cx():
                #uart.write('231')
                output_str="[%d]" % (231) #方式1
                uart.write(output_str+'\r\n')

            if max_blob3.cx() < max_blob2.cx() < max_blob1.cx():
                #uart.write('321')
                output_str="[%d]" % (321) #方式1
                uart.write(output_str+'\r\n')

            if max_blob3.cx()< max_blob1.cx()  < max_blob2.cx():
                output_str="[%d]" % (312)
                #uart.write('312')
                uart.write(output_str+'\r\n')
            led.off()
           # uart.write(data_out)
    #print(clock.fps())

`
### 智能物流搬运小车的物料管理系统 智能物流搬运小车不仅具备自动导航和路径规划能力,还集成了高效的物料管理系统。该系统旨在优化仓储管理和运输流程中的物料流动,确保高效、精准的操作。 #### 材料存储与分配机制 为了支持多样化的物料处理需求,智能物流搬运小车配备了灵活的材料存储单元。这些单元可以根据所承载物品的不同特性进行调整,比如尺寸、重量以及形状等参数[^1]。对于特定应用场景下的特殊要求,还可以定制化设计相应的装载装置,如用于机床加零件上下料操作或是适应于集装箱内部复杂环境的任务执行。 #### 自动化存取功能 借助先进的传感技术和智能控制算法,智能物流搬运小车实现了对物料的高度自动化管理。当接收到新的入库指令时,车辆能够依据预设规则找到最优存放位置;而出库请求到来之际,则可通过快速定位目标货架并将指定商品取出送至目的地。此过程无需人干预即可顺利完成,极大提高了作效率并降低了运营成本[^3]。 #### 数据追踪与库存监控 在整个运作过程中,每一个环节的数据都被实时记录下来,形成完整的物流链条信息流。这有助于管理者随时掌握当前库存状况及各批次货物的具体流向,便于及时做出决策调整生产计划或补充货源。同时,通过对历史数据的分析挖掘潜在问题所在之处,进一步提升整体服务水平和服务质量[^2]。 ```python def track_materials(material_id, location): """ 跟踪物料的位置变化 参数: material_id (str): 物料唯一标识符 location (tuple): 新的位置坐标(x,y) 返回: str: 更新后的状态描述 """ # 假定有一个数据库连接对象db db.execute(f"UPDATE materials SET position={location} WHERE id='{material_id}'") return f"Material {material_id} moved to new location at {location}" ```
评论 16
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

_cv_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值