Ask Your Question
1

How can I use /bumper topic data in move_base ?

asked 2017-11-06 03:56:55 -0600

rostaro gravatar image

updated 2017-11-20 23:33:56 -0600

Hi there,

I am new to ROS and ROS navigation stack. Right now I am trying to use /bumper topic data ( msg->left.state and msg->right.state ) on roomba_500_series in move_base. The topic has been already published from /roomba560_node. I would like to know how to use(subscribe) it in move_base. Please let me know if you know any. (What I would like to do is to use bumper's right state and its left state ( true or false ). For example, if right state is true, I let roomba turn left and go straight.)

*additional comment

I modified kobuki_bumper2pc as bumper2pc as follows.

//bumper2pc.cpp 
#include <ros/ros.h> 
#include <ros/ros.h>
#include <iostream>
#include <pluginlib/class_list_macros.h>
#include <roomba_500_series/Bumper.h>
#include "bumper2pc/bumper2pc.hpp"
#include <geometry_msgs/Twist.h>

namespace bumper2pc{
 bool left_bumper, right_bumper;

 //this function is defined in "bumper2pc.hpp"
 void Bumper2PcNodelet::BumperUpdateCB(const roomba_500_series::Bumper::ConstPtr& msg){
  left_bumper = msg->left.state;
  right_bumper = msg->right.state;
 }

 void Bumper2PcNodelet::coreSensorCB(const roomba_500_series::Bumper::ConstPtr& msg){

  left_bumper = msg->left.state;
  right_bumper = msg->right.state;

  ros::NodeHandle n;
  ros::Publisher vel_pub_ = n.advertise<geometry_msgs::Twist>("/cmd_vel", 1)
  geometry_msgs::Twist cmd_vel;

  if (left_bumper == 1){

   bool judge_left = true;
   while(judge_left == true){
    if(judge_left == false){ break; }

    cmd_vel.linear.x = 0.0;
    cmd_vel.angular.z = 0.0;
    vel_pub_.publish(cmd_vel);

    while(left_bumper == 1){
     cmd_vel.linear.x = 0.0;
     cmd_vel.angular.z = -0.78; //turn right while left bumper is true
     vel_pub_.publish(cmd_vel);

     bumper_update_sub_ = n.subscribe("/bumper", 1000, &Bumper2PcNodelet::BumperUpdateCB, this);  //update bumper data

    }

    while(right_bumper == 0 || left_bumper == 0){
     if(judge_left == false){ break; }

     cmd_vel.linear.x = 0.2;
     cmd_vel.angular.z = 0.0; 
     vel_pub_.publish(cmd_vel);  

     bumper_update_sub_ = n.subscribe("/bumper", 1000, &Bumper2PcNodelet::BumperUpdateCB, this);
     if(right_bumper == 1){ judge_left = false; }
     if(left_bumper == 1){ break; }
    }
   }
   return;
  }

  if (right_bumper == 1){
     //same as above ("left" -> "right")
  }

 void Bumper2PcNodelet::onInit(){
  ros::NodeHandle nh = this->getPrivateNodeHandle();

  core_sensor_sub_ = nh.subscribe("/bumper", 1000, &Bumper2PcNodelet::coreSensorCB, this);  //core_sensor_sub is defined in "bumper2pc.hpp"
 }
} //namespace bumper2pc

PLUGINLIB_EXPORT_CLASS(bumper2pc::Bumper2PcNodelet, nodelet::Nodelet);
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2017-11-06 09:49:05 -0600

David Lu gravatar image

The easiest option would probably be to translate the bumper data into a PointCloud, which you could then use as an input to your costmap.

edit flag offensive delete link more

Comments

I'm terribly sorry for the delay in my reply.

Thank you for answering my question. I used kobuki_bumper2pc and rewrited it. Finally, I could publish cmd_vel from bumper2pc according to bumper's states. Thank you very much.

rostaro gravatar imagerostaro ( 2017-11-20 02:35:19 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-11-06 03:55:37 -0600

Seen: 375 times

Last updated: Nov 20 '17