ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
In the end I've managed to do it like this:
TEST(SmokeTests, NodeStartingCorrectly) {
char arg0[] = "--ros-args";
char arg1[] = "--params-file";
char arg2[] = "test.yaml";
char* argv[] = { &arg0[0], &arg1[0], &arg2[0], NULL };
int argc = (int)(sizeof(argv) / sizeof(argv[0])) - 1;
// Initialization
rclcpp::init(argc, argv);
// Instantiation
rclcpp::Node::SharedPtr node = std::make_shared<PelicanUnit>();
rclcpp::executors::MultiThreadedExecutor executor;
executor.add_node(node);
std::thread t(
[&](){
ASSERT_NO_THROW(executor.spin(););
}
);
std::this_thread::sleep_for(std::chrono::seconds(5));
executor.cancel();
t.join(); // Wait for thread completion
rclcpp::shutdown();
}
I have not found another way with spin_some
or spin_until_future_complete
, probably due to something related to these issues: