示例#1
0
def handler2(channel):
    global handle_data
    l,c,r = line.line_data()
    if(c == 0 and l == 0 and r == 0):
        moter.setMoterControl(0, 5)
        handle_data = handle_data - 1
        print('handle',handle_data)
示例#2
0
def runT():
    print("start Deparking~~")
    #interrup
    gpio.GPIO.add_event_detect(line.pin_otc, gpio.GPIO.FALLING, callback = handler)
    gpio.GPIO.add_event_detect(line.pin_otl, gpio.GPIO.FALLING, callback = handler)
    gpio.GPIO.add_event_detect(line.pin_otr, gpio.GPIO.FALLING, callback = handler)

    while(True):
        l,c,r = line.line_data()
        moter.setMoterControl(0, 5)

        if(c+r+l != 0):
            moter.setMoterControl(speed, 2)
        else:
            break
示例#3
0
def reset():
    #통신이 끊겼을때
    #제자리로 돌아간다
    #서보 모터 아래로
    gpio.time.sleep(0.5)
    servo.setMoterControl(7)
    gpio.time.sleep(2)

    gpio.GPIO.add_event_detect(line.pin_otl,
                               gpio.GPIO.FALLING,
                               callback=handler)
    gpio.GPIO.add_event_detect(line.pin_otr,
                               gpio.GPIO.FALLING,
                               callback=handler)
    try:
        while (True):
            l, c, r = line.line_data()
            moter.setMoterControl(0, 5)

            #back
            if (l == 1 and c == 0 and r == 1):
                moter.setMoterControl(State.speed(), 2)

            #back right
            elif (l == 1 and r == 0):
                moter.setMoterControl(State.speed(), 6)

            #back left
            elif (l == 0 and r == 1):
                moter.setMoterControl(State.speed(), 8)

            #여기는 도착한 센서값 캐치후 on상태로 복귀
            if (l == 0 and c == 0 and r == 0):
                gpio.GPIO.remove_event_detect(line.pin_otl)
                gpio.GPIO.remove_event_detect(line.pin_otr)
                moter.setMoterControl(0, 5)
                State.setState(1)
                break

    except KeyboardInterrupt:
        ending()
        sys.exit()
示例#4
0
def restart():
    global handle_data
    gpio.GPIO.add_event_detect(line.pin_otl,
                               gpio.GPIO.FALLING,
                               callback=handler2)
    gpio.GPIO.add_event_detect(line.pin_otr,
                               gpio.GPIO.FALLING,
                               callback=handler2)
    try:
        while (True):
            l, c, r = line.line_data()

            #back
            if (l == 1 and c == 0 and r == 1):
                moter.setMoterControl(State.speed(), 2)

            #back right
            elif (l == 1 and r == 0):
                moter.setMoterControl(State.speed(), 6)

            #back left
            elif (l == 0 and r == 1):
                moter.setMoterControl(State.speed(), 8)

            moter.setMoterControl(0, 5)

            #여기는 도착한 센서값 캐치후 on상태로 복귀
            if (l == 0 and c == 0 and r == 0):
                print("restart handle : ", int(handle_data))
                if (handle_data != 0):
                    handle_data = handle_data - 1
                    moter.setMoterControl(State.speed(), 2)
                    gpio.time.sleep(0.6)
                    moter.setMoterControl(0, 5)
                elif (handle_data == 0):
                    gpio.GPIO.remove_event_detect(line.pin_otl)
                    gpio.GPIO.remove_event_detect(line.pin_otr)
                    gpio.time.sleep(0.5)
                    State.setState(10)
                    break

    except KeyboardInterrupt:
        ending()
        sys.exit()
示例#5
0
def runM():
    global handle_data
    try:
        if (State.car_type() == 0):
            while (True):
                data = client.sendNrecv(State.name() + ' : run')
                if (int(data) > 0):
                    State.setParkNumber(int(data))
                    break
                gpio.time.sleep(0.5)
        else:
            State.setParkNumber(int(State.car_number()))

        #interrup
        gpio.GPIO.add_event_detect(line.pin_otl,
                                   gpio.GPIO.FALLING,
                                   callback=handler)
        gpio.GPIO.add_event_detect(line.pin_otr,
                                   gpio.GPIO.FALLING,
                                   callback=handler)
        print("start parking~~")

        while (True):
            l, c, r = line.line_data()

            #forward
            if (l == 1 and c == 0 and r == 1):
                #print("go1")
                moter.setMoterControl(State.speed(), 1)

            #right
            elif (l == 1 and r == 0):
                #print("go2")
                moter.setMoterControl(State.speed(), 4)

            #left
            elif (l == 0 and r == 1):
                #print("go3")
                moter.setMoterControl(State.speed(), 3)

            moter.setMoterControl(0, 5)

            if (l == 0 and c == 0 and r == 0):
                print("go4")
                #park_number에 10을 나누어 1번 주차장인지 2번 주차장인지 판단
                _park_number = int(State.park_number() / 10) - 1
                if (_park_number > handle_data):
                    handle_data = handle_data + 1
                    moter.setMoterControl(State.speed(), 1)
                    gpio.time.sleep(0.6)
                    print(_park_number, "번 라인")
                else:
                    moter.setMoterControl(0, 5)
                    gpio.GPIO.remove_event_detect(line.pin_otl)
                    gpio.GPIO.remove_event_detect(line.pin_otr)
                    gpio.time.sleep(2)
                    print('인터럽트 해제 완료')
                    #빼내오는차 넣는차 검출
                    break

        _data = True
        if (State.car_type() == 0):
            arrive(str(State.park_number()), 'in')
            _data = goM()
        elif (State.car_type() == 1):
            arrive(str(State.park_number()), 'out')
            _data = backM()
        State.stateChange()
        State.setCarType(0)

    except KeyboardInterrupt:
        ending()
        sys.exit()
示例#6
0
def handler2(channel):
    l, c, r = line.line_data()
    gpio.time.sleep(0.5)
    if (c == 0 and l == 0 and r == 0):
        moter.setMoterControl(0, 5)
示例#7
0
def restart():
    global state
    gpio.GPIO.add_event_detect(line.pin_otl, gpio.GPIO.FALLING, callback = handler2)
    gpio.GPIO.add_event_detect(line.pin_otr, gpio.GPIO.FALLING, callback = handler2)
    try:   
        while(True):
            l,c,r = line.line_data()
            moter.setMoterControl(0, 5)

            #back
            if(l == 1 and c == 0 and r == 1):
                moter.setMoterControl(speed, 2)

            #back right
            elif(l == 1 and r == 0):
                moter.setMoterControl(speed, 6)

            #back left
            elif(l == 0 and r == 1):
                moter.setMoterControl(speed, 8)

            #여기는 도착한 센서값 캐치후 on상태로 복귀
            if(l == 0 and c == 0 and r == 0):
                moter.setMoterControl(0, 5)
                if(handle_data != 0):
                    moter.setMoterControl(speed, 1)
                    time.sleep(0.5)
                elif(handle_data == 0):
                    gpio.GPIO.remove_event_detect(line.pin_otl)
                    gpio.GPIO.remove_event_detect(line.pin_otr)
                    state = 10
                    break

    except KeyboardInterrupt:
        ending()
        sys.exit()
示例#8
0
def runM():
    global state, park_number, car_type, handle_data
    try:
        #interrup
        gpio.GPIO.add_event_detect(line.pin_otl, gpio.GPIO.FALLING, callback = handler)
        gpio.GPIO.add_event_detect(line.pin_otr, gpio.GPIO.FALLING, callback = handler)
        print("start parking~~")
        
        while(True):
            l,c,r = line.line_data()
            moter.setMoterControl(0, 5)

            #forward
            if(l == 1 and c == 0 and r == 1):
                print("go1")
                moter.setMoterControl(speed, 1)

            #right
            elif(l == 1 and r == 0):
                print("go2")
                moter.setMoterControl(speed, 4)

            #left
            elif(l == 0 and r == 1):
                print("go3")
                moter.setMoterControl(speed, 3)
                
            if(l == 0 and c == 0 and r == 0):
                print("go4")
                moter.setMoterControl(0, 5)
                #park_number에 10을 나누어 1번 주차장인지 2번 주차장인지 판단
                _park_number = int(park_number/10)+1
                if(_park_number != handle_data):
                    moter.setMoterControl(speed, 1)
                    time.sleep(0.5)
                else:
                    gpio.GPIO.remove_event_detect(line.pin_otl)
                    gpio.GPIO.remove_event_detect(line.pin_otr)
                    #빼내오는차 넣는차 검출
                    _data = True
                    if(car_type == 0):
                        _data = goM()
                    elif(car_type == 1):
                        _data = backM()
                    if(_data == True):
                        #제자리로
                        print('남은 주차 확인')
                        state = state + 1
                        car_type = 0
                    else:
                        #초기화 , 종료 
                        print('초기화')
                    moter.setMoterControl(0, 5)
                    break
                
    except KeyboardInterrupt:
        ending()
        sys.exit()
示例#9
0

def handler(channel):
    l, c, r = line.line_data()
    gpio.time.sleep(0.5)
    if (c == 0 and l == 0 and r == 0):
        moter.setMoterControl(0, 5)


while (True):
    l, c, r = line.line_data()

    #forward
    if (l == 1 and c == 0 and r == 1):
        #print("go1")
        moter.setMoterControl(speed, df)

    #right
    elif (l == 1 and r == 0):
        #print("go2")
        moter.setMoterControl(speed, 3)

    #left
    elif (l == 0 and r == 1):
        #print("go3")
        moter.setMoterControl(speed, 4)

    moter.setMoterControl(0, 5)

    if (l == 0 and c == 0 and r == 0):
        print("go4")
示例#10
0
import test_gpio as gpio
import test_moter as moter
import test_line as line

gpio.setting_gpio()
moter.setting()
line.setting()

moter.setMoterControl(70, 2)
moter.setMoterControl(70, 2)
moter.setMoterControl(70, 2)
moter.setMoterControl(70, 2)
moter.setMoterControl(70, 2)
moter.setMoterControl(70, 2)
moter.setMoterControl(70, 2)
moter.setMoterControl(70, 2)
moter.setMoterControl(70, 2)
moter.setMoterControl(70, 2)
moter.setMoterControl(70, 2)
moter.setMoterControl(70, 2)
moter.setMoterControl(70, 2)
moter.setMoterControl(70, 2)
moter.setMoterControl(70, 2)
moter.setMoterControl(70, 2)
moter.setMoterControl(70, 2)
moter.setMoterControl(70, 2)
gpio.cleaning()
示例#11
0
def runM():
    global state
    try:
        print("license number on")
        gpio.time.sleep(2);
        print("license number ok")

        print("send server : car on")
        gpio.time.sleep(1);
        print("recv server : go 4num")

        print("start parking~~")
        #interrup
        gpio.GPIO.add_event_detect(line.pin_otc, gpio.GPIO.FALLING, callback = handler)
        gpio.GPIO.add_event_detect(line.pin_otl, gpio.GPIO.FALLING, callback = handler)
        gpio.GPIO.add_event_detect(line.pin_otr, gpio.GPIO.FALLING, callback = handler)
        
        while(True):
            l,c,r = line.line_data()
            moter.setMoterControl(0, 5)
            #전부다 들어왔을떄
            if(c == 0 and l == 0 and r == 0):
                global interrupData
                gpio.GPIO.remove_event_detect(line.pin_otc)
                gpio.GPIO.remove_event_detect(line.pin_otl)
                gpio.GPIO.remove_event_detect(line.pin_otr)
                
                #지정 주차에 따라 오른쪽 왼쪽 앞쪽 판단 interrupt
                if(runNum%2 == 1 and runNum == interrupData):
                    print('번호 : ',runNum, '  rignt')
                    gpio.GPIO.add_event_detect(line.pin_otc, gpio.GPIO.FALLING, callback = handler)
                    while(True):
                        moter.setMoterControl(speed, 4)
                        moter.setMoterControl(0, 5)
                        l,c,r = line.line_data()
                        if(l == 1 and c == 0 and r == 1):
                            gpio.GPIO.remove_event_detect(line.pin_otc)
                            break
                elif(runNum%2 == 0 and runNum == interrupData):
                    print('번호 : ',runNum, '  left')
                    gpio.GPIO.add_event_detect(line.pin_otc, gpio.GPIO.FALLING, callback = handler)
                    while(True):
                        moter.setMoterControl(speed, 3)
                        moter.setMoterControl(0, 5)
                        l,c,r = line.line_data()
                        if(l == 1 and c == 0 and r == 1):
                            gpio.GPIO.remove_event_detect(line.pin_otc)
                            break
                else:
                    print('번호 : ',runNum, '  else')
                    gpio.GPIO.add_event_detect(line.pin_otl, gpio.GPIO.RISING, callback = handler)
                    gpio.GPIO.add_event_detect(line.pin_otr, gpio.GPIO.RISING, callback = handler)
                    while(True):
                        moter.setMoterControl(speed, 1)
                        moter.setMoterControl(0, 5)
                        l,c,r = line.line_data()
                        if(l == 1 and r == 1):
                            gpio.GPIO.remove_event_detect(line.pin_otl)
                            gpio.GPIO.remove_event_detect(line.pin_otr)
                            interrupData = interrupData + 2
                            break
                    
            #forward
            elif(l == 1 and c == 0 and r == 1):
                moter.setMoterControl(speed, 1)

            #right
            elif(l == 1 and r == 0):
                moter.setMoterControl(speed, 4)

            #left
            elif(l == 0 and r == 1):
                moter.setMoterControl(speed, 3)

            elif(l == 1 and c == 1 and r== 1):
                data = client.sendNrecv(name+' : arrive='+str(runNum))
                state = state + 1
                break
                
    except KeyboardInterrupt:
        ending()
        sys.exit()
示例#12
0
def handler(channel):
    if(runNum == 1):
        l,c,r = line.line_data()
        if(c == 0 and l == 0 and r == 0):
            moter.setMoterControl(0, 5)
            print('interrup!!!!!!!')
示例#13
0
def runT():
    global state
    try:
        print("start Deparking~~")
        #interrup
        gpio.GPIO.add_event_detect(line.pin_otc,
                                   gpio.GPIO.FALLING,
                                   callback=handler)
        gpio.GPIO.add_event_detect(line.pin_otl,
                                   gpio.GPIO.FALLING,
                                   callback=handler)
        gpio.GPIO.add_event_detect(line.pin_otr,
                                   gpio.GPIO.FALLING,
                                   callback=handler)
        #후진
        while (True):
            l, c, r = line.line_data()
            moter.setMoterControl(0, 5)

            if (c + r + l != 0):
                moter.setMoterControl(speed, 2)
            else:
                while (True):
                    l, c, r = line.line_data()
                    moter.setMoterControl(0, 5)
                    if (c + r + l == 0):
                        if (runNum % 2 == 1):
                            moter.setMoterControl(speed, 8)
                        else:
                            moter.setMoterControl(speed, 6)
                    else:
                        break
                break
        print('후진 완료 측면 후진 시작')

        #좌우 측만 후진
        while (True):
            l, c, r = line.line_data()
            moter.setMoterControl(0, 5)

            if (runNum % 2 == 1):
                if (c == 1 or l == 1 or r == 1):
                    moter.setMoterControl(speed, 8)
            elif (runNum % 2 == 0):
                if (c == 1 or l == 1 or r == 1):
                    moter.setMoterControl(speed, 6)
            if (c == 0 and l == 0 and r == 0):
                while (True):
                    l, c, r = line.line_data()
                    moter.setMoterControl(0, 5)
                    if (c + r + l == 0):
                        moter.setMoterControl(speed, 1)
                    else:
                        break
                break
        print('측면후진 완료 전진 시작')

        #후진후 전진
        while (True):
            l, c, r = line.line_data()
            moter.setMoterControl(0, 5)

            #forward
            if (l == 1 and c == 0 and r == 1):
                moter.setMoterControl(speed, 1)
            elif (l == 0 and c == 0 and r == 0):
                moter.setMoterControl(speed, 1)

            #right
            elif (l == 1 and r == 0):
                moter.setMoterControl(speed, 4)

            #left
            elif (l == 0 and r == 1):
                moter.setMoterControl(speed, 3)

            else:
                break

        gpio.GPIO.remove_event_detect(line.pin_otc)
        gpio.GPIO.remove_event_detect(line.pin_otl)
        gpio.GPIO.remove_event_detect(line.pin_otr)
        state = state + 1
    except KeyboardInterrupt:
        ending()
        sys.exit()
示例#14
0
            elif (state == 1):
                print('on')
                onM()

            elif (state == 2):
                print('check')
                checkM()

            elif (state == 3):
                if (runNum % 2 == 1):
                    interrupData = runNum % 2
                else:
                    interrupData = 2
                print('main')
                runM()
                moter.setMoterControl(0, 5)

            elif (state == 4):
                runT()
                print('stop')
                moter.setMoterControl(0, 5)

            else:
                time.sleep(4)
                print('end')

    except KeyboardInterrupt:
        ending()
        sys.exit()