====== Control System Talking to ROS ====== EEROS can work with ROS1 or ROS2. However, you have to make sure, that you compile EEROS with support for the right version of ROS. Further, the naming and use of the tools in ROS1 and ROS2 have slightly changed. ===== Using ROS1 ===== In the EEROS library you will find a directory with examples. For this example see [[https://github.com/eeros-project/eeros-framework/blob/master/examples/ros/RosTest1.cpp|RosTest1.cpp]]. Open a shell in the build directory of your EEROS library. This examples with ROS will only be present in your build directory if ROS was installed before building EEROS with ''-DUSE_ROS=TRUE'' set, see [[getting_started:ros_prep|Preparations and Building]]. If you work on a target make sure to setup the environment as given in [[getting_started:ros_run|]]. Open a shell and run $ roscore Open another shell in the build directory of your EEROS library and run $ sudo -E ./examples/ros/rosTest1 IMPORTANT You have to run a program using real time threads with root privileges. ==== Publishing ==== This example runs your EEROS application as a ROS node under the name ///eerosNode//. It publishes six topics * /test/analogSignal (of type eeros_msgs/msg/AnalogSignal with a single double value) * /test/analogSignalVector (of type eeros_msgs/msg/AnalogSignal with a vector of 7 entries of type double) * /test/digitalSignal (of type eeros_msgs/msg/DigitalSignal with a single bool value) * /test/digitalSignalVector (of type eeros_msgs/msg/DigitalSignal with a vector of 7 entries of type bool) * /test/safetyLevel (currently active safety level of type std_msgs/msg/String) * /test/odom (odometry data of type nav_msgs/msg/Odometry) With $ rosnode list you will see the new node. $ rostopic list will list all the topics which are published be our node. Open another shell to show the messages sent by EEROS, e.g. $ rostopic echo /test/analogSignalVector With $ rostopic hz /test/analogSignalVector you can easily check how often data is sent from out ROS node. Try to plot the data with $ rqt_plot /test/analogSignal /test/analogSignalVector/val[0] /test/analogSignalVector/val[1] /test/safetyLevel ==== Subscribing ==== Open another shell in the build directory of your EEROS library and run ''rosNodeTalker''. This is not a EEROS program but simply starts a ROS node which publishes a couple of test topics. As soon as ''rosNodeTalker'' runs, your example application will receive the two topics * /rosNodeTalker/vector (of type Matrix<2,1,double>) * /rosNodeTalker/val (of type double) and logs its transported message values into the console. Alternatively you could publish a single message from the command line with $ rostopic pub /rosNodeTalker/val std_msgs/Float64 -- -2.3 $ rostopic pub /rosNodeTalker/vector std_msgs/Float64MultiArray "{layout: {dim: [], data_offset: 0}, data: [2.5, 1.76]}" Use $ rqt_graph to show a graph with all involved nodes together with their topics. ===== Using ROS2 ===== In the EEROS library you will find a directory with examples. For this example see [[https://github.com/eeros-project/eeros-framework/blob/master/examples/ros2/RosTest1.cpp|RosTest1.cpp]]. Open a shell in the build directory of your EEROS library. This examples with ROS2 will only be present in your build directory if ROS2 was installed before building EEROS with ''-DUSE_ROS2=TRUE'' set, see [[getting_started:ros_prep|Preparations and Building]]. If you work on a target make sure to setup the environment as given in [[getting_started:ros_run|]]. Open a shell in the build directory of your EEROS library and run $ sudo -E ./examples/ros2/rosTest1 IMPORTANT You have to run a program using real time threads with root privileges. ==== Publishing ==== This example runs your EEROS application as a ROS node under the name ///eerosNode//. It publishes three topics * /test/vector (of type Matrix<7,1,double>) * /test/val (of type double) * /test/safetyLevel (of type string) With $ ros2 node list you will see the new node. $ ros2 topic list will list the three topics which are published be our node, ///test/val//, ///test/vector//, and ///test/safetyLevel//. Open another shell to show the messages sent by EEROS, e.g. $ ros2 topic echo /test/vector With $ ros2 topic hz /test/val you can easily check how often data is sent from out ROS node. ==== Subscribing ==== Open another shell in the build directory of your EEROS library and run ''rosNodeTalker''. This is not a EEROS program but simply starts a ROS node which publishes a couple of test topics. As soon as ''rosNodeTalker'' runs, your example application will receive the two topics * /rosNodeTalker/vector (of type Matrix<2,1,double>) * /rosNodeTalker/val (of type double) and logs its transported message values into the console. Alternatively you could publish a single message from the command line with $ ros2 topic pub /rosNodeTalker/val example_interfaces/msg/Float64 "data: -2.3" $ ros2 topic pub /rosNodeTalker/vector example_interfaces/msg/Float64MultiArray "{layout: {dim: [], data_offset: 0}, data: [2.5, 1.76]}" Use $ rqt to show a graph with all involved nodes together with their topics or to plot messages.