Skip to content

Instantly share code, notes, and snippets.

@youtalk
Last active June 5, 2017 22:08
Show Gist options
  • Save youtalk/6b9110647785f309a49aba5ff8a15197 to your computer and use it in GitHub Desktop.
Save youtalk/6b9110647785f309a49aba5ff8a15197 to your computer and use it in GitHub Desktop.
two_node_pipeline.cpp 2
// メッセージをSubscribeするSubscriberクラス
struct Consumer : public rclcpp::Node
{
Consumer(const std::string & name, const std::string & input)
: Node(name, "", true)
{
// input名のトピックをSubscribeするSubscriberを作成
sub_ = this->create_subscription<std_msgs::msg::Int32>(
input, [](std_msgs::msg::Int32::UniquePtr msg) { // std::unique_ptr<std_msgs::msg::Int32>の別名
printf(
" Received message with value: %d, and address: 0x%" PRIXPTR "\n", msg->data,
reinterpret_cast<std::uintptr_t>(msg.get())); // メッセージのポインタ・アドレスを整数表示
}, rmw_qos_profile_default);
}
rclcpp::Subscription<std_msgs::msg::Int32>::SharedPtr sub_;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment