ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

how to subscribe to bumper topic on move_base

asked 2017-12-11 03:23:30 -0500

rostaro gravatar image

updated 2017-12-20 11:06:38 -0500

I am a beginner at ROS and ROS navigation stack.

I have been using roomba_500_series and navigation stack (including move_base module). I would like to subscribe to /bumper topic in move_base. The topic type of /bumper is roomba_500_series/Bumper. I can already use bumper topic by using kobuki_bumper2pc. However I want to use the topic in move_base one way or another.

First of all, I would like to try to turn rommba left when the right bumper is true after publishing /cmd_vel. I modified move_base.cpp like below.

move_base.cpp (line: 902~) link text

//make sure that we send the velocity command to the base                             
//***modified part
 bump_sensor_sub_ = nh.subscribe("/bumper", 1000, &MoveBase::BumperSensorCB, this);  
 if (right_bumper==1){            
       cmd_vel.linear.x = 0.0;
       cmd_vel.linear.y = 0.0;
       cmd_vel.angular.z = 0.78;

       bump_sensor_sub_ = nh.subscribe("/bumper", 1000, &MoveBase::BumperSensorCB, this);
 }  //***

function MoveBase::BumperSensorCB which I made

void MoveBase::BumperSensorCB(const roomba_500_series::Bumper::ConstPtr& msg) 
    left_bumper = msg->left.state;
    right_bumper = msg->right.state;

right_bumper & left_bumper are boolean data type

bool right_bumper, left_bumper;

I modified move_base.cpp as noted above. However roomba doesn't work as I thought. It seems like MoveBase can't subscribe to /bumper topic now. Although, the cause might be CMakeLists.txt , I have no idea how to modify it to use /bumper topic from roomba_500_series.

Sorry that was such a long post and my poor English.

I would appreciate it if you could answer my question.

Thank you.

edit retag flag offensive close merge delete



Why did you modify move_base.cpp? Modifying source code as you did is generally not a good idea. If/when you update this package your modification will be gone.

jayess gravatar image jayess  ( 2017-12-20 13:52:47 -0500 )edit

I am trying to create new state_link text in MoveBase::executeCycle. When /bumper's state is unavoidably true, I'd like to control roomba in new state_.

rostaro gravatar image rostaro  ( 2017-12-21 06:13:27 -0500 )edit

The modifying code above is to confirm whether it works or not on an experimental basis. I am not a engineer, so I have no idea, it is good or not.

rostaro gravatar image rostaro  ( 2017-12-21 06:24:17 -0500 )edit

1 Answer

Sort by » oldest newest most voted

answered 2017-12-11 05:48:09 -0500

You are subscribing to the same topic in a while.

You have to subscribe only once.

Since you are already subscribing to the node before the while, try to remove the bump_sensor_sub_ = nh.subscribe("/bumper", 1000, &MoveBase::BumperSensorCB, this); that is inside the while(right_bumper==1){} and see if it works.

edit flag offensive delete link more


Thank you for answering my question and I`m sorry for the delay in my reply.

Actually, I am subscribing the same topic in a while. My intention is to exit the while by updating bumper data. Therefor, I am doing it. Please excuse my lack of explanation.

rostaro gravatar image rostaro  ( 2017-12-20 04:25:14 -0500 )edit

In terms of this question that I have posted, I have already solved the problem. The cause might be CmakeLists.txt. I appreciate your understanding and cooperation. Please excuse any mistakes in this letter. Thank you.

rostaro gravatar image rostaro  ( 2017-12-20 04:33:59 -0500 )edit

Question Tools



Asked: 2017-12-11 03:23:30 -0500

Seen: 723 times

Last updated: Dec 20 '17