Skip to content

Add type mapping info to documents - #190

Merged
sloretz merged 35 commits into
gh-pagesfrom
idl_type_mappings
Oct 15, 2018
Merged

sloretz merged 35 commits into
gh-pagesfrom
idl_type_mappings

Conversation

@sloretz

@sloretz sloretz commented Sep 13, 2018

Copy link
Copy Markdown
Contributor

This adds mappings between IDL types and other types.

@sloretz sloretz added the in review Waiting for review (Kanban column) label Sep 13, 2018
@sloretz sloretz self-assigned this Sep 13, 2018
Comment thread articles/142_idl.md Resolved
Comment thread articles/142_idl.md Resolved
Comment thread articles/142_idl.md Outdated
| -------- | --------- | ----------- | -------------------- |
| bool | \_Bool | bool | bool |
| octet | uint8\_t | uint8\_t | bytes with length 1 |
| char | char | char | str with length 1 |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this is a string, the question of the encoding may propagate here as well

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7c1d4a4 for signed char

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I threw in wchar and wstring as well. c9ddd20

I'm not yet sure if this doc should link to a separate unicode support design doc, or if that should be included here.

Comment thread articles/142_idl.md Outdated
| octet | uint8\_t | uint8\_t | bytes with length 1 |
| char | char | char | str with length 1 |
| float | float | float | float |
| double | double | double | float |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add long double here ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread articles/142_idl.md Outdated
IDL types mapped to different types in different languages.


| IDL type | C type | C++ type | Python type |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There seem to be differences between IDL types and DDS types. Would it make sense to have a DDS Type column here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By DDS types do you mean DDS-XTYPES 1.2?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be able to avoid adding DDS-XTYPES since the 1.2 spec has a mapping of DDS to IDL types already.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I was thinking of DDS-XTYPES, to have a reference of what will end up on the wire when using a given IDL type.


| ROS type | IDL type |
| ----------------------- | -------------- |
| static array | T\[N\] |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like these IDL types are named array, unbounded sequence etc in the article above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread articles/142_idl.md Outdated
| unbounded sequence of string | rcutils\_string\_array | | |
| bounded sequence of string | rcutils\_string\_array | | |
| array of octet | | | bytes |
| array of char | char * | std::string | str |

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may not make sense to have array of char map to char * in C because that means it couldn't contain a value of zero.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currently in C we have a custom data structure for this that has a size component, so I think it is possible for array elements to have any value in the char range in them, we would just not be able to treat it as a string (strlen etc).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

array of char and wchar no longer strings in cd1e3b2

Comment thread articles/142_idl.md Outdated
| bool | \_Bool | bool | bool |
| octet | uint8\_t | uint8\_t | bytes with length 1 |
| char | char16\_t | char16\_t | str with length 1 |
| wchar | signed char | char | str with length 1 |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Swap wchar and char types.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in d296cfb

Comment thread articles/142_idl.md Outdated
| string | char * | std::string | str |
| string<N> | char * | std::string | str |
| wstring | char16\_t * | std::u16string | str |
| wstring<N> | char16\_t * | std::u16string | str |

@dirk-thomas dirk-thomas Sep 14, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering about the different handling of bounded sequences compared to bounded (w)strings in C++. For the first we go through the hassle to provide our own data structure (to enforce the upper bound) for the other two we don't (atm).

Maybe we should use the same approach homogeneously - it could be either of the two, The effort and "customness" of types we define vs. the delayed check until the data structure is being passed to the lower levels.

@mikaelarguedas mikaelarguedas Sep 14, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I was thinking the same for the C part, currently in C we have custom data structure for all the dynamic types (bounded and unbounded). AFAICT in C++ we have a custom container for bounded vectors but nothing for strings ATM (as described in previous comment).

In the delayed check approach, when / how would the user be notified that the data doesnt fit?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when / how would the user be notified that the data doesnt fit?

The rclpy_publish function converts the Python object into a ROS C message. If any of the constraints are violated it can signaled through an exception.

Optionally we can offer a validation function which the user could invoke explicitly.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Python I would expect the user to not be allowed to place data bigger than the message specification at the Python level already (what we currently do with custom setters).

My question was about the C language that doesn't provide exceptions. If we map to a char(16_t) * I am not sure how we would restrict the memory allocation or report the error.

But your point still holds: it can be done when publish is called rather than when filling the message datastructure.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Python I would expect the user to not be allowed to place data bigger than the message specification at the Python level already (what we currently do with custom setters).

That is true but only covers the case where a field is being "assigned". But e.g. a list is mutable and new items can be added after the initial assignment with the property of the class being able to intercept (assuming we don't mock all method of the list instance).

My question was about the C language that doesn't provide exceptions. If we map to a char(16_t) * I am not sure how we would restrict the memory allocation or report the error.

In a future rclc client library the publish call can perform the validation the same way as in Python. While the publish in rcl could also check the constraints I would rather not do that and rely in the client library on top to do that. All of these functions have return code to signal error already (if exceptions are not available / used).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the publish in rcl could also check the constraints I would rather not do that and rely in the client library on top to do that.

Just adding it looks like either client libraries or the rmw implementations must check the constraints because rcl_publish sees the message as a void *.

In Python I would expect the user to not be allowed to place data bigger than the message specification at the Python level already (what we currently do with custom setters).

I think ros2/ros2#509 is a hint that ros2 should consider only checking the validity of the message once. From the perspective of ROS 2 as a library the message constraints don't matter until the message is used. From the perspective of a developer writing code constraint checking when a field is set is nice because it errors closer to the bug, but from the perspective of a user running the code it can be a significant performance hit for little gain when most of the time everything is working fine.

Comment thread articles/142_idl.md Outdated
| char | signed char | char | str with length 1 |
| wchar | char16\_t | char16\_t | str with length 1 |
| bool | \_Bool | bool | bool |
| octet | uint8\_t | uint8\_t | bytes with length 1 |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at newer specs I was wondering if the C++ mapping should be byte (available as of C++17) instead. To match the semantic C could then be mapped to unsigned char.

[We would need to check for availability across all targeted platforms. Even if not all support the type yet we could still make the decision today (using a custom typedef or using char directly) and switch to the standard type once available.]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at cppreference and Visual Studio conformance announcement it looks like all compilers support it

Comment thread articles/142_idl.md Outdated
| -------------- | ---------------------- | ------------------- | ----------- |
| T[N] | T[N] | std::array<T, N> | list |
| sequence<T> | struct {size\_t, T * } | std::vector<T> | list |
| sequence<T, N> | struct {size\_t, T * } | custom\_class<T, N> | list |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be struct {size\_t, T * , N } instead? (where N would be the max capacity)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think max should to be a const variable; because if it's non-const then it would need to be in two places. First in the struct that can be modified by a user, and second in code used to validate a message.

If that sounds reasonable then it implies the struct with a field for max capacity would be generated for every field. Alternatively a struct definition could be reused if the max capacity was a separate const variable.

const size_t example_msgs__example_bounded__sensor_readings__max_capacity = 64;
//  ...
struct example_msgs__example_bounded
{
  // ...
  rcutils_float_array * sensor_readings = NULL;
}

@dirk-thomas

Copy link
Copy Markdown
Member

1c4fa2f defines a custom mapping to bytes for octet arrays as well as (bounded) sequences.

Comment thread articles/142_idl.md Outdated
| unbounded sequence of string | rcutils\_string\_array | | |
| bounded sequence of string | rcutils\_string\_array | | |
| array of char | char * | std::string | str |
| array of wchar | char16\_t * | std::u16string | str |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The C and C++ mapping for arrays of (w)char need to be different since both don't allow for null characters which isn't forbidden for these IDL types.

Comment thread articles/142_idl.md Outdated
If a cell is blank then the default mapping is used.

| IDL type | C type | C++ type | Python type |
| ---------------------------- | ---------------------- | -------------- | ----------- |

@dirk-thomas dirk-thomas Sep 14, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to specify the mapping to use numpy for scalar type? E.g.

  • uint32[N]: numpy.ndarray(shape=(N, ), dtype=numpy.uint32)
  • sequence<uint32 [, N]\>: numpy.ndarray(shape=(0, ), dtype=numpy.uint32)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 for octet[N] being np.array(). It would make it easier to support multiple dimension arrays in the future. numpy seems like a minimal enough dependency. pip freeze after installing numpy in a venv only shows numpy and pkg-resources (which was in the env by default).

@dirk-thomas dirk-thomas Sep 14, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about other scalar types and sequences?

+1 for octet[N] being np.array()

For octet[N] bytes already provides a native mapping (without the usual Python overhead) so I am not sure about that case.

Comment thread articles/142_idl.md Outdated

### Constraint Checking

Generated code for messages is guaranteed to enforce constraints only when a message is published.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this sounds ambiguous:

guaranteed to enforce ... only when ... published

I don't think we want to indicate that the want to guarantee that we don't check it before. Maybe rephrase to:

Generated code for messages is only guaranteed to enforce constraints when a message is published.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread articles/142_idl.md
### Constraint Checking

Generated code for messages is guaranteed to enforce constraints only when a message is published.
For example, there might not be an error when a field constrained to be a fixed size array is assigned an array with the wrong size.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inject the following?

For example, depending on the language there ...

In Python we could (and probably will) check this trivially in the setter.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added another sentence saying constraint checks could be inconsistent depending on language features and performance cost 46ec109

Comment thread articles/142_idl.md Outdated

Generated code for messages is guaranteed to enforce constraints only when a message is published.
For example, there might not be an error when a field constrained to be a fixed size array is assigned an array with the wrong size.
In the future constraints might be checked when a field is set.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe append the following?

... and/or mutated.

Same for the next line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread articles/142_idl.md Outdated
| -------------- | --------------------------------- | ----------------- | ----------- |
| T[N] | T[N] | std::array<T, N> | list |
| sequence<T> | struct {size\_t, T * } | std::vector<T> | list |
| sequence<T, N> | struct {size\_t, T * }, size\_t N | std::vector<T, N> | list |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

std::vector doesn't have a second template argument N.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread articles/142_idl.md Outdated
| int64 | int64\_t | int64\_t | int |
| uint64 | uint64\_t | uint64\_t | int |

1. <a name="byte"></a>If std::byte is not available then uint8\_t is used instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of uint8_t I would suggest unsigned char since that is how it is defined in C++17.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4a49a00

Side note, I learned that in C and C++ an unsigned char is guaranteed to be 1 byte, but 1 byte may be more than 8 bits. It doesn't look like any modern systems do that, but if they do the number of bits in a byte is defined in <limits.h> or <climits> as CHAR_BIT.

Comment thread articles/142_idl.md Outdated
| sequence<octet> | | | bytes |
| sequence<octet, N> | | | bytes |
| array of string | struct {size\_t, T * }, size\_t N | | |
| int8[N] | | | numpy.array(dtype=numpy.int8) |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the fixed-size arrays also have shape=(N, )?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like it doesn't accept a keyword argument of shape, and the text of repr() doesn't show it either. As far as I can tell the shape is inferred from the data passed in.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The following lines work for me:

import numpy
numpy.ndarray(shape=(5, ), dtype=numpy.uint32)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, I was trying numpy.array(...). It looks like the underlying type is ndarray and array is just a helper to construct one. I'll change the types.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread articles/142_idl.md Outdated
If a cell is blank then the default mapping is used.

| IDL type | C type | C++ type | Python type |
| ---------------------------- | --------------------------------- | -------------- | -------------------------------- |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest to use the same order as in the first "Type Mapping" table (currently lines 56-70).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread articles/142_idl.md Outdated

| IDL type | C type | C++ type | Python type |
| ---------------------------- | --------------------------------- | -------------- | -------------------------------- |
| float[N] | | | numpy.array(dtype=numpy.float\_) |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float_? Isn't that the same as float64?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops it is. 4838992 makes float -> numpy.float32, double -> numpy.float64 and long double -> list(float)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add special mapping for long doubles be arrays of numpy.float128 as well?

Comment thread articles/142_idl.md Outdated
| -------- | ----------- | ------------------------------ | -------------------- |
| float | float | float | float |
| double | double | double | float |
| long double | long double | long double | float |

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thoughts on not initially supporting long double? It seems inconsistent across platforms and DDS vendors.

Visual Studio typedef'd long double to double which is 64bit
https://docs.microsoft.com/en-us/cpp/c-language/type-long-double?view=vs-2017

Connext works around this by mapping DDS_LongDouble to a char array (of size 16?) on some platforms and long double on others.
https://community.rti.com/static/documentation/connext-dds/5.2.3/doc/manuals/connext_dds/html_files/RTI_ConnextDDS_CoreLibraries_UsersManual/Content/UsersManual/Translations_for_IDL_Types.htm#Note2_LongDouble

Opensplice doesn't appear to support it. The grammar on page 589 / pdf page 617
only defines <floating_pt_type> as "float" and "double".

Fast-CDR uses the C++ type long double and serializes it as 16 bytes on the wire. https://github.com/eProsima/Fast-CDR/blob/1df42bbd1ea86a9c99bb8fa72104f19872235986/src/cpp/Cdr.cpp#L528

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My understanding from original discussion was that we should support all IDL types. @dirk-thomas is that correct?

Looking a bit more into it:

  • It looks like Connext and Fast-RTPS agree that it should be a 16-byte thing on the wire

The issues we face right now:

  • FastRTPS doesn't have special handling to account for the fact that the type has a different size on windows
  • OpenSplice doesn't support this type

Looking at Opensplice it appears that wchar and wstring are not supported either https://github.com/ADLINK-IST/opensplice/blob/36e4f9c250a640ade72d5af92084f5f5243ce96c/src/tools/idlpp/code/idl_unsupported.h.

Not convinced it should be a blocker for supporting it though. We may just need to have implementation specific limitations or workarounds

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

after talking with @mikaelarguedas I think this can be resolved by saying long double will be supported, but users will have to be cautious of middleware support for it.

I'm not sure if we should use the C and C++ type long double on all platforms, but that seems like the easiest thing to do for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added warning about long double on some platforms and middleware in
2082ba0

| -------- | ------------------ |
| bool | boolean |
| byte | octet |
| char | char |

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDL 7.2.6.2.1 says A char is an 8-bit quantity with a numerical value between 0 and 255 (decimal). The ROS 2 interface definition says char is [-128, 127]. Changing this type mapping to idl type int8 after discussing with @mjcarroll

@dirk-thomas dirk-thomas Oct 10, 2018 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mapping the ROS 1 type char to the IDL type int8 seems off to me.

In ROS 1 the char type (while deprecated) is defined as a uint8 in the docs as well as in the code.

Comment thread articles/142_idl.md Outdated
| float | float | float | float |
| double | double | double | float |
| long double | long double | long double[<sup>2</sup>](#ld) | float |
| char | signed char | char | str with length 1 |

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IDL 7.2.6.2.1 says A char is an 8-bit quantity with a numerical value between 0 and 255 (decimal). Changing to unsigned char in c and c++

| bool | boolean |
| byte | octet |
| char | char |
| char | short |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would an octet make more sense than a short in this case ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think short is a better fit than octet. IDL 4.2 section 7.4.1.4.3 says Octet literals have integer value in the range 0…255. char is an integer in range [-128, 27] in ros 2 .msg files #190 (comment)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still unclear why it is treated differently than the int8 type.

My understanding was that they both fit in 8-bit and can represent signed values, so I'm not sure why we should use a 16-bit type to store them

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got the int8 types mixed up. It should be fixed in e7c99ea

| char | short |
| float32 | float |
| float64 | double |
| int8 | octet |

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should map to idl type int8

| float32 | float |
| float64 | double |
| int8 | octet |
| uint8 | octet |

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should map to idl type uint8

Comment thread articles/142_idl.md
| string | char * | std::string | str |
| string<N> | char * | std::string | str |
| wstring | char16\_t * | std::u16string | str |
| wstring<N> | char16\_t * | std::u16string | str |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from previous discussion, I think string and wstring would be structs in C (like sequences) and not just pointers, isnt' it ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dirk-thomas and @sloretz Did we ever resolve this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly referring to this: #190 (comment) where array of char and wchar should be structs because they can contain zero?

I don't remember a discussion about wstring or string being structs instead of pointers though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A string / wstring must not contain null characters. Therefore a raw pointer is sufficient in this case.

The opposite case is char[] / wchar[] which doesn't have that restriction and therefore is stored as data ptr / size pair.

@deeplearningrobotics

Copy link
Copy Markdown

@dirk-thomas:

As far as I understand the current concept is to generate a ROS 2 specific C++ type from an IDL. This leads to the fact that two types with the same data exist.

  • One generated by ROS 2 from the IDL. I will call one such type ROS2LaserScan for later use.
  • Multiple types generated by each DDS implementation from the IDLs. I will call those types DDS1LaserScan, DDS2LaserScan etc. for later use.

I have two questions:

  1. Shared Memory / Zero Copy Shared memory performance

    A DDS implementation might be able to transmit a type DDS1LaserScan with one or zero copies. But
    it will not understand that structure of ROS2LaserScan. So ROS2LaserScan must be converted
    (most likely copied) into a DDS1LaserScan1.

    How do you preserve the single / zero-copy performance?

  2. Non ROS 2 DDS Participants*

    If a user wants to use directly DDS data writers and readers to access additional DDS features not
    available in ROS 2 he will be forced to use the DDS types. So an algorithm might using either using
    DDS1LaserScan or ROS2LaserScan.

    How do you plan integration of non-ROS 2 DDS systems without an performance impact due to type conversion?

Please also note that RTI and OpenSplice have (AFAIK) common IDL to C/C++ etc. type translations available here.

Thank you!

@dirk-thomas

dirk-thomas commented Oct 10, 2018 •

Copy link
Copy Markdown
Member

This leads to the fact that two types with the same data exist.

This is not a change to how the system already works. The user code always only interacts with a ROS type - it must not be coupled with a vendor specific type.

A DDS implementation might be able to transmit a type DDS1LaserScan with one or zero copies. But
it will not understand that structure of ROS2LaserScan. So ROS2LaserScan must be converted
(most likely copied) into a DDS1LaserScan1.

Even when using shared memory DDS implementations still need to serialize the published sample into the shared memory and on the other end deserialize it into a sample class. In the current typesupport implementations the overhead is that the ROS type is first converted to the vendor specific type which then gets serialized. Nothing should prevent a RMW implementation to skip the inbetween type and implement serialization logic from the ROS type directly.

But again: this is already the same in the current code and doesn't change in any way with the transition to using .idl file to describe the data structures.

How do you plan integration of non-ROS 2 DDS systems without an performance impact due to type conversion?

I think I don't understand the question. DDS systems define the type of exchanged sample and that is the "contract" between both endpoints. Since the data is exchanged in serialized form it is not relevant how the object representation looks like on both sides.

Please also note that RTI and OpenSplice have (AFAIK) common IDL to C/C++ etc. type translations available here.

Did you notice and differences between these translations and the ones proposed in ROS?

@deeplearningrobotics

Copy link
Copy Markdown

@dirk-thomas: Thank you for your reply.

Did you notice and differences between these translations and the ones proposed in ROS?

No, but I was hoping the IDL transition might enable a better interoperability between ROS 2 and native DDS application.

A lot of people ask us for all the DDS features. We want to provide that while still offering the simplicity of ROS 2. This is what makes things complicated.

In the current typesupport implementations the overhead is that the ROS type is first converted to the vendor specific type.

I was hoping for ROS 2 types having the following structure:

class ROS2PointCloud<DDSImplType> {
public:
  vector points() {
    return impl_->points();
  }
private:
  DDSImplType impl_;
};

This would allow transparent use of DDS and ROS 2 types.

I think I don't understand the question. DDS systems define the type of exchanged sample and that is the "contract" between both endpoints. Since the data is exchanged in serialized form it is not relevant how the object representation looks like on both sides.

I'll try to elaborate with an example. Assuming I write an algorithm taking in a ROS2PointCloud type.

void segmet_pc(ROS2PointCloud) {...}

Now someone wants to reuse this code in a pure DDS application. To be able to do that smoothly the output of the IDLs from ROS 2 should have the exact same API as DDS types so that I can reuse the code.

Another independent question:

  • Do you plan to support inheritance and unions?

@dirk-thomas

Copy link
Copy Markdown
Member

No, but I was hoping the IDL transition might enable a better interoperability between ROS 2 and native DDS application.

The transition to use IDL will allow at least all the supported types to be exchanged transparently (e.g. by consensus on the encoding of strings). Other than that I don't know which exact part you would like to see "better interoperability". Maybe you can describe specific cases.

I was hoping for ROS 2 types having the following structure: class ROS2PointCloud<DDSImplType>

Making every ROS 2 data type a template based on the concrete implementation is certainly undesired. This would require compile time knowledge of the chosen RMW impl as well as increase complexity of every code using ROS messages. One of the design goals is that the ROS data types are not tied to a specific implementation and can be used even without any RMW impl. in e.g. library API. Also your example implies that all members of the data structure are only to be accessed by methods. In earlier discussions the community strongly expressed the desire to keep member-based access to all the fields.

Now someone wants to reuse this code in a pure DDS application. To be able to do that smoothly the output of the IDLs from ROS 2 should have the exact same API as DDS types so that I can reuse the code.

Not even two different DDS implementations offer the very same API for the generated data structures. So how should ROS offer that across DDS vendors (and potentially non-DDS RMW impl)? That being said most types are very close to each other (if not even identical). So nothing prevents you from implementing two signatures of the function which then use a shared function to perform the logic or use a templated function if the content of the functions works for both types.

@wjwwood

wjwwood commented Oct 10, 2018

Copy link
Copy Markdown
Member

I'll try to elaborate with an example. Assuming I write an algorithm taking in a ROS2PointCloud type.

void segmet_pc(ROS2PointCloud) {...}

Now someone wants to reuse this code in a pure DDS application. To be able to do that smoothly the output of the IDLs from ROS 2 should have the exact same API as DDS types so that I can reuse the code.

I'd avoid using the ROS type or the DDS type in a library unless you're willing to live with the consequences of that decision (a dependency on one or the other).

So I don't agree with the conclusion that:

  • your library interface should be templated on a "Point cloud type" rather than a concrete type or
  • that in order to make use of that templated interface the ROS message structure needs to have an identical API to the DDS messages.

In ROS 1 (and planned for ROS 2) we have something where you can pub/sub whatever type you want so long as you tell us how to serialize and deserialize it, see:

https://wiki.ros.org/roscpp/Overview/MessagesSerializationAndAdaptingTypes#Example:_Adapting_a_custom_Vector3

I think this is the right way to address the concern of wanting to use data structures different from ROS's message data structures and without incurring copying costs (for both runtime and development time).

For instance, this allows us to pub/sub PCL point clouds rather than our sensor_msgs/PointCloud2:

typedef pcl::PointCloud<pcl::PointXYZ> PointCloud;

void callback(const PointCloud::ConstPtr& msg)
{
  printf ("Cloud: width = %d, height = %d\n", msg->width, msg->height);
  BOOST_FOREACH (const pcl::PointXYZ& pt, msg->points)
    printf ("\t(%f, %f, %f)\n", pt.x, pt.y, pt.z);
}

int main(int argc, char** argv)
{
  ros::init(argc, argv, "sub_pcl");
  ros::NodeHandle nh;
  ros::Subscriber sub = nh.subscribe<PointCloud>("points2", 1, callback);
  ros::spin();
}

-- from: https://wiki.ros.org/pcl_ros#CA-2c92c01374035f603e08bcde0eb24382b1ccd02e_6

So, from your example, if you'd like to use DDSImplType rather than the ROS2PointCloud, you just need to tell us how to get to the DDSImplType type from the wire protocol.

Comment thread articles/142_idl.md Outdated
| uint64[N] | | | numpy.ndarray(shape=(N, ), dtype=numpy.uint64) |
| sequence<uint64> | | | numpy.ndarray(dtype=numpy.uint64) |
| sequence<uint64, N> | | | numpy.ndarray(dtype=numpy.uint64) |
| array of string | struct {size\_t, T * }, size\_t N | | |

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"array" seems wrong here. The mapping suggests that it is a sequence (non static size).

Also the mapping doesn't seem to be different than the generic definition of arrays and sequences above? Should this line be removed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line probably should be removed, I think it made sense when the mapping was rcutils_string_array. array of string was trying to say string[N] from T[N] in the generic table, so the default type would be char * [N].

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✔️ removed in 828db25.

The same commit also consolidates the numpy mapping into a more readable "templated" form - while the cells get wider I hope it makes it more readable / comprehensible than the verbose version before.

@dirk-thomas dirk-thomas left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current state looks solid to me. I propose to get it merged as is.

@dirk-thomas

Copy link
Copy Markdown
Member

@mjcarroll Please review / approve.
@sloretz Please review / merge.

@sloretz

sloretz commented Oct 15, 2018

Copy link
Copy Markdown
Contributor Author

LGTM, merging

@sloretz
sloretz merged commit ff1d1e7 into gh-pages Oct 15, 2018
@sloretz sloretz removed the in review Waiting for review (Kanban column) label Oct 15, 2018
@sloretz
sloretz deleted the idl_type_mappings branch October 15, 2018 18:45
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

Successfully merging this pull request may close these issues.

6 participants