Robotics StackExchange | Archived questions

Segmentation fault when trying to access costmap

What is this cpp code trying to do? It is subscribing to /movebase/globalcostmap/costmap topic and then I am calling the constructor in Line 41 costmap_2d::Costmap2D(msg.info.width, msg.info.height, msg.info.resolution, msg.info.origin.position.x, msg.info.origin.position.y); to initialize the costmap The make plan is generating a path from start node to goal node(both these nodes are now being hard coded) and the path is published to a topic so that I can visualize it on Rviz

Problem: This is my code. https://github.com/Akashleena/RRTSTAR/blob/main/src/rrt_star_global_planner_node.cpp Check function Line269: bool RRTstarPlannerROS::collision(float wx, float wy) When I comment everything inside this function block I don't get segmentation fault otherwise I am getting segmentation fault. I think the segmentation fault is being cause bY these function call

Line 280 costmap_->getCost(mx, my))
Line 261 float origin_x = costmap_->getOriginX(), origin_y = costmap_->getOriginY();
Line 262   float resolution = costmap_->getResolution();

Can someone suggest a solution?

Asked by aleena_infinitynbeyond on 2021-11-19 03:07:02 UTC

Comments

Why did you comment: //worldToMap(wx, wy, mx, my); ? - Line 274

Asked by osilva on 2021-11-19 11:43:02 UTC

This code is very similar to: https://github.com/rafaelbarretorb/rrt_star_global_planner/blob/master/src/collision_detector.cpp

But if you don't update mx, my this may cause the issue later on.

Asked by osilva on 2021-11-19 11:46:18 UTC

@osilva I commented worldToMap() just to find out whether I am still getting a Segmentation fault even after commenting it and yes I was getting a segfault after commenting

Asked by aleena_infinitynbeyond on 2021-11-19 14:02:01 UTC

Yup as I said I will be uncommenting those lines and updating mx and my but the thing is when I uncomment I get a segfault, I want to get the costmap values and use those functions costmap_->getCost(mx, my)) Line 261 float origin_x = costmap_->getOriginX(), origin_y = costmap_->getOriginY(); Line 262 float resolution = costmap_->getResolution();

Yes, I have seen that repo https://github.com/rafaelbarretorb/rr... the only difference is this guy has wriiten athe RRT star plugin for the move_base node whereas I want to have a rrt star executable and so I am explicitly subscribing to the costmap and not using the costmap_ros wrapper which is being used when you want to have a global planner as a plugin to move_base.

Asked by aleena_infinitynbeyond on 2021-11-19 14:08:01 UTC

Answers