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

Revision history [back]

click to hide/show revision 1
initial version

I have figure it out. Instead of subscribe to turtlebot_node, I subscribe to roomba_500_series. Here is my modified code and it is working for me. Note that, turtlebot need to connect to roomba in order to receive sensor data from bumper. roomba_500_series also publish sensor data from ir_bumper. The code is:

#include <ros/ros.h>
#include <roomba_500_series/Bumper.h>
#include <geometry_msgs/Twist.h>
#include <ros/rate.h>
#include <iostream>
#include <stdio.h>                        

using namespace std;    
bool left_bumper, right_bumper;

//define the bumperCallback function
void bumperCallback(const roomba_500_series::Bumper::ConstPtr& msg)
{
     cout<<"Check point 11111111111111111"<<endl;
     left_bumper = msg->left.state;
     right_bumper = msg->right.state;
     cout<<"left bumper been hitted. value = "<<left_bumper<<endl;
     cout<<"right bumper been hitted. value = "<<right_bumper<<endl;
}

//ROS node entry point 
int main(int argc, char **argv)
{
     ros::init(argc, argv, "turtlebot_test_node");
    ros::NodeHandle n;

    ros::Subscriber bumperSubscriber = n.subscribe("/bumper", 1000, bumperCallback);
    ros::Publisher velocityPublisher = n.advertise<geometry_msgs::Twist>("cmd_vel", 1);

    //create a Twist message to publish the velocity
    geometry_msgs::Twist velMessage;
    velMessage.linear.x = 0.0;
    velMessage.angular.z = 0.0;

    //publish the message
    velocityPublisher.publish(velMessage);

   ros::spin();

   return 0;
}

I have figure it out. Instead of subscribe to turtlebot_node, I subscribe to roomba_500_series. Here is my modified code and it is working for me. Note that, turtlebot need needs to connect to roomba in order to receive sensor sensors data from bumper. roomba_500_series also publish sensor sensors data from ir_bumper. The code is:

#include <ros/ros.h>
#include <roomba_500_series/Bumper.h>
#include <geometry_msgs/Twist.h>
#include <ros/rate.h>
#include <iostream>
#include <stdio.h>                        

using namespace std;    
bool left_bumper, right_bumper;

//define the bumperCallback function
void bumperCallback(const roomba_500_series::Bumper::ConstPtr& msg)
{
     cout<<"Check point 11111111111111111"<<endl;
     left_bumper = msg->left.state;
     right_bumper = msg->right.state;
     cout<<"left bumper been hitted. value = "<<left_bumper<<endl;
     cout<<"right bumper been hitted. value = "<<right_bumper<<endl;
}

//ROS node entry point 
int main(int argc, char **argv)
{
     ros::init(argc, argv, "turtlebot_test_node");
    ros::NodeHandle n;

    ros::Subscriber bumperSubscriber = n.subscribe("/bumper", 1000, bumperCallback);
    ros::Publisher velocityPublisher = n.advertise<geometry_msgs::Twist>("cmd_vel", 1);

    //create a Twist message to publish the velocity
    geometry_msgs::Twist velMessage;
    velMessage.linear.x = 0.0;
    velMessage.angular.z = 0.0;

    //publish the message
    velocityPublisher.publish(velMessage);

   ros::spin();

   return 0;
}