Exemplo n.º 1
0
def main():
    # instantiate COMM object
    gMaxRobotNum = 1  # max number of robots to control
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    print 'Bluetooth starts'
    robotList = comm.robotList

    # settings

    grid_map, all_paths, success_paths, best_path = find_best_path(
        global_rows, global_cols, global_start, global_end, global_blocks)

    root = tk.Tk()
    # gui_handle.draw_virtual_world()  # this method runs in main thread
    gui_handle = GridGraphDisplay(frame=root,
                                  blocks=global_blocks,
                                  grid_map=grid_map,
                                  all_path=all_paths,
                                  success_paths=success_paths,
                                  start=global_start,
                                  end=global_end,
                                  best_path=best_path)
    behaviors = RobotBehaviorThread(robotList, best_path, global_orientation,
                                    gui_handle)
    behaviors.setDaemon(True)
    behaviors.start()

    root.mainloop()

    return
Exemplo n.º 2
0
def drive(instructions):
    comm = RobotComm(numRobot)
    comm.start()
    gRobotList = comm.robotList
    # return
    while (len(gRobotList) < numRobot):
        print "Waiting for robots"
        time.sleep(1)
    print "Robots on board. Driving start!"
    time.sleep(3)
    index = 0
    # for i in range(numRobot):
    # 	update(numRobot, 0)
    while index < len(instructions[0]):
        print "step #%d" % (index + 1)
        threads = []
        for i in range(numRobot):
            t = Thread(name="Moving robot %d" % (i + 1),
                       target=indivDrive,
                       args=(instructions[i][index], gRobotList[i], i, index))
            t.start()
            # time.sleep(3)
            threads.append(t)
        for t in threads:
            # print "Wait"
            t.join()
        # print "I'm done!"
        index += 1
        time.sleep(1)
Exemplo n.º 3
0
    def __init__(self):
        gMaxRobotNum = 1
        # max number of robots to control
        self.comm = RobotComm(gMaxRobotNum)
        self.comm.start()
        print 'Bluetooth starts'
        robotList = self.comm.robotList
        self.robotList = robotList
        self.go = False
        self.done = False

        return
Exemplo n.º 4
0
def main():
    max_robot_num = 2  # max number of robots to control
    comm = RobotComm(max_robot_num)
    comm.start()
    print 'Bluetooth starts'
    robotList = comm.robotList

    root = tk.Tk()
    root.geometry('850x850')

    ui = GUI(root, robotList)

    root.mainloop()
Exemplo n.º 5
0
def main():
    global robotList

    comm = RobotComm(1)
    comm.start()

    robotList = comm.robotList

    frame = tk.Tk()
    graph = GridGraph()

    # grid dimension
    graph.set_grid_rows(4)
    graph.set_grid_cols(3)

    # origin of grid is (0, 0) lower left corner
    # graph.obs_list = ([1,1],)    # in case of one obs. COMMA
    graph.obs_list = ([3, 0], [2, 2])

    graph.set_start('0-0')
    graph.set_goal('2-1')

    graph.make_grid()
    graph.connect_nodes()
    graph.compute_node_locations()

    bfs = BFS(graph.nodes)
    shortest = bfs.bfs_shortest_path('0-0', '3-2')

    program = GridGraphDisplay(frame, graph)
    program.display_graph()

    program.highlight_path(shortest[0])
    print(shortest[0])

    queue = Queue.Queue()

    watcher = threading.Thread(name='watcher',
                               target=run_watcher,
                               args=(robotList, queue))
    watcher.start()

    walker = threading.Thread(name='walker',
                              target=run_walker,
                              args=(robotList, queue))
    walker.start()

    beeper = threading.Thread(name='beeper',
                              target=run_beeper,
                              args=(robotList, queue))
    beeper.start()
Exemplo n.º 6
0
def main():

    maxRobotNum = 1

    comm = RobotComm(maxRobotNum)

    comm.start()

    robotList = comm.robotList

    action = RobotActionThread(robotList)

    action.start()

    root = tk.Tk()

    root.geometry('1000x500')

    gui = GUI(root, action)

    action.line_limit = gui.lines

    root.mainloop()

    comm.stop()
    comm.join()

    return
Exemplo n.º 7
0
def main():

    q = Queue.Queue()

    comm = RobotComm(gMaxRobotNum)

    comm.start()

    print 'Bluetooth starts'

    global gRobotList

    gRobotList = comm.robotList

    frame = tk.Tk()

    t_handle = BehaviorThreads()

    gui = GUI(frame, t_handle)

    #sm = StateMachine('Main FSM', q)
    # tm = MyMachine(gui, sm)

    frame.mainloop()

    comm.stop()

    comm.join()

    print("terminated!")
Exemplo n.º 8
0
def main():
    global gRobotList

    gMaxRobotNum = 1 # max number of robots to control
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    #print 'Bluetooth starts'
    gRobotList = comm.robotList
    
    root = tk.Tk() #root

    world_handle = VirtualHamsterWorld()
    t_update_world = threading.Thread(name='update_world', target=world_handle.update_virtual_world)
    t_update_world.daemon = True
    t_update_world.start()



    gui_handle = GUIpart(root, world_handle.vworld)
    gui_handle.draw_virtual_world()     # this method runs in main thread

    world_handle.set_numref(gui_handle.numref)

    root.mainloop()

    comm.stop()
    comm.join()
Exemplo n.º 9
0
    def init_server(self):
        self.comm = RobotComm(self.max_robot_num)
        self.server = Flask(__name__)

        CORS(self.server)

        @self.server.route('/')
        def ws_status():
            return jsonify({
                'online': True,
                'robots': self.format_list()
            })

        @self.server.route('/post/<robot_id>/<path:cmd_path>')
        def ws_raw_update(robot_id, cmd_path):
            cmds = cmd_path.split('/')

            if robot_id not in self.robot_list or not self.robot_list[robot_id].active:
                return jsonify({'online': True, 'success': False, 'error': 'robot_not_found', 'cmd_path': cmds})

            if cmds[0] == 'l_motor':
                self.set_wheel(0, int(cmds[1]), robot_id=robot_id)
            elif cmds[0] == 'r_motor':
                self.set_wheel(1, int(cmds[1]), robot_id=robot_id)
            elif cmds[0] == 'a_motor':
                self.set_wheel(0, int(cmds[1]), robot_id=robot_id)
                self.set_wheel(1, int(cmds[1]), robot_id=robot_id)
            elif cmds[0] == 'e_stop':
                self.set_wheel(0, 0, robot_id=robot_id)
                self.set_wheel(1, 0, robot_id=robot_id)
            elif cmds[0] == 't_tone':
                self.set_musical_note(int(cmds[1]), robot_id=robot_id)
            else:
                return jsonify({'online': True, 'success': False, 'error': 'cmd_not_found', 'cmd_path': cmds})

            return jsonify({
                'online': True,
                'success': True,
                'robots': self.format_list(),
                'cmd_path': cmds
            })

        self.s_thread = Thread(
            name='web server', target=self.server.run,
            kwargs={'debug': True, 'use_reloader': False}
        )
        self.s_thread.setDaemon(True)
        self.ul_thread = Thread(name='list watcher', target=self.update_robot_list)
        self.ul_thread.setDaemon(True)
Exemplo n.º 10
0
def main():

    width = input("Enter graph width, from 1-10: ")
    height = input("Enter graph height, from 1-10: ")
    start_col = input("Enter starting column, from 0-" + str(width - 1) + ": ")
    start_row = input("Enter starting row, from 0-" + str(height - 1) + ": ")
    if (width > 10 or height > 10 or start_row >= height
            or start_col >= width):
        print "Out of bounds"
        return

    graph = GridGraph()
    # grid dimension
    graph.set_grid_rows(width)
    graph.set_grid_cols(height)

    # origin of grid is (0, 0) lower left corner
    # graph.obs_list = ([1,1],)    # in case of one obs. COMMA

    # graph.set_start('0-0')
    # graph.obs_list = ("2-3", "1-1", "2-1", "2-2")
    # graph.set_goal('1-2')

    # graph.set_start('0-0')
    # graph.obs_list = ("2-1", "1-2")
    # graph.set_goal('2-2')

    graph.make_grid()
    graph.connect_nodes()
    graph.compute_node_locations()

    search = KnightSearch(start_row, start_col, width, height)
    order = search.solve_tour()

    # kt = KnightSearch(8, 8)
    # kt.tour(1, [], (0,0))
    # kt.print_board()

    gMaxRobotNum = 1  # max number of robots to control
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    print 'Bluetooth starts'
    robotList = comm.robotList

    behaviors = RobotBehaviorThread(robotList)
    path = list(behaviors.make_plan(order, width))
    behaviors.path_to_plan()
    behaviors.start()

    root = tk.Tk()
    graph_display = GridGraphDisplay(root, graph, path, behaviors)
    graph_display.display_graph()
    root.mainloop()

    comm.stop()
    comm.join()
    return
Exemplo n.º 11
0
def start():
    comm = RobotComm(1)
    comm.start()

    RobotThread(comm.robotList, None).start()

    frame = tk.Tk()
    frame.mainloop()

    comm.stop()
    comm.join()
Exemplo n.º 12
0
def main(argv=None): 
    global m
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    print 'Bluetooth starts'
    m = tk.Tk() #root
    drawQueue = Queue.Queue(0)

    #creating the virtual appearance of the robot
    canvas_width = 700 # half width
    canvas_height = 380 # half height
    rCanvas = tk.Canvas(m, bg="white", width=canvas_width*2, height=canvas_height*2)

    vrobot = virtual_robot()
    pi4 = 3.1415 / 4
    #----- initialize position and angle of robot -----#
    vrobot.set_robot_a_pos(-pi4*2, 230, 0)

    joystick = Joystick(comm, m, rCanvas, vrobot)

    # visual elements of the virtual robot 
    poly_points = [0,0,0,0,0,0,0,0]
    joystick.vrobot.poly_id = rCanvas.create_polygon(poly_points, fill='blue') #robot
    joystick.vrobot.prox_l_id = rCanvas.create_line(0,0,0,0, fill="red") #prox sensors  ---- here
    joystick.vrobot.prox_r_id = rCanvas.create_line(0,0,0,0, fill="red")
    joystick.vrobot.floor_l_id = rCanvas.create_oval(0,0,0,0, outline="white", fill="white") #floor sensors
    joystick.vrobot.floor_r_id = rCanvas.create_oval(0,0,0,0, outline="white", fill="white")

    time.sleep(1)

    update_vrobot_thread = threading.Thread(target=joystick.update_virtual_robot)
    update_vrobot_thread.daemon = True
    update_vrobot_thread.start()

    #create the virtual worlds that contains the virtual robot, pass the joystick to reuse the move forward, stop, etc. functions
    # joystick should then be renamed to 'set of functions used to move robot forwards, stop robot, etc.' b/c joystick functionality is not used
    vWorld = virtual_world(drawQueue, joystick, joystick.vrobot, rCanvas, canvas_width, canvas_height)
    rectA = [-260, -20, -220, 20]
    vWorld.add_obstacle(rectA)

    draw_world_thread = threading.Thread(target=draw_virtual_world, args=(vWorld, joystick))
    draw_world_thread.daemon = True
    draw_world_thread.start()

    gui = VirtualWorldGui(vWorld, m)

    gui.drawGrid()
    gui.drawMap()

    rCanvas.after(200, gui.updateCanvas, drawQueue)
    m.mainloop()

    for robot in joystick.gRobotList:
        robot.reset()
    comm.stop()
    comm.join()
Exemplo n.º 13
0
def main(argv=None):
    gMaxRobotNum = 2  # max number of robots to control
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    print 'Bluetooth starts'
    robotList = comm.robotList

    robot_handle = Robots(robotList)
    m = tk.Tk()  #root
    gui = UI(m, robot_handle)
    print("I GOT HERE")
    m.mainloop()
    comm.stop()
    comm.join()
Exemplo n.º 14
0
def main(argv=None):
    # instantiate COMM object
    comm = RobotComm(1, -50) #maxRobot = 1, minRSSI = -50
    if comm.start():
        print 'Communication starts'
    else:
        print 'Error: communication'
        return

    # instanciate Robot
    robotList = comm.get_robotList()

    global gFrame
    gFrame = tk.Tk()
    gFrame.geometry('600x500')
    #gFrame.focus_set()
    #gFrame.bind('<KeyPress>', joystick)

    gRobotDraw = draw.RobotDraw(gFrame, tk)

    # create behaviors using set
    global gBehaviors
    gBehaviors = {}
    # gBehaviors[0] = color.Behavior("color", robotList)
    # gBehaviors[1] = sound.Behavior("sound", robotList)
    # gBehaviors[2] = motion.Behavior("motion", robotList, 10)
    # gBehaviors[3] = proxy.Behavior("proxy", robotList, 85, 0.01, gRobotDraw.get_queue())
    gBehaviors[0] = scanning.Behavior("scanning", robotList, 16.0, gRobotDraw.get_queue())

    # start behavior threads using list
    behavior_threads = []
    for i in range(0, len(gBehaviors)):
        gBehaviors[i].set_bQuit(False)
        behavior_threads.append(threading.Thread(target=gBehaviors[i].behavior_loop, name = gBehaviors[i].get_name()))

    for thread in behavior_threads:
        thread.daemon = True
        thread.start()

    gRobotDraw.start()
    gFrame.mainloop()

    for behavior in behavior_threads:
        print "joining... ", behavior.getName()
        behavior.join()
        print behavior.getName(), "joined!"

    for robot in robotList:
        robot.reset()

    comm.stop()
    comm.join()

    print("terminated!")
def drive(instructions):
    comm = RobotComm(num_robot)
    comm.start()
    robot_list = comm.robotList
    while len(robot_list) < num_robot:
        print("Waiting for robots")
        time.sleep(1)
    print("Robots on board. Start driving.")
    time.sleep(3)
    index = 0
    while index < len(instructions[0]):
        print("step #%d" % (index + 1))
        threads = []
        for i in range(num_robot):
            ti = Thread(name="Moving robot %d" % (i + 1), target=drive_one_instruction,
                       args=(instructions[i][index], robot_list[i], i, index))
            ti.start()
            threads.append(ti)
        for ti in threads:
            ti.join()
        index += 1
        time.sleep(1)
Exemplo n.º 16
0
def main():
    max_robot_num = 1  # max number of robots to control
    comm = RobotComm(max_robot_num)
    comm.start()
    print 'Bluetooth starts'
    robotList = comm.robotList

    root = tk.Tk()
    t_handle = BehaviorThreads(robotList)
    gui = GUI(root, t_handle)

    root.mainloop()

    comm.stop()
    comm.join()
Exemplo n.º 17
0
def main(argv=None):
    gMaxRobotNum = 1 # max number of robots to control
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    print 'Bluetooth starts'
    robotList = comm.robotList

    robot_handle = Robots(robotList)
    m = tk.Tk() #m is tk.Tk() and root
    gui = UI(m, robot_handle) #m is tk.Tk() and root

    m.mainloop() # stop the program from ending. mainloop() is in tkinterface

    comm.stop()
    comm.join()
Exemplo n.º 18
0
def main():
  
    global gRobotList

    gMaxRobotNum = 1 
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    print 'Bluetooth starts'
    gRobotList = comm.robotList

    frame = tk.Tk()
    frame.mainloop()

    comm.stop()
    comm.join()
    print("terminated!")
def main():
    gMaxRobotNum = 1  # max number of robots to control
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    print 'Bluetooth starts'

    robot_list = comm.robotList
    behaviors = RobotBehavior(robot_list)

    frame = tk.Tk()
    GUI(frame, behaviors)
    frame.mainloop()

    comm.stop()
    comm.join()
    return
Exemplo n.º 20
0
def main():
    global gRobotList
    
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    print 'Bluetooth starts'
    gRobotList = comm.robotList
    #if don't want to connect to real robot
    #gRobotList = []
    m = tk.Tk() #root

    client = ThreadedVirtualWorld(m)
    m.mainloop()

    comm.stop()
    comm.join()
Exemplo n.º 21
0
def main(argv=None):
    global m
    global comm
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    print 'Bluetooth starts'
    m = tk.Tk() #root
    drawQueue = Queue.Queue(0)

    #creating tje virtual appearance of the robot
    canvas_width = 700 # half width
    canvas_height = 380 # half height
    rCanvas = tk.Canvas(m, bg="white", width=canvas_width*2, height=canvas_height*2)

    joystick = Joystick(comm, m, rCanvas, robot1_config)

    # visual elements of the virtual robot
    poly_points = [0,0,0,0,0,0,0,0]
    joystick.vrobot.poly_id = rCanvas.create_polygon(poly_points, fill='blue') #robot
    joystick.vrobot.prox_l_id = rCanvas.create_line(0,0,0,0, fill="red") #prox sensors
    joystick.vrobot.prox_r_id = rCanvas.create_line(0,0,0,0, fill="red")
    joystick.vrobot.floor_l_id = rCanvas.create_oval(0,0,0,0, outline="white", fill="white") #floor sensors
    joystick.vrobot.floor_r_id = rCanvas.create_oval(0,0,0,0, outline="white", fill="white")

    time.sleep(1)

    update_vrobot_thread = threading.Thread(target=joystick.update_virtual_robot)
    update_vrobot_thread.daemon = True
    update_vrobot_thread.start()

    #create the virtual worlds that contains the virtual robot
    vWorld = virtual_world(drawQueue, joystick.vrobot, rCanvas, canvas_width, canvas_height)

    boxes = [[0, 0, 40, 100] ,[40, 80, 140, 120] ,[120, -80, 200, 0] ,[0, -80, 40, -180] ,[40, -180, 300, -220] ,[300, -180, 340, 200] ,[300, 200, 0, 240]]
    for box in boxes:
        vWorld.add_obstacle(box)

    draw_world_thread = threading.Thread(target=draw_virtual_world, args=(vWorld, joystick))
    draw_world_thread.daemon = True
    draw_world_thread.start()

    gui = VirtualWorldGui(vWorld, joystick, m)

    rCanvas.after(200, gui.updateCanvas, drawQueue)
    m.mainloop()


    for robot in joystick.gRobotList:
        robot.reset()
    comm.stop()
    comm.join()
Exemplo n.º 22
0
def main():
    # instantiate COMM object
    gMaxRobotNum = 1; # max number of robots to control
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    print 'Bluetooth starts'  
    robotList = comm.robotList

    behaviors = RobotBehaviorThread(robotList)
    behaviors.start()

    frame = tk.Tk()
    GUI(frame, behaviors)
    frame.mainloop()

    comm.stop()
    comm.join()
    print("terminated!")
def main(argv=None):
    gMaxRobotNum = 1  # max number of robots to control
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    print 'Bluetooth starts'
    robotList = comm.robotList

    robot_handle = Robots(robotList)
    m = tk.Tk()  #root
    gui = UI(m, robot_handle)

    b2 = tk.Button(m, text='Exit')
    b2.pack(side='left')
    b2.bind('<Button-2>', UI.stopProg)

    m.mainloop()

    comm.stop()
    comm.join()
Exemplo n.º 24
0
def main():
    graph = GridGraph()
    # grid dimension
    graph.set_grid_rows(4)
    graph.set_grid_cols(3)

    # origin of grid is (0, 0) lower left corner
    # graph.obs_list = ([1,1],)    # in case of one obs. COMMA

    graph.set_start('0-2')
    graph.obs_list = ("2-3", "1-1", "2-1", "2-2")
    graph.set_goal('3-2')

    # graph.set_start('0-0')
    # graph.obs_list = ("2-1", "1-2")
    # graph.set_goal('2-2')

    graph.make_grid()
    graph.connect_nodes()
    graph.compute_node_locations()

    bfs = BFS(graph.nodes)
    path = bfs.bfs_shortest_path(graph.get_start_node(), graph.get_goal_node())

    gMaxRobotNum = 1  # max number of robots to control
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    print 'Bluetooth starts'
    robotList = comm.robotList

    behaviors = RobotBehaviorThread(robotList)
    behaviors.make_plan(path)
    behaviors.start()

    root = tk.Tk()
    graph_display = GridGraphDisplay(root, graph, behaviors)
    graph_display.display_graph(path, graph.get_start_node(),
                                graph.get_goal_node())

    comm.stop()
    comm.join()
    return
Exemplo n.º 25
0
def main(argv=None):

    paths = getPaths(1000, 600, 500, 200)
    drawList.append((500, 200))
    drawList.append((1500, 200))
    drawList.append((500, 800))
    drawList.append((1500, 800))

    # instantiate COMM object
    comm = RobotComm(2, -50) #maxRobot = 1, minRSSI = -50
    if comm.start():
        print 'Communication starts'
    else:
        print 'Error: communication'
        return

    # instantiate Robot
    robotList = comm.get_robotList()

    # create behaviors using set
    global gBehaviors
    gBehaviors = {}

    # start behavior threads using list
    behavior_threads = []
    behavior_threads.append(threading.Thread(target=command, args=(paths, robotList)))

    for thread in behavior_threads:
        thread.daemon = True
        thread.start()

    # start the cv thread
    main_thread()

    for behavior in behavior_threads:
        print "joining... ", behavior.getName()
        behavior.join()
        print behavior.getName(), "joined!"

    for robot in robotList:
        robot.reset()


    comm.stop()
    comm.join()

    print("terminated!")
Exemplo n.º 26
0
def main():
    max_robot_num = 1  # max number of robots to control
    comm = RobotComm(max_robot_num)
    comm.start()
    print 'Bluetooth starts'
    robotList = comm.robotList

    root = tk.Tk()
    # t_handle = BehaviorThreads(robotList)
    # gui = GUI(root, t_handle)

    mThread = threading.Thread(name="main thread",
                               target=mainThread,
                               args=[robotList])
    mThread.daemon = True
    mThread.start()

    root.mainloop()

    comm.stop()
    comm.join()
Exemplo n.º 27
0
def main(argv=None):
    gMaxRobotNum = 1
    # max number of robots to control
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    print 'Bluetooth starts'
    robotList = comm.robotList

    robot_moves = RobotMoves(robotList)
    m = tk.Tk()  #root
    gui = UI(m, robot_moves)

    # start a watcher thread
    display = SensorDisplayThread(gui.canvas, robotList)
    display.setDaemon(True)
    display.start()

    m.mainloop()

    comm.stop()
    comm.join()
Exemplo n.º 28
0
def main(argv=None):
    # instantiate COMM object
    comm = RobotComm(1, -50) #maxRobot = 1, minRSSI = -50
    if comm.start():
        print 'Communication starts'
    else:
        print 'Error: communication'
        return

    # instantiate Robot
    robotList = comm.get_robotList()

    # instantiate global variables gFrame and gBehavior
    settings.init()

    settings.gFrame = tk.Tk()
    settings.gFrame.geometry('600x500')

    gRobotDraw = draw.RobotDraw(settings.gFrame, tk)

    # create behaviors
    settings.gBehaviors[0] = scanning.Behavior("scanning", robotList, 4.0, gRobotDraw.get_queue())
    settings.gBehaviors[1] = collision.Behavior("collision", robotList, -50)

    gRobotDraw.start()
    settings.gFrame.mainloop()
    
    for behavior in behavior_threads:
        print "joining... ", behavior.getName()
        behavior.join()
        print behavior.getName(), "joined!"

    for robot in robotList:
        robot.reset()

    comm.stop()
    comm.join()

    print("terminated!")
Exemplo n.º 29
0
def main():
    grid = [4,4]
    obs=[]
    a = input("Enter an obs or enter 0")
    while (a != 0):
        obs.append(a)
        a = input("Enter an obs or enter 0")
    
    # start_node = str(input("Start Node (x-x):"))
    # end_node = str(input("End Node (x-x):"))
    start_node = '1-1'
    start_int = [1,1]
    end_node = '4-4'
    end_int = [4,4]
    graph, nodes_location = graphgen.main(grid,obs)
    
    print 'graph:', graph

    frame = tk.Tk()
    frame.title('Simple Graph Display')
    frame.geometry("400x400")
    display = tk_simple_graph_display.SimpleGraphDisplay(frame, graph, nodes_location, start_node, end_node)

    bfs = bfs_engine.BFS(graph)
    p = bfs.bfs_shortest_path(start_node, end_node)
    l = display.highlight_path(p)
    gMaxRobotNum = 1; # max number of robots to control
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    print 'Bluetooth starts'
    robotList = comm.robotList
    movem = movements.move(l, start_int, end_int,robotList)
    movem.start()
    frame.mainloop()
  
    comm.stop()
    comm.join()
    print("terminated!")
Exemplo n.º 30
0
def start(periodicFunc):
    global robotList, func
    func = periodicFunc
    comm = RobotComm(1)
    comm.start()
    print("Bluetooth running...")

    robotList = comm.robotList

    window = tk.Tk()
    canvas = tk.Canvas(window, bg="white", width = 100, height = 100)
    canvas.pack()

    button = tk.Button(window, text="Exit")
    button.pack()
    button.bind("<Button-1>", lambda _: shutdown(window))

    robotThread = Thread(target = runRobot)
    robotThread.start()
    window.mainloop()

    comm.stop()
    comm.join()
Exemplo n.º 31
0
def main():
    global gRobotList

    gMaxRobotNum = 0  # max number of robots to control
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    print 'Bluetooth starts'
    gRobotList = comm.robotList

    root = tk.Tk()  #root
    root.geometry = "630x880"
    world_handle = VirtualWorld(root)
    t_update_world = threading.Thread(name='update_world',
                                      target=world_handle.update_virtual_world)
    t_update_world.daemon = True
    t_update_world.start()

    gui_handle = GUI(root, world_handle.vworld, world_handle.stopProg)
    gui_handle.draw_virtual_world()  # this method runs in main thread

    root.mainloop()

    comm.stop()
    comm.join()
Exemplo n.º 32
0
def start(periodicFunc, mapClickCallback, imageClickCallback):
    global robotList, func
    func = periodicFunc
    comm = RobotComm(1)
    comm.start()
    print("Bluetooth running...")

    robotList = comm.robotList

    window = tk.Tk()

    image = np.zeros((1080, 960, 3), dtype=np.uint8)
    image = Image.fromarray(image)
    image = ImageTk.PhotoImage(image)

    imagePanel = tk.Label(image=image)
    imagePanel.image = image
    imagePanel.bind("<Button-1>", imageClickCallback)
    imagePanel.pack(side="top", padx=10, pady=10)

    def _updateImage(img):
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        img = Image.fromarray(img)
        img = ImageTk.PhotoImage(img)

        imagePanel.configure(image=img)
        imagePanel.image = img

    image2 = np.zeros((1080, 960, 3), dtype=np.uint8)
    image2 = Image.fromarray(image2)
    image2 = ImageTk.PhotoImage(image2)

    imagePanel2 = tk.Label(image=image2, borderwidth=2, relief="solid")
    imagePanel2.image = image2

    imagePanel2.bind("<Button-1>", mapClickCallback)

    imagePanel2.pack(side="bottom", padx=10, pady=10)

    def _updateImage2(img):
        img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        img = Image.fromarray(img)
        img = ImageTk.PhotoImage(img)

        imagePanel2.configure(image=img)
        imagePanel2.image = img

    global updateImageFunc
    updateImageFunc = _updateImage

    global updateImage2Func
    updateImage2Func = _updateImage2

    button = tk.Button(window, text="Exit")
    button.pack()
    button.bind("<Button-1>", lambda _: shutdown(window))

    robotThread = Thread(target=runRobot)
    robotThread.start()
    window.mainloop()

    comm.stop()
    comm.join()
Exemplo n.º 33
0
def main(argv=None):
    global m, comm
    global sleepTime
    sleepTime = 0.01
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    print 'Bluetooth starts'
    m = tk.Tk() #root
    drawQueue = Queue.Queue(0)

    global lastMoveDirection
    lastMoveDirection = "NORTH"

    canvas_width = 500 #original: 700 # half width
    canvas_height = 200 # original 380half height
    rCanvas = tk.Canvas(m, bg="black", width=canvas_width*2, height=canvas_height*2)

    global joystick
    
    joystick = Joystick(comm, m, rCanvas)

    # visual elements of the virtual robots
    pacman_points = [0,0,0,0,0,0,0,0]
    blinky_points = [120,120,120,120,120,120,120,120]
    inky_points =[-120,-120,-120,-120,-120,-120,-120,-120]
    poly_points = [pacman_points, blinky_points, inky_points]
    colors = ['yellow', 'red', 'cyan']
    for agentIndex in range(3):
        joystick.vrobots[agentIndex].poly_id = rCanvas.create_polygon(poly_points[agentIndex], fill=colors[agentIndex]) #robots, pacman, blinky(top right), inky(bottom left)
        joystick.vrobots[agentIndex].prox_l_id = rCanvas.create_line(0,0,0,0, fill="red") #prox sensors
        joystick.vrobots[agentIndex].prox_r_id = rCanvas.create_line(0,0,0,0, fill="red")
        joystick.vrobots[agentIndex].floor_l_id = rCanvas.create_oval(0,0,0,0, outline="white", fill="white") #floor sensors
        joystick.vrobots[agentIndex].floor_r_id = rCanvas.create_oval(0,0,0,0, outline="white", fill="white")
    
    time.sleep(1)

    #create the virtual worlds that contains the virtual robot

    vWorld = virtual_world(drawQueue, joystick.vrobots, rCanvas, canvas_width, canvas_height)
    
    ''' objects in the world '''
    rectangles = []
    pellets = []
    super_pellets = []
    
    # pacman map/walls
    rectangles.append([-150, -150, 150, 150]) #overall square
    rectangles.append([-90, 90, -30, 30])
    rectangles.append([90, 90, 30, 30])
    rectangles.append([-90, -90, -30, -30])
    rectangles.append([90, -90, 30, -30])


    #pacman pellets/capsules/food
    for index_x in range(BOARD_SIZE):
        for index_y in range(BOARD_SIZE):
            x_position = -120 + (60*index_x)
            y_position = -120 + (60*index_y)
            if (index_x == 0 and index_y == 4) or (index_x == 4 and index_y == 0):
                new_super_pellet = [x_position, y_position]
                super_pellets.append(new_super_pellet)
            elif not ((index_x == 0 and index_y == 0) or (index_x ==2 and index_y == 2) or (index_x ==4 and index_y ==4) or (index_x == 1 and index_y == 1) or (index_x == 3 and index_y == 1) or (index_x == 1 and index_y == 3) or (index_x==3 and index_y==3)):
                new_pellet = [x_position, y_position]
                pellets.append(new_pellet)

    vWorld.add_score_label([175,-175])

    for pill in pellets:
        vWorld.add_pellet(pill)
    for super_pill in super_pellets:
        vWorld.add_super_pellet(super_pill)
    for rect in rectangles:
        vWorld.add_obstacle(rect)


    draw_world_thread = threading.Thread(target=draw_virtual_world, args=(vWorld, joystick))
    draw_world_thread.daemon = True
    draw_world_thread.start()

    gui = VirtualWorldGui(vWorld, m)

    gui.drawGrid()
    gui.drawMap()

    rCanvas.after(200, gui.updateCanvas, drawQueue)
    m.mainloop()

    for robot in joystick.gRobotList:
        robot.reset()
    comm.stop()
    comm.join()
Exemplo n.º 34
0
Arquivo: ai.py Projeto: crognale/cs123
def main():
  global gRobotList, gQuit
  global gCanvas, frame, gHamsterBox
  global display_thread, monitor_thread, dispatch_thread
  global gBeepQueue, gWheelQueue, drawQueue
  global vWorld

  comm = RobotComm(gMaxRobotNum)
  comm.start()
  print 'Bluetooth started'

  gRobotList = comm.robotList

  monitor_thread = False
  dispatch_thread= False

  display_thread = False

  # create UI
  frame = tk.Tk()
  canvas_width = 700 # half width
  canvas_height = 380 # half height
  gCanvas = tk.Canvas(frame, bg="white", width=canvas_width*2, height=canvas_height*2)
  draw_track()

  vrobot =  virtual_robot()
  pi4 = 3.1415 / 4

  # robot starting positions
  vrobot.set_robot_a_pos(pi4*2, -520, 340)

  # keyboard input
  joystick =  Joystick(comm, frame, gCanvas, vrobot)
  poly_points = [0,0,0,0,0,0,0,0]
  joystick.vrobot.poly_id = gCanvas.create_polygon(poly_points, fill='blue') #robot
  joystick.vrobot.prox_l_id = gCanvas.create_line(0,0,0,0, fill="red") #prox sensors  ---- here
  joystick.vrobot.prox_r_id = gCanvas.create_line(0,0,0,0, fill="red")
  joystick.vrobot.floor_l_id = gCanvas.create_oval(0,0,0,0, outline="white", fill="white") #floor sensors
  joystick.vrobot.floor_r_id = gCanvas.create_oval(0,0,0,0, outline="white", fill="white")

  time.sleep(1)

  update_vrobot_thread = threading.Thread(target=joystick.update_virtual_robot)
  update_vrobot_thread.daemon = True
  update_vrobot_thread.start()


  # virtual world UI
  drawQueue = Queue.Queue(0)
  vWorld = virtual_world(drawQueue, joystick, vrobot, gCanvas, canvas_width, canvas_height)
  landmark = [-500, 220, -460, 180]
  vWorld.add_obstacle(landmark)

  draw_world_thread = threading.Thread(target=draw_virtual_world, args=(vWorld,))
  draw_world_thread.daemon = True
  draw_world_thread.start()

  gui = VirtualWorldGui(vWorld, frame)

  gui.drawGrid()
  gui.drawMap()

  gCanvas.after(200, gui.updateCanvas, drawQueue)
  frame.mainloop()

  gQuit = True

  for robot in gRobotList:
    robot.reset()
  time.sleep(1.0)
  comm.stop()
  comm.join()

  print 'Terminated'
def main(argv=None):
    global m
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    print 'Bluetooth starts'
    m = tk.Tk()  #root
    drawQueue = Queue.Queue(0)

    #creating the virtual appearance of the robot
    canvas_width = 700  # half width
    canvas_height = 380  # half height
    rCanvas = tk.Canvas(m,
                        bg="white",
                        width=canvas_width * 2,
                        height=canvas_height * 2)

    vrobot = virtual_robot()
    pi4 = 3.1415 / 4
    #----- initialize position and angle of robot -----#
    vrobot.set_robot_a_pos(-pi4 * 2, 230, 0)

    joystick = Joystick(comm, m, rCanvas, vrobot)

    # visual elements of the virtual robot
    poly_points = [0, 0, 0, 0, 0, 0, 0, 0]
    joystick.vrobot.poly_id = rCanvas.create_polygon(poly_points,
                                                     fill='blue')  #robot
    joystick.vrobot.prox_l_id = rCanvas.create_line(
        0, 0, 0, 0, fill="red")  #prox sensors  ---- here
    joystick.vrobot.prox_r_id = rCanvas.create_line(0, 0, 0, 0, fill="red")
    joystick.vrobot.floor_l_id = rCanvas.create_oval(
        0, 0, 0, 0, outline="white", fill="white")  #floor sensors
    joystick.vrobot.floor_r_id = rCanvas.create_oval(0,
                                                     0,
                                                     0,
                                                     0,
                                                     outline="white",
                                                     fill="white")

    time.sleep(1)

    update_vrobot_thread = threading.Thread(
        target=joystick.update_virtual_robot)
    update_vrobot_thread.daemon = True
    update_vrobot_thread.start()

    #create the virtual worlds that contains the virtual robot, pass the joystick to reuse the move forward, stop, etc. functions
    # joystick should then be renamed to 'set of functions used to move robot forwards, stop robot, etc.' b/c joystick functionality is not used
    vWorld = virtual_world(drawQueue, joystick, joystick.vrobot, rCanvas,
                           canvas_width, canvas_height)
    #objects in the world
    rectF = [0, -50, 40, 50]
    rectE = [-100, -180, 0, -140]
    rectD = [-140, -180, -100, -80]
    rectC = [-100, 140, 0, 180]
    rectB = [-140, 80, -100, 180]
    rectA = [-260, -20, -220, 20]
    vWorld.add_obstacle(rectF)
    vWorld.add_obstacle(rectE)
    vWorld.add_obstacle(rectD)
    vWorld.add_obstacle(rectC)
    vWorld.add_obstacle(rectB)
    vWorld.add_obstacle(rectA)

    draw_world_thread = threading.Thread(target=draw_virtual_world,
                                         args=(vWorld, joystick))
    draw_world_thread.daemon = True
    draw_world_thread.start()

    gui = VirtualWorldGui(vWorld, m)

    # #---- create a new thread to update the physical robot
    # update_probot_thread = threading.Thread(target=gui.nextStep)
    # update_probot_thread.daemon = True
    # update_probot_thread.start()

    gui.drawGrid()
    gui.drawMap()

    rCanvas.after(200, gui.updateCanvas, drawQueue)
    m.mainloop()

    #---------------- Automatically scan for box (not needed for assignment) --------------#

    # start a state machine and set initial state (unnecessary)

    # set up event queue

    # define dispatcher

    # define handler

    for robot in joystick.gRobotList:
        robot.reset()
    comm.stop()
    comm.join()
Exemplo n.º 36
0
class PathFollower():
    def __init__(self):
        gMaxRobotNum = 1
        # max number of robots to control
        self.comm = RobotComm(gMaxRobotNum)
        self.comm.start()
        print 'Bluetooth starts'
        robotList = self.comm.robotList
        self.robotList = robotList
        self.go = False
        self.done = False

        return

    def run(self, path):
        robot = None
        #0:N, 1:E, 2:S, 3:W
        currentDir = 0
        while not self.done:
            for robot in self.robotList:
                if robot and self.go:
                    #############################################
                    # START OF YOUR WORKING AREA!!!
                    #############################################
                    speed = 40
                    # robot.set_wheel(0, 0)
                    # robot.set_wheel(1,0)
                    robot.set_wheel(0, speed)
                    robot.set_wheel(1, speed)
                    left = robot.get_floor(0)
                    right = robot.get_floor(1)
                    # print("Left: " + str(left)+"\t"+"Right: "+str(right))

                    if right < 75 and left < 75:
                        #intersection??
                        robot.set_wheel(0, speed)
                        robot.set_wheel(1, speed)
                        time.sleep(0.2)
                        robot.set_wheel(0, 0)
                        robot.set_wheel(1, 0)

                        left = robot.get_floor(0)
                        right = robot.get_floor(1)
                        if (True):
                            nextDir = path[0]
                            del path[0]
                            robot.set_musical_note(40)
                            time.sleep(0.1)
                            robot.set_musical_note(0)

                            tTime = 0.6
                            #straight
                            if nextDir == currentDir:
                                print("GOING straight")
                            #right
                            elif nextDir == currentDir + 1 or (
                                    nextDir == 0 and currentDir == 3):
                                print("TURNING RIGHT")
                                robot.set_wheel(0, 50)
                                robot.set_wheel(1, -50)
                                time.sleep(tTime)
                                #left
                            elif nextDir == currentDir - 1 or (
                                    nextDir == 3 and currentDir == 0):
                                print("TURNING LEFT")
                                robot.set_wheel(0, -50)
                                robot.set_wheel(1, 50)
                                time.sleep(tTime)
                            elif nextDir == (currentDir + 2) % 4:
                                print("TURNING AROUND???")
                                robot.set_wheel(0, 50)
                                robot.set_wheel(1, -50)
                                time.sleep(2 * tTime)
                            currentDir = nextDir

                    elif (right - left) > 15:
                        robot.set_wheel(1, speed)
                        robot.set_wheel(0, 0)
                        # print("Turning Left")
                        time.sleep(0.03)
                    elif (left - right) > 15:
                        robot.set_wheel(0, speed)
                        robot.set_wheel(1, 0)
                        # print("Turning Right")
                        time.sleep(0.03)

    def runPath(self, path):
        self.go = True
        thread = threading.Thread(name="Run Thread",
                                  target=self.run,
                                  args=[path])
        thread.daemon = True
        thread.start()

    def exit(self):
        self.go = False
        self.done = True
        self.comm.stop()
        self.comm.join()
        print("terminated!")
        sys.exit(0)
Exemplo n.º 37
0
def main():
  global gRobotList, gQuit
  global gCanvas, frame, gHamsterBox
  global monitor_thread, dispatch_thread
  global gBeepQueue, gWheelQueue, drawQueue
  global vWorld
  global joystick

  comm = RobotComm(gMaxRobotNum)
  comm.start()
  print 'Bluetooth started'

  gRobotList = comm.robotList

  monitor_thread = False
  dispatch_thread= False

  # create UI: two separate Tkinter windows
  # 1. frame = course track display
  # 2. gFrame = localization scanning display
  frame = tk.Tk()
  canvas_width = 700 # half width
  canvas_height = 380 # half height
  gCanvas = tk.Canvas(frame, bg="white", width=canvas_width*2, height=canvas_height*2)
  draw_track()

  settings.init()
  settings.gFrame = tk.Tk()
  settings.gFrame.geometry('600x500')
  gRobotDraw = draw.RobotDraw(settings.gFrame, tk)
  # create scanning behavior
  settings.gBehaviors[0] = scanning.Behavior("scanning", gRobotList, 4.0, gRobotDraw.get_queue())

  gRobotDraw.start()

  # create 2 virtual robot data objects
  vrobot = []
  joystick = []
  keyBindings = []
  for robot_i in range(gMaxRobotNum):
    vrobot.append ( virtual_robot() )
    pi4 = 3.1415 / 4

    # robot starting positions
    vrobot[robot_i].set_robot_a_pos(pi4*2, -520 + robot_i * 40, +340 - robot_i * 80)

    # keyboard input
    if robot_i == 0:
      keyBindings = ['w','s','a','d','x']
    elif robot_i == 1:
      keyBindings = ['i','k','j','l',',']
    joystick.append( Joystick(comm, frame, gCanvas, vrobot[robot_i], robot_i, keyBindings) )
    poly_points = [0,0,0,0,0,0,0,0]
    joystick[robot_i].vrobot.poly_id = gCanvas.create_polygon(poly_points, fill='blue') #robot
    joystick[robot_i].vrobot.prox_l_id = gCanvas.create_line(0,0,0,0, fill="red") #prox sensors  ---- here
    joystick[robot_i].vrobot.prox_r_id = gCanvas.create_line(0,0,0,0, fill="red")
    joystick[robot_i].vrobot.floor_l_id = gCanvas.create_oval(0,0,0,0, outline="white", fill="white") #floor sensors
    joystick[robot_i].vrobot.floor_r_id = gCanvas.create_oval(0,0,0,0, outline="white", fill="white")

    time.sleep(1)

    update_vrobot_thread = threading.Thread(target=joystick[robot_i].update_virtual_robot)
    update_vrobot_thread.daemon = True
    update_vrobot_thread.start()

  # virtual world UI
  drawQueue = Queue.Queue(0)
  vWorld = virtual_world(drawQueue, joystick[0], vrobot[0], gCanvas, canvas_width, canvas_height)
  landmark = [-500, 220, -460, 180]
  vWorld.add_obstacle(landmark)

  draw_world_thread = threading.Thread(target=draw_virtual_world, args=(vWorld,))
  draw_world_thread.daemon = True
  draw_world_thread.start()

  gui = VirtualWorldGui(vWorld, frame)

  gui.drawGrid()
  gui.drawMap()

  gCanvas.after(200, gui.updateCanvas, drawQueue)
  frame.mainloop()

  gQuit = True

  for robot in gRobotList:
    robot.reset()
  time.sleep(1.0)
  comm.stop()
  comm.join()

  print 'Terminated'
def main(argv=None): 
    global m
    comm = RobotComm(gMaxRobotNum)
    comm.start()
    print 'Bluetooth starts'
    m = tk.Tk() #root
    drawQueue = Queue.Queue(0)

    #creating the virtual appearance of the robot
    canvas_width = 700 # half width
    canvas_height = 380 # half height
    rCanvas = tk.Canvas(m, bg="white", width=canvas_width*2, height=canvas_height*2)

    vrobot = virtual_robot()
    pi4 = 3.1415 / 4
    #----- initialize position and angle of robot -----#
    vrobot.set_robot_a_pos(-pi4*2, 230, 0)

    joystick = Joystick(comm, m, rCanvas, vrobot)

    # visual elements of the virtual robot 
    poly_points = [0,0,0,0,0,0,0,0]
    joystick.vrobot.poly_id = rCanvas.create_polygon(poly_points, fill='blue') #robot
    joystick.vrobot.prox_l_id = rCanvas.create_line(0,0,0,0, fill="red") #prox sensors  ---- here
    joystick.vrobot.prox_r_id = rCanvas.create_line(0,0,0,0, fill="red")
    joystick.vrobot.floor_l_id = rCanvas.create_oval(0,0,0,0, outline="white", fill="white") #floor sensors
    joystick.vrobot.floor_r_id = rCanvas.create_oval(0,0,0,0, outline="white", fill="white")

    time.sleep(1)

    update_vrobot_thread = threading.Thread(target=joystick.update_virtual_robot)
    update_vrobot_thread.daemon = True
    update_vrobot_thread.start()

    #create the virtual worlds that contains the virtual robot, pass the joystick to reuse the move forward, stop, etc. functions
    # joystick should then be renamed to 'set of functions used to move robot forwards, stop robot, etc.' b/c joystick functionality is not used
    vWorld = virtual_world(drawQueue, joystick, joystick.vrobot, rCanvas, canvas_width, canvas_height)
    #objects in the world
    rectF = [0, -50, 40, 50]
    rectE = [-100, -180, 0, -140]
    rectD = [-140, -180, -100, -80]
    rectC = [-100, 140, 0, 180]
    rectB = [-140, 80, -100, 180]
    rectA = [-260, -20, -220, 20]
    vWorld.add_obstacle(rectF)
    vWorld.add_obstacle(rectE)
    vWorld.add_obstacle(rectD)
    vWorld.add_obstacle(rectC)
    vWorld.add_obstacle(rectB)
    vWorld.add_obstacle(rectA)

    draw_world_thread = threading.Thread(target=draw_virtual_world, args=(vWorld, joystick))
    draw_world_thread.daemon = True
    draw_world_thread.start()

    gui = VirtualWorldGui(vWorld, m)

    # #---- create a new thread to update the physical robot
    # update_probot_thread = threading.Thread(target=gui.nextStep)
    # update_probot_thread.daemon = True
    # update_probot_thread.start()

    gui.drawGrid()
    gui.drawMap()

    rCanvas.after(200, gui.updateCanvas, drawQueue)
    m.mainloop()


    #---------------- Automatically scan for box (not needed for assignment) --------------# 

    # start a state machine and set initial state (unnecessary)

    # set up event queue

    # define dispatcher

    # define handler


    for robot in joystick.gRobotList:
        robot.reset()
    comm.stop()
    comm.join()