-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Publishing is slow in Docker with MutliThreadedExecutor
ros2/rclcpp#1487 Signed-off-by: Tomoya.Fujita <Tomoya.Fujita@sony.com>
- Loading branch information
1 parent
c7e4f34
commit ce0d33d
Showing
2 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#include <chrono> | ||
#include <condition_variable> | ||
#include <memory> | ||
#include <mutex> | ||
#include <string> | ||
#include <thread> | ||
|
||
#include "rclcpp/rclcpp.hpp" | ||
#include "std_msgs/msg/string.hpp" | ||
|
||
using namespace std::chrono_literals; | ||
|
||
/* This example creates a subclass of Node and uses std::bind() to register a | ||
* member function as a callback from the timer. */ | ||
|
||
class MinimalPublisher : public rclcpp::Node | ||
{ | ||
public: | ||
MinimalPublisher() | ||
: Node("minimal_publisher"), count_(0) | ||
{ | ||
publisher_ = this->create_publisher<std_msgs::msg::String>("topic", 10); | ||
timer_ = this->create_wall_timer( | ||
1ms, std::bind(&MinimalPublisher::timer_callback, this)); // 1kHz | ||
} | ||
|
||
private: | ||
void timer_callback() | ||
{ | ||
auto message = std_msgs::msg::String(); | ||
message.data = "Hello, world! " + std::to_string(count_++); | ||
// RCLCPP_INFO(this->get_logger(), "Publishing: '%s'", message.data.c_str()); | ||
publisher_->publish(message); | ||
} | ||
rclcpp::TimerBase::SharedPtr timer_; | ||
rclcpp::Publisher<std_msgs::msg::String>::SharedPtr publisher_; | ||
size_t count_; | ||
}; | ||
|
||
int main(int argc, char * argv[]) | ||
{ | ||
rclcpp::init(argc, argv); | ||
|
||
rclcpp::executors::MultiThreadedExecutor exe; | ||
// rclcpp::executors::SingleThreadedExecutor exe; | ||
|
||
std::shared_ptr<MinimalPublisher> pub = std::make_shared<MinimalPublisher>(); | ||
exe.add_node(pub->get_node_base_interface()); | ||
|
||
exe.spin(); | ||
rclcpp::shutdown(); | ||
return 0; | ||
} |