Skip to content

[Question] The sampling points generated by flat_patch_sampling are highly unevenly distributed #4281

@DrPengZhe

Description

@DrPengZhe

I am using flat_patch_sampling to collect obstacle-free points as initial positions for my robots. However, when visualizing these points in yellow, I found that their distribution across the map is extremely uneven—some areas contain a large number of points, while others have very few. This uneven distribution undermines my goal of having robots spawn randomly and uniformly across the terrain. Since I am using only a single sub-terrain, I am not sure what is causing the issue. Below is the code I used to generate the terrain:

        terrain_cfg = TerrainImporterCfg(
            num_envs=self.num_envs,
            prim_path="/World/defaultGroundPlane",
            terrain_type="generator",
            terrain_generator=TerrainGeneratorCfg(
                seed=0,
                curriculum=False,
                size=(75.0, 75.0),
                border_width=5.0,
                num_rows=1,
                num_cols=1,
                horizontal_scale=0.1,
                vertical_scale=0.1, 
                use_cache=False,
                sub_terrains={
                    "obstacles": HfDiscreteObstaclesTerrainCfg(
                        obstacle_height_mode="fixed",   # The mode to use for the obstacle height:   choice   fixed
                        size=(75.0, 75.0),
                        horizontal_scale=0.1,
                        vertical_scale=0.1,  # 1.0   0.1
                        border_width=0.0,
                        num_obstacles=50,
                        obstacle_width_range=(1.0, 2.0),
                        obstacle_height_range=(10.0, 10.0), 
                        platform_width=0.1, 
                        flat_patch_sampling={
                            "target": FlatPatchSamplingCfg(
                                num_patches=20000,
                                patch_radius=0.8,  
                                max_height_diff=0.)
                        },
                    )
                },
            ),
        )
        terrain: TerrainImporter = terrain_cfg.class_type(terrain_cfg)
        self.valid_positions: torch.Tensor = terrain.flat_patches['target']   # [num_rows, num_cols, num_patches, 3]

And I also set patch_radius = 0.8, but some sampled points still appear inside obstacles. From the visualization, you can clearly see yellow points located on top of obstacles. I tried adjusting this value to 0.9, 1.0, and so on, but none of these settings solved the issue. Unfortunately, I am unable to inspect the internal implementation of the flat_patch_sampling function to understand how its sampling logic works. This problem has been troubling me for quite a while. Any help or insight would be greatly appreciated!

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions