예제 #1
0
def get_vis_base_gen(task, base_range):
    robot = task.robot
    fixed = get_fixed_bodies(task)
    base_joints = get_group_joints(robot, 'base')

    def gen(o, p):
        if o in task.rooms:  # TODO: predicate instead
            return
        # default_conf = arm_conf(a, g.carry)
        # joints = get_arm_joints(robot, a)
        # TODO: check collisions with fixed links
        target_point = point_from_pose(p.value)
        base_generator = visible_base_generator(robot, target_point,
                                                base_range)
        while True:
            set_pose(o, p.value)  # p.assign()
            bq = Conf(robot, base_joints, next(base_generator))
            # bq = Pose(robot, get_pose(robot))
            bq.assign()
            if any(pairwise_collision(robot, b) for b in fixed):
                yield None
            else:
                yield (bq, )

    # TODO: return list_fn & accelerated
    return gen
예제 #2
0
def get_vis_gen(problem, max_attempts=25, base_range=(0.5, 1.5)):
    robot = problem.robot
    fixed = get_fixed_bodies(problem)
    base_joints = get_group_joints(robot, 'base')
    head_joints = get_group_joints(robot, 'head')

    def gen(o, p):
        # default_conf = arm_conf(a, g.carry)
        # joints = get_arm_joints(robot, a)
        # TODO: check collisions with fixed links
        target_point = point_from_pose(p.value)
        base_generator = visible_base_generator(robot, target_point,
                                                base_range)
        while True:
            for _ in range(max_attempts):
                set_pose(o, p.value)
                base_conf = next(base_generator)
                #set_base_values(robot, base_conf)
                set_joint_positions(robot, base_joints, base_conf)
                if any(pairwise_collision(robot, b) for b in fixed):
                    continue
                head_conf = inverse_visibility(robot, target_point)
                if head_conf is None:  # TODO: test if visible
                    continue
                #bq = Pose(robot, get_pose(robot))
                bq = Conf(robot, base_joints, base_conf)
                hq = Conf(robot, head_joints, head_conf)
                yield (bq, hq)
                break
            else:
                yield None

    return gen
예제 #3
0
def get_inverse_visibility_fn(task, collisions=True):
    robot = task.robot
    head_joints = get_group_joints(robot, 'head')
    obstacles = get_fixed_bodies(task) if collisions else []

    def fn(o, p, bq):
        set_pose(o, p.value)  # p.assign()
        bq.assign()
        if o in task.rooms:
            waypoints = plan_scan_path(task.robot, tilt=ROOM_SCAN_TILT)
            set_group_conf(robot, 'head', waypoints[0])
            path = plan_waypoints_joint_motion(robot,
                                               head_joints,
                                               waypoints[1:],
                                               obstacles=obstacles,
                                               self_collisions=SELF_COLLISIONS)
            if path is None:
                return None
            ht = create_trajectory(robot, head_joints, path)
            hq = ht.path[0]
        else:
            target_point = point_from_pose(p.value)
            head_conf = inverse_visibility(robot, target_point)
            if head_conf is None:  # TODO: test if visible
                return None
            hq = Conf(robot, head_joints, head_conf)
            ht = Trajectory([hq])
        return (hq, ht)

    return fn
예제 #4
0
def plan_head_traj(task, head_conf):
    robot = task.robot
    obstacles = get_fixed_bodies(task)  # TODO: movable objects
    # head_conf = get_joint_positions(robot, head_joints)
    # head_path = [head_conf, hq.values]
    head_joints = get_group_joints(robot, 'head')
    head_path = plan_direct_joint_motion(robot,
                                         head_joints,
                                         head_conf,
                                         obstacles=obstacles,
                                         self_collisions=SELF_COLLISIONS)
    assert (head_path is not None)
    return create_trajectory(robot, head_joints, head_path)
예제 #5
0
def move_look_trajectory(task,
                         trajectory,
                         max_tilt=np.pi / 6):  # max_tilt=INF):
    # TODO: implement a minimum distance instead of max_tilt
    # TODO: pr2 movement restrictions
    #base_path = [pose.to_base_conf() for pose in trajectory.path]
    base_path = trajectory.path
    if not base_path:
        return trajectory
    obstacles = get_fixed_bodies(task)  # TODO: movable objects
    robot = base_path[0].body
    target_path = get_target_path(trajectory)
    waypoints = []
    index = 0
    with BodySaver(robot):
        #current_conf = base_values_from_pose(get_pose(robot))
        for i, conf in enumerate(base_path):  # TODO: just do two loops?
            conf.assign()
            while index < len(target_path):
                if i < index:
                    # Don't look at past or current conf
                    target_point = target_path[index]
                    head_conf = inverse_visibility(
                        robot, target_point)  # TODO: this is slightly slow
                    #print(index, target_point, head_conf)
                    if (head_conf is not None) and (head_conf[1] < max_tilt):
                        break
                index += 1
            else:
                head_conf = get_group_conf(robot, 'head')
            set_group_conf(robot, 'head', head_conf)
            #print(i, index, conf.values, head_conf) #, get_pose(robot))
            waypoints.append(np.concatenate([conf.values, head_conf]))
    joints = tuple(base_path[0].joints) + tuple(get_group_joints(
        robot, 'head'))
    #joints = get_group_joints(robot, 'base') + get_group_joints(robot, 'head')
    #set_pose(robot, unit_pose())
    #set_group_conf(robot, 'base', current_conf)
    path = plan_waypoints_joint_motion(robot,
                                       joints,
                                       waypoints,
                                       obstacles=obstacles,
                                       self_collisions=SELF_COLLISIONS)
    return create_trajectory(robot, joints, path)
예제 #6
0
def inspect_trajectory(task, trajectory):
    if not trajectory.path:
        return
    robot = trajectory.path[0].body
    obstacles = get_fixed_bodies(task)  # TODO: movable objects
    # TODO: minimum distance of some sort (to prevent from looking at the bottom)
    # TODO: custom lower limit as well
    head_waypoints = []
    for target_point in get_target_path(trajectory):
        head_conf = inverse_visibility(robot, target_point)
        # TODO: could also draw the sequence of inspected points as the head moves
        if head_conf is None:
            continue
        head_waypoints.append(head_conf)
    head_joints = get_group_joints(robot, 'head')
    #return create_trajectory(robot, head_joints, head_waypoints)
    head_path = plan_waypoints_joint_motion(robot,
                                            head_joints,
                                            head_waypoints,
                                            obstacles=obstacles,
                                            self_collisions=SELF_COLLISIONS)
    assert (head_path is not None)
    return create_trajectory(robot, head_joints, head_path)