Example #1
0
    def test_run_random_engine(self):
        add_custom_gazebo_resource_path(
            os.path.join(
                os.path.dirname(os.path.abspath(__file__)),
                'gazebo_models'))
        manager = EngineManager()
        manager.add_constraint(**WORKSPACE_CONSTRAINT)
        self.assertTrue(manager.has_constraint('cool_workspace'))
        const = manager.get_constraint('cool_workspace')
        self.assertIsInstance(const, WorkspaceConstraint)

        manager.add_constraint(**TANGENT_CONSTRAINT)
        self.assertTrue(manager.has_constraint('tangent_to_ground_plane'))
        const = manager.get_constraint('tangent_to_ground_plane')
        self.assertIsInstance(const, TangentConstraint)

        manager.add(**RANDOM_ENGINE)
        self.assertIn('add_random_objects', manager.tags)
        self.assertEqual(manager.size, 1)

        engine = manager.get('add_random_objects')
        self.assertIsNotNone(engine)
        self.assertIsInstance(engine, RandomPoseEngine)

        models = engine.run()
        self.assertIsNotNone(models)
        self.assertIsInstance(models, list)
        self.assertEqual(len(models), 2)
Example #2
0
    def test_actor_walking(self):
        add_custom_gazebo_resource_path(os.path.join(CUR_DIR, 'gazebo_models'))
        sdf = parse_sdf(
            os.path.join(CUR_DIR, 'gazebo_models', 'test_actor_walking',
                         'model.sdf'))
        self.assertIsNotNone(sdf)
        self.assertIsNotNone(sdf.actors)
        self.assertEqual(len(sdf.actors), 1)

        actor = Actor.from_sdf(sdf.actors[0])
        self.assertIsNotNone(actor)

        self.assertEqual(actor.name, 'actor')
        self.assertEqual(actor.pose.position[0], 0)
        self.assertEqual(actor.pose.position[1], 0)
        self.assertEqual(actor.pose.position[2], 0)

        self.assertEqual(len(actor.animations), 1)
        self.assertEqual(actor.animations[0].name, 'walking')
        self.assertEqual(actor.animations[0].filename,
                         'model://test_actor_walking/meshes/walk.dae')
        self.assertEqual(actor.animations[0].scale, 1)
        self.assertEqual(actor.animations[0].interpolate_x, True)

        self.assertEqual(len(actor.script.trajectories), 1)
        self.assertEqual(actor.script.trajectories[0].id, 0)
        self.assertEqual(actor.script.trajectories[0].type, 'walking')

        self.assertEqual(len(actor.script.trajectories[0].waypoints), 32)
Example #3
0
    def test_add_constraint(self):
        add_custom_gazebo_resource_path(
            os.path.join(
                os.path.dirname(os.path.abspath(__file__)),
                'gazebo_models'))
        manager = EngineManager()
        manager.add_constraint(**WORKSPACE_CONSTRAINT)
        self.assertTrue(manager.has_constraint('cool_workspace'))
        const = manager.get_constraint('cool_workspace')
        self.assertIsInstance(const, WorkspaceConstraint)

        manager.add_constraint(**TANGENT_CONSTRAINT)
        self.assertTrue(manager.has_constraint('tangent_to_ground_plane'))
        const = manager.get_constraint('tangent_to_ground_plane')
        self.assertIsInstance(const, TangentConstraint)
Example #4
0
    def test_actor_relative_paths(self):
        add_custom_gazebo_resource_path(os.path.join(CUR_DIR, 'gazebo_models'))
        sdf = parse_sdf(
            os.path.join(CUR_DIR, 'gazebo_models', 'test_actor_relative_paths',
                         'model.sdf'))
        self.assertIsNotNone(sdf)
        self.assertIsNotNone(sdf.actors)
        self.assertEqual(len(sdf.actors), 1)

        actor = Actor.from_sdf(sdf.actors[0])
        self.assertIsNotNone(actor)

        self.assertEqual(actor.name, 'actor_test')
        self.assertEqual(actor.pose.position[0], 0)
        self.assertEqual(actor.pose.position[1], 0)
        self.assertEqual(actor.pose.position[2], 1)

        self.assertEqual(len(actor.animations), 8)
        self.assertEqual(len(actor.script.trajectories), 13)
Example #5
0
    def test_parse_biome_from_heightmap(self):
        add_custom_gazebo_resource_path(
            os.path.join(CUR_DIR, '..', 'examples', 'models'))

        # Parse the SDF file
        sdf = parse_sdf(
            os.path.join(CUR_DIR, '..', 'examples', 'models',
                         'pcg_winding_valley_heightmap', 'model.sdf'))
        self.assertIsNotNone(sdf)

        sdf_heightmap = sdf.models[0].links[0].visuals[0].geometry.heightmap
        biome = Biome.from_sdf(sdf_heightmap)

        self.assertIsNotNone(biome)
        self.assertEqual(biome.n_elevation_zones, 3)
        self.assertEqual(biome.n_moisture_zones, 1)

        for i in range(biome.n_elevation_zones):
            tag = biome.get_biome(i, 0)
            self.assertIsNotNone(tag)
            self.assertIsNotNone(biome.get_diffuse(tag))
            self.assertIsNotNone(biome.get_normal(tag))
Example #6
0
    def test_run_fixed_pose_engine(self):
        add_custom_gazebo_resource_path(
            os.path.join(
                os.path.dirname(os.path.abspath(__file__)),
                'gazebo_models'))
        manager = EngineManager()

        manager.add(**FIXED_ENGINE)
        self.assertIn('add_fixed_models', manager.tags)
        self.assertEqual(manager.size, 1)

        engine = manager.get('add_fixed_models')
        self.assertIsNotNone(engine)
        self.assertIsInstance(engine, FixedPoseEngine)

        models = engine.run()
        self.assertIsNotNone(models)
        self.assertIsInstance(models, list)
        self.assertEqual(len(models), 1)

        self.assertEqual(np.sum(models[0].pose.position), 0)
        self.assertEqual(np.sum(models[0].pose.quat[0:3]), 0)
Example #7
0
    def test_add_engines(self):
        add_custom_gazebo_resource_path(
            os.path.join(
                os.path.dirname(os.path.abspath(__file__)),
                'gazebo_models'))
        manager = EngineManager()

        manager.add(**FIXED_ENGINE)
        self.assertIn('add_fixed_models', manager.tags)
        self.assertEqual(manager.size, 1)

        engine = manager.get('add_fixed_models')
        self.assertIsNotNone(engine)
        self.assertIsInstance(engine, FixedPoseEngine)

        manager.add(**RANDOM_ENGINE)
        self.assertIn('add_random_objects', manager.tags)
        self.assertEqual(manager.size, 2)

        engine = manager.get('add_random_objects')
        self.assertIsNotNone(engine)
        self.assertIsInstance(engine, RandomPoseEngine)
Example #8
0
    def test_parse_heightmap_model(self):
        add_custom_gazebo_resource_path(
            os.path.join(CUR_DIR, '..', 'examples', 'models'))

        # Parse the SDF file
        sdf = parse_sdf(
            os.path.join(CUR_DIR, '..', 'examples', 'models',
                         'pcg_winding_valley_heightmap', 'model.sdf'))
        self.assertIsNotNone(sdf)
        self.assertIsNotNone(sdf.models)
        self.assertEqual(len(sdf.models[0].links[0].visuals), 1)
        self.assertEqual(len(sdf.models[0].links[0].collisions), 1)

        sdf_heightmap = sdf.models[0].links[0].visuals[0].geometry.heightmap
        self.assertIsNotNone(sdf_heightmap)

        uri_path_prefix = \
            'model://pcg_winding_valley_heightmap/materials/textures'
        self.assertIn(uri_path_prefix, sdf_heightmap.uri.value)
        self.assertEqual(len(sdf_heightmap.textures), 3)
        for texture in sdf_heightmap.textures:
            self.assertIn(uri_path_prefix, texture.diffuse.value)
            self.assertIn(uri_path_prefix, texture.normal.value)
            self.assertEqual(texture.size.value, [10])
        self.assertEqual(len(sdf_heightmap.blends), 2)
        for blend in sdf_heightmap.blends:
            self.assertGreater(blend.min_height.value, 0)
            self.assertGreater(blend.fade_dist.value, 0)
        self.assertEqual(sdf_heightmap.size.value, [1000, 1000, 25])
        self.assertEqual(sdf_heightmap.pos.value, [0, 0, -4])

        sdf_heightmap = \
            sdf.models[0].links[0].collisions[0].geometry.heightmap
        self.assertIsNotNone(sdf_heightmap)

        self.assertIn(uri_path_prefix, sdf_heightmap.uri.value)
        self.assertEqual(sdf_heightmap.size.value, [1000, 1000, 25])
        self.assertEqual(sdf_heightmap.pos.value, [0, 0, -4])
Example #9
0
    def test_from_sdf(self):
        add_custom_gazebo_resource_path(
            os.path.join(CUR_DIR, '..', 'examples', 'models'))

        # Parse the SDF file
        sdf = parse_sdf(
            os.path.join(CUR_DIR, '..', 'examples', 'models',
                         'pcg_winding_valley_heightmap', 'model.sdf'))
        self.assertIsNotNone(sdf)

        # Convert SDF heightmap element to simulation heightmap element
        sdf_heightmap = sdf.models[0].links[0].visuals[0].geometry.heightmap
        heightmap = Heightmap.from_sdf(sdf_heightmap)
        self.assertIsNotNone(heightmap)

        output_sdf = heightmap.to_sdf()
        self.assertIsNotNone(output_sdf)

        sdf_heightmap = \
            sdf.models[0].links[0].collisions[0].geometry.heightmap
        heightmap = Heightmap.from_sdf(sdf_heightmap)
        self.assertIsNotNone(heightmap)

        output_sdf = heightmap.to_sdf()
        self.assertIsNotNone(output_sdf)

        self.assertEqual(sdf_heightmap.size.value, output_sdf.size.value)
        self.assertEqual(sdf_heightmap.pos.value, output_sdf.pos.value)

        # Convert model to SimulationModel element
        model = SimulationModel.from_sdf(sdf.models[0])
        self.assertIsNotNone(model)
        output_sdf = model.to_sdf()
        self.assertIsNotNone(output_sdf)

        self.assertIsNotNone(output_sdf)
        self.assertEqual(len(output_sdf.links[0].visuals), 1)
        self.assertEqual(len(output_sdf.links[0].collisions), 1)

        sdf_heightmap = output_sdf.links[0].visuals[0].geometry.heightmap
        self.assertIsNotNone(sdf_heightmap)

        uri_path_prefix = \
            'model://pcg_winding_valley_heightmap/materials/textures'
        self.assertIn(uri_path_prefix, sdf_heightmap.uri.value)
        self.assertEqual(len(sdf_heightmap.textures), 3)
        for texture in sdf_heightmap.textures:
            self.assertIn(uri_path_prefix, texture.diffuse.value)
            self.assertIn(uri_path_prefix, texture.normal.value)
            self.assertEqual(texture.size.value, [10])
        self.assertEqual(len(sdf_heightmap.blends), 2)
        for blend in sdf_heightmap.blends:
            self.assertGreater(blend.min_height.value, 0)
            self.assertGreater(blend.fade_dist.value, 0)
        self.assertEqual(sdf_heightmap.size.value, [1000, 1000, 25])
        self.assertEqual(sdf_heightmap.pos.value, [0, 0, -4])

        sdf_heightmap = \
            output_sdf.links[0].collisions[0].geometry.heightmap
        self.assertIsNotNone(sdf_heightmap)

        self.assertIn(uri_path_prefix, sdf_heightmap.uri.value)
        self.assertEqual(sdf_heightmap.size.value, [1000, 1000, 25])
        self.assertEqual(sdf_heightmap.pos.value, [0, 0, -4])
        engine_name='random_pose',
        models=list(models.keys()),
        max_num=models,
        model_picker='random',
        no_collision=True,
        min_distance=0.0,
        policies=[placement_policy],
        constraints=local_constraints
    )
    for door_room_range in rooms_range[3:]:
        world_generator.world.rm_model(tag=world_name+'_door'+str(door_room_range.area))
    # Run placement engine
    world_generator.run_engines(attach_models=True)
    world_generator.world.name = world_name

    time_end=time.time()
    
    if args.preview:
        world_generator.world.show()
    print('time cost',time_end-time_start,'s')
    add_custom_gazebo_resource_path(args.export_models_dir)

    # Export world to file and walls model as Gazebo model
    # full_world_filename = world_generator.export_world(
    #     output_dir=args.export_world_dir,
    #     filename=world_generator.world.name + '.world',
    #     models_output_dir=args.export_models_dir,
    #     overwrite=True)

    # print('World file: {}'.format(full_world_filename))