Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Play old bagfiles #69

Merged
merged 49 commits into from
Dec 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f7230e1
GH-138 Move calculation of bag size
Martin-Idel-SI Nov 29, 2018
c49e5bb
GH-138 Make sure that no attempt to create a converter is made when t…
botteroa-si Nov 27, 2018
bee97e2
GH-138 Add play end-to-end test for rosbag v2 plugin
botteroa-si Nov 27, 2018
3ff9ca3
GH-130 Add rosbag2_bag_v2_plugins package
botteroa-si Nov 19, 2018
60c1c03
GH-131 don't build plugins on Windows
Martin-Idel-SI Nov 20, 2018
a343231
GH-129 Add function to be generated
Martin-Idel-SI Nov 21, 2018
4a0268c
GH-138 Add generator code
Martin-Idel-SI Nov 29, 2018
1bf26e8
GH-138 Use cmake files to find ros1 packages
Martin-Idel-SI Nov 29, 2018
8e263ae
GH-138 Write storage plugin for rosbag v2 bags
botteroa-si Nov 26, 2018
75d6bae
GH-141 Add initial version of vendor package
Martin-Idel-SI Nov 29, 2018
68bd2ec
GH-141 Improve vendor package to build on Mac
Martin-Idel-SI Nov 29, 2018
958838b
GH-141 Use unmanaged Instance of class-loader
Martin-Idel-SI Nov 29, 2018
8da1462
GH-141 Reduce patch and copy new toplevle CMakeLists by hand
Martin-Idel-SI Nov 29, 2018
9ab6a5f
GH-141 Fix Shared Instance usage
Martin-Idel-SI Nov 29, 2018
8ff3b3a
GH-141 Improve maintainability of vendor package
Martin-Idel-SI Nov 29, 2018
ee803d9
GH-138 Cleanup CMakeLists
Martin-Idel-SI Nov 29, 2018
1d5b984
GH-138 Link against rclcpp - necessary for ros1_bridge
Martin-Idel-SI Nov 29, 2018
f395cc0
GH-138 Avoid crash when trying to play v2 bags which contain unknown …
botteroa-si Nov 29, 2018
81e71ce
GH-138 Add CLI -s <storage_id> option to ros2 bag info and use it in …
botteroa-si Nov 29, 2018
12cfd4e
GH-138 Add end-to-end info test for rosbag v2 files
botteroa-si Nov 29, 2018
4d81520
GH-138 Add method to extract filename from path to FilesystemHelpers
Martin-Idel-SI Nov 30, 2018
8ff5ef9
GH-138 Add unit tests to rosbag_storage
botteroa-si Nov 29, 2018
03ffad3
GH-138 Add proper logging for topics which cannot be converted
Martin-Idel-SI Nov 30, 2018
d6730c0
GH-138 Improve finding dependencies of ros1
Martin-Idel-SI Nov 30, 2018
7d27771
GH-141 Explicitly import transitive dependencies of vendor package
Martin-Idel-SI Nov 30, 2018
736f801
GH-138 Skip tests via ament if ros1 is not available
Martin-Idel-SI Nov 30, 2018
6919c29
GH-133 First split of plugins
Martin-Idel-SI Dec 4, 2018
5a921ec
GH-133 Write serialized rosbag message
Martin-Idel-SI Dec 4, 2018
ca0c8f5
GH-133 Improve converter plugin
Martin-Idel-SI Dec 4, 2018
d7fb396
GH-133 Add plugin to be found by pluginlib
Martin-Idel-SI Dec 4, 2018
c27d142
GH-133 Remove empty check in converter
Martin-Idel-SI Dec 4, 2018
2f757e9
GH-133 Assert serialization format in unit tests for storage
Martin-Idel-SI Dec 4, 2018
80da1f9
GH-133 Delete superfluous include folder
Martin-Idel-SI Dec 4, 2018
c395673
GH-133 get_all_topics_and_types returns only valid ros2 types
Martin-Idel-SI Dec 4, 2018
4868eb5
GH-133 Improve end to end test
Martin-Idel-SI Dec 5, 2018
69e1fce
GH-133 Reformulate info message in case of missing ros1-ros2 mapping …
botteroa-si Dec 5, 2018
7383691
GH-14 Find messages first
Martin-Idel-SI Dec 5, 2018
bc4beb8
Explicitly print message when on Windows
Karsten1987 Dec 6, 2018
a0ef6da
GH-14 Refactor rosbag_storage vendor package
Martin-Idel-SI Dec 6, 2018
93cabd4
GH-14 Reflect renames of converter interfaces
Martin-Idel-SI Dec 6, 2018
a7c54a9
GH-156 Workaround for path problems
Martin-Idel-SI Dec 11, 2018
3293b94
GH-156 Add documentation for plugin
Martin-Idel-SI Dec 11, 2018
b5bd408
GH-156 Fix the pluginlib version to greater 2
Martin-Idel-SI Dec 11, 2018
ae4e683
GH-156 Prohibit CMake from declaring paths as system paths
Martin-Idel-SI Dec 11, 2018
3fac836
GH-156 Prohibit system include paths for rosbag plugins
Martin-Idel-SI Dec 11, 2018
2f959a9
GH-14 Split patches
Martin-Idel-SI Dec 11, 2018
c3d797c
make README more verbose
Karsten1987 Dec 15, 2018
3d5fdb4
add plugin specific readme
Karsten1987 Dec 15, 2018
7892832
more readme for bag_v2 plugin
Karsten1987 Dec 15, 2018
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
125 changes: 118 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
# rosbag2

THIS IS WORK IN PROGRESS AND NOT READY TO BE USED YET
THIS IS WORK IN PROGRESS AND SHOULD BE USED WITH CARE

Repository for implementing ROSBag2 as described in its corresponding [design article](https://github.com/ros2/design/blob/f69fbbd11848e3dd6866b71a158a1902e31e92f1/articles/rosbags.md)
Repository for implementing rosbag2 as described in its corresponding [design article](https://github.com/ros2/design/blob/f69fbbd11848e3dd6866b71a158a1902e31e92f1/articles/rosbags.md)

## Build instructions
## Installation instructions

Create a new workspace:
## Debian packages

rosbag2 packages are available via debian packages and thus can be installed via

```
$ sudo apt-get install ros2bag rosbag2*
```

For other platforms than Linux, rosbag2 has to be built from source as it's currently not part of the latest (ros2.repos file)[https://github.com/ros2/ros2/blob/master/ros2.repos].

## Build from source

It is recommended to create a new overlay workspace on top of your current ROS 2 installation.

```
$ mkdir -p ~/rosbag_ws/src
Expand All @@ -22,18 +34,117 @@ $ git clone https://github.com/ros2/rosbag2.git
Then build all the packages with this command:

```
$ colcon build --merge-install
$ colcon build [--merge-install]
```

The `--merge-install` flag is optional but ensures a cleaner environment which is helpful for development.
The `--merge-install` flag is optional and installs all packages into one folder rather than isolated folders for each package.

#### Executing tests

The tests can be run using the following commands:

```
$ colcon test --merge-install
$ colcon test [--merge-install]
$ colcon test-result --verbose
```

The first command executes the test and the second command displays the errors (if any).

## Using rosbag2

rosbag2 is part of the ROS 2 command line interfaces.
This repo introduces a new verb called `bag` and thus serves as the entry point of using rosbag2.
As of the time of writing, there are three commands available for `ros2 bag`:

* record
* play
* info

### Recording data

In order to record all topics currently available in the system:

```
$ ros2 bag record -a
```

The command above will record all available topics and discovers new topics as they appear while recording.
This auto-discovery of new topics can be disabled by given the command line argument `--no-discovery`.

To record a set of predefined topics, one can specify them on the command line explicitly.

```
$ ros2 bag record <topic1> <topic2> … <topicN>
```

The specified topics don't necessarily have to be present at start time.
The discovery function will automatically recognize if one of the specified topics appeared.
In the same fashion, this auto discovery can be disabled with `--no-discovery`.

If not further specified, `ros2 bag record` will create a new folder named to the current time stamp and stores all data within this folder.
A user defined name can be given with `-o, --output`.

### Replaying data

After recording data, the next logical step is to replay this data:

```
$ ros2 bag play <bag_file>
```

The bag file is by default set to the folder name where the data was previously recorded in.

### Analyzing data

The recorded data can be analyzed by displaying some meta information about it:

```
$ ros2 bag info <bag_file>
```

You should see something along these lines:

```
Files: demo_strings.db3
Bag size: 44.5 KiB
Storage id: sqlite3
Duration: 8.501s
Start: Nov 28 2018 18:02:18.600 (1543456938.600)
End Nov 28 2018 18:02:27.102 (1543456947.102)
Messages: 27
Topic information: Topic: /chatter | Type: std_msgs/String | Count: 9 | Serialization Format: cdr
Topic: /my_chatter | Type: std_msgs/String | Count: 18 | Serialization Format: cdr
```

## Storage format plugin architecture

Looking at the output of the `ros2 bag info` command, we can see a field called `storage id:`.
rosbag2 specifically was designed to support multiple storage formats.
This allows a flexible adaptation of various storage formats depending on individual use cases.
As of now, this repository comes with two storage plugins.
The first plugin, sqlite3 is chosen by default.
If not specified otherwise, rosbag2 will store and replay all recorded data in an SQLite3 database.
Secondly, rosbag2 provides support for legacy ROS 1 bag data. __TODO(karsten1987) Add link when rosindex ran__.

In order to use a specified (non-default) storage format plugin, rosbag2 has a command line argument for it:

```
$ ros2 bag <record> | <play> | <info> -s <sqlite3> | <rosbag2_v2> | <custom_plugin>
```

Have a look at each of the individual plugins for further information.

## Serialization format plugin architecture

Looking further at the output of `ros2 bag info`, we can see another field attached to each topic called `Serialization Format`.
By design, ROS 2 is middleware agnostic and thus can leverage multiple communication frameworks.
The default middleware for ROS 2 is DDS which has `cdr` as its default binary serialization format.
However, other middleware implementation might have different formats.
If not specified, `ros2 bag record -a` will record all data in the middleware specific format.
This however also means that such a bag file can't easily be replayed with another middleware format.

rosbag2 implements a serialization format plugin architecture which allows the user the specify a certain serialization format.
When specified, rosbag2 looks for a suitable converter to transform the native middleware protocol to the target format.
This also allows to record data in a native format to optimize for speed, but to convert or transform the recorded data into a middleware agnostic serialization format.

By default, rosbag2 can convert from and to CDR as it's the default serialization format for ROS 2.
69 changes: 69 additions & 0 deletions ros1_rosbag_storage_vendor/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
cmake_minimum_required(VERSION 3.5)
project(ros1_rosbag_storage_vendor)

# Default to C99
if(NOT CMAKE_C_STANDARD)
set(CMAKE_C_STANDARD 99)
endif()

# Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)

# We don't need to build on Windows for now
if(WIN32)
Martin-Idel-SI marked this conversation as resolved.
Show resolved Hide resolved
message("Replay ROS1 rosbags is currently not supported on Windows systems")
return()
endif()

set(git_apply git apply)

include(ExternalProject)
# We have to include a number of patches to the rosbag
# 1. rosbag1_encryption_patch includes https://github.com/ros/ros_comm/pull/1499, without it, pluginlib won't link
# 2. The next two patches patch the pluginlib usage:
# Missing boost/bind include
# Using pluginlib with boost results in compile errors on some systems, so we need to switch to pluginlib without boost
# 3. The next patches patch the catkin package to ament and renames it
# Patching to ament is necessary as otherwise colcon needs to build a catkin package together with an ament package, which is impossible
# Renaming the package is necessary on some systems to not confuse the linker
#
# Note that we need to build with CMAKE_NO_SYSTEM_FROM_IMPORTED. This prohibits cmake from
# declaring any paths as "internal" (flagged with -isystem instead of -I) which can result in this
# vendor package building against the wrong pluginlib, because the paths get switched.
# Symptoms of wrong paths: The build of the rosbag for ROS 1 plugins fails with missing symbols
# like ros::package::getPlugins(...) when linking the vendor package
ExternalProject_Add(ros1_rosbag_storage
DOWNLOAD_DIR ${CMAKE_CURRENT_BINARY_DIR}/download
URL https://github.com/ros/ros_comm/archive/669fbd32d2f92cc295f4b024fcb2f982fddec0f0.zip
URL_MD5 4c8b4c33165b223870f5d77bb697bef6
TIMEOUT 60
SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/sources
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=${CMAKE_CURRENT_BINARY_DIR}/rosbag_install -DCMAKE_NO_SYSTEM_FROM_IMPORTED=1
PATCH_COMMAND
${git_apply} ${CMAKE_CURRENT_SOURCE_DIR}/resources/rosbag1_encryption_patch.diff &&
${git_apply} ${CMAKE_CURRENT_SOURCE_DIR}/resources/bagh.diff &&
${git_apply} ${CMAKE_CURRENT_SOURCE_DIR}/resources/bagcpp.diff &&
${git_apply} ${CMAKE_CURRENT_SOURCE_DIR}/resources/bagcpp_name.diff &&
${git_apply} ${CMAKE_CURRENT_SOURCE_DIR}/resources/plugin_descriptionxml.diff &&
${git_apply} ${CMAKE_CURRENT_SOURCE_DIR}/resources/packagexml.diff &&
${git_apply} ${CMAKE_CURRENT_SOURCE_DIR}/resources/cmakeliststxt.diff &&
${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/cmake/CMakeLists.txt.in ${CMAKE_CURRENT_BINARY_DIR}/sources/CMakeLists.txt
)

install(
DIRECTORY
${CMAKE_CURRENT_BINARY_DIR}/rosbag_install/
DESTINATION
${CMAKE_INSTALL_PREFIX}/
)

ament_package()
5 changes: 5 additions & 0 deletions ros1_rosbag_storage_vendor/cmake/CMakeLists.txt.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# We download ros_comm, which does not contain a toplevel CMakeLists so colcon can't find the entry
# point and claims there is nothing to build.
# This is also an opportunity, because we want to only build rosbag_storage anyways
Karsten1987 marked this conversation as resolved.
Show resolved Hide resolved
cmake_minimum_required(VERSION 3.5)
add_subdirectory(tools/rosbag_storage)
18 changes: 18 additions & 0 deletions ros1_rosbag_storage_vendor/package.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>ros1_rosbag_storage_vendor</name>
<version>0.0.0</version>
<description>Vendor package for rosbag_storage of ROS1</description>
<maintainer email="karsten.knese@googlemail.com">Karsten Knese</maintainer>
<license>Apache License 2.0</license>

<buildtool_depend>ament_cmake</buildtool_depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>

<export>
<build_type>ament_cmake</build_type>
</export>
</package>
22 changes: 22 additions & 0 deletions ros1_rosbag_storage_vendor/resources/bagcpp.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/tools/rosbag_storage/src/bag.cpp b/tools/rosbag_storage/src/bag.cpp
index 7e2e67171..073072934 100644
--- a/tools/rosbag_storage/src/bag.cpp
+++ b/tools/rosbag_storage/src/bag.cpp
@@ -40,6 +40,7 @@
#include <iomanip>

#include <boost/foreach.hpp>
+#include <boost/bind.hpp>

#include "console_bridge/console.h"

@@ -222,7 +223,8 @@ void Bag::setEncryptorPlugin(std::string const& plugin_name, std::string const&
if (!chunks_.empty()) {
throw BagException("Cannot set encryption plugin after chunks are written");
}
- encryptor_ = encryptor_loader_.createInstance(plugin_name);
+ auto unmanaged_instance = encryptor_loader_.createUnmanagedInstance(plugin_name);
+ encryptor_ = std::shared_ptr<rosbag::EncryptorBase>(unmanaged_instance);
encryptor_->initialize(*this, plugin_param);
}

29 changes: 29 additions & 0 deletions ros1_rosbag_storage_vendor/resources/bagcpp_name.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
diff --git a/tools/rosbag_storage/src/bag.cpp b/tools/rosbag_storage/src/bag.cpp
index 073072934..13a7fc8fc 100644
--- a/tools/rosbag_storage/src/bag.cpp
+++ b/tools/rosbag_storage/src/bag.cpp
@@ -58,12 +58,13 @@ using ros::Time;

namespace rosbag {

-Bag::Bag() : encryptor_loader_("rosbag_storage", "rosbag::EncryptorBase")
+Bag::Bag() : encryptor_loader_("ros1_rosbag_storage", "rosbag::EncryptorBase")
{
init();
}

-Bag::Bag(string const& filename, uint32_t mode) : encryptor_loader_("rosbag_storage", "rosbag::EncryptorBase")
+Bag::Bag(string const& filename, uint32_t mode)
+: encryptor_loader_("ros1_rosbag_storage", "rosbag::EncryptorBase")
{
init();
open(filename, mode);
@@ -71,7 +72,7 @@ Bag::Bag(string const& filename, uint32_t mode) : encryptor_loader_("rosbag_stor

#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES

-Bag::Bag(Bag&& other) : encryptor_loader_("rosbag_storage", "rosbag::EncryptorBase") {
+Bag::Bag(Bag&& other) : encryptor_loader_("ros1_rosbag_storage", "rosbag::EncryptorBase") {
init();
swap(other);
}
22 changes: 22 additions & 0 deletions ros1_rosbag_storage_vendor/resources/bagh.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/tools/rosbag_storage/include/rosbag/bag.h b/tools/rosbag_storage/include/rosbag/bag.h
index c65533011..e75ef9c78 100644
--- a/tools/rosbag_storage/include/rosbag/bag.h
+++ b/tools/rosbag_storage/include/rosbag/bag.h
@@ -35,6 +35,8 @@
#ifndef ROSBAG_BAG_H
#define ROSBAG_BAG_H

+#include <memory>
+
#include "rosbag/macros.h"

#include "rosbag/buffer.h"
@@ -354,7 +356,7 @@ private:
// Encryptor plugin loader
pluginlib::ClassLoader<rosbag::EncryptorBase> encryptor_loader_;
// Active encryptor
- boost::shared_ptr<rosbag::EncryptorBase> encryptor_;
+ std::shared_ptr<rosbag::EncryptorBase> encryptor_;
};

} // namespace rosbag
Loading