Exemplo n.º 1
0
 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
Exemplo n.º 2
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)
Exemplo n.º 3
0
def inspect_trajectory(trajectory):
    if not trajectory.path:
        return
    robot = trajectory.path[0].body
    # 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=None,
                                            self_collisions=False)
    assert (head_path is not None)
    return create_trajectory(robot, head_joints, head_path)
Exemplo n.º 4
0
 def gen(objective):
     base_joints = get_group_joints(robot, 'base')
     head_joints = get_group_joints(robot, 'head')
     target_point = get_point(objective)
     base_generator = visible_base_generator(robot, target_point,
                                             base_range)
     lower_limits, upper_limits = get_custom_limits(robot, base_joints,
                                                    custom_limits)
     while True:
         base_conf = next(base_generator)
         if not all_between(lower_limits, base_conf, upper_limits):
             continue
         bq = Conf(robot, base_joints, base_conf)
         bq.assign()
         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
         hq = Conf(robot, head_joints, head_conf)
         y = None
         yield (bq, hq, y)
Exemplo n.º 5
0
 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=None,
                                            self_collisions=False)
         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)