10 #include <mrpt/core/round.h>
19 int main(
int argc,
char** argv)
22 #if PACKAGE_ROS_VERSION == 1
26 rclcpp::init(argc, argv);
37 std::string world_file;
41 #if PACKAGE_ROS_VERSION == 1
46 private_node_handle_.
param(
"simul_rate", rate, 100.0);
47 private_node_handle_.
param(
"world_file", world_file, std::string(
""));
49 n->get_parameter(
"world_file", world_file);
50 n->get_parameter(
"simul_rate", rate);
52 const auto periodMs = mrpt::round(1e6 /
static_cast<double>(rate));
56 node->launch_mvsim_server();
59 if (!world_file.empty()) node->loadWorldModel(world_file);
62 node->mvsim_world_->headless(node->headless_);
63 node->mvsim_world_->connectToServer();
65 #if PACKAGE_ROS_VERSION == 1
69 dynamic_reconfigure::Server<mvsim::mvsimNodeConfig> dr_srv;
70 dr_srv.setCallback([&node](mvsim::mvsimNodeConfig&
config, uint32_t level)
71 {
return node->configCallback(
config, level); });
75 #if PACKAGE_ROS_VERSION == 1
87 const auto timer_ = rclcpp::create_timer(
88 n, ros_clock, std::chrono::microseconds(periodMs),
91 if (rclcpp::ok()) node->spin();
97 std::cout <<
"[rclcpp::on_shutdown] Destroying MVSIM node..." << std::endl;
98 node->terminateSimulation();
99 std::cout <<
"[rclcpp::on_shutdown] MVSIM node destroyed." << std::endl;
108 catch (
const std::exception& e)
110 #if PACKAGE_ROS_VERSION == 1
111 std::cerr << e.what() << std::endl;
113 RCLCPP_ERROR_STREAM(n->get_logger(),
"Exception in main node body:\n" << e.what());