Skip to content

Commit fb5ffc1

Browse files
Fix deprecated subscription callbacks in tutorials (#2079)
* Fix deprecated subscription callbacks in tutorials Namely, the `void shared_ptr<MsgT>` subscription callback has been deprecated. As such, snippets using that signature has been replaced with `void shared_ptr<const MsgT>` subscription callbacks. Signed-off-by: Abrar Rahman Protyasha <[email protected]> Co-authored-by: Chris Lalancette <[email protected]>
1 parent c8d1957 commit fb5ffc1

File tree

6 files changed

+10
-10
lines changed

6 files changed

+10
-10
lines changed

source/Tutorials/Custom-ROS2-Interfaces.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ Subscriber:
325325
}
326326

327327
private:
328-
void topic_callback(const tutorial_interfaces::msg::Num::SharedPtr msg) const // CHANGE
328+
void topic_callback(const tutorial_interfaces::msg::Num::ConstSharedPtr msg) const // CHANGE
329329
{
330330
RCLCPP_INFO_STREAM(this->get_logger(), "I heard: '" << msg->num << "'"); // CHANGE
331331
}

source/Tutorials/FastDDS-Configuration/FastDDS-Configuration.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ In a new source file named ``src/sync_async_reader.cpp`` write the following con
343343
/**
344344
* Actions to run every time a new message is received
345345
*/
346-
void topic_callback(const std_msgs::msg::String::SharedPtr msg) const
346+
void topic_callback(const std_msgs::msg::String::ConstSharedPtr msg) const
347347
{
348348
RCLCPP_INFO(this->get_logger(), "I heard: '%s'", msg->data.c_str());
349349
}

source/Tutorials/Ros2bag/Recording-A-Bag-From-Your-Own-Node.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ Inside the ``dev_ws/src/bag_recorder_nodes/src`` directory, create a new file ca
101101
{
102102
rclcpp::Time time_stamp = this->now();
103103

104-
writer_->write(*msg, "chatter", "std_msgs/msg/String", time_stamp);
104+
writer_->write(msg, "chatter", "std_msgs/msg/String", time_stamp);
105105
}
106106

107-
rclcpp::Subscription<rclcpp::SerializedMessage>::SharedPtr subscription_;
107+
rclcpp::Subscription<std_msgs::msg::String>::SharedPtr subscription_;
108108
std::unique_ptr<rosbag2_cpp::Writer> writer_;
109109
};
110110

@@ -171,7 +171,7 @@ This is why we pass in the topic name and the topic type.
171171

172172
.. code-block:: C++
173173

174-
writer_->write(*msg, "chatter", "std_msgs/msg/String", time_stamp);
174+
writer_->write(msg, "chatter", "std_msgs/msg/String", time_stamp);
175175

176176
The class contains two member variables.
177177

@@ -184,7 +184,7 @@ The class contains two member variables.
184184

185185
.. code-block:: C++
186186

187-
rclcpp::Subscription<rclcpp::SerializedMessage>::SharedPtr subscription_;
187+
rclcpp::Subscription<std_msgs::msg::String>::SharedPtr subscription_;
188188
std::unique_ptr<rosbag2_cpp::Writer> writer_;
189189

190190
The file finishes with the ``main`` function used to create an instance of the node and start ROS processing it.

source/Tutorials/Tf2/Writing-A-Tf2-Broadcaster-Cpp.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Open the file using your preferred text editor.
106106
}
107107

108108
private:
109-
void handle_turtle_pose(const std::shared_ptr<turtlesim::msg::Pose> msg)
109+
void handle_turtle_pose(const std::shared_ptr<const turtlesim::msg::Pose> msg)
110110
{
111111
rclcpp::Time now = this->get_clock()->now();
112112
geometry_msgs::msg::TransformStamped t;

source/Tutorials/Topics/Topic-Statistics-Tutorial.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ Open the file using your preferred text editor.
104104
}
105105

106106
private:
107-
void topic_callback(const std_msgs::msg::String::SharedPtr msg) const
107+
void topic_callback(const std_msgs::msg::String::ConstSharedPtr msg) const
108108
{
109109
RCLCPP_INFO(this->get_logger(), "I heard: '%s'", msg->data.c_str());
110110
}

source/Tutorials/Writing-A-Simple-Cpp-Publisher-And-Subscriber.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ Open the ``subscriber_member_function.cpp`` with your text editor.
356356
}
357357

358358
private:
359-
void topic_callback(const std_msgs::msg::String::SharedPtr msg) const
359+
void topic_callback(const std_msgs::msg::String::ConstSharedPtr msg) const
360360
{
361361
RCLCPP_INFO(this->get_logger(), "I heard: '%s'", msg->data.c_str());
362362
}
@@ -398,7 +398,7 @@ The only field declaration in this class is the subscription.
398398
.. code-block:: C++
399399

400400
private:
401-
void topic_callback(const std_msgs::msg::String::SharedPtr msg) const
401+
void topic_callback(const std_msgs::msg::String::ConstSharedPtr msg) const
402402
{
403403
RCLCPP_INFO(this->get_logger(), "I heard: '%s'", msg->data.c_str());
404404
}

0 commit comments

Comments
 (0)