示例#1
0
def fly(client: airsim.MultirotorClient, args: argparse.Namespace) -> None:
    initial_pose = client.simGetVehiclePose()
    if args.verbose:
        ff.print_pose(initial_pose, airsim.to_eularian_angles)

    if args.flush:
        client.simFlushPersistentMarkers()

    # NOTE we have to use (-y, -x, -z), and not (x, -y, -z), because these
    # files were exported from Unreal Engine as FBX with Force Front XAxis
    BUILDING = False
    STATUE = True

    def convert_position(p, t, s):
        if BUILDING or STATUE:
            if t is not None: p += t
            if s is not None: p *= s
            x, y, z = map(float, p)
            return Vector3r(-y, -x, -z)
        else:
            return convert_uavmvs_to_airsim_position(p, t, s)

    points = [
        # convert_uavmvs_to_airsim_position(_, translation=args.offset, scaling=args.scale)
        convert_position(_, args.offset, args.scale)
        for _ in args.points[::args.every_k]
    ]
    client.simPlotPoints(points,
                         Rgba.Blue,
                         POINT_CLOUD_POINT_SIZE,
                         is_persistent=True)

    if args.trajectory is not None:
        camera_poses, camera_positions = [], []
        for i, camera in enumerate(args.trajectory):
            if not camera.spline_interpolated:  # XXX
                pose = convert_uavmvs_to_airsim_pose(camera=camera,
                                                     translation=args.offset,
                                                     scaling=args.scale)
                # print(f"=== {i} ===")
                # print(camera)
                # print(pose)
                camera_poses.append(pose)
                camera_positions.append(pose.position)

        # client.simPlotLineStrip(camera_positions, Rgba.Black, TRAJECTORY_THICKNESS, is_persistent=True)
        # client.simPlotPoints(camera_positions, Rgba.White, CAMERA_POSE_SIZE, is_persistent=True)
        client.simPlotTransforms(camera_poses,
                                 10 * CAMERA_POSE_SIZE,
                                 is_persistent=True)

    if args.edit:
        enter_edit_mode(client, points)
示例#2
0
def fly(client: airsim.MultirotorClient, args: argparse.Namespace) -> None:
    if args.flush:
        client.simFlushPersistentMarkers()

    if not args.transformation:
        poses = [
            Pose(record.position, record.orientation)
            for record in args.recording.values()
        ]
        positions = [record.position for record in args.recording.values()]
    else:
        matrix = np.loadtxt(
            args.transformation)  # load the 4x4 transformation matrix
        print(matrix)
        poses = []
        positions = []
        for record in args.recording.values():
            pos = Vector3r(*np.matmul(matrix, np.append(record.position, 1)))
            poses.append(Pose(pos, record.orientation))
            positions = [pos]

    if args.axes:
        client.simPlotTransforms(poses,
                                 scale=100.0,
                                 thickness=2.5,
                                 is_persistent=True)
    else:
        client.simPlotPoints(positions,
                             args.color,
                             size=10,
                             is_persistent=True)

    if args.lines:
        client.simPlotLineStrip(positions,
                                args.color,
                                thickness=2.5,
                                is_persistent=True)

    if args.aim:
        line_list = []
        for pose in poses:
            line_list.append(pose.position)
            x_axis, _, _ = AirSimNedTransform.local_axes_frame(pose)
            line_list.append(pose.position + x_axis * 100)
        client.simPlotLineList(line_list,
                               args.color,
                               thickness=2.5,
                               is_persistent=True)
示例#3
0
def fly(client: airsim.MultirotorClient, args: argparse.Namespace) -> None:
    if args.flush:
        client.simFlushPersistentMarkers()

    def pose_from_meshroom_to_airsim(meshroom_pose):
        assert len(meshroom_pose.center) == 3 and len(
            meshroom_pose.rotation) == 9, meshroom_pose
        xyzw = MeshroomTransform.rotation(meshroom_pose.rotation,
                                          as_xyzw_quaternion=True)
        return Pose(Vector3r(*meshroom_pose.center), Quaternionr(*xyzw))

    poses = [
        pose_from_meshroom_to_airsim(pose)
        for pose in args.poses_dict.values()
    ]
    positions = [pose.position for pose in poses]

    if args.axes:
        client.simPlotTransforms(poses,
                                 scale=75.0,
                                 thickness=2.5,
                                 is_persistent=True)
    else:
        client.simPlotPoints(positions,
                             args.color,
                             size=10,
                             is_persistent=True)

    if args.lines:
        client.simPlotLineStrip(positions,
                                args.color,
                                thickness=2.5,
                                is_persistent=True)

    if args.transformation:
        meshroom_to_airsim = np.loadtxt(
            args.transformation)  # load the 4x4 transformation matrix
        print(meshroom_to_airsim)

        def align_meshroom_to_airsim(meshroom_pose,
                                     meshroom_to_airsim_transform):
            # NOTE this transformation is only based on the positions (and not on the orientations)
            meshroom_pos = np.append(meshroom_pose.position.to_numpy_array(),
                                     1)  # [x, y, z, 1]
            airsim_pos = np.matmul(meshroom_to_airsim_transform, meshroom_pos)
            return Pose(Vector3r(*airsim_pos), meshroom_pose.orientation)

        aligned_poses = [
            align_meshroom_to_airsim(pose, meshroom_to_airsim)
            for pose in poses
        ]
        aligned_positions = [pose.position for pose in aligned_poses]

        if args.axes:
            client.simPlotTransforms(aligned_poses,
                                     scale=75.0,
                                     thickness=2.5,
                                     is_persistent=True)
        else:
            client.simPlotPoints(aligned_positions,
                                 args.color,
                                 size=10,
                                 is_persistent=True)

        if args.lines:
            client.simPlotLineStrip(positions,
                                    args.color,
                                    thickness=2.5,
                                    is_persistent=True)