Polling Subscriber#
Agnocast provides agnocast::PollingSubscriber, a pull-based subscription that lets you fetch the latest message on demand rather than receiving it via a callback. This corresponds to the subscription->take() pattern in rclcpp, but returns a zero-copy shared pointer from shared memory instead of copying data into a provided message.
PollingSubscriber is available at both Stage 1 (rclcpp::Node) and Stage 2 (agnocast::Node).
Migration from rclcpp take()#
Before (rclcpp)#
```cpp
class MyPollingNode : public rclcpp::Node
{
rclcpp::Subscription
void timer_callback() { std_msgs::msg::String msg; rclcpp::MessageInfo msg_info; if (sub_->take(msg, msg_info)) { RCLCPP_INFO(get_logger(), "Polled: %s", msg.data.c_str()); } }
public:
MyPollingNode() : Node("my_polling_node")
{
sub_ = create_subscription
timer_ = create_wall_timer(1s,
std::bind(&MyPollingNode::timer_callback, this));
} }; ```
After (Agnocast Stage 1)#
```cpp
class MyPollingNode : public rclcpp::Node
{
agnocast::PollingSubscriber
void timer_callback() { auto msg = sub_->take_data(); // (2) if (msg) { RCLCPP_INFO(get_logger(), "Polled: %s", msg->data.c_str()); } }
public:
MyPollingNode() : Node("my_polling_node")
{
sub_ = agnocast::create_subscription
timer_ = create_wall_timer(1s,
std::bind(&MyPollingNode::timer_callback, this));
} }; ```
Key changes:
rclcpp::Subscription→agnocast::PollingSubscriber(no dummy callback needed)sub_->take(msg, msg_info)→sub_->take_data()which returns anagnocast::ipc_shared_ptr<const T>(zero-copy)- Use
agnocast::create_subscriptionfree function (no callback argument)
After (Agnocast Stage 2)#
```cpp
class MyPollingNode : public agnocast::Node // (1)
{
agnocast::PollingSubscriber
void timer_callback() { auto msg = sub_->take_data(); if (msg) { RCLCPP_INFO(get_logger(), "Polled: %s", msg->data.c_str()); } }
public:
MyPollingNode() : Node("my_polling_node")
{
sub_ = this->create_subscription
timer_ = this->create_wall_timer(1s,
std::bind(&MyPollingNode::timer_callback, this));
} }; ```
Additional changes from Stage 1:
- Base class changes to
agnocast::Node - Timer type changes to
agnocast::TimerBase::SharedPtr - Subscription creation uses member function instead of free function