I defined the subscription as follows to get msg when other node publishes to the "mytopic" topics:
subscription = this->create_subscription(
"mytopic", 10, std::bind(&MinimalSubscriber::topic_callback, this, _1));
And I wanna copy the above msg from the topic_callback when it called to the function of Process() to do something else,so how can i get the latest msg ,and how can idesign the node,like following to handle : the function of Process() should be executed onece the topic_callback is called.
class MyNode : public rclcpp::Node
{
public:
MyNode();
~MyNode();
bool Init();
bool Start();
rclcpp::callback_group::CallbackGroup::SharedPtr cb_group_sub_topic1;
rclcpp::callback_group::CallbackGroup::SharedPtr cb_group_sub_topic2;
//local msg copied from sub and to be process
std_msgs::msg::String local_msg1;
std_msgs::msg::String local_msg2;
}
And need define something else...?
Please open questions like this on https://answers.ros.org, which is our central Question and Answer site. You'll get a better answer there, and it will be searchable for the future.
I defined the subscription as follows to get msg when other node publishes to the "mytopic" topics: subscription = this->create_subscription(
"mytopic", 10, std::bind(&MinimalSubscriber::topic_callback, this, _1));
And I wanna copy the above msg from the topic_callback when it called to the function of Process() to do something else,so how can i get the latest msg ,and how can idesign the node,like following to handle : the function of Process() should be executed onece the topic_callback is called.
class MyNode : public rclcpp::Node { public: MyNode(); ~MyNode(); bool Init(); bool Start();
private: bool Process(); std::string timing_string(); void on_topic1(const std_msgs::msg::String::SharedPtr msg); void on_topic2(const std_msgs::msg::String::SharedPtr msg);
rclcpp::Subscription::SharedPtr topic1sub;
rclcpp::Subscription::SharedPtr topic2sub;
rclcpp::callback_group::CallbackGroup::SharedPtr cb_group_sub_topic1; rclcpp::callback_group::CallbackGroup::SharedPtr cb_group_sub_topic2; //local msg copied from sub and to be process std_msgs::msg::String local_msg1; std_msgs::msg::String local_msg2; } And need define something else...?