zm0612 / Hybrid_A_Star

Hybrid A Star algorithm C++ implementation
Other
633 stars 138 forks source link

confusion between map_grid_resolution vs state_grid_resolution #5

Closed LotfiZ closed 2 years ago

LotfiZ commented 2 years ago

Hi dear,

First, you made an amazing job here ! your code is really clean and understandable at some point.

Now, i'm trying to integrate your implementation as a global planner into the pipeline of the navigation stack in ROS. I'm almost done but there is few things that did not work well specially with obstacle collision setup ! i'm thinking in the initialization of the costmap ( occupancy grid) because i did some changes there as i was having some troubles with segmentation fault.

for example : i have a map with a resolution of 0.025 m/p and i setup the map_resolution parameter to 1 because i want to use the same resolution for the map grid and state grid. However i think that i did not manage to understand well the subtlety between the map_grid_resolution and state_grid_resolution.

Last thing, why you are using this to iterate over the map to set the obstacle :

for (unsigned int w = 0; w < map_w; ++w) {
            for (unsigned int h = 0; h < map_h; ++h) {
                auto x = static_cast<unsigned int> ((w + 0.5) * map_resolution
                                                    / current_costmap_ptr_->info.resolution);
                auto y = static_cast<unsigned int> ((h + 0.5) * map_resolution
                                                    / current_costmap_ptr_->info.resolution);
               if (current_costmap_ptr_->data[y * current_costmap_ptr_->info.width + x]) {
                    kinodynamic_astar_searcher_ptr_->SetObstacle(w, h);
                }
} 

Instead of just iterating over the map directly like this :

for (unsigned int w = 0; w < map_w; ++w) {
            for (unsigned int h = 0; h < map_h; ++h) {

               if (current_costmap_ptr_->data[h * current_costmap_ptr_->info.width + w]) {
                    kinodynamic_astar_searcher_ptr_->SetObstacle(w, h);
                }
}

For sure that there is an obvious reason here but i can't catch it.

If this is not relevant, please feel free to close the issue.

Thank you !

zm0612 commented 2 years ago

Hello, @LotfiZ

thank you very much for your attention to my project. Due to the busy work recently, I did not reply to you in time. I am very sorry.

The question you are confused about is indeed rather difficult in my opinion.

map_grid_resolution: It represents the precision of the map. state_grid_resolution: It represents the search accuracy of the state space.

I'll try to explain this to you, but since it's really abstract, I can't promise to explain it. I try my best.

The state space is the search space of hybrid a star, which is a three-dimensional space. state_grid_resolution represents the resolution of the state variables when I search in this space. More specifically, it represents the state variables x and y. resolution. And why map_grid_resolution and state_grid_resolution should be set separately, because if the sampling of the state space is too small, the search time will be very slow. And map_grid_resolution represents the resolution of the actual scene map. The smaller it is, the finer the division of the space is, so my vehicle can get closer to the obstacle without colliding.

As for why I didn't write the following code as you said, in fact, I was lazy here, because I didn't separate map_grid_resolution and state_grid_resolution, which caused some coupling between them. So you can see my way of writing, if you can understand the difference between map_grid_resolution and state_grid_resolution, you can try to improve it here.

for (unsigned int w = 0; w < map_w; ++w) {
            for (unsigned int h = 0; h < map_h; ++h) {

               if (current_costmap_ptr_->data[h * current_costmap_ptr_->info.width + w]) {
                    kinodynamic_astar_searcher_ptr_->SetObstacle(w, h);
                }
}
LotfiZ commented 2 years ago

Hello @zm0612,

Thank you very much for taking from your time explain the difference between the two resolution, i understand more the difference ! I'll dig more this concept and try to do something about it.

Thank you again !!