diff --git a/rosbag2_examples/rosbag2_examples_cpp/src/simple_bag_player.cpp b/rosbag2_examples/rosbag2_examples_cpp/src/simple_bag_player.cpp index 124c00585..522059bfb 100644 --- a/rosbag2_examples/rosbag2_examples_cpp/src/simple_bag_player.cpp +++ b/rosbag2_examples/rosbag2_examples_cpp/src/simple_bag_player.cpp @@ -1,5 +1,18 @@ +// Copyright 2024 Open Source Robotics Foundation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include -#include #include #include #include @@ -13,46 +26,47 @@ using namespace std::chrono_literals; class SimpleBagPlayer : public rclcpp::Node { - public: - SimpleBagPlayer(const std::string & bag_filename) - : Node("playback_node") - { - publisher_ = this->create_publisher("chatter", 10); - - timer_ = this->create_wall_timer(100ms, - [this](){return this->timer_callback();} - ); - - reader_.open(bag_filename); - } +public: + explicit SimpleBagPlayer(const std::string & bag_filename) + : Node("playback_node") + { + publisher_ = this->create_publisher("chatter", 10); + + timer_ = this->create_wall_timer( + 100ms, + [this](){return this->timer_callback();} + ); + + reader_.open(bag_filename); + } - private: - void timer_callback() - { - while (reader_.has_next()) { - rosbag2_storage::SerializedBagMessageSharedPtr msg = reader_.read_next(); +private: + void timer_callback() + { + while (reader_.has_next()) { + rosbag2_storage::SerializedBagMessageSharedPtr msg = reader_.read_next(); - if (msg->topic_name != "chatter") { - continue; - } + if (msg->topic_name != "chatter") { + continue; + } - rclcpp::SerializedMessage serialized_msg(*msg->serialized_data); - std_msgs::msg::String::SharedPtr ros_msg = std::make_shared(); + rclcpp::SerializedMessage serialized_msg(*msg->serialized_data); + std_msgs::msg::String::SharedPtr ros_msg = std::make_shared(); - serialization_.deserialize_message(&serialized_msg, ros_msg.get()); + serialization_.deserialize_message(&serialized_msg, ros_msg.get()); - publisher_->publish(*ros_msg); - std::cout << ros_msg->data << "\n"; + publisher_->publish(*ros_msg); + std::cout << ros_msg->data << "\n"; - break; - } + break; } + } - rclcpp::TimerBase::SharedPtr timer_; - rclcpp::Publisher::SharedPtr publisher_; + rclcpp::TimerBase::SharedPtr timer_; + rclcpp::Publisher::SharedPtr publisher_; - rclcpp::Serialization serialization_; - rosbag2_cpp::Reader reader_; + rclcpp::Serialization serialization_; + rosbag2_cpp::Reader reader_; }; int main(int argc, char ** argv) @@ -67,4 +81,4 @@ int main(int argc, char ** argv) rclcpp::shutdown(); return 0; -} \ No newline at end of file +} diff --git a/rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/simple_bag_player.py b/rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/simple_bag_player.py index da897e1d6..e09da9e33 100644 --- a/rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/simple_bag_player.py +++ b/rosbag2_examples/rosbag2_examples_py/rosbag2_examples_py/simple_bag_player.py @@ -12,6 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import sys + import rclpy from rclpy.node import Node from rclpy.serialization import deserialize_message @@ -43,7 +44,6 @@ def timer_callback(self): self.get_logger().info(ros_msg.data) - def main(args=None): rclpy.init(args=args) sbr = SimpleBagPlayer(sys.argv[1])