Advertisement
Guest User

subscribe and publish in the same class

a guest
Aug 2nd, 2011
822
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. class Spinner {
  2.   ros::NodeHandle n_;
  3.   ros::Publisher spin_pub;
  4.   ros::Subscriber sub;
  5. public:
  6.   Spinner(ros::NodeHandle n) :
  7.     n_(n)
  8.   {
  9.     spin_pub = n.advertise<geometry_msgs::Twist> ("/turtlebot_node/cmd_vel", 1000);
  10.     sub = n.subscribe("/robot_pose_ekf/odom_combined", 1000,  spin_cb);  //Does not work!
  11.   }
  12.  
  13.   void spin_cb(const geometry_msgs::PoseWithCovarianceStamped msg)
  14.   {
  15.     //do stuff
  16.   }
  17. };
  18.  
  19. int main(int argc, char** argv)
  20. {
  21.   ros::init(argc, argv, "spin");
  22.   ros::NodeHandle n;
  23.   Spinner spin_object = Spinner(n);
  24.   ros::spin();
  25.   return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement