micro-ROS / micro_ros_arduino

micro-ROS library for Arduino
Apache License 2.0
443 stars 115 forks source link

Long action name does not work for action server #1138

Closed metanav closed 2 years ago

metanav commented 2 years ago

Steps to reproduce the issue

I am using the action server example below. The action server starts up and connects successfully to the microROS agent with the action name length equals or below 30 characters but fails to start for longer action names.

Note: See the rclc_action_server_init_default function call in the setup().

Action Server Code Snippet:

void setup()
{
  set_microros_transports();
  allocator = rcl_get_default_allocator();
  // creat init_options
  RCCHECK(rclc_support_init(&support, 0, NULL, &allocator));
  // create node
  RCCHECK(rclc_node_init_default(&node, "fibonacci_action_server_rcl", "", &support));
  // Create action service
  RCCHECK(
    rclc_action_server_init_default(
      &action_server,
      &node,
      &support,
      ROSIDL_GET_ACTION_TYPE_SUPPORT(control_msgs, FollowJointTrajectory),
      "/namespace/follow_joint_trajectory" // <-- This does not work but this works -->  "/ns/follow_joint_trajectory"
    ));

  // create executor
  rclc_executor_init(&executor, &support.context, 1, &allocator);

  RCCHECK(
    rclc_executor_add_action_server(
      &executor,
      &action_server,
      10,
      ros_goal_request,
      sizeof(control_msgs__action__FollowJointTrajectory_SendGoal_Request),
      goal_callback,
      cancel_callback,
      (void *) &action_server));

}

void loop()
{
  RCSOFTCHECK(rclc_executor_spin_some(&executor, RCL_MS_TO_NS(100)));
}

Expected behavior

The action server should be running despite of the action name length that should be limited only by the MAX_SIZE (I am not sure the size but the addtwoints service example works with long name for example 50 chars)

When the action name length is below 30 characters it works. MicroROS Agent log:

[1660372403.975499] info     | TermiosAgentLinux.cpp | init                     | running...             | fd: 3
[1660372404.694606] info     | Root.cpp           | delete_client            | delete                 | client_key: 0x1D4F37F6
[1660372404.694653] info     | SessionManager.hpp | destroy_session          | session closed         | client_key: 0x1D4F37F6, address: 0
[1660372404.694670] info     | Root.cpp           | create_client            | create                 | client_key: 0x1EA16175, session_id: 0x81
[1660372404.694676] info     | SessionManager.hpp | establish_session        | session established    | client_key: 0x1EA16175, address: 0
[1660372404.702219] info     | ProxyClient.cpp    | create_participant       | participant created    | client_key: 0x1EA16175, participant_id: 0x000(1)
[1660372404.707220] info     | ProxyClient.cpp    | create_replier           | replier created        | client_key: 0x1EA16175, requester_id: 0x000(7), participant_id: 0x000(1)
[1660372404.711586] info     | ProxyClient.cpp    | create_replier           | replier created        | client_key: 0x1EA16175, requester_id: 0x001(7), participant_id: 0x000(1)
[1660372404.715842] info     | ProxyClient.cpp    | create_replier           | replier created        | client_key: 0x1EA16175, requester_id: 0x002(7), participant_id: 0x000(1)
[1660372404.718823] info     | ProxyClient.cpp    | create_topic             | topic created          | client_key: 0x1EA16175, topic_id: 0x000(2), participant_id: 0x000(1)
[1660372404.721160] info     | ProxyClient.cpp    | create_publisher         | publisher created      | client_key: 0x1EA16175, publisher_id: 0x000(3), participant_id: 0x000(1)
[1660372404.723654] info     | ProxyClient.cpp    | create_datawriter        | datawriter created     | client_key: 0x1EA16175, datawriter_id: 0x000(5), publisher_id: 0x000(3)
[1660372404.726721] info     | ProxyClient.cpp    | create_topic             | topic created          | client_key: 0x1EA16175, topic_id: 0x001(2), participant_id: 0x000(1)
[1660372404.729146] info     | ProxyClient.cpp    | create_publisher         | publisher created      | client_key: 0x1EA16175, publisher_id: 0x001(3), participant_id: 0x000(1)
[1660372404.732263] info     | ProxyClient.cpp    | create_datawriter        | datawriter created     | client_key: 0x1EA16175, datawriter_id: 0x001(5), publisher_id: 0x001(3)
[1660372404.734924] info     | ProxyClient.cpp    | create_topic             | topic created          | client_key: 0x1EA16175, topic_id: 0x002(2), participant_id: 0x000(1)
[1660372404.737238] info     | ProxyClient.cpp    | create_publisher         | publisher created      | client_key: 0x1EA16175, publisher_id: 0x002(3), participant_id: 0x000(1)
[1660372404.739864] info     | ProxyClient.cpp    | create_datawriter        | datawriter created     | client_key: 0x1EA16175, datawriter_id: 0x002(5), publisher_id: 0x002(3)

Actual behavior

The server failed to start when action name length is longer than 30 characters.

EDIT: The rclc_action_server_init_default function returns error code = 1.

MicroROS Agent log:

[1660371458.804388] info     | TermiosAgentLinux.cpp | init                     | running...             | fd: 3
[1660371458.804666] info     | Root.cpp           | set_verbose_level        | logger setup           | verbose_level: 4
[1660371459.471054] info     | Root.cpp           | create_client            | create                 | client_key: 0x1D4F37F6, session_id: 0x81
[1660371459.471116] info     | SessionManager.hpp | establish_session        | session established    | client_key: 0x1D4F37F6, address: 0
[1660371459.485590] info     | ProxyClient.cpp    | create_participant       | participant created    | client_key: 0x1D4F37F6, participant_id: 0x000(1)

Additional information

I am using a precompiled library with the modified colcon_verylowmem.meta.

  "-DRMW_UXRCE_MAX_NODES=1",
  "-DRMW_UXRCE_MAX_PUBLISHERS=3",
  "-DRMW_UXRCE_MAX_SUBSCRIPTIONS=1",
  "-DRMW_UXRCE_MAX_SERVICES=3",
  "-DRMW_UXRCE_MAX_CLIENTS=1",
  "-DRMW_UXRCE_MAX_HISTORY=1",
  "-DRMW_UXRCE_TRANSPORT=custom"
Acuadros95 commented 2 years ago

You need to increase the topic name length with "-DRMW_UXRCE_TOPIC_NAME_MAX_LENGTH=100".

Default value is 60, but actions servers use extended names for their services, for example:

root@mydevice:/home/microros_ws# ros2 service list --include-hidden-services
/namespace/follow_joint_trajectory/_action/cancel_goal
/namespace/follow_joint_trajectory/_action/get_result
/namespace/follow_joint_trajectory/_action/send_goal

Extra characters are added on micro-ROS layer to handle ROS2 Topic and Service name mapping to DDS, that is why you are just at the limit with 30 characters.

Closing as this should solve the issue, reopen if needed.