====== Example for Making your EEROS Application a ROS Node ====== Back to [[getting_started:ros|]]. ===== Working with ROS1 ===== Your test program might look like #include #include #include int main(int argc, char **argv) { ... eeros::control::rosTools::initNode("eerosNode"); // initialize the ROS node in your main function and give it a name. log.info() << "ROS node initialized."; signal(SIGINT, ...); ... All ROS tools such as ''rqt'' will list your EEROS application under the name ''eerosNode''. \\ If you want to register a signal handler, e.g. for shutting down a system (see [[getting_started:practical_problems:abort|]]), you have to register it after the ROS node is initialized. The ROS node will properly shut down as soon as the last node handler is destroyed when going out of scope. ===== Working with ROS2 ===== Your test program might look like #include #include #include int main(int argc, char **argv) { ... RosTools::initRos(argc, argv); auto node = RosTools::initNode("eerosNode"); if (node != nullptr) log.info() << "ROS node initialized: " << node->get_name(); ... ControlSystem cs(node, dt); ... When defining a control system which uses ROS subscriber or publisher blocks, you have to pass this node to them. All ROS tools such as ''rqt'' will list your EEROS application under the name ''eerosNode''. The variable ''node'' has to be passed to all blocks in the control system which publish or subscribe to ROS messages.\\ If you want to register a signal handler, e.g. for shutting down a system (see [[getting_started:practical_problems:abort|]]), you have to register it after the ROS node is initialized. The ROS node will properly shut down as soon as the last node handler is destroyed when going out of scope.