Unable to publish to move_base

asked 2019-04-28 17:08:20 -0500

Neeharika gravatar image

updated 2019-04-28 20:21:06 -0500

I am trying to stop the robot and this the code I have written in my program

ros::Publisher pub1 = nh_->advertise<actionlib_msgs::goalid> ("/move_base/cancel", 1000);

actionlib_msgs::GoalID msg;

msg.id = "";



But, the robot continues to move and I even checked by listening to the topic using the below command but found no response.

rostopic echo /move_base/cancel

However, when I try to publish to the topic, directly from terminal, it works.

rostopic pub /move_base/cancel actionlib_msgs/GoalID -- {}

and also listening to the topic

rostopic echo /move_base/cancel

gives the below message

stamp: secs: 0 nsecs: 0 id: ''

Any idea why this might happen?

Node handle declaration:

class Door {

public: Door(ros::NodeHandle* nh);

protected: ros::NodeHandle *nh_;


Door::Door( ros::NodeHandle* nh ) {

nh_ = nh;

int main(int argc, char**argv) {
ros::init(argc, argv,"robot_navigation");

ros::NodeHandle nh;

ros::NodeHandle privateNode("~");
Door door(&nh);

edit retag flag offensive close merge delete


Can you please edit the question to add your node handle declaration?

janindu gravatar image janindu  ( 2019-04-28 19:45:50 -0500 )edit

Yes, included the node declaration

Neeharika gravatar image Neeharika  ( 2019-04-28 20:21:31 -0500 )edit

If you don't have subscribers, you don't need ros::spinOnce(). However, that's not the problem here. Where does your publisher code come in your class Door, and how is it called inside the main()?

janindu gravatar image janindu  ( 2019-04-28 20:39:56 -0500 )edit

From main, run() is called (which is a member function of Door). Inside run(), I am listening to the topic /odom and in it's corresponding callback function, I have the publisher code for /move_base/cancel.

Neeharika gravatar image Neeharika  ( 2019-04-28 21:16:13 -0500 )edit

You need to show your code please.

janindu gravatar image janindu  ( 2019-04-28 21:17:03 -0500 )edit