User Tools

Site Tools


getting_started:ros_example

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
getting_started:ros_example [2023/02/27 15:04] ursgrafgetting_started:ros_example [2023/02/27 16:46] (current) – [Working with ROS2] ursgraf
Line 15: Line 15:
 find_package( roslib REQUIRED ) find_package( roslib REQUIRED )
 if (roslib_FOUND) if (roslib_FOUND)
- message( STATUS "-> ROS found"+  message( STATUS "-> ROS found"
- add_definitions(-DROS_FOUND) +  add_definitions(-DROS_FOUND) 
- include_directories( "${roslib_INCLUDE_DIRS}"+  include_directories( "${roslib_INCLUDE_DIRS}"
- message( STATUS "roslib_INCLUDE_DIRS: " ${roslib_INCLUDE_DIRS} ) +  message( STATUS "roslib_INCLUDE_DIRS: " ${roslib_INCLUDE_DIRS} ) 
- list(APPEND ROS_LIBRARIES "${roslib_LIBRARIES}"+  list(APPEND ROS_LIBRARIES "${roslib_LIBRARIES}"
- find_package( rosconsole REQUIRED) +  find_package( rosconsole REQUIRED) 
- list(APPEND ROS_LIBRARIES "${rosconsole_LIBRARIES}"+  list(APPEND ROS_LIBRARIES "${rosconsole_LIBRARIES}"
- find_package( roscpp REQUIRED ) +  find_package( roscpp REQUIRED ) 
- list(APPEND ROS_LIBRARIES "${roscpp_LIBRARIES}")+  list(APPEND ROS_LIBRARIES "${roscpp_LIBRARIES}"
 +  add_definitions(-DUSE_ROS)
 else() else()
- message( STATUS "-> ROS NOT found")+  message( STATUS "-> ROS NOT found")
 endif() endif()
  
Line 55: Line 56:
 The CMake file for the EEROS application using ROS2 has to be expanded as follows: The CMake file for the EEROS application using ROS2 has to be expanded as follows:
 <code> <code>
-cmake_minimum_required(VERSION 3.5.1)+cmake_minimum_required(VERSION 3.10)
 project(testProject) project(testProject)
- +
 set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
  
 ## ROS ## ROS
-message(STATUS "looking for package 'ROS'"+message(STATUS "looking for package 'ROS2'"
-find_package( rclcpp REQUIRED )+find_package(rclcpp REQUIRED)
 if (rclcpp_FOUND) if (rclcpp_FOUND)
- message( STATUS "-> ROS2 found"+  message(STATUS "-> ROS2 found"
- add_definitions(-DROS2_FOUND) +  add_definitions(-DROS2_FOUND) 
- include_directories( "${rclcpp_INCLUDE_DIRS}"+  include_directories( "${rclcpp_INCLUDE_DIRS}"
- message( STATUS "rclcpp_INCLUDE_DIRS: " ${rclcpp_INCLUDE_DIRS} ) +  message(STATUS "rclcpp_INCLUDE_DIRS: " ${rclcpp_INCLUDE_DIRS}) 
- list(APPEND ROS_LIBRARIES "${rclcpp_LIBRARIES}"+  list(APPEND ROS_LIBRARIES "${rclcpp_LIBRARIES}"
- find_package( rosconsole REQUIRED+  find_package(rosconsole QUIET
- list(APPEND ROS_LIBRARIES "${rosconsole_LIBRARIES}")+  list(APPEND ROS_LIBRARIES "${rosconsole_LIBRARIES}"
 +  add_definitions(-DUSE_ROS2)
 else() else()
- message( STATUS "-> ROS2 NOT found")+  message( STATUS "-> ROS2 NOT found")
 endif() endif()
  
 find_package(EEROS REQUIRED) find_package(EEROS REQUIRED)
-include_directories(${EEROS_INCLUDE_DIR}) +
-link_directories(${EEROS_LIB_DIR}) +
- +
 add_executable(testProject main.cpp) add_executable(testProject main.cpp)
-target_link_libraries(testProject eeros ${EEROS_LIBS} ${ROS_LIBRARIES})+target_link_libraries(testProject PRIVATE eeros ${EEROS_LIBS} ${ROS_LIBRARIES})
 </code> </code>
  
Line 86: Line 86:
 <code cpp> <code cpp>
 #include <eeros/control/ros2/EerosRosTools.hpp> #include <eeros/control/ros2/EerosRosTools.hpp>
-#include <ros/ros.h>+#include <rclcpp/rclcpp.hpp>
 #include <signal.h> #include <signal.h>
      
Line 94: Line 94:
   if (node != nullptr) log.info() << "ROS node initialized: " << node->get_name();   if (node != nullptr) log.info() << "ROS node initialized: " << node->get_name();
   signal(SIGINT, ...);   signal(SIGINT, ...);
 +  ...
 +  ControlSystem cs(node, dt);
   ...   ...
 </code> </code>
 +
 +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.\\ 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. 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. The ROS node will properly shut down as soon as the last node handler is destroyed when going out of scope.
getting_started/ros_example.1677506646.txt.gz · Last modified: 2023/02/27 15:04 by ursgraf