ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

Why the basic example of service in ROS2 doesnt use rosidl?

asked 2022-04-25 02:51:49 -0600

Peanpepu gravatar image

updated 2022-04-25 02:53:02 -0600

In the migrating article from ROS to ROS2, it says that for messages and services we have to add on CMakeLists.txt and on package.xml some rosidl lines. So why on "Writing a simple service and client (C++)" it doesnt use it and in which cases we should use it? Thanks in advance

edit retag flag offensive close merge delete

Comments

Can you link us these articles? Especially the first one about migrating

ljaniec gravatar image ljaniec  ( 2022-04-25 03:14:06 -0600 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-04-25 03:25:50 -0600

ljaniec gravatar image

updated 2022-04-25 04:27:11 -0600

I am not sure if this is it, but in the ROS2 tutorials the package example_interfaces is used - there in CMakeLists.txt you have these lines:

find_package(ament_cmake REQUIRED)
find_package(rosidl_default_generators REQUIRED)

rosidl_generate_interfaces(${PROJECT_NAME}
  "action/Fibonacci.action"
  ...
  "srv/Trigger.srv"
)
install(FILES mapping_rules.yaml DESTINATION share/${PROJECT_NAME})

ament_export_dependencies(rosidl_default_runtime)
ament_package()

and in package.xml:

<package format="3">
  <name>example_interfaces</name>
  <version>0.9.3</version>
  <description>Contains message and service definitions used by the examples.</description>
  <maintainer email="mabel@openrobotics.org">Mabel Zhang</maintainer>
  <license>Apache License 2.0</license>
  <author email="dthomas@openrobotics.org">Dirk Thomas</author>
  <author email="jacob@openrobotics.org">Jacob Perron</author>
  <buildtool_depend>ament_cmake</buildtool_depend>
  <buildtool_depend>rosidl_default_generators</buildtool_depend>
  <depend>action_msgs</depend>
  <exec_depend>rosidl_default_runtime</exec_depend>
  <member_of_group>rosidl_interface_packages</member_of_group>

A note about package_name_interfacesfrom https://docs.ros.org/en/foxy/Tutorial... :

While best practice is to declare interfaces in dedicated interface packages, sometimes it can be convenient to declare, create and use an interface all in one package.

The dependencies in the basic service examples are fulfilled with ament_target_dependencies(service_main rclcpp example_interfaces) in their CMakeLists.txt(e.g. https://github.com/ros2/examples/blob...).

edit flag offensive delete link more

Comments

Ok thank you. However, if i want to use a srv from my own folder i have to include all these rosidl stuff, isnt it? The migrating article is this one: "https://docs.ros.org/en/foxy/Contribu..." And the service basic example is the one you have seen: "https://docs.ros.org/en/foxy/Tutorial..."

Peanpepu gravatar image Peanpepu  ( 2022-04-25 04:03:33 -0600 )edit

Overall, yes - you can use ament macro ament_target_dependenciesin your package too (https://docs.ros.org/en/foxy/How-To-G...)

ljaniec gravatar image ljaniec  ( 2022-04-25 04:23:37 -0600 )edit

If this is the correct answer, please upvote and accept it so others can see that it has been answered

ljaniec gravatar image ljaniec  ( 2022-04-25 05:17:59 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2022-04-25 02:51:49 -0600

Seen: 335 times

Last updated: Apr 25 '22