Пример #1
0
def scanStore():
    global currentx, currenty  #设置为全局变量,存放当前位置
    # camera = Camera_init()					#摄像头初始化
    # camera.cap = cap = cv2.VideoCapture(0)
    line = 'a'
    list_ware = [[(0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0)],
                 [(9, 0), (9, 1), (9, 2), (9, 3), (9, 4), (9, 5)],
                 [(9, 9), (8, 9), (7, 9), (6, 9), (5, 9), (4, 9)],
                 [(0, 9), (0, 8), (0, 7), (0, 6), (0, 5), (0, 4)]]  #货架位置
    for wares in list_ware:
        i = 1
        print("机械臂转动进程")
        armControl.ware_arm(line)  #参数值为char类型
        for ware in wares:
            print("移动进程")
            runControl.runControl(currentx, currenty, ware[0], ware[1])
            time.sleep(1)

            name = line + str(i)
            print("货仓拍照进程")
            send.send_receive(name)  #pi<->win拍摄照片,参数为a1,a2等
            # picture.append(camera.use_Camera(name))	#拍摄照片,传回照片
            i += 1
            currentx = ware[0]  #更新当前位置
            currenty = ware[1]
            # print("curx = "+str(currentx) + " cury = "+str(currenty))
        time.sleep(1)

        # pic_ware.append(camera.split_Camera2(picture,line))#图片切割成上下两部分

        # print("判空进程")
        # empty_ware.append(Empty.judgeEmpty(line))		   #判空,返回列表,压入列表['a1-L','a4-H','a3-L']

        line = ord(line)
        line += 1
        line = chr(line)  #更新货架标志a,b,c,d

    print("图片切割进程")
    send.send('3')  #pi->win图片切割
    time.sleep(1)

    print("判空进程")
    send.send('4')  #pi->win图片判空
Пример #2
0
def grabPlace(planningSite):
    print("root_path:")
    print(planningSite)
    print(type(planningSite))
    global currentx
    global currenty
    i = 0
    for index in planningSite:
        if i % 2 == 0:  #抓取货物
            runControl.runControl(currentx, currenty, index[0],
                                  index[1])  #到指定点
            print("货物抓取步骤")
            if index[0] == 4:
                dir = 4
            elif index[0] == 7:
                dir = 1
            elif index[0] == 5:
                dir = 2
            elif index[0] == 2:
                dir = 3

            #机械臂动作和行进是同步进行的,需要进行串口通信:arduino发ok给树莓派
            print("机械臂准备工作")
            print("nano1")
            armControl.good_arm(dir)  #机械臂抓取的准备工作——转向
            time.sleep(1)  #动作完成后延时1s
            print("nano2")
            armControl.gesture()  #准备工作——准备抓取动作
            print("nano1")
            armControl.paw('m')  #爪子张开动作

            if index[2].split('-')[1] == '1':  #根据需要向左或者右,走半步
                print("向左走半步")
                halfPath.left(index[0])
            elif index[2].split('-')[1] == '3':
                print("向右走半步")
                halfPath.right(index[0])
            time.sleep(1)  #左右半步走完之后,延时1s

            print("向前走半步")
            halfPath.forward(index[0])  #走半步
            time.sleep(1)  #走半步之后,延时1s
            print("nano2")
            armControl.gooddown()  #爪子下降

            iden = good_identify(index[2].split('-')[0])
            print("抓取货物动作")
            print("nano1")
            armControl.grab_good(iden)  #机械臂根据不同的物体,做不同的动作,传输的是物品对应的编号
            print("nano2")
            armControl.init()
            print("向后退半步")
            halfPath.back(index[0])  #退半步
            time.sleep(1)  #退半步之后,延时1s

            if index[2].split('-')[1] == '1':  #根据需要向左或者右,退半步
                print("向右退半步")
                halfPath.right(index[0])
            elif index[2].split('-')[1] == '3':
                print("向左退半步")
                halfPath.left(index[0])
            time.sleep(1)  #左右半步退完之后,延时1s

            currentx = index[0]  #更新当前路径
            currenty = index[1]

        else:  #放置货物
            if index[0] >= 0 and index[0] <= 5 and index[1] == 0:
                dir = 'd'  #放到A货仓
                x = index[0]
                y = index[1] + 1
            elif index[0] == 9 and index[1] >= 0 and index[1] <= 5:
                dir = 'a'  #放到B货仓
                x = index[0] - 1
                y = index[1]
            elif index[0] >= 4 and index[0] <= 9 and index[1] == 9:
                dir = 'b'  #放到C货仓
                x = index[0]
                y = index[1] - 1
            elif index[0] == 0 and index[1] >= 4 and index[1] <= 9:
                dir = 'c'  #放到D货仓
                x = index[0] + 1
                y = index[1]
            else:
                continue
            runControl.runControl(currentx, currenty, x, y)  #到指定点
            print("货物放置动作")

            print("机械臂准备工作")
            print("nano1")
            armControl.ware_arm(dir)  #机械臂准备工作——转向
            if index[2] == 'H':
                dir = 'h'
            elif index[2] == 'L':
                dir = 'j'
            print("nano2")
            armControl.place_ware(dir)  #上下层准备
            time.sleep(1)

            print("进一步动作")
            runControl.runControl(x, y, index[0], index[1])
            print("nano2")
            armControl.waredown(dir)  #货物放下
            print("nano1")
            armControl.paw('m')  #放置

            runControl.runControl(index[0], index[1], x, y)  #退回一格

            # if index[2] == 'H':
            # 	dir = '5'
            # elif index[2] == 'L':
            # 	dir = '6'
            print("nano1")
            armControl.paw('0')  #爪子闭合
            print("nano2")
            armControl.init()  #恢复到初始化动作

            currentx = x  #更新路径
            currenty = y

        i += 1  #区分抓和放