Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support LifeCycleNode #107

Open
elsayedelsheikh opened this issue Jan 19, 2025 · 0 comments
Open

Support LifeCycleNode #107

elsayedelsheikh opened this issue Jan 19, 2025 · 0 comments

Comments

@elsayedelsheikh
Copy link

What is the recommended way while dealing with LifeCycle nodes?

File lifecycle_example.hpp:

protected:
    void dataCallback(sensor_msgs::msg::PointCloud2::ConstSharedPtr msg);
    point_cloud_transport::Subscriber data_sub_;
    sensor_msgs::msg::PointCloud2::ConstSharedPtr data_;

File lifecycle_example.cpp:

void lifeCycleNodeExample::configure()
{
  rclcpp_lifecycle::LifecycleNode::SharedPtr node = node_.lock();
  if (!node) {
    throw std::runtime_error{"Failed to lock node"};
  }

  std::string source_topic;

  getParameters(source_topic);

  data_sub_ = point_cloud_transport::create_subscription(
    std::dynamic_pointer_cast<rclcpp::Node>(node),
    source_topic,
    std::bind(&lifeCycleNodeExample::dataCallback, this, std::placeholders::_1),
    "raw"
  );
}

lifeCycleNodeExample::~lifeCycleNodeExample()
{
  RCLCPP_INFO(logger_, "[%s]: Destroying PointCloud", source_name_.c_str());
  data_sub_.shutdown();
}

Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant