// Node that consumes messages. structConsumer : public rclcpp::Node { Consumer(const std::string & name, const std::string & input) : Node(name, rclcpp::NodeOptions().use_intra_process_comms(true)) { // Create a subscription on the input topic which prints on receipt of new messages. sub_ = this->create_subscription<std_msgs::msg::Int32>( input, 10, [](std_msgs::msg::Int32::UniquePtr msg) { printf( " Received message with value: %d, and address: 0x%" PRIXPTR "\n", msg->data, reinterpret_cast<std::uintptr_t>(msg.get())); }); }
Published message with value: 0, and address: 0x5625E3159130 Received message with value: 0, and address: 0x5625E3159130 Published message with value: 1, and address: 0x5625E3159130 Received message with value: 1, and address: 0x5625E3159130 Published message with value: 2, and address: 0x5625E3159130 Received message with value: 2, and address: 0x5625E3159130 Published message with value: 3, and address: 0x5625E3159130 Received message with value: 3, and address: 0x5625E3159130 Published message with value: 4, and address: 0x5625E3159130 Received message with value: 4, and address: 0x5625E3159130 Published message with value: 5, and address: 0x5625E3159130 Received message with value: 5, and address: 0x5625E3159130 Published message with value: 6, and address: 0x5625E3159130 Received message with value: 6, and address: 0x5625E3159130 Published message with value: 7, and address: 0x5625E3159130 Received message with value: 7, and address: 0x5625E3159130 Published message with value: 8, and address: 0x5625E3159130 Received message with value: 8, and address: 0x5625E3159130 Published message with value: 9, and address: 0x5625E3159130 Received message with value: 9, and address: 0x5625E3159130