Exemplo n.º 1
0
 def _extract_tf_msg(tf_msg):
     px = tf_msg.translation.x; py = tf_msg.translation.y; pz = tf_msg.translation.z 
     ox = tf_msg.rotation.x; oy = tf_msg.rotation.y
     oz = tf_msg.rotation.z; ow = tf_msg.rotation.w
     quat = [ox, oy, oz, ow]
     rot_euler = trans.euler_from_quaternion(quat)
     homo_mat = np.mat(trans.quaternion_matrix(quat))
     homo_mat[:3,3] = np.mat([[px, py, pz]]).T
     return homo_mat, quat, rot_euler
Exemplo n.º 2
0
 def _extract_pose_msg(pose):
     px = pose.position.x; py = pose.position.y; pz = pose.position.z
     ox = pose.orientation.x; oy = pose.orientation.y
     oz = pose.orientation.z; ow = pose.orientation.w
     quat = [ox, oy, oz, ow]
     rot_euler = trans.euler_from_quaternion(quat)
     homo_mat = np.mat(trans.quaternion_matrix(quat))
     homo_mat[:3,3] = np.mat([[px, py, pz]]).T
     return homo_mat, quat, rot_euler
Exemplo n.º 3
0
 def _extract_tf_msg(tf_msg):
     px = tf_msg.translation.x; py = tf_msg.translation.y; pz = tf_msg.translation.z 
     ox = tf_msg.rotation.x; oy = tf_msg.rotation.y
     oz = tf_msg.rotation.z; ow = tf_msg.rotation.w
     quat = [ox, oy, oz, ow]
     rot_euler = trans.euler_from_quaternion(quat)
     homo_mat = np.mat(trans.quaternion_matrix(quat))
     homo_mat[:3,3] = np.mat([[px, py, pz]]).T
     return homo_mat, quat, rot_euler
Exemplo n.º 4
0
 def _extract_pose_msg(pose):
     px = pose.position.x; py = pose.position.y; pz = pose.position.z
     ox = pose.orientation.x; oy = pose.orientation.y
     oz = pose.orientation.z; ow = pose.orientation.w
     quat = [ox, oy, oz, ow]
     rot_euler = trans.euler_from_quaternion(quat)
     homo_mat = np.mat(trans.quaternion_matrix(quat))
     homo_mat[:3,3] = np.mat([[px, py, pz]]).T
     return homo_mat, quat, rot_euler
Exemplo n.º 5
0
    def _make_generic(args):
        try:
            if type(args[0]) == str:
                frame_id = args[0]
                header, homo_mat, rot_quat, rot_euler = PoseConv._make_generic(
                    args[1:])
                if homo_mat is None:
                    return None, None, None, None
                if header is None:
                    header = [0, rospy.Time.now(), '']
                header[2] = frame_id
                return header, homo_mat, rot_quat, rot_euler

            if len(args) == 2:
                return PoseConv._make_generic(((args[0], args[1]), ))
            elif len(args) == 1:
                pose_type = PoseConv.get_type(*args)
                if pose_type is None:
                    return None, None, None, None
                if pose_type == 'pose_msg':
                    homo_mat, rot_quat, rot_euler = PoseConv._extract_pose_msg(
                        args[0])
                    return None, homo_mat, rot_quat, rot_euler
                elif pose_type == 'pose_stamped_msg':
                    homo_mat, rot_quat, rot_euler = PoseConv._extract_pose_msg(
                        args[0].pose)
                    seq = args[0].header.seq
                    stamp = args[0].header.stamp
                    frame_id = args[0].header.frame_id
                    return [seq, stamp,
                            frame_id], homo_mat, rot_quat, rot_euler
                elif pose_type == 'tf_msg':
                    homo_mat, rot_quat, rot_euler = PoseConv._extract_tf_msg(
                        args[0])
                    return None, homo_mat, rot_quat, rot_euler
                elif pose_type == 'tf_stamped_msg':
                    homo_mat, rot_quat, rot_euler = PoseConv._extract_tf_msg(
                        args[0].transform)
                    seq = args[0].header.seq
                    stamp = args[0].header.stamp
                    frame_id = args[0].header.frame_id
                    return [seq, stamp,
                            frame_id], homo_mat, rot_quat, rot_euler
                elif pose_type == 'point_msg':
                    homo_mat, rot_quat, rot_euler = PoseConv._extract_point_msg(
                        args[0])
                    return None, homo_mat, rot_quat, rot_euler
                elif pose_type == 'point_stamped_msg':
                    homo_mat, rot_quat, rot_euler = PoseConv._extract_point_msg(
                        args[0].point)
                    seq = args[0].header.seq
                    stamp = args[0].header.stamp
                    frame_id = args[0].header.frame_id
                    return [seq, stamp,
                            frame_id], homo_mat, rot_quat, rot_euler
                elif pose_type == 'twist_msg':
                    homo_mat, rot_quat, rot_euler = PoseConv._extract_twist_msg(
                        args[0])
                    return None, homo_mat, rot_quat, rot_euler
                elif pose_type == 'twist_stamped_msg':
                    homo_mat, rot_quat, rot_euler = PoseConv._extract_twist_msg(
                        args[0].twist)
                    seq = args[0].header.seq
                    stamp = args[0].header.stamp
                    frame_id = args[0].header.frame_id
                    return [seq, stamp,
                            frame_id], homo_mat, rot_quat, rot_euler
                elif pose_type == 'homo_mat':
                    return (None, np.mat(args[0]),
                            trans.quaternion_from_matrix(args[0]).tolist(),
                            trans.euler_from_matrix(args[0]))
                elif pose_type in [
                        'pos_rot', 'pos_euler', 'pos_quat', 'pos_axis_angle'
                ]:
                    pos_arg = np.mat(args[0][0])
                    if pos_arg.shape == (1, 3):
                        # matrix is row, convert to column
                        pos = pos_arg.T
                    elif pos_arg.shape == (3, 1):
                        pos = pos_arg

                    if pose_type == 'pos_axis_angle':
                        homo_mat = np.mat(np.eye(4))
                        homo_mat[:3, :3] = axis_angle_to_rot_mat(
                            args[0][1][0], args[0][1][1])
                        quat = trans.quaternion_from_matrix(homo_mat)
                        rot_euler = trans.euler_from_matrix(homo_mat)
                    elif pose_type == 'pos_rot':
                        # rotation matrix
                        homo_mat = np.mat(np.eye(4))
                        homo_mat[:3, :3] = np.mat(args[0][1])
                        quat = trans.quaternion_from_matrix(homo_mat)
                        rot_euler = trans.euler_from_matrix(homo_mat)
                    else:
                        rot_arg = np.mat(args[0][1])
                        if rot_arg.shape[1] == 1:
                            rot_arg = rot_arg.T
                        rot_list = rot_arg.tolist()[0]
                        if pose_type == 'pos_euler':
                            # Euler angles rotation
                            homo_mat = np.mat(trans.euler_matrix(*rot_list))
                            quat = trans.quaternion_from_euler(*rot_list)
                            rot_euler = rot_list
                        elif pose_type == 'pos_quat':
                            # quaternion rotation
                            homo_mat = np.mat(
                                trans.quaternion_matrix(rot_list))
                            quat = rot_list
                            rot_euler = trans.euler_from_quaternion(quat)

                    homo_mat[:3, 3] = pos
                    return None, homo_mat, np.array(quat), rot_euler
        except:
            pass

        return None, None, None, None
Exemplo n.º 6
0
    def _make_generic(args):
        try:
            if type(args[0]) == str:
                frame_id = args[0]
                header, homo_mat, rot_quat, rot_euler = PoseConv._make_generic(args[1:])
                if homo_mat is None:
                    return None, None, None, None
                if header is None:
                    header = [0, rospy.Time.now(), '']
                header[2] = frame_id
                return header, homo_mat, rot_quat, rot_euler

            if len(args) == 2:
                return PoseConv._make_generic(((args[0], args[1]),))
            elif len(args) == 1:
                pose_type = PoseConv.get_type(*args)
                if pose_type is None:
                    return None, None, None, None
                if pose_type == 'pose_msg':
                    homo_mat, rot_quat, rot_euler = PoseConv._extract_pose_msg(args[0])
                    return None, homo_mat, rot_quat, rot_euler
                elif pose_type == 'pose_stamped_msg':
                    homo_mat, rot_quat, rot_euler = PoseConv._extract_pose_msg(args[0].pose)
                    seq = args[0].header.seq
                    stamp = args[0].header.stamp
                    frame_id = args[0].header.frame_id
                    return [seq, stamp, frame_id], homo_mat, rot_quat, rot_euler
                elif pose_type == 'tf_msg':
                    homo_mat, rot_quat, rot_euler = PoseConv._extract_tf_msg(args[0])
                    return None, homo_mat, rot_quat, rot_euler
                elif pose_type == 'tf_stamped_msg':
                    homo_mat, rot_quat, rot_euler = PoseConv._extract_tf_msg(args[0].transform)
                    seq = args[0].header.seq
                    stamp = args[0].header.stamp
                    frame_id = args[0].header.frame_id
                    return [seq, stamp, frame_id], homo_mat, rot_quat, rot_euler
                elif pose_type == 'point_msg':
                    homo_mat, rot_quat, rot_euler = PoseConv._extract_point_msg(args[0])
                    return None, homo_mat, rot_quat, rot_euler
                elif pose_type == 'point_stamped_msg':
                    homo_mat, rot_quat, rot_euler = PoseConv._extract_point_msg(args[0].point)
                    seq = args[0].header.seq
                    stamp = args[0].header.stamp
                    frame_id = args[0].header.frame_id
                    return [seq, stamp, frame_id], homo_mat, rot_quat, rot_euler
                elif pose_type == 'twist_msg':
                    homo_mat, rot_quat, rot_euler = PoseConv._extract_twist_msg(args[0])
                    return None, homo_mat, rot_quat, rot_euler
                elif pose_type == 'twist_stamped_msg':
                    homo_mat, rot_quat, rot_euler = PoseConv._extract_twist_msg(args[0].twist)
                    seq = args[0].header.seq
                    stamp = args[0].header.stamp
                    frame_id = args[0].header.frame_id
                    return [seq, stamp, frame_id], homo_mat, rot_quat, rot_euler
                elif pose_type == 'homo_mat':
                    return (None, np.mat(args[0]), trans.quaternion_from_matrix(args[0]).tolist(),
                            trans.euler_from_matrix(args[0]))
                elif pose_type in ['pos_rot', 'pos_euler', 'pos_quat']:
                    pos_arg = np.mat(args[0][0])
                    rot_arg = np.mat(args[0][1])
                    if pos_arg.shape == (1, 3):
                        # matrix is row, convert to column
                        pos = pos_arg.T
                    elif pos_arg.shape == (3, 1):
                        pos = pos_arg

                    if pose_type == 'pos_rot':
                        # rotation matrix
                        homo_mat = np.mat(np.eye(4))
                        homo_mat[:3,:3] = rot_arg
                        quat = trans.quaternion_from_matrix(homo_mat)
                        rot_euler = trans.euler_from_matrix(homo_mat)
                    else:
                        if rot_arg.shape[1] == 1:
                            rot_arg = rot_arg.T
                        rot_list = rot_arg.tolist()[0]
                        if pose_type == 'pos_euler':
                            # Euler angles rotation
                            homo_mat = np.mat(trans.euler_matrix(*rot_list))
                            quat = trans.quaternion_from_euler(*rot_list)
                            rot_euler = rot_list
                        elif pose_type == 'pos_quat':
                            # quaternion rotation
                            homo_mat = np.mat(trans.quaternion_matrix(rot_list))
                            quat = rot_list
                            rot_euler = trans.euler_from_quaternion(quat)

                    homo_mat[:3, 3] = pos
                    return None, homo_mat, np.array(quat), rot_euler
        except:
            pass

        return None, None, None, None