locusrobotics / robot_navigation

Spiritual successor to ros-planning/navigation.
444 stars 149 forks source link

Segmentation fault on costmap_adapter::getValue and Locomotor freezes randomly #102

Open yyagin opened 1 year ago

yyagin commented 1 year ago

Hello, I am getting a segmentation fault, so I run the locomotor with the debugger on (noetic branch compiled from source with the "RelWithDebInfo" flag). It's caused by an index value that is not in the bounds of the size of the costmap.

unsigned char CostmapAdapter::getValue(const unsigned int x, const unsigned int y) const
{
  unsigned int index = costmap_->getIndex(x, y);
  return costmap_->getCharMap()[index];
} 

I fixed it with changing the code something like this:

{
  unsinged char result{0};
  const auto charmap_size =  costmap_->getSizeInCellsX() * costmap_->getSizeInCellsY();
  const auto index = costmap_->getIndex(x, y);
  index > charmap_size - 1 ?  result = nav_core2::Costmap::NO_INFORMATION : result =costmap_->getCharMap()[index];
  return result;
}

It seems like it's resolved.

Another issue is, I really do not know it's related to getValue problem but, Locomotor freezes, robot stops and both costmaps are not updating and this is happening randomly (As far as I tested, I cannot come up with a cause for this.) I run the Locomotor with the debugger again and I put breakpoints randomly to understand where the code is stuck. I found that it's stuck in ObstacleFootprintCritic::scorePose function. You can see in the attachment where I put the breakpoint and scope variables. I think that there is something wrong with start_index_.x, end_index_.x and side_index_. Their type is unsigned int but is it possible to any assignment done from a negative integer? For example, in the line.cpp L54-L56 there is an assignment from nav_grid::SignedIndex to end_index_ and it's type is nav_grid::Index. Is it intentional, or is there something wrong with it?

image