Skip to content

Commit

Permalink
Implement reading from rosbag2 files (#64)
Browse files Browse the repository at this point in the history
I've implemented reading from rosbag2 files. I've used
`rosbag2_transport::ReaderWriterFactory` so that both compressed and
uncompressed bagfiles can be handled.
  • Loading branch information
Rayman authored Jun 20, 2024
1 parent 0e7ac45 commit 5c47482
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ project(swri_console)
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(rcl_interfaces REQUIRED)
find_package(rosbag2_transport REQUIRED)

### QT PACKAGES ###
find_package(Qt5Core REQUIRED)
Expand Down Expand Up @@ -68,6 +69,7 @@ ament_target_dependencies(${PROJECT_NAME}
ament_cmake
rclcpp
rcl_interfaces
rosbag2_transport
)

install(TARGETS ${PROJECT_NAME}
Expand Down
1 change: 0 additions & 1 deletion include/swri_console/bag_reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#include <QString>
#include <QMetaType>

#include <rclcpp/rclcpp.hpp>
#include <rcl_interfaces/msg/log.hpp>

namespace swri_console
Expand Down
2 changes: 1 addition & 1 deletion package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<depend>libqt5-core</depend>
<depend>libqt5-gui</depend>
<depend>libqt5-widgets</depend>
<!-- <depend>rosbag_storage</depend> -->
<depend>rosbag2_transport</depend>
<depend>rclcpp</depend>
<depend>rcl_interfaces</depend>

Expand Down
45 changes: 18 additions & 27 deletions src/bag_reader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,54 +33,45 @@
#include <QMessageBox>

#include "swri_console/bag_reader.h"

// #include <rosbag/bag.h>
// #include <rosbag/view.h>
#include <rclcpp/rclcpp.hpp>
#include <rosbag2_transport/reader_writer_factory.hpp>

using namespace swri_console;

void BagReader::readBagFile(const QString& filename)
{
/*
rosbag::Bag bag;
bag.open(filename.toStdString(), rosbag::bagmode::Read);
std::vector<std::string> topics;
topics.push_back(std::string("/rosout"));
rosbag2_storage::StorageOptions storage_options;
storage_options.uri = filename.toStdString();
auto reader = rosbag2_transport::ReaderWriterFactory::make_reader(storage_options);
reader->open(storage_options);

rosbag::View view(bag, rosbag::TopicQuery(topics));
rosbag::View::const_iterator iter;
while (reader->has_next()) {
auto msg = reader->read_next();

for(iter = view.begin(); iter != view.end(); ++iter)
{
rosgraph_msgs::LogConstPtr log = iter->instantiate<rosgraph_msgs::Log>();
if (log != NULL ) {
emit logReceived(log);
}
else {
qWarning("Got a message that was not a log message but a: %s", iter->getDataType().c_str());
if (msg->topic_name != "/rosout") {
continue;
}

// Deserialize the message
rclcpp::SerializedMessage serialized_msg(*msg->serialized_data);
auto log = std::make_shared<rcl_interfaces::msg::Log>();
rclcpp::Serialization<rcl_interfaces::msg::Log> serialization_;
serialization_.deserialize_message(&serialized_msg, log.get());

emit logReceived(log);
}
*/

emit finishedReading();
}

void BagReader::promptForBagFile()
{
QMessageBox::information(nullptr,
tr("Bag files not supported"),
tr("Reading and writing bag files is not yet supported in ROS 2."));
/*
QString filename = QFileDialog::getOpenFileName(nullptr,
tr("Open Bag File"),
QDir::homePath(),
tr("Bag Files (*.bag)"));
tr("Bag Files (*.mcap)"));

if (filename != nullptr)
{
readBagFile(filename);
}
*/
}

0 comments on commit 5c47482

Please sign in to comment.