10 #include <mrpt/core/round.h> 19 int main(
int argc,
char** argv)
22 #if PACKAGE_ROS_VERSION == 1 26 rclcpp::init(argc, argv);
27 auto n = rclcpp::Node::make_shared(
"mvsim");
33 std::shared_ptr<MVSimNode> node = std::make_shared<MVSimNode>(n);
37 std::string world_file;
41 #if PACKAGE_ROS_VERSION == 1 47 private_node_handle_.
param(
"simul_rate", rate, 100.0);
48 private_node_handle_.
param(
"world_file", world_file, std::string(
""));
50 n->get_parameter(
"world_file", world_file);
51 n->get_parameter(
"simul_rate", rate);
53 const auto periodMs = mrpt::round(1e6 / static_cast<double>(rate));
57 node->launch_mvsim_server();
60 if (!world_file.empty()) node->loadWorldModel(world_file);
63 node->mvsim_world_->headless(node->headless_);
64 node->mvsim_world_->connectToServer();
66 #if PACKAGE_ROS_VERSION == 1 70 dynamic_reconfigure::Server<mvsim::mvsimNodeConfig> dr_srv;
71 dynamic_reconfigure::Server<mvsim::mvsimNodeConfig>::CallbackType cb;
72 cb = boost::bind(&MVSimNode::configCallback, node.get(), _1, _2);
73 dr_srv.setCallback(cb);
77 #if PACKAGE_ROS_VERSION == 1 88 auto ros_clock = rclcpp::Clock::make_shared();
89 auto timer_ = rclcpp::create_timer(
90 n, ros_clock, std::chrono::microseconds(periodMs), [&]() {
91 if (rclcpp::ok()) node->spin();
94 rclcpp::on_shutdown([&]() {
95 std::cout <<
"[rclcpp::on_shutdown] Destroying MVSIM node..." 97 node->terminateSimulation();
98 std::cout <<
"[rclcpp::on_shutdown] MVSIM node destroyed." 108 catch (
const std::exception& e)
110 #if PACKAGE_ROS_VERSION == 1 111 std::cerr << e.what() << std::endl;
114 n->get_logger(),
"Exception in main node body:\n"
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
int main(int argc, char **argv)
ROSCPP_DECL void spinOnce()