示例#1
0
def exec_cmd(filename):
    with open(filename, "r") as f:
        data = yaml.load_all(f)
        s = next(data)
    js = JointState()
    genpy.message.fill_message_args(js, s)
    robot = ClopemaRobotCommander("arms")
    rs = robot.get_current_state()

    if has_arms(rs, js):
        robot = ClopemaRobotCommander("arms")

        robot.set_joint_value_target(js)
        traj = robot.plan()
        if args['--speed'] is not None:
            print "Speed   ", "%+3.2f" % float(args['--speed'])
        else:
            print "Speed   ", "%+3.2f" % robot.get_robot_speed()

        if len(traj.joint_trajectory.points) <= 0:
            print "No valid trajectory found please check the robot output."
        else:
            r = ask("Execute trajectory? ", {'Y': 'Yes', 'n': 'No'})
            if r == 'y':
                if args['--speed'] is not None:
                    robot.set_robot_speed(float(args['--speed']))

                robot.execute(traj)

    if has_ext(rs, js):
        robot = ClopemaRobotCommander("ext")

        robot.set_joint_value_target(js)
        traj = robot.plan()
        if args['--speed'] is not None:
            print "Speed   ", "%+3.2f" % float(args['--speed'])
        else:
            print "Speed   ", "%+3.2f" % robot.get_robot_speed()

        if len(traj.joint_trajectory.points) <= 0:
            print "No valid trajectory found please check the robot output."
        else:
            r = ask("Execute trajectory? ", {'Y': 'Yes', 'n': 'No'})
            if r == 'y':
                if args['--speed'] is not None:
                    robot.set_robot_speed(float(args['--speed']))

                robot.execute(traj)

    if args['--sof']:
        robot.set_servo_power_off(True)
示例#2
0
        print args

    # Initialize node
    rospy.init_node(_NODE_NAME, anonymous=True)

    # Initialize robot
    robot = ClopemaRobotCommander("arms")

    trajs = read_msgs(args['<file_name>'], RobotTrajectory)

    # Check speed
    if args['--speed'] is not None:
        print "Speed   ", "%+3.2f" % float(args['--speed'])
    else:
        print "Speed   ", "%+3.2f" % robot.get_robot_speed()

    if not args['--force']:
        r = ask("Execute trajectory? ", {'Y':'Yes','n':'No'})
    else:
        r = 'y'

    if r == 'y':
        if args['--speed'] is not None:
            robot.set_robot_speed(float(args['--speed']))

        for traj in trajs:
            robot.execute(traj)

    if not args['--no-sof']:
        robot.set_servo_power_off(True)
示例#3
0
def compute_polish_move(hold_point,
                        start_point,
                        length=0.1,
                        frame_id="base_link"):

    # Compute the third point
    p0 = point_to_np(hold_point)
    p1 = point_to_np(start_point)
    v = p1 - p0
    v = v / np.linalg.norm(v)
    p2 = p1 + length * v
    rospy.loginfo("p0=%s, p1=%s, p2=%s", str(p0), str(p1), str(p2))

    # Get the vector angle
    a = np.arctan2(v[1], v[0])
    rospy.loginfo("Angle: [%f, %f]", a - angle_limit, a + angle_limit)

    # Generate poses
    poses0 = generate_poses(p0, 0, 2 * np.pi, no_candidates)

    poses1 = generate_poses(p1, a - angle_limit, a + angle_limit,
                            no_candidates)
    poses2 = generate_poses(p2, a - angle_limit, a + angle_limit,
                            no_candidates)

    candidates = [(p[0], p[1][0], p[1][1])
                  for p in itertools.product(poses0, zip(poses1, poses2))]

    arms = ClopemaRobotCommander("arms")
    state = RobotState.from_robot_state_msg(arms.get_current_state())

    trajs = []
    for p0, p1, p2 in candidates:
        trajs = []
        state0 = deepcopy(state)

        # Point for the first arm
        r1_p03 = deepcopy(p0)
        r1_p03.position.z = r1_p03.position.z + table_ofset
        r1_p12 = deepcopy(p0)

        # Points for the second arm
        r2_p0 = deepcopy(p1)
        r2_p0.position.z = r2_p0.position.z + table_ofset
        r2_p1 = deepcopy(p1)
        r2_p2 = deepcopy(p2)
        r2_p3 = deepcopy(p2)
        r2_p3.position.z = r2_p3.position.z + table_ofset

        try:
            state0.update_from_pose(pose_stamped(r1_p03, frame_id=frame_id),
                                    ik_link_id=r1_ik_link)
        except Exception as e:
            rospy.logwarn("Arm: %s, pose: %s: %s", str(r1_ik_link),
                          show_pose(r1_p03), str(e))
            continue
        try:
            state0.update_from_pose(pose_stamped(r2_p0, frame_id=frame_id),
                                    ik_link_id=r2_ik_link)
        except Exception as e:
            rospy.logwarn("Arm: %s, pose: %s: %s", str(r2_ik_link),
                          show_pose(r2_p0), str(e))
            continue

        arms.set_start_state_to_current_state()
        arms.set_joint_value_target(state0.joint_state)
        traj = arms.plan()
        trajs.append(traj)

        if not traj:
            rospy.logwarn("Unable to plan to initial position.")
            continue

        arms.set_start_state(state0)
        arms.set_pose_reference_frame(frame_id)
        wp_1 = [r1_p12, r1_p12, r1_p03]
        wp_2 = [r2_p1, r2_p2, r2_p3]
        traj, fraction = arms.compute_cartesian_path(zip(wp_1, wp_2),
                                                     (r1_ik_link, r2_ik_link),
                                                     jump_threshold=2,
                                                     avoid_collisions=False)

        if fraction < 1:
            rospy.logwarn("Unable to interpolate polish move")
            continue

        enable_collisions = [("t3_desk", "r1_gripper"),
                             ("t3_desk", "r2_gripper")]
        if not services.check_trajectory(
                state0, traj, enable_collisions, wait_timeout=1):
            rospy.logwarn("Found trajectory is in collision!")
            continue

        trajs.append(traj)
        break

    print len(trajs)
    arms.set_robot_speed(0.05)
    arms.execute(trajs[0])
    arms.execute(trajs[1])