示例#1
0
def evaluate(inp, client, l, DBlocation):
    inp = inp.split(' ')
    status = client.status()

    if len(inp) > 1 and not str(inp[1]):
        inp.pop()

    if inp[0] == 'p' or 'play' == (inp[0]):
        try:
            if not status['state'] == 'stop':
                if len(inp) == 1:
                    util.pause(client)
                else:
                    util.play(client, int(inp[1]))
            else:
                if len(inp) == 1:
                    util.play(client, 0)
                else:
                    util.play(client, int(inp[1]))
        except:
            print('mpd error: bad song index')
    elif inp[0] == 'pause':
        util.pause(client)
    elif inp[0] == 'next' or inp[0] == 'n':
        util.next(client)
    elif inp[0] == 'previous' or inp[0] == 'ps':
        util.previous(client)
    elif inp[0] == 'stop':
        util.stop(client)
    elif inp[0] == 'pl' or inp[0] == 'playlist':
        util.print_playlist(client)
    elif inp[0] == 'update' or inp[0] == 'u':
        util.update(client)
    elif inp[0] == 'clear':
        util.clear(client)
    elif inp[0] == 'random':
        util.mpdrandom(client, inp[1])
    elif inp[0] == 'shuffle':
        util.shuffle(client)
    elif inp[0] == 'consume':
        util.consume(client, inp[1])
    elif inp[0] == 'swap':
        util.swap(client, int(inp[1]) - 1, int(inp[2]) - 1)
    elif inp[0] == 'single':
        util.single(client, inp[1])
    elif inp[0] == 'search' or inp[0] == 's':
        if '-f' in inp or '--filter' in inp:
            l = util.mpdsearch(inp[1], inp, DBlocation, True)
        else:
            l = util.mpdsearch(inp[1], inp, DBlocation, False)
    elif inp[0] == 'a' or inp[0] == 'add':
        if l:
            for line in l:
                client.add(line)
        else:
            print('You have to search first!')
    elif inp[0] == 'q' or inp[0] == 'quit':
        quit()
    return l
def track_object(objs, labels):

    #global delay
    global x_deviation, y_deviation, tolerance, arr_track_data

    if (len(objs) == 0):
        print("no objects to track")
        ut.stop()
        ut.red_light("OFF")
        arr_track_data = [0, 0, 0, 0, 0, 0]
        return

    #ut.head_lights("OFF")
    k = 0
    flag = 0
    for obj in objs:
        lbl = labels.get(obj.id, obj.id)
        k = arr_valid_objects.count(lbl)
        if (k > 0):
            x_min, y_min, x_max, y_max = list(obj.bbox)
            flag = 1
            break

    #print(x_min, y_min, x_max, y_max)
    if (flag == 0):
        print("selected object no present")
        return

    x_diff = x_max - x_min
    y_diff = y_max - y_min
    print("x_diff: ", round(x_diff, 5))
    print("y_diff: ", round(y_diff, 5))

    obj_x_center = x_min + (x_diff / 2)
    obj_x_center = round(obj_x_center, 3)

    obj_y_center = y_min + (y_diff / 2)
    obj_y_center = round(obj_y_center, 3)

    #print("[",obj_x_center, obj_y_center,"]")

    x_deviation = round(0.5 - obj_x_center, 3)
    y_deviation = round(0.5 - obj_y_center, 3)

    print("{", x_deviation, y_deviation, "}")

    #move_robot()
    thread = Thread(target=move_robot)
    thread.start()
    #thread.join()

    #print(cmd)

    arr_track_data[0] = obj_x_center
    arr_track_data[1] = obj_y_center
    arr_track_data[2] = x_deviation
    arr_track_data[3] = y_deviation
def move_robot():
    global x_deviation, y_deviation, tolerance, arr_track_data
    
    print("moving robot .............!!!!!!!!!!!!!!")
    print(x_deviation, y_deviation, tolerance, arr_track_data)
    
    if(abs(x_deviation)<tolerance and abs(y_deviation)<tolerance):
        cmd="Stop"
        delay1=0
        ut.stop()
        ut.red_light("ON")
    
    else:
        ut.red_light("OFF")
        if (abs(x_deviation)>abs(y_deviation)):
            if(x_deviation>=tolerance):
                cmd="Move Left"
                delay1=get_delay(x_deviation,'l')
                
                ut.left()
                time.sleep(delay1)
                ut.stop()
                
            if(x_deviation<=-1*tolerance):
                cmd="Move Right"
                delay1=get_delay(x_deviation,'r')
                
                ut.right()
                time.sleep(delay1)
                ut.stop()
        else:
            
            if(y_deviation>=tolerance):
                cmd="Move Forward"
                delay1=get_delay(y_deviation,'f')
                
                ut.forward()
                time.sleep(delay1)
                ut.stop()
                
            if(y_deviation<=-1*tolerance):
                cmd="Move Backward"
                delay1=get_delay(y_deviation,'b')
                
                ut.back()
                time.sleep(delay1)
                ut.stop()
    
    
    arr_track_data[4]=cmd
    arr_track_data[5]=delay1
示例#4
0
def track_object(objs,labels):
   
    global x_deviation, y_max, tolerance
    
    if(len(objs)==0):
        print("no objects to track")
        ut.stop()
        ut.red_light("OFF")
        return

    k=0
    flag=0
    for obj in objs:
        lbl=labels.get(obj.id, obj.id)
        k = arr_valid_objects.count(lbl)
        if (k>0):
            x_min, y_min, x_max, y_max = list(obj.bbox)
            flag=1
            break
        
    #print(x_min, y_min, x_max, y_max)
    if(flag==0):
        print("selected object no present")
        return
        
    x_diff=x_max-x_min
    y_diff=y_max-y_min
         
    obj_x_center=x_min+(x_diff/2)
    obj_x_center=round(obj_x_center,3)
    
    obj_y_center=y_min+(y_diff/2)
    obj_y_center=round(obj_y_center,3)
    
    x_deviation=round(0.5-obj_x_center,3)
    y_max=round(y_max,3)
        
    print("{",x_deviation,y_max,"}")
   
    thread = Thread(target = move_robot)
    thread.start()
示例#5
0
def move_robot():
    global x_deviation, y_max, tolerance
    
    if(abs(x_deviation)<tolerance):
        if(y_max>0.9):
            ut.red_light("ON")
            ut.stop()
            print("reached person...........")
    
        else:
            ut.red_light("OFF")
            ut.forward()
            print("moving robot ...FORWARD....!!!!!!!!!!!!!!")
    
    
    else:
        ut.red_light("OFF")
        if(x_deviation>=tolerance):
            delay1=get_delay(x_deviation)
                
            ut.left()
            time.sleep(delay1)
            ut.stop()
            print("moving robot ...Left....<<<<<<<<<<")
    
                
        if(x_deviation<=-1*tolerance):
            delay1=get_delay(x_deviation)
                
            ut.right()
            time.sleep(delay1)
            ut.stop()
            print("moving robot ...Right....>>>>>>>>")
def move_robot():
    global x_deviation, y_max, tolerance, arr_track_data

    print("moving robot .............!!!!!!!!!!!!!!")
    print(x_deviation, tolerance, arr_track_data)

    y = 1 - y_max  #distance from bottom of the frame

    if (abs(x_deviation) < tolerance):
        delay1 = 0
        if (y < 0.1):
            cmd = "Stop"
            ut.red_light("ON")
            ut.stop()
        else:
            cmd = "forward"
            ut.red_light("OFF")
            ut.forward()

    else:
        ut.red_light("OFF")
        if (x_deviation >= tolerance):
            cmd = "Move Left"
            delay1 = get_delay(x_deviation)

            ut.left()
            time.sleep(delay1)
            ut.stop()

        if (x_deviation <= -1 * tolerance):
            cmd = "Move Right"
            delay1 = get_delay(x_deviation)

            ut.right()
            time.sleep(delay1)
            ut.stop()

    arr_track_data[4] = cmd
    arr_track_data[5] = delay1
示例#7
0
	def fin():
		my_client.close()
		if not dontrunserver:
			util.stop(pid)
示例#8
0
 def handle(self, handler_input):
     # type: (HandlerInput) -> Response
     logger.info("In PauseCommandHandler")
     return util.stop(text=None,
                      response_builder=handler_input.response_builder)
示例#9
0
 def handle(self, handler_input):
     # type: (HandlerInput) -> Response
     logger.info("In CancelOrStopIntentHandler")
     _ = handler_input.attributes_manager.request_attributes["_"]
     return util.stop(_(data.STOP_MSG), handler_input.response_builder)
示例#10
0
sys.path.insert(0, '/var/www/html/earthrover')
import util as ut

#dynamically obtain path of current file
local_path = os.path.dirname(os.path.realpath(__file__))

ut.init_gpio()

while 1:

    f1 = open(local_path + "/web/range.txt", "r+")
    distance = f1.read(20)
    f1.close()

    print("distance:", distance)

    #if due to some reason file is empty, ignore such occurance
    if (distance == "" or distance == "--"):
        print("blank file")
        continue

    if (float(distance) <
            30):  #to be removed from here, move to seperate python file
        ut.back()
        ut.speak_tts("obstacle detected", "f")
        time.sleep(1)
        ut.stop()

    time.sleep(0.2)