ROS2: Working with Ament

1,341 views
Skip to first unread message

Aptschihu Buktu

unread,
Sep 6, 2016, 11:13:29 AM9/6/16
to ROS SIG NG ROS


At the moment I starting to understand how Ament works. So I take these Tutorials:
I'm primary interested in how does talker and listener works and how they are to build. The last point is very hard to understand. I reduced the given example and try to understand what happens there. If I see the make output (building, linking) I see that there are linked always the same objects and libraries regardless if it is an `talker`,  `talker__rmw_fastrtps_cpp` or `talker__rmw_opensplice_cpp` (see the readable ament_overlay_buildlog.md). But what does makes the different between these three programs at the end? Is there any define or flag? How is it possible to build only `talker__rmw_fastrtps_cpp`?

Kind regards,
Alex

CMakeLists.txt
package.xml
ament_overlay_buildlog.md

Dirk Thomas

unread,
Sep 6, 2016, 12:00:49 PM9/6/16
to ROS SIG NG ROS
Hi Alex,

the behavior to build multiple targets using different RMW implementations has nothing to do with `ament` itself. The CMake function `call_for_each_rmw_implementation` is provided by the `rmw` package (https://github.com/ros2/rmw/blob/master/rmw_implementation_cmake/cmake/call_for_each_rmw_implementation.cmake). It allows to build multiple targets each linked to a different rmw implementation. Many of the example and demo packages are currently building binaries against all available rmw implementations (in your case FastRTPS and OpenSplice). If you only care about FastRTPS you could simply not install OpenSplice and FastRTPS would be your only rmw implementation.

The CMake you posted calls `call_for_each_rmw_implementation` which invokes the passed macro for each RMW implementation found. Each target is created with multiple suffixes (`${target}${target_suffix}`). And the rmw implementation is selected by linking against the specific version of the rclcpp library (`rclcpp${target_suffix}`).

In your own packages you probably don't want to create multiple targets but only use one RMW implementation. FastRTPS will be the default (based on alphabetical order). The `rclcpp` library without a suffix is being linked against the default rmw implementation available on your system. Something like this should be enough and avoids building multiple variations of each library / executable:

# no loop around this
add_executable(target ...)
ament_target_dependencies(target rclcpp ...)

Cheers,
- Dirk


--
You received this message because you are subscribed to the Google Groups "ROS SIG NG ROS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ros-sig-ng-ros+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aptschihu Buktu

unread,
Sep 6, 2016, 1:58:54 PM9/6/16
to ROS SIG NG ROS
Hi Thomas,

thank you very much. This makes the world a bit clearer :)

With your information I create this  package.xml

   
 <?xml version="1.0"?>
   
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
   
<package format="2">
   
       
<!-- Init Stuff -->
       
<name>ros2_e01</name>
       
<version>0.0.0</version>
       
<description>First try to build an Package using Ament.</description>
       
<maintainer email="al...@tu.de">Alexander</maintainer>
       
<license>Apache License 2.0</license>

       
<!-- choose the desired buildtool -->
       
<buildtool_depend>ament_cmake</buildtool_depend>
       
<buildtool_depend>rosidl_default_generators</buildtool_depend>

       
<!-- packages required at build time -->
       
<build_depend>rclcpp</build_depend>
       
<build_depend>std_msgs</build_depend>

       
<!-- packages required at execution time -->
       
<exec_depend>rclcpp</exec_depend>
       
<exec_depend>rosidl_default_runtime</exec_depend>
       
<exec_depend>std_msgs</exec_depend>

       
<!-- which build tool shall use -->
       
<export>
         
<build_type>ament_cmake</build_type>
       
</export>
   
</package>

CMakeLists.txt

    cmake_minimum_required(VERSION 3.5)

    project
(ros2_e01)

   
if(NOT WIN32)
       
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -Wall -Wextra")
    endif
()

    find_package
(ament_cmake REQUIRED)
    find_package
(rclcpp REQUIRED)
    find_package
(std_msgs REQUIRED)

    message
(STATUS ">> this is cmake configuring the target talker with rmw_fastrtps_cpp >>")
    get_rclcpp_information
( rmw_fastrtps_cpp
                            rclcpp__rmw_fastrtps_cpp
)
    add_executable
( talker__rmw_fastrtps_cpp
                    src
/topics/talker.cpp )
    ament_target_dependencies
( talker__rmw_fastrtps_cpp
                               rclcpp__rmw_fastrtps_cpp
                               std_msgs
                               example_interfaces
)
    install
( TARGETS talker__rmw_fastrtps_cpp
             DESTINATION bin
)

    message
(STATUS ">> this is cmake configuring the target listener with rmw_fastrtps_cpp >>")
    add_executable
( listener__rmw_fastrtps_cpp
                    src
/topics/listener.cpp )
    ament_target_dependencies
( listener__rmw_fastrtps_cpp
                               rclcpp__rmw_fastrtps_cpp
                               std_msgs
                               example_interfaces
)
    install
( TARGETS listener__rmw_fastrtps_cpp
             DESTINATION bin
)

    ament_package
()

This works now very well. Thank you again.

Kind regards,
Alex

Reply all
Reply to author
Forward
0 new messages