Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switching to example_interfaces #4336

Open
wants to merge 2 commits into
base: rolling
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/Concepts/Advanced/About-Internal-Interfaces.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ The following diagram layouts the path from user defined ``rosidl`` files, e.g.

The right hand side of the diagram shows how the ``.msg`` files are passed directly to language specific code generators, e.g. ``rosidl_generator_cpp`` or ``rosidl_generator_py``.
These generators are responsible for creating the code that the user will include (or import) and use as the in-memory representation of the messages that were defined in the ``.msg`` files.
For example, consider the message ``std_msgs/String``, a user might use this file in C++ with the statement ``#include <std_msgs/msg/string.hpp>``, or they might use the statement ``from std_msgs.msg import String`` in Python.
For example, consider the message ``example_interfaces/String``, a user might use this file in C++ with the statement ``#include <example_interfaces/msg/string.hpp>``, or they might use the statement ``from example_interfaces.msg import String`` in Python.
These statements work because of the files generated by these language specific (but middleware agnostic) generator packages.

Separately, the ``.msg`` files are used to generate type support code for each type.
Expand Down
6 changes: 3 additions & 3 deletions source/Concepts/Basic/About-Command-Line-Tools.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ Publish messages in one terminal with:

.. code-block:: bash

$ ros2 topic pub /chatter std_msgs/msg/String "data: Hello world"
$ ros2 topic pub /chatter example_interfaces/msg/String "data: Hello world"
publisher: beginning loop
publishing #1: std_msgs.msg.String(data='Hello world')
publishing #1: example_interfaces.msg.String(data='Hello world')

publishing #2: std_msgs.msg.String(data='Hello world')
publishing #2: example_interfaces.msg.String(data='Hello world')

Echo messages received in another terminal with:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ Apply the following changes to use ``ament_cmake`` instead of ``catkin``:

rosidl_generate_interfaces(${PROJECT_NAME}
${msg_files}
DEPENDENCIES std_msgs
DEPENDENCIES example_interfaces
)

*
Expand Down Expand Up @@ -127,7 +127,7 @@ Replace ``catkin_add_gtest`` with ``ament_add_gtest``.
+ ament_add_gtest(${PROJECT_NAME}-some-test src/test/test_something.cpp)
+ ament_target_dependencies(${PROJECT_NAME)-some-test
+ "rclcpp"
+ "std_msgs")
+ "example_interfaces")
+ target_link_libraries(${PROJECT_NAME}-some-test
+ ${PROJECT_NAME}_some_dependency)
+ endif()
Expand Down Expand Up @@ -221,9 +221,9 @@ For usages of ``ros::Time``:

* Replace all instances of ``ros::Time`` with ``rclcpp::Time``

* If your messages or code makes use of std_msgs::Time:
* If your messages or code makes use of example_interfaces::Time:

* Convert all instances of std_msgs::Time to builtin_interfaces::msg::Time
* Convert all instances of example_interfaces::Time to builtin_interfaces::msg::Time

* Convert all ``#include "std_msgs/time.h`` to ``#include "builtin_interfaces/msg/time.hpp"``

Expand Down Expand Up @@ -320,9 +320,9 @@ Here is the content of those three files:
<license>Apache 2.0</license>
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>std_msgs</build_depend>
<build_depend>example_interfaces</build_depend>
<run_depend>roscpp</run_depend>
<run_depend>std_msgs</run_depend>
<run_depend>example_interfaces</run_depend>
</package>

``src/talker/CMakeLists.txt``:
Expand All @@ -331,7 +331,7 @@ Here is the content of those three files:

cmake_minimum_required(VERSION 2.8.3)
project(talker)
find_package(catkin REQUIRED COMPONENTS roscpp std_msgs)
find_package(catkin REQUIRED COMPONENTS roscpp example_interfaces)
catkin_package()
include_directories(${catkin_INCLUDE_DIRS})
add_executable(talker talker.cpp)
Expand All @@ -345,15 +345,15 @@ Here is the content of those three files:

#include <sstream>
#include "ros/ros.h"
#include "std_msgs/String.h"
#include "example_interfaces/String.h"
int main(int argc, char **argv)
{
ros::init(argc, argv, "talker");
ros::NodeHandle n;
ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);
ros::Publisher chatter_pub = n.advertise<example_interfaces::String>("chatter", 1000);
ros::Rate loop_rate(10);
int count = 0;
std_msgs::String msg;
example_interfaces::String msg;
while (ros::ok())
{
std::stringstream ss;
Expand Down Expand Up @@ -435,13 +435,13 @@ library API:
//#include "ros/ros.h"
#include "rclcpp/rclcpp.hpp"

To get the ``std_msgs/String`` message definition, in place of
``std_msgs/String.h``, we need to include ``std_msgs/msg/string.hpp``:
To get the ``example_interfaces/String`` message definition, in place of
``example_interfaces/String.h``, we need to include ``example_interfaces/msg/string.hpp``:

.. code-block:: cpp

//#include "std_msgs/String.h"
#include "std_msgs/msg/string.hpp"
//#include "example_interfaces/String.h"
#include "example_interfaces/msg/string.hpp"

Changing C++ library calls
~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand All @@ -461,9 +461,9 @@ changes to the names of namespace and methods.

.. code-block:: cpp

// ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);
// ros::Publisher chatter_pub = n.advertise<example_interfaces::String>("chatter", 1000);
// ros::Rate loop_rate(10);
auto chatter_pub = node->create_publisher<std_msgs::msg::String>("chatter",
auto chatter_pub = node->create_publisher<example_interfaces::msg::String>("chatter",
1000);
rclcpp::Rate loop_rate(10);

Expand All @@ -478,8 +478,8 @@ The creation of the outgoing message is different in the namespace:

.. code-block:: cpp

// std_msgs::String msg;
std_msgs::msg::String msg;
// example_interfaces::String msg;
example_interfaces::msg::String msg;

In place of ``ros::ok()``, we call ``rclcpp::ok()``:

Expand Down Expand Up @@ -528,21 +528,21 @@ Putting it all together, the new ``talker.cpp`` looks like this:
#include <sstream>
// #include "ros/ros.h"
#include "rclcpp/rclcpp.hpp"
// #include "std_msgs/String.h"
#include "std_msgs/msg/string.hpp"
// #include "example_interfaces/String.h"
#include "example_interfaces/msg/string.hpp"
int main(int argc, char **argv)
{
// ros::init(argc, argv, "talker");
// ros::NodeHandle n;
rclcpp::init(argc, argv);
auto node = rclcpp::Node::make_shared("talker");
// ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);
// ros::Publisher chatter_pub = n.advertise<example_interfaces::String>("chatter", 1000);
// ros::Rate loop_rate(10);
auto chatter_pub = node->create_publisher<std_msgs::msg::String>("chatter", 1000);
auto chatter_pub = node->create_publisher<example_interfaces::msg::String>("chatter", 1000);
rclcpp::Rate loop_rate(10);
int count = 0;
// std_msgs::String msg;
std_msgs::msg::String msg;
// example_interfaces::String msg;
example_interfaces::msg::String msg;
// while (ros::ok())
while (rclcpp::ok())
{
Expand Down Expand Up @@ -584,8 +584,8 @@ We make the same addition in the run dependencies and also update from the

<!-- <run_depend>roscpp</run_depend> -->
<exec_depend>rclcpp</exec_depend>
<!-- <run_depend>std_msgs</run_depend> -->
<exec_depend>std_msgs</exec_depend>
<!-- <run_depend>example_interfaces</run_depend> -->
<exec_depend>example_interfaces</exec_depend>

In ROS 1, we use ``<depend>`` to simplify specifying dependencies for both
compile-time and runtime.
Expand All @@ -594,7 +594,7 @@ We can do the same in ROS 2:
.. code-block:: xml

<depend>rclcpp</depend>
<depend>std_msgs</depend>
<depend>example_interfaces</depend>

We also need to tell the build tool what *kind* of package we are, so that it knows how
to build us.
Expand Down Expand Up @@ -622,9 +622,9 @@ Putting it all together, our ``package.xml`` now looks like this:
<buildtool_depend>ament_cmake</buildtool_depend>
<!-- <build_depend>roscpp</build_depend> -->
<!-- <run_depend>roscpp</run_depend> -->
<!-- <run_depend>std_msgs</run_depend> -->
<!-- <run_depend>example_interfaces</run_depend> -->
<depend>rclcpp</depend>
<depend>std_msgs</depend>
<depend>example_interfaces</depend>
<export>
<build_type>ament_cmake</build_type>
</export>
Expand Down Expand Up @@ -666,10 +666,10 @@ With ``ament_cmake``, we find each package individually, starting with ``ament_c

.. code-block:: cmake

#find_package(catkin REQUIRED COMPONENTS roscpp std_msgs)
#find_package(catkin REQUIRED COMPONENTS roscpp example_interfaces)
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(example_interfaces REQUIRED)

System dependencies can be found as before:

Expand Down Expand Up @@ -716,7 +716,7 @@ It automatically handles both the include directories defined in
#target_link_libraries(talker ${catkin_LIBRARIES})
ament_target_dependencies(talker
rclcpp
std_msgs)
example_interfaces)

To link with packages that are not ament packages, such as system dependencies
like ``Boost``, or a library being built in the same ``CMakeLists.txt``, use
Expand Down Expand Up @@ -748,7 +748,7 @@ Optionally, we can export dependencies for downstream packages:

.. code-block:: cmake

ament_export_dependencies(std_msgs)
ament_export_dependencies(example_interfaces)

Putting it all together, the new ``CMakeLists.txt`` looks like this:

Expand All @@ -763,26 +763,26 @@ Putting it all together, the new ``CMakeLists.txt`` looks like this:
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
#find_package(catkin REQUIRED COMPONENTS roscpp std_msgs)
#find_package(catkin REQUIRED COMPONENTS roscpp example_interfaces)
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(example_interfaces REQUIRED)
#catkin_package()
#include_directories(${catkin_INCLUDE_DIRS})
include_directories(include)
add_executable(talker talker.cpp)
#target_link_libraries(talker ${catkin_LIBRARIES})
ament_target_dependencies(talker
rclcpp
std_msgs)
example_interfaces)
#install(TARGETS talker
# RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION})
install(TARGETS talker
DESTINATION lib/${PROJECT_NAME})
install(DIRECTORY include/
DESTINATION include)
ament_export_include_directories(include)
ament_export_dependencies(std_msgs)
ament_export_dependencies(example_interfaces)
ament_package()

Building the ROS 2 code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ ROS 2 publishers by default request ``volatile`` Durability.

.. code-block:: console

ros2 topic pub -r 0.1 --qos-durability transient_local /talker std_msgs/String "data: Hello World"
ros2 topic pub -r 0.1 --qos-durability transient_local /talker example_interfaces/String "data: Hello World"

In order for Ros2Bag to record the data, we would want to override the recording policy for that specific topic like so:

Expand Down Expand Up @@ -108,4 +108,4 @@ We can see the results with ``ros2 topic``

.. code-block:: console

ros2 topic echo --qos-reliability best_effort /talker std_msgs/String
ros2 topic echo --qos-reliability best_effort /talker example_interfaces/String
12 changes: 6 additions & 6 deletions source/Tutorials/Advanced/Allocator-Template-Tutorial.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ But first, we'll declare a few aliases to shorten the names.
using rclcpp::memory_strategies::allocator_memory_strategy::AllocatorMemoryStrategy;
using Alloc = std::pmr::polymorphic_allocator<void>;
using MessageAllocTraits =
rclcpp::allocator::AllocRebind<std_msgs::msg::UInt32, Alloc>;
rclcpp::allocator::AllocRebind<example_interfaces::msg::UInt32, Alloc>;
using MessageAlloc = MessageAllocTraits::allocator_type;
using MessageDeleter = rclcpp::allocator::Deleter<MessageAlloc, std_msgs::msg::UInt32>;
using MessageUniquePtr = std::unique_ptr<std_msgs::msg::UInt32, MessageDeleter>;
using MessageDeleter = rclcpp::allocator::Deleter<MessageAlloc, example_interfaces::msg::UInt32>;
using MessageUniquePtr = std::unique_ptr<example_interfaces::msg::UInt32, MessageDeleter>;

Now we can create our resources with the custom allocator:

Expand All @@ -85,15 +85,15 @@ Now we can create our resources with the custom allocator:
auto alloc = std::make_shared<Alloc>(&mem_resource);
rclcpp::PublisherOptionsWithAllocator<Alloc> publisher_options;
publisher_options.allocator = alloc;
auto publisher = node->create_publisher<std_msgs::msg::UInt32>(
auto publisher = node->create_publisher<example_interfaces::msg::UInt32>(
"allocator_tutorial", 10, publisher_options);

rclcpp::SubscriptionOptionsWithAllocator<Alloc> subscription_options;
subscription_options.allocator = alloc;
auto msg_mem_strat = std::make_shared<
rclcpp::message_memory_strategy::MessageMemoryStrategy<
std_msgs::msg::UInt32, Alloc>>(alloc);
auto subscriber = node->create_subscription<std_msgs::msg::UInt32>(
example_interfaces::msg::UInt32, Alloc>>(alloc);
auto subscriber = node->create_subscription<example_interfaces::msg::UInt32>(
"allocator_tutorial", 10, callback, subscription_options, msg_mem_strat);

std::shared_ptr<rclcpp::memory_strategy::MemoryStrategy> memory_strategy =
Expand Down
Loading
Loading