Skip to content

Commit

Permalink
update style after running tests
Browse files Browse the repository at this point in the history
Signed-off-by: Sangtaek Lee <[email protected]>
  • Loading branch information
sangteak601 committed Mar 6, 2024
1 parent 76f6b4b commit 6b276b1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 34 deletions.
80 changes: 47 additions & 33 deletions rosbag2_examples/rosbag2_examples_cpp/src/simple_bag_player.cpp
Original file line number Diff line number Diff line change
@@ -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 <chrono>
#include <functional>
#include <iostream>
#include <memory>
#include <string>
Expand All @@ -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<std_msgs::msg::String>("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<std_msgs::msg::String>("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<std_msgs::msg::String>();
rclcpp::SerializedMessage serialized_msg(*msg->serialized_data);
std_msgs::msg::String::SharedPtr ros_msg = std::make_shared<std_msgs::msg::String>();

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<std_msgs::msg::String>::SharedPtr publisher_;
rclcpp::TimerBase::SharedPtr timer_;
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_;

rclcpp::Serialization<std_msgs::msg::String> serialization_;
rosbag2_cpp::Reader reader_;
rclcpp::Serialization<std_msgs::msg::String> serialization_;
rosbag2_cpp::Reader reader_;
};

int main(int argc, char ** argv)
Expand All @@ -67,4 +81,4 @@ int main(int argc, char ** argv)
rclcpp::shutdown();

return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 6b276b1

Please sign in to comment.