Beispiel #1
0
    def handle_dialog(self, curr_state, dev, observer):
        if self.disallow_dialog:
            return False

        if curr_state.get('tree', None) is None:
            return False
        tree = curr_state.get('tree')
        ret = dialog.detect_dialog(tree)
        if not ret[0]:
            return False

        # sometimes pop up slowly
        dev.wait_idle()
        gui_state = observer.grab_state(dev, no_img=True)
        curr_state.merge(gui_state)
        tree = curr_state.get('tree')
        ret = dialog.detect_dialog(tree)
        if not ret[0]:
            return False

        logger.info("dialog detected")
        buttonsid = ret[1]

        if len(buttonsid) == 1:
            logger.info("single button dialog")
            # what else can you do?
            loc = locator.itemid_locator(buttonsid[0])
            op = operation.Operation("click", loc)
            ret = op.do(dev, observer, curr_state, environ.empty, self)
            gui_state = observer.grab_state(dev)
            curr_state.merge(gui_state)
            return ret

        if len(buttonsid) == 0:
            logger.info("no buttons")
            return False

        types = {}
        for buttonid in buttonsid:
            logger.info("%s", util.describe_node(tree[buttonid], short=True))
            button_type = dialog.detect_dialog_button(tree, buttonid, buttonsid)
            if button_type is None:
                return False
            types[button_type] = buttonid

        action_to_do = dialog.decide_dialog_action(tree)
        logger.info("types: %s,  decide to click %s", types, action_to_do)
        if action_to_do in types:
            loc = locator.itemid_locator(types[action_to_do])
            op = operation.Operation("click", loc)
            ret = op.do(dev, observer, curr_state, environ.empty, self)
            gui_state = observer.grab_state(dev)
            curr_state.merge(gui_state)
            return ret
        else:
            logger.info("can't find the decided action")
            return False
Beispiel #2
0
def move_to_dest(session, current_robot_pose, goal):
    op = operation.Operation()
    pi = math.pi
    current_positon = current_robot_pose
    motion_service = session.service("ALMotion")
    memory_service = session.service("ALMemory")
    theta_difference = op.normalize_angle(goal[2] - current_robot_pose[2])
    #theta_difference = math.atan2(goal[1]-current_robot_pose[1],goal[0]-current_robot_pose[0])-current_robot_pose[2]
    LD.stop()
    memory_service.insertData("goal", goal)
    motion_service.moveTo(0.0, 0.0, theta_difference, move_config)
    current_robot_pose[2] = math.atan2(goal[1], goal[0])
    motion_service.angleInterpolation("HeadPitch", -0.10584473609924316, 0.5,
                                      True)
    memory_service.insertData("state", "start")
    LD.sub()
    memory_service.insertData("dV3", [0.0, 0.0, 0.0, 0.0])
    #exp_dist =math.hypot(goal[1]-current_robot_pose[1],goal[0]-current_robot_pose[0])
    init_position = motion_service.getRobotPosition(True)
    if goal[2] > 3 or goal[2] < -3:
        print "a", current_robot_pose[0] - goal[0], current_robot_pose[
            1] - goal[1]
        motion_service.moveTo(current_robot_pose[0] - goal[0],
                              current_robot_pose[1] - goal[1], 0.0)
    else:
        print "b", goal[0] - current_robot_pose[0], goal[
            1] - current_robot_pose[1]
        motion_service.moveTo(goal[0] - current_robot_pose[0],
                              goal[1] - current_robot_pose[1], 0.0)

    while memory_service.getData("state") == "start":
        pass
    def get_new_operation(self):
        """
        This function return new operation by user input.

        :return: new operation object
        """
        desc = input("Enter operation description: ")
        money = int(self.user_input(lambda: input("Enter money =  ")))
        return operation.Operation(self.get_datetime(), desc, money)
Beispiel #4
0
def gohome():
    return MicroTest(
        steps=[
            operation.Operation('home'),
            #        operation.Operation('wait', None, {'time': 1000}),
        ],
        state_change={'screen': 'init'},
        name='go home',
        feature_name='meta',
        meta=True,
        prio=-1000)
Beispiel #5
0
 def __init__(self, session):
     print "landmark"
     self.operation = operation.Operation()
     #LandmarkPose() is a fn. defined below
     self.landmark_pose = LandmarkPose()
     self.memory_service = session.service("ALMemory")
     self.motion_service = session.service("ALMotion")
     self.posture_service = session.service("ALRobotPosture")
     self.manager_service = session.service("ALBehaviorManager")
     self.behaviorName = "landmardetection-b5c7a4/behavior_1"
     self.sub()
Beispiel #6
0
def operation_parse(input):
    # 'g' command
    if graph_pattern.match(input):
        opr = operation.Operation(graph, 'g')
    # 'r' command
    elif remove_pattern.match(input):
        street_name = street_name_pattern.findall(input).pop()
        street_name = string.lower(street_name)
        opr = operation.Operation(graph, 'r', street_name)
    # 'ac' command
    elif add_change_pattern.match(input):
        cmd = input[0]
        street_name = street_name_pattern.findall(input).pop()
        street_name = string.lower(street_name)
        points = []
        get_points(input, points)
        validate(points)
        opr = operation.Operation(graph, cmd, street_name, points)
    # invalid command
    else:
        raise Exception('Incorrect input format')

    opr.run()
Beispiel #7
0
def create_transformer_output(input_df, json_data):
    tr = tc.TransFormer(json_data)
    if tr.error:
        return None

    output_df = pd.DataFrame([], columns = tr.columns)
    logger.info("Started processing of individual generator")
    for generator in tr.generator_list:
        operation_obj = op.Operation(generator, input_df, output_df)
        if not operation_obj.valid_flag:
            return None
    logger.info("Operations performed")
    output_df = filter_columns(output_df, tr)
    op.drop_nan_rows(output_df)
    output_df = rounded_two_decimal(output_df)
    
    return output_df
Beispiel #8
0
def restart_test(appname):
    return MicroTest(
        steps=[
            operation.Operation('stop', None, {'name': appname}),
            operation.Operation('start', None, {'name': appname}),
            operation.Operation('wait', None, {'time': 1000}),
            operation.Operation('waitact', None, {'name': appname}),
            operation.Operation('waitready'),
            operation.Operation('waitready'),
        ],
        conds=[condition.Condition('notequal', {'screen': 'init'})],
        name="restart app",
        feature_name="meta",
        meta=True,
        prio=-30,
        state_change=config.restart_state_change)
Beispiel #9
0
def init_test(appname):
    test = MicroTest(
        steps=[
            operation.Operation('clear', None, {'name': appname}),
            #operation.Operation('kbdoff'),
            operation.Operation('start', None, {'name': appname}),
            operation.Operation('wait', None, {'time': 1000}),
            operation.Operation('waitact', None, {'name': appname}),
            operation.Operation('waitready'),
            operation.Operation('waitready'),
        ],
        conds=[condition.Condition('equal', {'screen': 'init'})],
        name="start app",
        feature_name="meta",
        meta=True)
    for prop in config.init_state:
        test.add_change(prop, config.init_state[prop])
    return test
Beispiel #10
0
 def kbd_on(self):
     operation.Operation("kbdon").do(self.dev, self.observer, state.State(),
                                     environ.empty, self.tlib)
Beispiel #11
0
    def GoToDo():

        nonlocal switcher
        while True:
            #Draw the list
            os.system('clear')
            a = draw.Draw(today.todolist, today.name)
            b = draw.Draw(future.todolist, future.name)
            c = draw.Draw(post.todolist, post.name)
            d = draw.Draw(comp.todolist, comp.name)
            a.draw_TODO()
            b.draw_TODO()
            c.draw_TODO()
            d.draw_TODO()
            print("-" * 40)
            #Here is a problem
            if switcher % 4 == 0:
                try:
                    future.todolist[future.cursor[0]][2] = '[   ]'
                except:
                    pass
                current = today
                print("Your Current position: Today")
            elif switcher % 4 == 1:
                try:

                    today.todolist[today.cursor[0]][2] = '[   ]'
                except:
                    pass
                current = future
                print("Your Current position: Future")
            elif switcher % 4 == 2:
                try:
                    post.todolist[post.cursor[0]][2] = '[   ]'
                except:
                    pass

                current = post
                print("Your Current position: Gone")
            elif switcher % 4 == 3:

                try:
                    comp.todolist[post.cursor[0]][2] = '[   ]'
                except:
                    pass

                current = comp
                print("Your Current position: Complete")

            print("* * * * * * * Description * * * * * * *\n")
            try:
                print("->", current.todolist[current.cursor[0]][3])
            except:
                print("Nothing here")
            print("- - - - - - - - - - - - - - - - - - - -")

            action = useraction.get_user_action()

            if action == 'Switch':
                switcher += 1
                continue
            if action in useraction.moves:
                while True:
                    try:
                        movement.moves(action, current)
                        break
                    except IndexError:
                        print("Uhoh..Out of Range..")
                        break
                continue
            else:
                op = operation.Operation(current, post, comp, future, today)
                if op.execution(action, userid) == 0:
                    return False