Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ Inside the ``ros2_ws/src/bag_recorder_nodes/src`` directory, create a new file c

writer_->open("my_bag");

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

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

.. code-block:: C++

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

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

.. code-block:: C++

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

Within the subscription callback, the first thing to do is determine the time stamp to use for the stored message.
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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void MyRobotDriver::init(

cmd_vel_subscription_ = node->create_subscription<geometry_msgs::msg::Twist>(
"/cmd_vel", rclcpp::SensorDataQoS().reliable(),
[this](const geometry_msgs::msg::Twist::SharedPtr msg){
[this](const geometry_msgs::msg::Twist::ConstSharedPtr msg){
this->cmd_vel_msg.linear = msg->linear;
this->cmd_vel_msg.angular = msg->angular;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ ObstacleAvoider::ObstacleAvoider() : Node("obstacle_avoider") {

left_sensor_sub_ = create_subscription<sensor_msgs::msg::Range>(
"/left_sensor", 1,
[this](const sensor_msgs::msg::Range::SharedPtr msg){
[this](const sensor_msgs::msg::Range::ConstSharedPtr msg){
return this->leftSensorCallback(msg);
}
);

right_sensor_sub_ = create_subscription<sensor_msgs::msg::Range>(
"/right_sensor", 1,
[this](const sensor_msgs::msg::Range::SharedPtr msg){
[this](const sensor_msgs::msg::Range::ConstSharedPtr msg){
return this->rightSensorCallback(msg);
}
);
}

void ObstacleAvoider::leftSensorCallback(
const sensor_msgs::msg::Range::SharedPtr msg) {
const sensor_msgs::msg::Range::ConstSharedPtr msg) {
left_sensor_value = msg->range;
}

void ObstacleAvoider::rightSensorCallback(
const sensor_msgs::msg::Range::SharedPtr msg) {
const sensor_msgs::msg::Range::ConstSharedPtr msg) {
right_sensor_value = msg->range;

auto command_message = std::make_unique<geometry_msgs::msg::Twist>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ class ObstacleAvoider : public rclcpp::Node {
explicit ObstacleAvoider();

private:
void leftSensorCallback(const sensor_msgs::msg::Range::SharedPtr msg);
void rightSensorCallback(const sensor_msgs::msg::Range::SharedPtr msg);
void leftSensorCallback(const sensor_msgs::msg::Range::ConstSharedPtr msg);
void rightSensorCallback(const sensor_msgs::msg::Range::ConstSharedPtr msg);

rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr publisher_;
rclcpp::Subscription<sensor_msgs::msg::Range>::SharedPtr left_sensor_sub_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Open the file using your preferred text editor.
stream << "/" << turtlename_.c_str() << "/pose";
std::string topic_name = stream.str();

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

// Read message content and assign it to
Expand Down