Robotics StackExchange | Archived questions

Subscribing to move_base feedback

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

Asked by khasreto on 2019-08-10 15:47:38 UTC

Comments

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

Asked by zmk5 on 2019-08-10 16:37:32 UTC

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

Asked by jayess on 2019-08-10 21:16:16 UTC

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

Asked by zmk5 on 2019-08-10 21:17:51 UTC

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)

Asked by khasreto on 2019-08-11 08:39:44 UTC

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.

Asked by zmk5 on 2019-08-11 11:21:56 UTC

the same result

Asked by khasreto on 2019-08-11 14:53:16 UTC

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 :)

Asked by khasreto on 2019-08-11 15:03:22 UTC

Answers