예제 #1
0
    def load_tests(cls, files):
        """
        Add one test for each input file. For each input file named
        "test_XXX.json" creates a new test member function that will generate
        output files "result_XXX.json" and "result_XXX.pdf".
        """
        for file in files:
            if file.stem.startswith('test_'):
                test_name = file.stem[5:]
                cls.test_names.append(test_name)
                world = World.from_file(file)

                # Dynamically add member function for this test.
                def fn(self,
                       test_name=test_name,
                       world=world,
                       start=world.world['start'],
                       goal=world.world['goal'],
                       resolution=world.world['resolution'],
                       margin=world.world['margin'],
                       expected_path_length=world.world.get(
                           'expected_path_length', None)):
                    self.helper_test(test_name, world, start, goal, resolution,
                                     margin, expected_path_length)

                setattr(cls, 'test_' + test_name, fn)
                # Remove any pre-existing output files for this test.
                # TODO: The 'missing_ok' argument becomes available in Python
                # 3.8, at which time contextlib is no longer needed.
                with contextlib.suppress(FileNotFoundError):
                    (cls.outpath / ('result_' + test_name + '.json')).unlink()
                with contextlib.suppress(FileNotFoundError):
                    (cls.outpath / ('result_' + test_name + '.pdf')).unlink()
예제 #2
0
    def load_tests(cls, files, enable_timeouts=False, redirect_stdout=True):
        """
        Add one test for each input file. For each input file named
        "test_XXX.json" creates a new test member function that will generate
        output files "result_XXX.json" and "result_XXX.pdf".
        """
        std_target = None if redirect_stdout else sys.stdout
        for file in files:
            if file.stem.startswith('test_'):
                test_name = file.stem[5:]
                cls.test_names.append(test_name)
                world = World.from_file(file)

                # Timeouts must be enabled and have value in test_*.json file.
                timeout = None
                if enable_timeouts:
                    with open(file) as f:
                        test_dict = json.load(f)
                        if 'timeout' in test_dict.keys():
                            timeout = test_dict['timeout']

                # Dynamically add member function for this test.
                @timeout_decorator.timeout(
                    timeout,
                    exception_message="Test reached time limit of {} seconds".
                    format(timeout))
                def fn(self,
                       test_name=test_name,
                       world=world,
                       start=world.world['start'],
                       goal=world.world['goal']):
                    self.helper_test(test_name, world, start, goal, std_target)

                setattr(cls, 'test_' + test_name, fn)
                # Remove any pre-existing output files for this test.
                # TODO: The 'missing_ok' argument becomes available in Python
                # 3.8, at which time contextlib is no longer needed.
                with contextlib.suppress(FileNotFoundError):
                    (cls.outpath / ('result_' + test_name + '.json')).unlink()
                with contextlib.suppress(FileNotFoundError):
                    (cls.outpath / ('result_' + test_name + '.pdf')).unlink()
예제 #3
0
        position = np.zeros((t.shape[0], 3))
        position[:, 0] = np.cos(t)
        position[:, 1] = np.sin(t)
        theta = t % (2 * np.pi)
        rotvec = theta * np.array([[0], [0], [1]])
        rotation = Rotation.from_rotvec(rotvec.T).as_dcm()
        return (t, position, rotation)

    (time, position, rotation) = dummy_sim_result()

    wall_start = datetime.now()
    animate(time, position, rotation, world, filename)
    wall_elapsed = (datetime.now() - wall_start).total_seconds()
    wall_fps = time.size / wall_elapsed
    print('render time = {:.0f} s'.format(wall_elapsed))
    print('render fps = {:.0f}'.format(wall_fps))


if __name__ == '__main__':
    from flightsim.world import World

    world = World.from_file('worlds/grid_forest.json')

    print('Test .mp4 rendering.')
    test(world=world, filename='data_out/quadrotor.mp4')
    plt.show()

    print('Test live view.')
    test(world=world, filename=None)
    plt.show()
예제 #4
0
# Improve figure display on high DPI screens.
# mpl.rcParams['figure.dpi'] = 200

# Choose a test example file. You should write your own example files too!
# filename = '../util/test_window.json'
# filename = '../util/test_maze.json'
# filename = '../util/test_lab_1.json'
# filename = '../util/test_lab_2.json'
filename = '../util/test_lab_3.json'
# filename = '../util/mymap.json'

# Load the test example.
file = Path(inspect.getsourcefile(
    lambda: 0)).parent.resolve() / '..' / 'util' / filename
world = World.from_file(file)  # World boundary and obstacles.
start = world.world['start']  # Start point, shape=(3,)
goal = world.world['goal']  # Goal point, shape=(3,)

# This object defines the quadrotor dynamical model and should not be changed.
quadrotor = Quadrotor(quad_params)
robot_radius = 0.25

# Your SE3Control object (from project 1-1).
my_se3_control = SE3Control(quad_params)

# Your MapTraj object. This behaves like the trajectory function you wrote in
# project 1-1, except instead of giving it waypoints you give it the world,
# start, and goal.
planning_start_time = time.time()
my_world_traj = WorldTraj(world, start, goal)