Skip to content

Commit 3888dd3

Browse files
mini-1235mergify[bot]
authored andcommitted
Update subscription callback signatures (#6005)
Signed-off-by: Maurice <[email protected]> (cherry picked from commit bf46139)
1 parent 9859325 commit 3888dd3

File tree

5 files changed

+11
-11
lines changed

5 files changed

+11
-11
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ Inside the ``ros2_ws/src/bag_recorder_nodes/src`` directory, create a new file c
9494

9595
writer_->open("my_bag");
9696

97-
auto subscription_callback_lambda = [this](std::shared_ptr<rclcpp::SerializedMessage> msg){
97+
auto subscription_callback_lambda = [this](std::shared_ptr<const rclcpp::SerializedMessage> msg){
9898
rclcpp::Time time_stamp = this->now();
9999

100100
writer_->write(msg, "chatter", "std_msgs/msg/String", time_stamp);
@@ -144,7 +144,7 @@ We will write data to the bag in the callback.
144144

145145
.. code-block:: C++
146146

147-
auto subscription_callback_lambda = [this](std::shared_ptr<rclcpp::SerializedMessage> msg){
147+
auto subscription_callback_lambda = [this](std::shared_ptr<const rclcpp::SerializedMessage> msg){
148148
rclcpp::Time time_stamp = this->now();
149149

150150
writer_->write(msg, "chatter", "std_msgs/msg/String", time_stamp);
@@ -162,7 +162,7 @@ We do this for two reasons.
162162

163163
.. code-block:: C++
164164

165-
auto subscription_callback_lambda = [this](std::shared_ptr<rclcpp::SerializedMessage> msg){
165+
auto subscription_callback_lambda = [this](std::shared_ptr<const rclcpp::SerializedMessage> msg){
166166

167167
Within the subscription callback, the first thing to do is determine the time stamp to use for the stored message.
168168
This can be anything appropriate to your data, but two common values are the time at which the data was produced, if known, and the time it is received.

source/Tutorials/Advanced/Simulators/Webots/Code/MyRobotDriver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ void MyRobotDriver::init(
2525

2626
cmd_vel_subscription_ = node->create_subscription<geometry_msgs::msg::Twist>(
2727
"/cmd_vel", rclcpp::SensorDataQoS().reliable(),
28-
[this](const geometry_msgs::msg::Twist::SharedPtr msg){
28+
[this](const geometry_msgs::msg::Twist::ConstSharedPtr msg){
2929
this->cmd_vel_msg.linear = msg->linear;
3030
this->cmd_vel_msg.angular = msg->angular;
3131
}

source/Tutorials/Advanced/Simulators/Webots/Code/ObstacleAvoider.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,26 @@ ObstacleAvoider::ObstacleAvoider() : Node("obstacle_avoider") {
77

88
left_sensor_sub_ = create_subscription<sensor_msgs::msg::Range>(
99
"/left_sensor", 1,
10-
[this](const sensor_msgs::msg::Range::SharedPtr msg){
10+
[this](const sensor_msgs::msg::Range::ConstSharedPtr msg){
1111
return this->leftSensorCallback(msg);
1212
}
1313
);
1414

1515
right_sensor_sub_ = create_subscription<sensor_msgs::msg::Range>(
1616
"/right_sensor", 1,
17-
[this](const sensor_msgs::msg::Range::SharedPtr msg){
17+
[this](const sensor_msgs::msg::Range::ConstSharedPtr msg){
1818
return this->rightSensorCallback(msg);
1919
}
2020
);
2121
}
2222

2323
void ObstacleAvoider::leftSensorCallback(
24-
const sensor_msgs::msg::Range::SharedPtr msg) {
24+
const sensor_msgs::msg::Range::ConstSharedPtr msg) {
2525
left_sensor_value = msg->range;
2626
}
2727

2828
void ObstacleAvoider::rightSensorCallback(
29-
const sensor_msgs::msg::Range::SharedPtr msg) {
29+
const sensor_msgs::msg::Range::ConstSharedPtr msg) {
3030
right_sensor_value = msg->range;
3131

3232
auto command_message = std::make_unique<geometry_msgs::msg::Twist>();

source/Tutorials/Advanced/Simulators/Webots/Code/ObstacleAvoider.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class ObstacleAvoider : public rclcpp::Node {
99
explicit ObstacleAvoider();
1010

1111
private:
12-
void leftSensorCallback(const sensor_msgs::msg::Range::SharedPtr msg);
13-
void rightSensorCallback(const sensor_msgs::msg::Range::SharedPtr msg);
12+
void leftSensorCallback(const sensor_msgs::msg::Range::ConstSharedPtr msg);
13+
void rightSensorCallback(const sensor_msgs::msg::Range::ConstSharedPtr msg);
1414

1515
rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr publisher_;
1616
rclcpp::Subscription<sensor_msgs::msg::Range>::SharedPtr left_sensor_sub_;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ Open the file using your preferred text editor.
101101
stream << "/" << turtlename_.c_str() << "/pose";
102102
std::string topic_name = stream.str();
103103

104-
auto handle_turtle_pose = [this](const std::shared_ptr<turtlesim_msgs::msg::Pose> msg){
104+
auto handle_turtle_pose = [this](const std::shared_ptr<const turtlesim_msgs::msg::Pose> msg){
105105
geometry_msgs::msg::TransformStamped t;
106106

107107
// Read message content and assign it to

0 commit comments

Comments
 (0)