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

Revision history [back]

I think that your: pub_data.publish(tw); and publisher related stuff must go in tour callback function.

Something like that:

class PublishData
{
  ros::NodeHandle n;
  ros::NodeHandle n1;
  geometry_msgs::Twist tw;
public:
  PublishData()
  {
    tw.linear.x = 0.1;
    ros::Publisher pub_data = n.advertise<geometry_msgs::Twist>("/mobile_base/commands/velocity", 10);
    ros::Subscriber bumper = n.subscribe("/mobile_base/events/bumper",1,callback);
    ROS_INFO("DataPublished");
    while(ros::ok())
    {
        //ROS_WARN("In Loop.");
        ros::spin();
    }
  }
  void callback(const kobuki_msgs::BumperEventConstPtr msg)
  {
     ROS_ERROR("MOVE!!! Bumper pressed.");
     ROS_INFO("MOVE!!! Bumper pressed.");
     pub_data.publish(tw);
  }
};