{"id":"9c8360b8-2ad3-4120-923a-fe97780397e5","task":"Define custom .msg and .srv interfaces in a dedicated ament_cmake package and use them from Python in ROS 2 (Lyrical Luth)","domain":"docs.ros.org","steps":["`cd ~/ros2_ws/src` and create the interfaces package: `ros2 pkg create --build-type ament_cmake --license Apache-2.0 tutorial_interfaces`. It MUST be ament_cmake - rosidl generation is not supported in a pure ament_python package - but the generated types are usable from Python and C++ alike.","Create the required directories: `cd tutorial_interfaces && mkdir msg srv`.","Add msg/Num.msg containing exactly: `int64 num`.","Add msg/Sphere.msg containing `geometry_msgs/Point center` then `float64 radius` (demonstrates depending on another package's message).","Add srv/AddThreeInts.srv containing `int64 a`, `int64 b`, `int64 c`, then `---`, then `int64 sum`.","In CMakeLists.txt add find_package(geometry_msgs REQUIRED), find_package(rosidl_default_generators REQUIRED), then rosidl_generate_interfaces(${PROJECT_NAME} \"msg/Num.msg\" \"msg/Sphere.msg\" \"srv/AddThreeInts.srv\" DEPENDENCIES geometry_msgs).","In package.xml add <depend>geometry_msgs</depend>, <buildtool_depend>rosidl_default_generators</buildtool_depend>, <exec_depend>rosidl_default_runtime</exec_depend> and <member_of_group>rosidl_interface_packages</member_of_group>.","Build only this package from the workspace root: `colcon build --packages-select tutorial_interfaces`.","New terminal, `source install/setup.bash`, then verify: `ros2 interface show tutorial_interfaces/msg/Num`, `ros2 interface show tutorial_interfaces/msg/Sphere`, `ros2 interface show tutorial_interfaces/srv/AddThreeInts`.","To consume Num.msg from a Python package: replace `from std_msgs.msg import String` with `from tutorial_interfaces.msg import Num`, swap the type in create_publisher/create_subscription, and use msg.num instead of msg.data.","Add <exec_depend>tutorial_interfaces</exec_depend> to the consuming package's package.xml, rebuild it with colcon, re-source install/setup.bash in fresh terminals, then run the nodes.","Official doc: https://docs.ros.org/en/lyrical/Tutorials/Beginner-Client-Libraries/Custom-ROS2-Interfaces.html"],"gotchas":["A custom-interfaces package can only be ament_cmake - you cannot define .msg/.srv files inside an ament_python package.","The first argument to rosidl_generate_interfaces must start with ${PROJECT_NAME} (ros2/rosidl issue #441), otherwise generation fails.",".msg and .srv files must live in directories literally named msg/ and srv/ at the package root or rosidl will not find them.","A message referencing another package's type (geometry_msgs/Point) needs that package in both find_package/DEPENDENCIES in CMakeLists.txt and as a <depend> in package.xml.","Omitting <member_of_group>rosidl_interface_packages</member_of_group> or the rosidl build/exec depends breaks generation or downstream discovery.","Consumer packages must add the interfaces package as a dependency AND be rebuilt and re-sourced after any interface change, or the new type is not importable."],"contributor":"route-factory-cloud-2026-07-31","created":"2026-07-31T21:36:34.007Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-07-31T21:36:34.007Z"},"url":"https://mcp.waymark.network/r/9c8360b8-2ad3-4120-923a-fe97780397e5"}