getting_started:ros_example
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| getting_started:ros_example [2023/02/09 10:23] – ursgraf | getting_started:ros_example [2024/12/10 08:17] (current) – [Working with ROS2] ursgraf | ||
|---|---|---|---|
| Line 4: | Line 4: | ||
| ===== Working with ROS1 ===== | ===== Working with ROS1 ===== | ||
| - | The CMake file for the EEROS application using ROS1 has to be expanded as follows: | ||
| - | < | ||
| - | cmake_minimum_required(VERSION 3.5.1) | ||
| - | project(testProject) | ||
| - | |||
| - | set(CMAKE_CXX_STANDARD 14) | ||
| - | |||
| - | ## ROS | ||
| - | message(STATUS " | ||
| - | find_package( roslib REQUIRED ) | ||
| - | if (roslib_FOUND) | ||
| - | message( STATUS "-> ROS found" | ||
| - | add_definitions(-DROS_FOUND) | ||
| - | include_directories( " | ||
| - | message( STATUS " | ||
| - | list(APPEND ROS_LIBRARIES " | ||
| - | find_package( rosconsole REQUIRED) | ||
| - | list(APPEND ROS_LIBRARIES " | ||
| - | find_package( roscpp REQUIRED ) | ||
| - | list(APPEND ROS_LIBRARIES " | ||
| - | else() | ||
| - | message( STATUS "-> ROS NOT found" | ||
| - | endif() | ||
| - | |||
| - | find_package(EEROS REQUIRED) | ||
| - | include_directories(${EEROS_INCLUDE_DIR}; | ||
| - | link_directories(${EEROS_LIB_DIR}; | ||
| - | |||
| - | add_executable(testProject main.cpp) | ||
| - | target_link_libraries(testProject eeros ucl ${CMAKE_DL_LIBS} ${ROS_LIBRARIES}) | ||
| - | </ | ||
| - | |||
| Your test program might look like | Your test program might look like | ||
| <code cpp> | <code cpp> | ||
| Line 45: | Line 13: | ||
| ... | ... | ||
| eeros:: | eeros:: | ||
| - | ros:: | ||
| log.info() << "ROS node initialized."; | log.info() << "ROS node initialized."; | ||
| signal(SIGINT, | signal(SIGINT, | ||
| Line 56: | Line 23: | ||
| ===== Working with ROS2 ===== | ===== Working with ROS2 ===== | ||
| - | The CMake file for the EEROS application using ROS2 has to be expanded as follows: | ||
| - | < | ||
| - | cmake_minimum_required(VERSION 3.5.1) | ||
| - | project(testProject) | ||
| - | |||
| - | set(CMAKE_CXX_STANDARD 14) | ||
| - | |||
| - | ## ROS | ||
| - | message(STATUS " | ||
| - | find_package( rclcpp REQUIRED ) | ||
| - | if (rclcpp_FOUND) | ||
| - | message( STATUS "-> ROS2 found" | ||
| - | add_definitions(-DROS2_FOUND) | ||
| - | include_directories( " | ||
| - | message( STATUS " | ||
| - | list(APPEND ROS_LIBRARIES " | ||
| - | find_package( rosconsole REQUIRED) | ||
| - | list(APPEND ROS_LIBRARIES " | ||
| - | else() | ||
| - | message( STATUS "-> ROS2 NOT found" | ||
| - | endif() | ||
| - | |||
| - | find_package(EEROS REQUIRED) | ||
| - | include_directories(${EEROS_INCLUDE_DIR}) | ||
| - | link_directories(${EEROS_LIB_DIR}) | ||
| - | |||
| - | add_executable(testProject main.cpp) | ||
| - | target_link_libraries(testProject eeros ${EEROS_LIBS} ${ROS_LIBRARIES}) | ||
| - | </ | ||
| Your test program might look like | Your test program might look like | ||
| <code cpp> | <code cpp> | ||
| - | #include < | + | #include < |
| - | #include < | + | |
| #include < | #include < | ||
| | | ||
| int main(int argc, char **argv) { | int main(int argc, char **argv) { | ||
| ... | ... | ||
| - | auto node = eeros:: | + | |
| + | | ||
| if (node != nullptr) log.info() << "ROS node initialized: | if (node != nullptr) log.info() << "ROS node initialized: | ||
| - | | + | ... |
| + | 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 '' | All ROS tools such as '' | ||
| If you want to register a signal handler, e.g. for shutting down a system (see [[getting_started: | If you want to register a signal handler, e.g. for shutting down a system (see [[getting_started: | ||
| 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.1675934623.txt.gz · Last modified: 2023/02/09 10:23 by ursgraf