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 @@ -96,6 +96,15 @@ Inside the ``ros2_ws/src/bag_recorder_nodes/src`` directory, create a new file c

writer_->open("my_bag");

<<<<<<< HEAD
=======
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);
};

>>>>>>> bf46139 (Update subscription callback signatures (#6005))
subscription_ = create_subscription<std_msgs::msg::String>(
"chatter", 10, std::bind(&SimpleBagRecorder::topic_callback, this, _1));
}
Expand Down Expand Up @@ -146,6 +155,15 @@ We will write data to the bag in the callback.

.. code-block:: C++

<<<<<<< HEAD
=======
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);
};

>>>>>>> bf46139 (Update subscription callback signatures (#6005))
subscription_ = create_subscription<std_msgs::msg::String>(
"chatter", 10, std::bind(&SimpleBagRecorder::topic_callback, this, _1));

Expand All @@ -158,8 +176,12 @@ We do this for two reasons.

.. code-block:: C++

<<<<<<< HEAD
void topic_callback(std::shared_ptr<rclcpp::SerializedMessage> msg) const
{
=======
auto subscription_callback_lambda = [this](std::shared_ptr<const rclcpp::SerializedMessage> msg){
>>>>>>> bf46139 (Update subscription callback signatures (#6005))

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,13 +25,21 @@ void MyRobotDriver::init(

cmd_vel_subscription_ = node->create_subscription<geometry_msgs::msg::Twist>(
"/cmd_vel", rclcpp::SensorDataQoS().reliable(),
<<<<<<< HEAD
std::bind(&MyRobotDriver::cmdVelCallback, this, std::placeholders::_1));
}

void MyRobotDriver::cmdVelCallback(
const geometry_msgs::msg::Twist::SharedPtr msg) {
cmd_vel_msg.linear = msg->linear;
cmd_vel_msg.angular = msg->angular;
=======
[this](const geometry_msgs::msg::Twist::ConstSharedPtr msg){
this->cmd_vel_msg.linear = msg->linear;
this->cmd_vel_msg.angular = msg->angular;
}
);
>>>>>>> bf46139 (Update subscription callback signatures (#6005))
}

void MyRobotDriver::step() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,36 @@ ObstacleAvoider::ObstacleAvoider() : Node("obstacle_avoider") {

left_sensor_sub_ = create_subscription<sensor_msgs::msg::Range>(
"/left_sensor", 1,
<<<<<<< HEAD
std::bind(&ObstacleAvoider::leftSensorCallback, this,
std::placeholders::_1));

right_sensor_sub_ = create_subscription<sensor_msgs::msg::Range>(
"/right_sensor", 1,
std::bind(&ObstacleAvoider::rightSensorCallback, this,
std::placeholders::_1));
=======
[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::ConstSharedPtr msg){
return this->rightSensorCallback(msg);
}
);
>>>>>>> bf46139 (Update subscription callback signatures (#6005))
}

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,39 @@ Open the file using your preferred text editor.
stream << "/" << turtlename_.c_str() << "/pose";
std::string topic_name = stream.str();

<<<<<<< HEAD
subscription_ = this->create_subscription<turtlesim::msg::Pose>(
=======
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
// corresponding tf variables
t.header.stamp = this->get_clock()->now();
t.header.frame_id = "world";
t.child_frame_id = turtlename_.c_str();

// Turtle only exists in 2D, thus we get x and y translation
// coordinates from the message and set the z coordinate to 0
t.transform.translation.x = msg->x;
t.transform.translation.y = msg->y;
t.transform.translation.z = 0.0;

// For the same reason, turtle can only rotate around one axis
// and this why we set rotation in x and y to 0 and obtain
// rotation in z axis from the message
tf2::Quaternion q;
q.setRPY(0, 0, msg->theta);
t.transform.rotation.x = q.x();
t.transform.rotation.y = q.y();
t.transform.rotation.z = q.z();
t.transform.rotation.w = q.w();

// Send the transformation
tf_broadcaster_->sendTransform(t);
};
subscription_ = this->create_subscription<turtlesim_msgs::msg::Pose>(
>>>>>>> bf46139 (Update subscription callback signatures (#6005))
topic_name, 10,
std::bind(&FramePublisher::handle_turtle_pose, this, std::placeholders::_1));
}
Expand Down
Loading