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

fastddsgen and ros2 gen msg, TypeSupport member m_typeSize id different, why? #32

Open
Eternity1987 opened this issue Dec 31, 2024 · 2 comments

Comments

@Eternity1987
Copy link

Eternity1987 commented Dec 31, 2024

file Vec2Image1m.msg :

shm_msgs/Image1m[2] images

fastddsgen:
fastddsgen -d {src_path} -de final -I . -t {temp_path} -typeros2 -cs {idls_str}

img_v3_02i3_eda8b31a-f570-4da3-9cd6-58404a93952g
img_v3_02i3_47995073-60e8-4e35-9a35-777fd1552bbg

ros2 gen:
img_v3_02i3_d9a19fff-b384-47e2-bd5a-1fcce0526a4g

fastddsgen m_typeSize value is: 2098236 + 4
ros2 m_typeSize value is: 2098232 + 4

can you help me explain?

@ZhenshengLee
Copy link
Owner

  1. the m_typeSize is decided by the definition of the struct.
  2. the struct is defined by the generated headers.
  3. for the reason why they are different, please check the generated header from fastddsgen and rosidl.
  4. the header generated by fastddsgen can be seen easily
  5. the header generated by rosidl can be checked in build/${PACKAGE_NAME}/rosidl_generator_cpp/${PACKAGE_NAME}/msg/Vec2Image1m.hpp
  6. you can check more info in build/${PACKAGE_NAME}/rosidl_typesupport_fastrtps_cpp/${PACKAGE_NAME}/msg/detail

@Eternity1987
Copy link
Author

  1. the m_typeSize is decided by the definition of the struct.m_typeSize由结构体的定义决定。
  2. the struct is defined by the generated headers.结构体由生成的标头定义。
  3. for the reason why they are different, please check the generated header from fastddsgen and rosidl.关于它们不同的原因,请检查 FastDDSGEN 和 Rosidl 生成的 Header。
  4. the header generated by fastddsgen can be seen easilyFastDDSGEN 生成的 header 可以很容易地看到
  5. the header generated by rosidl can be checked in build/${PACKAGE_NAME}/rosidl_generator_cpp/${PACKAGE_NAME}/msg/Vec2Image1m.hppRosidl 生成的标头可以签入 build/${PACKAGE_NAME}/rosidl_generator_cpp/${PACKAGE_NAME}/msg/Vec2Image1m.hpp
  6. you can check more info in build/${PACKAGE_NAME}/rosidl_typesupport_fastrtps_cpp/${PACKAGE_NAME}/msg/detail您可以在 build/${PACKAGE_NAME}/rosidl_typesupport_fastrtps_cpp/${PACKAGE_NAME}/msg/detail

Thank you for your response. I understand the files you are talking about. In ROS 2, the size is calculated in the code,

size_t
ROSIDL_TYPESUPPORT_FASTRTPS_CPP_PUBLIC_shm_msgs
max_serialized_size_Vec2Image1m(
  bool & full_bounded,
  bool & is_plain,
  size_t current_alignment)
{
  size_t initial_alignment = current_alignment;

  const size_t padding = 4;
  const size_t wchar_size = 4;
  size_t last_member_size = 0;
  (void)last_member_size;
  (void)padding;
  (void)wchar_size;

  full_bounded = true;
  is_plain = true;

  // Member: images
  {
    size_t array_size = 2;
    last_member_size = 0;
    for (size_t index = 0; index < array_size; ++index) {
      bool inner_full_bounded;
      bool inner_is_plain;
      size_t inner_size =
        shm_msgs::msg::typesupport_fastrtps_cpp::max_serialized_size_Image1m(
        inner_full_bounded, inner_is_plain, current_alignment);
      last_member_size += inner_size;
      current_alignment += inner_size;
      full_bounded &= inner_full_bounded;
      is_plain &= inner_is_plain;
    }
  }

  size_t ret_val = current_alignment - initial_alignment;
  if (is_plain) {
    // All members are plain, and type is not empty.
    // We still need to check that the in-memory alignment
    // is the same as the CDR mandated alignment.
    using DataType = shm_msgs::msg::Vec2Image1m;
    is_plain =
      (
      offsetof(DataType, images) +
      last_member_size
      ) == ret_val;
  }

  return ret_val;
}

similar to Fast DDS, both showing a size of 2098232 when using sizeof. However, in ROS 2, this value is determined by a function, while in Fast DDS, during template instantiation, a macro shows 2098236, which is 4 more than in ROS 2. I'm not entirely sure about this difference.
img_v3_02i3_eda8b31a-f570-4da3-9cd6-58404a93952g
This discrepancy might cause Fast DDS to send messages that ROS 2 cannot receive, while ROS 2 can send messages that Fast DDS can receive.
img_v3_02i2_26915e48-1d32-4728-865d-fd38db84c14g

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants