Last active
June 5, 2017 22:09
-
-
Save youtalk/16fd6f928fde80cf98b604423e60d574 to your computer and use it in GitHub Desktop.
two_node_pipeline.cpp 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// メッセージをPublishするPublisherクラス | |
struct Producer : public rclcpp::Node | |
{ | |
Producer(const std::string & name, const std::string & output) | |
: Node(name, "", true) | |
{ | |
// output名のトピックをPublishするPublisherを作成 | |
pub_ = this->create_publisher<std_msgs::msg::Int32>(output, rmw_qos_profile_default); | |
// decltype(pub_.get())>はrclcpp::Publisher<std_msgs::msg::Int32>* | |
// std::remove_pointer<decltype(pub_.get())>はrclcpp::Publisher<std_msgs::msg::Int32> | |
// std::remove_pointer<decltype(pub_.get())>::typeはstd_msgs::msg::Int32 | |
// と読むのでしょうか? | |
std::weak_ptr<std::remove_pointer<decltype(pub_.get())>::type> captured_pub = pub_; | |
// 1Hzでタイマー実行されるコールバック設定 | |
auto callback = [captured_pub]() -> void { | |
auto pub_ptr = captured_pub.lock(); | |
if (!pub_ptr) { | |
return; | |
} | |
static int32_t count = 0; | |
std_msgs::msg::Int32::UniquePtr msg(new std_msgs::msg::Int32()); | |
msg->data = count++; | |
printf( | |
"Published message with value: %d, and address: 0x%" PRIXPTR "\n", msg->data, | |
reinterpret_cast<std::uintptr_t>(msg.get())); // メッセージのポインタ・アドレスを整数表示 | |
pub_ptr->publish(msg); | |
}; | |
timer_ = this->create_wall_timer(1s, callback); | |
} | |
rclcpp::Publisher<std_msgs::msg::Int32>::SharedPtr pub_; | |
rclcpp::TimerBase::SharedPtr timer_; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment