Migration

Executor

#include "ros/ros.h"

int main(int argc, char **argv) {
   ros::init(argc, argv, "talker");
   ros::NodeHandle n;

   ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);
   ros::Rate loop_rate(10);

   int count = 0;
   while (ros::ok()) {
      ros::spinOnce();
      loop_rate.sleep();
   }

   return 0;
}

Logger

NODELET_INFO("Initializing nodelet TemplatePackageNodelet..."); // only for nodelet
ROS_INFO("Publishing: '%s'", message.data.c_str());

Launch

from launch import LaunchDescription
from launch_ros.actions import Node

def generate_launch_description():
   return LaunchDescription([
      Node(
            package='turtlesim',
            namespace='turtlesim1',
            executable='turtlesim_node',
            name='sim'
      ),
      Node(
            package='turtlesim',
            namespace='turtlesim2',
            executable='turtlesim_node',
            name='sim'
      ),
      Node(
            package='turtlesim',
            executable='mimic',
            name='mimic',
            remappings=[
               ('/input/pose', '/turtlesim1/turtle1/pose'),
               ('/output/cmd_vel', '/turtlesim2/turtle1/cmd_vel'),
            ]
      )
   ])

CMake

# TODO

Publisher and Subscriber

ros::Publisher publisher = n.advertise<std_msgs::String>("topic", 10);

Image Transport

// Use the image_transport classes instead.
#include <ros/ros.h>
#include <image_transport/image_transport.h>

void imageCallback(const sensor_msgs::ImageConstPtr &msg) {
// ...
}

ros::NodeHandle nh;
image_transport::ImageTransport it(nh);
image_transport::Subscriber sub = it.subscribe("in_image_base_topic", 1, imageCallback);
image_transport::Publisher pub = it.advertise("out_image_base_topic", 1);

// 类方法(其API需要bind)
image_transport::Subscriber sub =
   it.subscribe("in/image", 1, std::bind(&TensorrtYoloNodelet::callback, this, _1));