ROS Wiki ではこの方法についてあまり触れていないので、ここにまとめておきます。



#include "ros/ros.h"
#include "sensor_msgs/Image.h"

class SubPub
  ros::NodeHandle n_;
  ros::Publisher pub_;
  ros::Subscriber sub_;

  void callback(const sensor_msgs::Image &msg_sub);

    sub_ = n_.subscribe("/topic_sub", 1000, &SubPub::callback, this);
    pub_ = n_.advertise<sensor_msgs::Image>("/topic_pub", 1000);

void SubPub::callback(const sensor_msgs::Image &msg_sub)
  sensor_msgs::Image msg_pub;

  // 処理


int main(int argc, char *argv[])
  ros::init(argc, argv, "node_subpub");
  SubPub subpub;


/topic_sub というトピックをsubscribeし、/topic_pub というトピックをpublishするようにしています。

また、メッセージ型としては、sensor_msgs::Image をsubscribeし、同じ型をpublishするようにしています。






  1. 6ccpBPqZNu より:


  2. graliontorile より:

    Thanks for sharing superb informations. Your site is so cool. I’m impressed by the details that you have on this site. It reveals how nicely you understand this subject. Bookmarked this web page, will come back for extra articles. You, my pal, ROCK! I found simply the info I already searched everywhere and simply couldn’t come across. What an ideal site.

  3. YAYrcDpMnRdxb6wi9o8uUuavcR9oXJbPdNzhFeZv5qTcleR0yZ1T32rBxv13ThWxutnDDjUh0q7xWKjzDDX6weLgA0o9oAspfaWTOJ94bCIqkfPf1A462mNuQLypgL3F14WklCrF0oSLJwVpjRXCQuCnl9RYk

  4. I’ve been absent for some time, but now I remember why I used to love this website. Thank you, I¦ll try and check back more often. How frequently you update your web site?

  5. xin gaming demo より:

    Wow! Thank you! I continuously needed to write on my blog something like that. Can I include a fragment of your post to my site?

  6. slot terbaik より:

    Some genuinely great info , Sword lily I discovered this.

  7. Magnificent site. Lots of useful information here. I am sending it to several pals ans also sharing in delicious. And obviously, thanks on your sweat!

  8. pragmatic slot より:

    Appreciate it for helping out, wonderful info. “Riches cover a multitude of woes.” by Menander.

  9. I love your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to do it for you? Plz answer back as I’m looking to design my own blog and would like to know where u got this from. cheers

  10. Fastwin77 より:

    I am glad to be a visitant of this unadulterated weblog! , thanks for this rare information! .

  11. Betwing88 より:

    Great blog! Do you have any tips for aspiring writers? I’m hoping to start my own blog soon but I’m a little lost on everything. Would you advise starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m totally confused .. Any recommendations? Kudos!