Skip to content

Adding a get_slot_fields_and_types method to python msg classes - #19

Merged
dirk-thomas merged 2 commits into
ros2:masterfrom
PickNikRobotics:adding-slot-types-to-python-msgs
Nov 19, 2018
Merged

Adding a get_slot_fields_and_types method to python msg classes#19
dirk-thomas merged 2 commits into
ros2:masterfrom
PickNikRobotics:adding-slot-types-to-python-msgs

Conversation

@mlautman

Copy link
Copy Markdown
Contributor

This adds a _slot_types field to python message classes as was requested here: #16

This attempts to remain as true to the ROS1 functionality as possible

@tfootetfoote added the in review Waiting for review (Kanban column) label Nov 3, 2018
@mlautman

Copy link
Copy Markdown
ContributorAuthor

@dirk-thomas

@[for field in spec.fields]@
@[ if field.type.is_primitive_type() ]@
@[ if field.type.is_array ]@
'@(get_python_type(field.type))[@(field.type.array_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.

This doesn't distinguish between a static array (with a fixed size) and a dynamic array (either with an upper bound or without a bound).

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

True. Do you have a preferred method to denote the different types of arrays? I didn't have a strong intuition here

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 either the same notation as in the .msg or an object representation. Thinking about it the second one is probably be better in terms of stability with the upcoming change to .idl files since the notation will change (see https://github.com/ros2/design/blob/gh-pages/articles/142_idl.md).

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

fixed

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 the patch I don't see where the type is being distinguished?

@mlautmanmlautmanNov 13, 2018

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

My apologies, I got my branches mixed up. All of my changes are in one commit (9454002) but I'm unsure of whether I should cherry pick that commit on top of master or 0.5.2. Since this is targeting master, I assume that I should cherry pick on top of that, but doing so causes the build to fail for unrelated reasons..

/home/mike/ws_rqt2/build/rosidl_generator_py/rosidl_generator_py/rosidl_generator_py/msg/_string_arrays_s.c:12:10: fatal error: rosidl_generator_c/primitives_sequence.h: No such file or directory #include <rosidl_generator_c/primitives_sequence.h> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. /home/mike/ws_rqt2/build/rosidl_generator_py/rosidl_generator_py/rosidl_generator_py/msg/_nested_s.c:12:10: fatal error: rosidl_generator_c/primitives_sequence.h: No such file or directory #include <rosidl_generator_c/primitives_sequence.h> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ compilation terminated. /home/mike/ws_rqt2/build/rosidl_generator_py/rosidl_generator_py/rosidl_generator_py/msg/_various_s.c:12:10: fatal error: rosidl_generator_c/primitives_sequence.h: No such file or directory #include <rosidl_generator_c/primitives_sequence.h>

Is there a .repos available with the most recent ros2 branches that I should use for making PR's to master?

Copy link
Copy Markdown
ContributorAuthor

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.

It depends on what you are trying to build. I would suggest using the .repos files from the master branch in the ros2/ros2 repo and building everything from source for your use case. Then a patch based on the master of this repo will work.

(The opposite would be to use the bouncy branch of the .repos file and then also target the bouncy branch in this repo. But usually all contributions are targeting the default branch and only in case of severe bug fixes are being considered for backporting afterwards.)

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 seems to pass on CI: Build Status

@mlautman
mlautmanforce-pushed the adding-slot-types-to-python-msgs branch 2 times, most recently from 7ed6394 to 47cf04cCompareNovember 5, 2018 22:15
@mlautman

Copy link
Copy Markdown
ContributorAuthor

@dirk-thomas ready for another review

Comment threadrosidl_generator_py/resource/_msg.py.em Outdated
@mlautman
mlautmanforce-pushed the adding-slot-types-to-python-msgs branch 2 times, most recently from 068fe49 to 85aa7b7CompareNovember 16, 2018 17:27
@mlautman

Copy link
Copy Markdown
ContributorAuthor

@dirk-thomas Changed _slot_types_dict to get_slot_types_dict() and added noqa W504 where appropriate to pass flake8

@mlautman

Copy link
Copy Markdown
ContributorAuthor

@dirk-thomas

Copy link
Copy Markdown
Member

Ignoring W504 all over the place isn't necessary. This has been addressed in the linter configuration already a while ago: ament/ament_lint#110.

@mlautman

Copy link
Copy Markdown
ContributorAuthor

@dirk-thomas It still fails locally with colcon build test --package-select rosidl_python without that change

@dirk-thomas

Copy link
Copy Markdown
Member

It still fails locally

Are you using the latest default branches of all the other ROS 2 repos?

return True

@@classmethod
def get_slot_types_dict(cls):

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Suggested change
defget_slot_types_dict(cls):
defget_slot_fields_and_types(cls):

Comment threadrosidl_generator_py/test/test_interfaces.py Outdated
Comment threadrosidl_generator_py/test/test_interfaces.py Outdated
Comment threadrosidl_generator_py/test/test_interfaces.py Outdated
Comment threadrosidl_generator_py/test/test_interfaces.py Outdated
Comment threadrosidl_generator_py/resource/_msg.py.em Outdated

@@classmethod
def get_fields_and_field_types(cls):
return cls._slot_types_dict

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since this is a getter, should it return a shallow copy so that you can modify the underlying dictionary?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Good catch. Fixed.

@mlautman
mlautmanforce-pushed the adding-slot-types-to-python-msgs branch 2 times, most recently from e820439 to ac9c660CompareNovember 19, 2018 20:29
@mlautmanmlautman changed the title Adding a slot_type message field to python msg classesAdding a get_slot_fields_and_types method to python msg classesNov 19, 2018
@mlautman
mlautmanforce-pushed the adding-slot-types-to-python-msgs branch from ac9c660 to 40d4bccCompareNovember 19, 2018 20:48
@mlautman

Copy link
Copy Markdown
ContributorAuthor

@dirk-thomas I am using the ros2.repos that you passed along to us with the 0.5.2 release.

I went back and removed W504. I also changed the code to return a copy of the dict rather than the dict itself per @brawner's comment

Comment threadrosidl_generator_py/resource/_msg.py.em Outdated
@mlautman
mlautmanforce-pushed the adding-slot-types-to-python-msgs branch from 343ce69 to 706a5ddCompareNovember 19, 2018 21:40
@dirk-thomas

Copy link
Copy Markdown
Member

This can be merged as is for now. With the coming change I will likely change this in the following way:

  • Store the types in a class constant, e.g. SLOT_TYPES.
  • Change the data structure from a mutable dict to an immutable tuple of abstract types
  • Either remove the class method (or rename it to get_slot_types which zips __slots__ and SLOT_TYPES and returns an ordered dictionary).

@dirk-thomas
dirk-thomas merged commit fc8b868 into ros2:masterNov 19, 2018
@dirk-thomasdirk-thomas removed the in review Waiting for review (Kanban column) label Nov 19, 2018
@mlautman
mlautman deleted the adding-slot-types-to-python-msgs branch November 19, 2018 23:06
@mlautman
mlautman restored the adding-slot-types-to-python-msgs branch November 26, 2018 21:08
@mlautman
mlautman deleted the adding-slot-types-to-python-msgs branch November 26, 2018 21:08
@mlautman
mlautman restored the adding-slot-types-to-python-msgs branch November 26, 2018 21:08
Sign up for freeto 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.

4 participants

@mlautman@dirk-thomas@brawner@tfoote