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

Output FIle #10

Merged
merged 1 commit into from
Oct 20, 2024
Merged
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
4 changes: 2 additions & 2 deletions ros/include/kinematic_icp_ros/nodes/offline_node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <string>

// ROS
#include <filesystem>
#include <rclcpp/node.hpp>
#include <rclcpp/node_options.hpp>
#include <sophus/se3.hpp>
Expand All @@ -51,8 +52,7 @@ class OfflineNode {
// store data for the experiments
using PoseWithStamp = std::pair<double, Sophus::SE3d>;
std::vector<PoseWithStamp> poses_with_timestamps_;
std::string output_dir_;
std::string poses_filename_;
std::filesystem::path output_pose_file_;

// Offline node specifics
BagMultiplexer bag_multiplexer_;
Expand Down
16 changes: 8 additions & 8 deletions ros/src/kinematic_icp_ros/nodes/offline_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@
#include "kinematic_icp_ros/utils/indicators.hpp"

namespace {
std::string generateOutputFilename(const std::string &bag_filename) {
std::filesystem::path generateOutputFilename(const std::string &bag_filename) {
size_t last_dot = bag_filename.find_last_of(".");
std::string output_file = bag_filename.substr(0, last_dot);
output_file += "_kinematic_icp_poses_tum.txt";
std::filesystem::path output_path(output_file);
return output_path.filename().string();
return output_path.filename();
}
} // namespace

Expand All @@ -55,21 +55,21 @@ OfflineNode::OfflineNode(const rclcpp::NodeOptions &options) {
odometry_server_ = std::make_shared<LidarOdometryServer>(node_);

auto bag_filename = node_->declare_parameter<std::string>("bag_filename");
poses_filename_ = generateOutputFilename(bag_filename);
output_dir_ = node_->declare_parameter<std::string>("output_dir");
const auto poses_filename = generateOutputFilename(bag_filename);
output_pose_file_ = std::filesystem::path(node_->declare_parameter<std::string>("output_dir"));
output_pose_file_ /= poses_filename;
auto tf_bridge = std::make_shared<BufferableBag::TFBridge>(node_);
bag_multiplexer_.AddBag(BufferableBag(bag_filename, tf_bridge, pcl_topic_));
}

void OfflineNode::writePosesInTumFormat() {
const std::string output_file = output_dir_ + poses_filename_;
std::ofstream file(output_file);
std::ofstream file(output_pose_file_);
if (!file.is_open()) {
std::cerr << "Error opening file: " << output_file << std::endl;
std::cerr << "Error opening file: " << output_pose_file_ << std::endl;
return;
}

RCLCPP_INFO_STREAM(node_->get_logger(), "Saving poses in TUM format in " << output_file);
RCLCPP_INFO_STREAM(node_->get_logger(), "Saving poses in TUM format in " << output_pose_file_);

// Iterate over the poses and timestamps
for (const auto &[timestamp, pose] : poses_with_timestamps_) {
Expand Down
Loading