Robotics StackExchange | Archived questions

How to convert gmapping datas into a new frame with a different resolution ?

Hi all,

I want to create a new map according to the data from the map generated by the gmapping but according to the robot position and orientation and other specifications, I'm going to explain exactly what I want. So here's the initial situation : image description

This new map must respect those rules :

image description

Here is the code for this part it might help you see what I'm doing :

std::vector<double> unknown_counter(tile_map_size);
std::vector<double> obstacle_counter(tile_map_size);
std::vector<double> free_counter(tile_map_size);
std::vector<double> number_cells(tile_map_size);

float x_from_map_origin = 0.0;
float y_from_map_origin = 0.0;
int tile_index = 0;
for (int map_row = 0; map_row < map_metadata.width; map_row++)
   {
    for (int map_column = 0; map_column < map_metadata.height; map_column++)
    {
          number_cells[tile_index] += 1;
          x_from_map_origin = map_metadata.origin.position.x + map_row * map_metadata.resolution;
          y_from_map_origin = map_metadata.origin.position.y + map_column * map_metadata.resolution;
          tile_index = floor((x_from_map_origin - tile_map_metadata.origin.position.x)/tile_length_) + floor((y_from_map_origin - tile_map_metadata.origin.position.y)/tile_length_) * tile_map_metadata.width;

          if (occupancy_grid_temp.data[map_row + map_column*map_metadata.width] == OCCUPIED_CELL)
          {       
                obstacle_counter[tile_index] += 1;
          }
          else if (occupancy_grid_temp.data[map_row + map_column*map_metadata.width] == UNKNOWN_CELL)
          {
               unknown_counter[tile_index] += 1;
           }
           else 
           {
                free_counter[tile_index] += 1;
           }
       }
}
std::vector<int8_t> vect(tile_map_size);
tile_map_occupancy_grid.data = vect;
tile_map_occupancy_grid.info = tile_map_metadata;
for (int tile_map_index = 0; tile_map_index < tile_map_size; tile_map_index++)
{
       //If there is more than 80% of obstacles
       if (100*obstacle_counter[tile_map_index]/number_cells[tile_map_index] > 80)
       {
            tile_map_occupancy_grid.data[tile_map_index] = 100;
       }
       //if there's at least 20% of space
       else if (100*free_counter[tile_map_index]/number_cells[tile_map_index] > 20)
       {
            tile_map_occupancy_grid.data[tile_map_index] = 0;
       }
       else
       {
            tile_map_occupancy_grid.data[tile_map_index] = 50;
       }
}

I'm currently able to get to this result because I'm launching my node before the robot moves so the odom and map frames are aligned. My problem is now to get to this result : image description

If I move the robot before creating the new map (and that will happen), since the orientation has changed it makes all the situation a lot more complex. So I have these questions :

I hope you understand my problem and I'm open for suggestions if you have a hint on how to solve it. Thank you in advance

Asked by Delb on 2018-08-16 08:51:23 UTC

Comments

Answers