micro-ROS / micro_ros_setup

Support macros for building micro-ROS-based firmware.
Apache License 2.0
365 stars 133 forks source link

ROS2 nodes do not see microros custom agent #666

Closed N-K1998 closed 1 year ago

N-K1998 commented 1 year ago

Issue template

I have defined a custom transport (custom agent) for Microros and I want my ros2 nodes to use that transport on Linux. I am executing the command ros2 run micro_ros_agent micro_ros_agent to run the custom agent and ros2 run cpp_pubsub listener of the cpp_pubsub example provided by ROS2. The CMake of the ROS2 application is the following:

cmake_minimum_required(VERSION 3.8)
project(cpp_pubsub)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
# uncomment the following section in order to fill in
# further dependencies manually.
# find_package(<dependency> REQUIRED)

add_executable(talker src/publisher_member_function.cpp)
add_executable(listener src/subscriber_member_function.cpp)
ament_target_dependencies(talker rclcpp std_msgs)
ament_target_dependencies(listener rclcpp std_msgs)

install(TARGETS
          talker
          listener
            DESTINATION lib/${PROJECT_NAME})

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  # the following line skips the linter which checks for copyrights
  # comment the line when a copyright and license is added to all source files
  set(ament_cmake_copyright_FOUND TRUE)
  # the following line skips cpplint (only works in a git repo)
  # comment the line when this package is in a git repo and when
  # a copyright and license is added to all source files
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

ament_package()

This file is placed inside microros_ws/src/uros/cpp_pubsub. Inside the uros folder, there is also the micro-ROS-agent folder containing the files for the agent. How can I force the ros2 nodes to use the custom transport?

pablogs9 commented 1 year ago

Hello @N-K1998 I do not fully understand your issue. Please answer these questions:

N-K1998 commented 1 year ago

I am sorry, I cannot provide you with the details of the custom transport but it works. The custom agent can communicate with microros clients. The question is if it is possible for an agent to be able to communicate with a normal ROS2 node, not a microros client, through the DDS.

pablogs9 commented 1 year ago

If you need to implement custom transport for DDS, you need to ask in Fast DDS repo as far as it is not related to micro-ROS or Micro XRCE-DDS.

If the micro-ROS part is working successfully, let me know if we can close this issue.

N-K1998 commented 1 year ago

Yes, the microros part works correctly but the XRCE-DDS cannot communicate with the standard DDS global data space. Is there a possibility that the agent is running on a different DDS than the one belonging to ROS2 nodes?

pablogs9 commented 1 year ago

Not at all, if you micro-ROS Client and Agent are communicating correctly, the DDS communication shall happen between ROS 2 and the Agent.

If you could share a log of the agent with the flag -v6 we can provide some more help.

N-K1998 commented 1 year ago

This is the output. I have run the agent with ros2 run micro_ros_agent micro_ros_agent and the listener using RMW_IMPLEMENTATION=rmw_fastrtps_cpp ros2 run cpp_pubsub listener.

[1695740581.430718] info     | CustomAgent.cpp    | init                     | Custom agent status: opened | SHM_CUSTOM agent running
[1695740585.050332] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x00000000, len: 24, data:
0000: 80 00 00 00 00 01 10 00 58 52 43 45 01 00 01 0F 28 F2 1A 49 81 00 FC 01
[1695740585.050836] info     | Root.cpp           | create_client            | create                 | client_key: 0x28F21A49, session_id: 0x81
[1695740585.055125] info     | SessionManager.hpp | establish_session        | session established    | client_key: 0x28F21A49, address: ID: 0
[1695740585.055462] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740585.055576] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 19, data:
0000: 81 00 00 00 04 01 0B 00 00 00 58 52 43 45 01 00 01 0F 00
[1695740585.066631] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 52, data:
0000: 81 80 00 00 01 07 2C 00 00 0A 00 01 01 03 00 00 1D 00 00 00 00 01 00 00 15 00 00 00 70 75 62 6C
0020: 69 73 68 65 72 5F 63 6F 75 6E 74 5F 6E 6F 64 65 00 00 00 00
[1695740585.098260] info     | ProxyClient.cpp    | create_participant       | participant created    | client_key: 0x28F21A49, participant_id: 0x000(1)
[1695740585.098690] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740585.098818] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 14, data:
0000: 81 80 00 00 05 01 06 00 00 0A 00 01 00 00
[1695740585.098991] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740585.099068] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 01 00 00 00 80
[1695740585.109637] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 01 00 00 00 80
[1695740585.114808] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 84, data:
0000: 81 80 01 00 01 07 4A 00 00 0B 00 02 02 03 00 00 3C 00 00 00 16 00 00 00 72 74 2F 66 72 65 65 52
0020: 54 4F 53 5F 70 75 62 6C 69 73 68 65 72 00 00 01 1C 00 00 00 73 74 64 5F 6D 73 67 73 3A 3A 6D 73
0040: 67 3A 3A 64 64 73 5F 3A 3A 49 6E 74 33 32 5F 00 00 01 00 00
[1695740585.115357] info     | ProxyClient.cpp    | create_topic             | topic created          | client_key: 0x28F21A49, topic_id: 0x000(2), participant_id: 0x000(1)
[1695740585.115603] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740585.115696] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 14, data:
0000: 81 80 01 00 05 01 06 00 00 0B 00 02 00 00
[1695740585.115799] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740585.115901] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 02 00 00 00 80
[1695740585.142486] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 02 00 00 00 80
[1695740585.147659] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 24, data:
0000: 81 80 02 00 01 07 10 00 00 0C 00 03 03 03 00 00 02 00 00 00 00 00 00 01
[1695740585.148156] info     | ProxyClient.cpp    | create_publisher         | publisher created      | client_key: 0x28F21A49, publisher_id: 0x000(3), participant_id: 0x000(1)
[1695740585.148569] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740585.148651] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 14, data:
0000: 81 80 02 00 05 01 06 00 00 0C 00 03 00 00
[1695740585.148687] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740585.148761] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 03 00 00 00 80
[1695740585.175375] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 03 00 00 00 80
[1695740585.180535] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 36, data:
0000: 81 80 03 00 01 07 1C 00 00 0D 00 05 05 03 00 00 0E 00 00 00 00 02 01 00 03 00 01 00 0A 00 00 00
0020: 00 00 00 03
[1695740585.186216] info     | ProxyClient.cpp    | create_datawriter        | datawriter created     | client_key: 0x28F21A49, datawriter_id: 0x000(5), publisher_id: 0x000(3)
[1695740585.186482] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740585.186626] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 14, data:
0000: 81 80 03 00 05 01 06 00 00 0D 00 05 00 00
[1695740585.186762] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740585.186899] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 04 00 00 00 80
[1695740585.208244] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 04 00 00 00 80
[1695740585.217378] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 16, data:
0000: 81 80 04 00 07 01 08 00 00 0E 00 05 00 00 00 00
[1695740585.217622] debug    | DataWriter.cpp     | write                    | [** <<DDS>> **]        | client_key: 0x00000000, len: 4, data:
0000: 00 00 00 00
[1695740585.217757] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740585.217921] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 05 00 00 00 80
[1695740590.238991] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 16, data:
0000: 81 80 05 00 07 01 08 00 00 0F 00 05 01 00 00 00
[1695740590.239440] debug    | DataWriter.cpp     | write                    | [** <<DDS>> **]        | client_key: 0x00000000, len: 4, data:
0000: 01 00 00 00
[1695740590.239651] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740590.239840] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 06 00 00 00 80
[1695740595.249028] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 16, data:
0000: 81 80 06 00 07 01 08 00 00 10 00 05 02 00 00 00
[1695740595.249342] debug    | DataWriter.cpp     | write                    | [** <<DDS>> **]        | client_key: 0x00000000, len: 4, data:
0000: 02 00 00 00
[1695740595.249458] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740595.249593] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 07 00 00 00 80
[1695740600.259074] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 16, data:
0000: 81 80 07 00 07 01 08 00 00 11 00 05 03 00 00 00
[1695740600.259398] debug    | DataWriter.cpp     | write                    | [** <<DDS>> **]        | client_key: 0x00000000, len: 4, data:
0000: 03 00 00 00
[1695740600.259606] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740600.259868] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 08 00 00 00 80
[1695740605.269120] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 16, data:
0000: 81 80 08 00 07 01 08 00 00 12 00 05 04 00 00 00
[1695740605.269461] debug    | DataWriter.cpp     | write                    | [** <<DDS>> **]        | client_key: 0x00000000, len: 4, data:
0000: 04 00 00 00
[1695740605.269890] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740605.270058] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 09 00 00 00 80
[1695740610.279165] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 16, data:
0000: 81 80 09 00 07 01 08 00 00 13 00 05 05 00 00 00
[1695740610.279483] debug    | DataWriter.cpp     | write                    | [** <<DDS>> **]        | client_key: 0x00000000, len: 4, data:
0000: 05 00 00 00
[1695740610.279604] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740610.279707] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 0A 00 00 00 80
[1695740615.289212] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 16, data:
0000: 81 80 0A 00 07 01 08 00 00 14 00 05 06 00 00 00
[1695740615.289681] debug    | DataWriter.cpp     | write                    | [** <<DDS>> **]        | client_key: 0x00000000, len: 4, data:
0000: 06 00 00 00
[1695740615.289893] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740615.290083] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 0B 00 00 00 80
[1695740620.299256] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 16, data:
0000: 81 80 0B 00 07 01 08 00 00 15 00 05 07 00 00 00
[1695740620.299500] debug    | DataWriter.cpp     | write                    | [** <<DDS>> **]        | client_key: 0x00000000, len: 4, data:
0000: 07 00 00 00
[1695740620.299672] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740620.299802] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 0C 00 00 00 80
[1695740625.309304] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 16, data:
0000: 81 80 0C 00 07 01 08 00 00 16 00 05 08 00 00 00
[1695740625.309553] debug    | DataWriter.cpp     | write                    | [** <<DDS>> **]        | client_key: 0x00000000, len: 4, data:
0000: 08 00 00 00
[1695740625.309724] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740625.309852] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 0D 00 00 00 80
[1695740630.319403] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 16, data:
0000: 81 80 0D 00 07 01 08 00 00 17 00 05 09 00 00 00
[1695740630.319650] debug    | DataWriter.cpp     | write                    | [** <<DDS>> **]        | client_key: 0x00000000, len: 4, data:
0000: 09 00 00 00
[1695740630.319825] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740630.319950] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 0E 00 00 00 80
[1695740635.329533] debug    | CustomAgent.cpp    | recv_message             | [==>> SHM_CUSTOM <<==] | client_key: 0x28F21A49, len: 16, data:
0000: 81 80 0E 00 07 01 08 00 00 18 00 05 0A 00 00 00
[1695740635.329851] debug    | DataWriter.cpp     | write                    | [** <<DDS>> **]        | client_key: 0x00000000, len: 4, data:
0000: 0A 00 00 00
[1695740635.329956] info     | agent_main.cpp     | operator()               | SendMsg:               | called
[1695740635.330091] debug    | CustomAgent.cpp    | send_message             | [** <<SHM_CUSTOM>> **] | client_key: 0x28F21A49, len: 13, data:
0000: 81 00 00 00 0A 01 05 00 0F 00 00 00 80
pablogs9 commented 1 year ago

Well, this log shows that DDS communication is happening, check the [** <<DDS>> **].

Are your ROS2 node using ROS_DOMAIN_ID=0?

N-K1998 commented 1 year ago

I have tried now by executing ROS_DOMAIN_ID=0 ros2 run cpp_pubsub listener & > log.txt and ROS_DOMAIN_ID=0 ros2 run cpp_pubsub talker > /dev/null 2> /dev/null &. I got the same output.

pablogs9 commented 1 year ago

As far as I understand this is a DDS issue between the agent and your ROS 2 node.

Are both entities running on the same computer? Are you using dockers somehow? Is possible to share a Wireshark captura of the RTPS traffic on the network?

N-K1998 commented 1 year ago

The problem was on the topic the listener was subscribed to. Thank you for your support.