Exemplo n.º 1
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.º 2
0
 def gen(o, p):
     if o in task.rooms:
         #bq = Pose(robot, unit_pose())
         #bq = state.poses[robot]
         bq = Conf(robot, base_joints, np.zeros(len(base_joints)))
         #hq = Conf(robot, head_joints, np.zeros(len(head_joints)))
         #ht = create_trajectory(robot, head_joints, plan_pause_scan_path(robot, tilt=tilt))
         waypoints = plan_scan_path(task.robot, tilt=tilt)
         set_group_conf(robot, 'head', waypoints[0])
         path = plan_waypoints_joint_motion(robot,
                                            head_joints,
                                            waypoints[1:],
                                            obstacles=None,
                                            self_collisions=False)
         ht = create_trajectory(robot, head_joints, path)
         yield bq, ht.path[0], ht
     else:
         for bq, hq in vis_gen(o, p):
             ht = Trajectory([hq])
             yield bq, ht.path[0], ht
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 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)
Exemplo n.º 5
0
 def gen_fn(index, pose, grasp):
     body = brick_from_index[index].body
     #world_pose = get_link_pose(robot, tool_link)
     #draw_pose(world_pose, length=0.04)
     #set_pose(body, multiply(world_pose, grasp.attach))
     #draw_pose(multiply(pose.value, invert(grasp.attach)), length=0.04)
     #wait_for_interrupt()
     set_pose(body, pose.value)
     for _ in range(max_attempts):
         set_joint_positions(robot, movable_joints,
                             sample_fn())  # Random seed
         attach_pose = multiply(pose.value, invert(grasp.attach))
         attach_conf = inverse_kinematics(robot, tool_link, attach_pose)
         if attach_conf is None:
             continue
         approach_pose = multiply(attach_pose, ([0, 0, -0.1], unit_quat()))
         #approach_pose = multiply(pose.value, invert(grasp.approach))
         approach_conf = inverse_kinematics(robot, tool_link, approach_pose)
         if approach_conf is None:
             continue
         # TODO: retreat
         path = plan_waypoints_joint_motion(
             robot,
             movable_joints, [approach_conf, attach_conf],
             obstacles=obstacle_from_name.values(),
             self_collisions=True,
             disabled_collisions=disabled_collisions)
         if path is None:
             continue
         #path = [approach_conf, attach_conf]
         attachment = Attachment(robot, tool_link, grasp.attach, body)
         traj = MotionTrajectory(robot,
                                 movable_joints,
                                 path,
                                 attachments=[attachment])
         yield approach_conf, traj
         break