예제 #1
0
def music():
    """[summary]
    Play music
    Returns:
        [type] -- [description]
    """

    robot = Robot()
    robot.send_command('music')
    data = {"1": 1}
    return json.dumps(data)
예제 #2
0
def left():
    """[summary]
    Turnning left
    Returns:
        [type] -- [description]
    """

    robot = Robot()
    robot.send_command('left')
    #distance = robot.read_from_robots()
    return json.dumps(0)
예제 #3
0
def reset_pos():
    """[summary]
    Reset the robot
    Returns:
        [type] -- [description]
    """

    robot = Robot()
    robot.send_command('reset')
    print("Reset")
    data = {"1": 1}
    return json.dumps(data)
예제 #4
0
def down():
    """[summary]
    Moving backward
    Returns:
        [type] -- [description]
    """

    robot = Robot()
    robot.send_command('backward')
    #distance = robot.read_from_robots()
    data = {"1": 1}
    return json.dumps(0)
예제 #5
0
def up():
    """[summary]
    Moving forward
    Returns:
        [type] -- [description]
    """

    robot = Robot()
    robot.send_command('forward')
    #distance = robot.read_from_robots()
    x = 0
    y = 0
    return json.dumps(0)
예제 #6
0
def send_command():
    """
    This is the function for the web page to do the\n
    background processing for the controller.

    Returns:
        The data of the objects which robot gets.
    """
    # data = {}
    # try:
    #     robot = Robot()
    #     robot.send_command('look around')

    #     done = robot.read_from_robots()
    #     while done is not True:
    #         done = robot.read_from_robots()
    #         # wait for done
    #     data = listObjects(robot, x, y)

    # # robot.move_to_smallest_obj()
    # except Exception as e:
    #     print(e)
    # return json.dumps(data)
    # thread = threading.Thread(target=robot.read_from_robots)
    # thread.start()
    ir = []
    pin = []
    data = {}
    robot = Robot()
    robot.send_command('look around')
    done = robot.read_from_robots()
    while done is not True:
        done = robot.read_from_robots()
    print(len(robot.objects))
    robot.send_command("stop")
    x = robot.x_pos
    y = robot.y_pos
    data = listObjects(robot, x, y, robot.angle)

    # Dict of ir data and ping data
    return json.dumps(data)
예제 #7
0
def get_raw_data():
    """[summary]
    This is the function for getting the raw data from robot
    Returns:
        [type] -- [description]
    """

    ir = []
    pin = []
    data = {}
    try:
        robot = Robot()
        robot.send_command('look around')
        done = robot.read_from_robots()
        while done is not True:
            done = robot.read_from_robots()
        print("Getting the raw data")
        ir_data = robot.ir_sensor_data
        ir_degress = r_to_degrees(robot.ir_sensor_radians)
        cal_ir_data = []
        for i in ir_data:
            #cal_ir_data.append(robot.calculate_the_distance(selection="use",ir_data=i))
            cal_ir_data.append(i)
        pin_data = robot.pin_sensor_data
        pin_degress = r_to_degrees(robot.pin_sensor_radians)
        robot.send_command("stop")
        for i, d in enumerate(cal_ir_data):
            ir.append([ir_degress[i], d])

        for i, d in enumerate(pin_data):
            pin.append([pin_degress[i], d])

        # Dict of ir data and ping data
        data = {'pin': pin, 'ir': ir}
    except Exception as e:
        print(e)
    return json.dumps(data)
예제 #8
0
def stop():
    """[summary]
    Stop the robot
    Returns:
        [type] -- [description]
    """

    robot = Robot()
    robot.send_command('stop')
    time.sleep(0.1)
    for i in range(2):
        robot.read_from_robots()
    # Data from robot
    #
    # obj = listObjectWhileMoving(robot.calculate_the_distance(selection="use",ir_data=robot.ir_data),
    #                             robot.x_pos,
    #                             robot.y_pos, robot.angle)
    #cancel the print object while moving
    data = {"x": robot.x_pos, "y": robot.y_pos, "angle": robot.angle}
    return json.dumps(data)
예제 #9
0
def ping():
    robot = Robot()
    robot.send_command('ping')
예제 #10
0
def auto():
    """
    Let the robot auto move
    """

    robot = Robot()
    starting_time = time.time()
    turned = False
    while True:
        robot.send_command("forward")
        time.sleep(random.uniform(1, 2))
        robot.send_command("stop")
        time.sleep(4.6)
        time.sleep(0.5)
        robot.send_command("look around")
        print("Looking around")
        done = robot.read_from_robots()
        while done is not True:
            done = robot.read_from_robots()
        robot.send_command("stop")
        time.sleep(4)
        print(len(robot.objects))

        if turned is False and time.time() - starting_time > 260:
            robot.send_command("left")
            time.sleep(4)
            robot.send_command("stop")
            turned = True

        if (len(robot.objects) > 2):
            count = 0
            for i in robot.objects:
                if i.calculate_width() < 13:
                    count = count + 1
            if (count >= 2):
                robot.send_command("music")
                robot.send_command("stop")
                print("Finished!!!")
            break
        if time.time() - starting_time > 300:
            robot.send_command("music")
            robot.send_command("stop")
            print("Finished!!!")
            break
        robot.objects = []
    return