Subscribing to move_base feedback

asked 2019-08-10 15:47:38 -0600

khasreto gravatar image

updated 2019-08-11 15:22:32 -0600

Hi,

I have following problem:

I simply want to now the current status published by move_base actionserver, but the problem is that I can't make any changes to current move base goal so I can. I want to treat this rather than normal topic, I tried that but it always gives errors[core dumped]

#include "ros/ros.h"
#include "std_msgs/String.h"
#include <actionlib/client/terminal_state.h>
#include <actionlib_msgs/GoalStatusArray.h>

void statusCallback(const actionlib_msgs::GoalStatusArray &msg) {
  ROS_INFO("calling");
   int status = msg.status_list[0].status;
   ROS_INFO("I heard status: %d", status);
}

int main(int argc, char **argv) {

  ros::init(argc, argv, "sub_state_node");

  ros::NodeHandle nh;
  ROS_INFO("inicialized");
  ros::Subscriber move_base_sub = nh.subscribe("move_base/status", 1, statusCallback);
  ros::Subscriber cmd_sub = nh.subscribe("cmd_vel", 1, cmdCallback);
  ROS_INFO("made sub");
  ros::spin();

  return 0;
}

Do you guys found solution for this problem?

Edit: I've updated code

edit retag flag offensive close merge delete

Comments

Are your action server and subscriber using the same callback method?

zmk5 gravatar image zmk5  ( 2019-08-10 16:37:32 -0600 )edit

It would be useful to post the entire error instead of the end of it

jayess gravatar image jayess  ( 2019-08-10 21:16:16 -0600 )edit

Yes, if you could give us the error and a more detailed, concise explanation of what you are trying to do would be helpful :-)

zmk5 gravatar image zmk5  ( 2019-08-10 21:17:51 -0600 )edit

I only want to know current status of move_base/status topic and call appropriate service for each status. So I came to idea to subscribe this topic but it's not that simple because every time callback function should be executed node crashes

rosrun simulation sub_state_node
[ INFO] [1565530644.474089423]: inicialized
[ INFO] [1565530644.506886144]: made sub
[ INFO] [1565530644.727230590]: calling
Segmentation fault (core dumped)
khasreto gravatar image khasreto  ( 2019-08-11 08:39:44 -0600 )edit

Add the ::ConstPtr& to the end of the message for the callback, so it would look like this:

void statusCallback(const actionlib_msgs::GoalStatusArray::ConstPtr& msg)

See if this works.

zmk5 gravatar image zmk5  ( 2019-08-11 11:21:56 -0600 )edit

the same result

khasreto gravatar image khasreto  ( 2019-08-11 14:53:16 -0600 )edit
1

But I fount accidentally that this problem occurs only if any goal was passed to move base and status=' ' I surmise that memory is not allocated before sending any goal and this is the problem. Solution is to add if statement checking size of status_list :)

khasreto gravatar image khasreto  ( 2019-08-11 15:03:22 -0600 )edit