Skip to content

Commit e6ebbf1

Browse files
authored
Fixes to the recording a bag tutorial. (#2093)
This makes the tutorial work on Galactic. In particular: 1. Switch to using a std_msgs/msg/String for the first example. That's what 'demo_nodes_cpp::Talker' uses, so this should match. 2. Fix up the API calls in the generating your own data node so it actually works. 3. Rename the data object to data_ to better match convention. Signed-off-by: Chris Lalancette <[email protected]>
1 parent ab1babd commit e6ebbf1

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

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

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Navigate into the ``dev_ws/src`` directory and create a new package:
4848

4949
.. code-block:: console
5050
51-
ros2 pkg create --build-type ament_cmake bag_recorder_nodes --dependencies rclcpp rosbag2_cpp example_interfaces
51+
ros2 pkg create --build-type ament_cmake bag_recorder_nodes --dependencies example_interfaces rclcpp rosbag2_cpp std_msgs
5252
5353
Your terminal will return a message verifying the creation of your package ``bag_recorder_nodes`` and all its necessary files and folders.
5454
The ``--dependencies`` argument will automatically add the necessary dependency lines to ``package.xml`` and ``CMakeLists.txt``.
@@ -76,7 +76,7 @@ Inside the ``dev_ws/src/bag_recorder_nodes/src`` directory, create a new file ca
7676

7777

7878
#include <rclcpp/rclcpp.hpp>
79-
#include <example_interfaces/msg/string.hpp>
79+
#include <std_msgs/msg/string.hpp>
8080

8181
#include <rosbag2_cpp/writer.hpp>
8282

@@ -92,7 +92,7 @@ Inside the ``dev_ws/src/bag_recorder_nodes/src`` directory, create a new file ca
9292

9393
writer_->open("my_bag");
9494

95-
subscription_ = create_subscription<example_interfaces::msg::String>(
95+
subscription_ = create_subscription<std_msgs::msg::String>(
9696
"chatter", 10, std::bind(&SimpleBagRecorder::topic_callback, this, _1));
9797
}
9898

@@ -101,7 +101,7 @@ 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", "example_interfaces/msg/String", time_stamp);
104+
writer_->write(*msg, "chatter", "std_msgs/msg/String", time_stamp);
105105
}
106106
107107
rclcpp::Subscription<rclcpp::SerializedMessage>::SharedPtr subscription_;
@@ -142,7 +142,7 @@ We will write data to the bag in the callback.
142142

143143
.. code-block:: C++
144144

145-
subscription_ = create_subscription<example_interfaces::msg::String>(
145+
subscription_ = create_subscription<std_msgs::msg::String>(
146146
"chatter", 10, std::bind(&SimpleBagRecorder::topic_callback, this, _1));
147147

148148
The callback itself is different from a typical callback.
@@ -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", "example_interfaces/msg/String", time_stamp);
174+
writer_->write(*msg, "chatter", "std_msgs/msg/String", time_stamp);
175175
176176
The class contains two member variables.
177177

@@ -218,7 +218,7 @@ Below the dependencies block, which contains ``find_package(rosbag2_cpp REQUIRED
218218
.. code-block:: console
219219
220220
add_executable(simple_bag_recorder src/simple_bag_recorder.cpp)
221-
ament_target_dependencies(simple_bag_recorder rclcpp rosbag2_cpp)
221+
ament_target_dependencies(simple_bag_recorder rclcpp rosbag2_cpp std_msgs)
222222
223223
install(TARGETS
224224
simple_bag_recorder
@@ -336,7 +336,7 @@ Inside the ``dev_ws/src/bag_recorder_nodes/src`` directory, create a new file ca
336336
DataGenerator()
337337
: Node("data_generator")
338338
{
339-
data.data = 0;
339+
data_.data = 0;
340340
writer_ = std::make_unique<rosbag2_cpp::Writer>();
341341

342342
writer_->open("timed_synthetic_bag");
@@ -353,14 +353,14 @@ Inside the ``dev_ws/src/bag_recorder_nodes/src`` directory, create a new file ca
353353
private:
354354
void timer_callback()
355355
{
356-
writer_->write(data, "synthetic", "example_interfaces/msg/Int32", now());
356+
writer_->write(data_, "synthetic", now());
357357

358-
++data.data;
358+
++data_.data;
359359
}
360360

361361
rclcpp::TimerBase::SharedPtr timer_;
362362
std::unique_ptr<rosbag2_cpp::Writer> writer_;
363-
example_interfaces::msg::Int32 data;
363+
example_interfaces::msg::Int32 data_;
364364
};
365365

366366
int main(int argc, char * argv[])
@@ -403,12 +403,12 @@ The timer fires with a one-second period, and calls the given member function wh
403403

404404
Within the timer callback, we generate (or otherwise obtain, e.g. read from a serial port connected to some hardware) the data we wish to store in the bag.
405405
The important difference between this and the previous sample is that the data is not yet serialised.
406-
Instead we are passing to the writer object a ROS message data type, in this case an instance of ``example_interfaces/msg/Int32``.
406+
Instead we are passing a ROS message data type to the writer object, in this case an instance of ``example_interfaces/msg/Int32``.
407407
The writer will serialise the data for us before writing it into the bag.
408408

409409
.. code-block:: C++
410410

411-
writer_->write(data, "synthetic", now());
411+
writer_->write(data_, "synthetic", now());
412412

413413
4.3 Add executable
414414
~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)