ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | Q&A answers.ros.org

# Segmentation fault while modifying move_base

Hello all,

I am currently trying to modify the move_base a bit such that the plan thread runs continuously and not dependent on the executeCB function of the action server.

However, when I try doing this I get Segmentation error due to accessing the mutex of costmap_2d in the makePlan function.

I have been trying to figure out the issue since a few days now, but have no clue whats going wrong.

I am not an expert programmer and new to threads. SO please pardon me if this query sounds naive.

edit retag close merge delete

Sort by » oldest newest most voted

You are accessing a part of memory that doesn't exist. I change move_base the last week. The code were made to be initialize once, if you try to initialize again without destroy the objects, you will get Segmentation error.

If you don't do that, the problem is the global variables, for example this parameters: runPlanner_=false; state_ = PLANNING; recovery_index_ = 0; recovery_trigger_ = PLANNING_R; you need to be careful with that. Most important, any time you want acess something of the planner_costmap_ros_ or controller_costmap_ros_, you need to do

planner_costmap_ros_->stop();
controller_costmap_ros_->stop();


or pause (planner_costmap_ros_->pause();) depending what you want and then do planner_costmap_ros_->start(); to free the mutex.

They use the mutex to have threads, and to limit acess to objects that multiple threads try do acess, is like a traffic light, if is red none can acess, if green, a thread can ask acess and if obtain the acess, the traffic light become red, the thread to something, and then free the object, and turn traffic light to green.

When you see boost::unique_lock<boost::mutex> lock(planner_mutex_); and lock.unlock(); is what happening. I don't konw if this coment help you anything, but this was my experience.

Good luck, I lost almost two weeks on move_base. 1 week to understand why the segmentation error, the other doing my code.

more

Hello,

Sorry for a delay reply. And thank you for your answer. It was very helpful. I could get the segmentation error solved. However, I still had one query. What I am doing currently is separating costmaps from move base. So in movebase I use costmaps which are created basically in other node. You mentioned I need to do planner_costmap_ros_->stop() and/or controller_costmap_ros_->stop() before using the costmaps. So even for my requirement I should do this in move_base before using the costmaps?

more

Depends, if you have several process to get access of your costmaps my answer is yes. This in move_base is needed, because, when you are refreshing the data of costmap through the laser readings, your move_base could not read that data, or will get a segmentation error.

( 2015-08-28 12:55:00 -0500 )edit

Two process trying to get the same data at the same time will create conflicts. That's why the mutex. If I helped put a vote on my first answer.

( 2015-08-28 12:56:37 -0500 )edit