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

Modernize / Modularize xacro #120

Conversation

rhaschke
Copy link
Contributor

@rhaschke rhaschke commented Sep 30, 2021

This is the new PR replacing #109 / #113 already announced in #113 (review).

Summary

The key goal followed by the restructuring is a simple and scalable approach to specify different hand variants.
Until, for each variant essentially a separate xacro file was required. With this PR, we can essentially resolve everything using either full_hand.urdf.xacro or hand_lite.urdf.xacro. Using the macro parameter fingers one can specify which fingers are needed. With parameters [tip|mid|prox]_sensor(s) one can choose individual (tactile) sensors. The already existing variable hand_type can now also be used to specify muscle or muscletrans hands.

Changes w.r.t. #109 / #113:

TODOs:

@rhaschke rhaschke force-pushed the pr-modernize-modularize-xacro branch from 461f2c7 to 91c2ecb Compare October 1, 2021 06:23
@rhaschke
Copy link
Contributor Author

rhaschke commented Oct 1, 2021

@beatrizleon: How can I access the results of the failing CI jobs at AWS?

@rhaschke rhaschke force-pushed the pr-modernize-modularize-xacro branch 2 times, most recently from 0d69acb to 929fac3 Compare October 1, 2021 13:14
@rhaschke
Copy link
Contributor Author

rhaschke commented Oct 1, 2021

I added a series of commits fixing most compatibility-test issues. The only remaining issue are some lost xmlns attributes as illustrated in this comparison showing the differences between generated URDF files from test/robots.old vs. robots. That's what the compatibility test compares as well. I'm not sure where these attributes got lost.
@guihomework, maybe you have an idea?

The good news is that processing the new robot URDFs yields the same results as in a741b66.
That's already much better than the results from the original PR, shown in this and following diffs.

@guihomework guihomework mentioned this pull request Oct 1, 2021
4 tasks
@guihomework
Copy link
Contributor

That's what the compatibility test compares as well. I'm not sure where these attributes got lost. @guihomework, maybe you have an idea?

I think I traced the problem to the presence of the include of the full_hand (defining the macro shadowhand) within the definition of the macro shadowhand there https://github.com/shadow-robot/sr_common/pull/120/files#diff-d505b43845bf4e41bf9a24883f9c24aef30837e1f512253f29313889990ce805R14

I was first surprised a macro redefinition was possible, so I tried to rename one of the macro either the exterior, or the interior one, but it does not change anything as long the include is inside the outer macro redefinition
Of course with the same macro name, one cannot put the include outside the new definition. It fails with
invalid parameter "fingers"
because the macro call inside, wants to call the newly defined macro (recursivity issue ahead), instead of the included one.

I find this already too tricky for me, so cannot provide a fix. I hope this pin pointing suffices to guide to a possible true cause (within xacro itself I suppose)

@guihomework
Copy link
Contributor

@rhaschke I think I am done looking at the code and answering your questions. Everything I found was bad understanding of the code. sorry for the noise.
the compat test is not python2.7 compatible so I cannot test it myself under melodic, even calling it with python3 and some of the rospkg for python3 we have fails on Bionic.
I suppose it does not matter, @beatrizleon and @devops-shadowrobot will confirm it does what they need.

@rhaschke
Copy link
Contributor Author

rhaschke commented Oct 1, 2021

I think I traced the problem to the presence of the include of the full_hand within the definition of the macro shadowhand.

Thanks for tracing this down! I will have a look.

@rhaschke
Copy link
Contributor Author

rhaschke commented Oct 2, 2021

Indeed, the culprit was an issue in xacro: namespaces imported within a macro were not lifted. Fixed via ros/xacro#285.

@guihomework
Copy link
Contributor

Indeed, the culprit was an issue in xacro: namespaces imported within a macro were not lifted. Fixed via ros/xacro#285.

I would never have generated such a case my self as I would never have attempt redefining a macro that has the same name that itself calls the macro name.
This "courage" of doing so requires a great knowledge on how xacro effectively works to know it will do what is desired.

@rhaschke
Copy link
Contributor Author

rhaschke commented Oct 2, 2021

The problem was actually more fundamental: Any namespaces imported by a xacro:include within a macro were ignored - even if the include file doesn't do anything else than providing those namespaces. See the corresponding unit test I added in xacro for an example.
Redefining macros (or properties) is perfectly fine in xacro. As macros create a new scope, all symbols newly defined within the macro don't even affect the parent scope. That is, the original macro stays untouched when doing so.

@rhaschke
Copy link
Contributor Author

rhaschke commented Oct 2, 2021

I think I am done looking at the code and answering your questions.

Thanks a lot. Do you mind to also formally approve this PR if you are fine with it?

@guihomework
Copy link
Contributor

I think I am done looking at the code and answering your questions.

Thanks a lot. Do you mind to also formally approve this PR if you are fine with it?

I cannot test it easily immediately, I need to update my noetic/focal install first. I did not prepare my PR for noetic so cannot know what else can happen without testing.

@guihomework
Copy link
Contributor

The problem was actually more fundamental: Any namespaces imported by a xacro:include within a macro were ignored - even if the include file doesn't do anything else than providing those namespaces. See the corresponding unit test I added in xacro for an example. Redefining macros (or properties) is perfectly fine in xacro. As macros create a new scope, all symbols newly defined within the macro don't even affect the parent scope. That is, the original macro stays untouched when doing so.

Not trivial to me, but probably fine for python developers.

@rhaschke
Copy link
Contributor Author

rhaschke commented Oct 2, 2021

I cannot test it easily immediately, I need to update my noetic/focal install first.

Note that the noetic-devel branches of this package as well as of xacro both work fine under Melodic as well. No need to install Noetic/Focal for testing.

@beatrizleon
Copy link
Contributor

beatrizleon commented Oct 3, 2021

@rhaschke We were working on refactoring this repo with the help of @guihomework with the following purposes:

  1. Be able to use one xacro to build all our hands (removing the need to create a xacro per hand configuration inside robots folder)
  2. Have a way to easily specify the number of fingers and tactile sensors
  3. Introduce a way to specify the hand version differentiating the meshes on each of them.

I had a work in progress branch: https://github.com/shadow-robot/sr_common/tree/F_refactoring_meshes. It was based on the changes that @guihomework did on his proposed branch which were really helpful. With this new refactoring, I will create a new branch based on this one and show you what is the idea. It will be great to improve this as it has lots of deprecated code, unused meshes, etc

Thanks both for you help with this. It is going slowly because of my lack of time to spend coding but hopefully with all your help, we will be able to finish this refactoring soon.

@beatrizleon
Copy link
Contributor

I checked the CI error and the issue is:
Copyright check failure: There are 1 files without copyright notices: ./sr_description/test/test_compatibility.py

pi is available globally in xacro as python's math.pi
@rhaschke
Copy link
Contributor Author

rhaschke commented Oct 3, 2021

I had a work in progress branch: https://github.com/shadow-robot/sr_common/tree/F_refactoring_meshes, based on #109.
With this new refactoring, I will create a new branch based on this one and show you what is the idea. It will be great to improve this as it has lots of deprecated code, unused meshes, etc.

I will shortly rebase this PR onto the latest noetic-devel and apply the announced squashes.

Using `'text' in variable` is a rather sloppy equivalence check.
This commit attempts to harden these checks using the following regexp
replacements:

- More specific test of hand_type
  ('hand.+?') in ([a-z_]+)  ->  $2.startswith($1)

- More specific variable tests
  ('.+') in ([a-z_]+)  ->  $2 == $1
Improve extensibility (adding more sensors) by emloying an exclusive-if-and-final-else
strategy, utilizing a helper variable. This way we avoid augmenting the list in the
'sensor in [...]' tests.
Use python's None value as default to know whether old parameters were specified.
- hand_mt -> muscletrans
- hand_m -> muscle, regexp: (["' ])hand_m -> $1muscle
- hand_e_plus -> motor+
- hand_e -> motor
As xacro returns unicode objects from property evaluations
we cannot apply str.lower to them in Python 2.x
In Python 3.x str and unicode is essentially the same.
@rhaschke rhaschke force-pushed the pr-modernize-modularize-xacro branch from 516c5d2 to a8fecfa Compare October 4, 2021 19:32
@rhaschke
Copy link
Contributor Author

rhaschke commented Oct 4, 2021

I factored out the ubi tactile sensor definitions and merged ubi-agni#3

<bumperTopicName>contacts/${prefix}th/middle</bumperTopicName>
</plugin>
</sensor>
<selfCollide>true</selfCollide>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@guihomework: This selfCollide tag is part of the unless clause here, while in all other places it's outside.
Is this one wrong here?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes it makes no sense to remove the selfcollide here and not at other places, yet another mistake of mine.

side note : I am not convinced anymore by the current set of true/false on the self collide in the fingers, but I think it is a tricky matter (at least I remember it was not obvious) and if the current set works one should not try change it.

@guihomework
Copy link
Contributor

I factored out the ubi tactile sensor definitions.

I don't know why this is necessary, since shadow robot company supports the ubi sensors, even in the driver.

@rhaschke
Copy link
Contributor Author

rhaschke commented Oct 4, 2021

I don't know why this is necessary, since shadow robot company supports the ubi sensors, even in the driver.

As you said yourself: they can only be used with our custom urdf repos, which will never merged into public.

@guihomework
Copy link
Contributor

guihomework commented Oct 4, 2021

I don't know why this is necessary, since shadow robot company supports the ubi sensors, even in the driver.

As you said yourself: they can only be used with our custom urdf repos, which will never merged into public.

Not exactly what I said : I said that the taxels cannot be used without our tactile_toolbox, and could maybe be removed, but the visual/collision of the ubi could stay there as they do not need the tactile_toolbox. They were merged by shadow there shadow-robot/sr-ros-interface#253 and there was a distinction in the urdf for ubi that I had added already at shadow-robot/sr-ros-interface#147 and was also accepted upstream.

We always wanted to have as maximum things merged upstream as possible. If this an effort to now clean up their repo from tip sensor they do not sell, sure, then this the reason, but it is not a problem to have our visual tips even without tactile_toolbox.

EDIT: one advantage of having ubi remain in the possible sensors, is that when they upgrade the package, they will take care of keeping the ubi sensor as part of the list/future new way of handling sensors, when if they do not see it, we will have more issues to upgrade in the future.

@rhaschke rhaschke marked this pull request as ready for review October 4, 2021 22:32
@rhaschke rhaschke requested review from a team as code owners October 4, 2021 22:32
@rhaschke
Copy link
Contributor Author

rhaschke commented Oct 4, 2021

As a maintainer, I wouldn't like to have external sources in my repo that I cannot validate.
From my point of view, it is cleaner that we maintain our sensor addons on our side.
Yes, my point of view has changed on this since 2014 - due to much more experience in maintaining repositories.

Use textual sensor specifications:
- tip_sensors=bio
- tip_sensors='th=bio, ff=bio, mf=std, rf=std, lf=none'
- tip_sensors='bio, bio, std, std, none'

- Rename backward_compat.urdf.xacro -> process_sensor_parameters.xacro
- Introduce macro validate_tokens
@rhaschke rhaschke force-pushed the pr-modernize-modularize-xacro branch from 3b49c7f to 42cb509 Compare October 5, 2021 01:01
@rhaschke rhaschke mentioned this pull request Oct 5, 2021
@guihomework guihomework mentioned this pull request Oct 5, 2021
4 tasks
@beatrizleon
Copy link
Contributor

I am working now in a branch, so give me a few days to finish this.

About the hand_type, what we would like to have is:
E: hand_e (dexterous hand)
G: hand_lite
G-:hand_extra_lite (I am not sure about this, probably we don't need it as it is a one finger less than G)

I am modifying them in the process_hand_type_parameter.xacro file.

I wanted to ask you if you are still using a muscle or muscletrans hand? As I said before, we have only few clients with that and we are not currently supporting any. Same for the shadow arm. I would like to know if you need that we keep support for those

@guihomework
Copy link
Contributor

@beatrizleon in place of the team in Paris UPMC who has a ShadowArm and won't probably notice those discussions here, I would say, either they should fork to keep it (please announce it to the customers), or your company should create a legacy sr_description package, with things that you supported in the past, but won't anymore. This way it stays visible (and not hidden in history that is no easy to find), in the state they are now.
I personally like companies who still provide old drivers for winXP etc in a legacy section of their website. It is just a matter of dragging the files along but they require less maintenance and are separated for the supported ones.

Regarding the muscle hands in my current team, I think they were never used with ROS, but the same about the meshes and URDFs as for the Shadow Muscle arm applies IMHO. If for any reason someone would like to integrate the muscles hands in ROS on his own, finding the resources without digging in history would be nice.

@rhaschke
Copy link
Contributor Author

rhaschke commented Oct 9, 2021

I confirm that we never used the muscle hands with ROS (and probably won't do it).

About the hand_type, what we would like to have is:
E: hand_e (dexterous hand)
G: hand_lite
G-:hand_extra_lite (I am not sure about this, probably we don't need it as it is a one finger less than G)

If hand_lite and extra_lite only differ in a finger less, there is no need for another hand type. Fingers can be added or removed in a modular fashion in the xacro. I think you just need to distinguish the two different forearms.

@beatrizleon
Copy link
Contributor

Thanks both. I will create the legacy repo and delete arm and muscle hands as it will be easier for us to not keep this compatibility with things that nobody needs.

@rhaschke
Copy link
Contributor Author

rhaschke commented Oct 9, 2021

Dear @beatrizleon, skimming through your changes in 417b7a0, I noticed the following potential issues:

  • It seems like you removed the std sensor type. This was intended to be used as the default for Gazebo.
  • You renamed the hand_type motor to E in process_hand_type_parameter.xacro, but not yet in all other locations.
  • It looks like you moved many mesh files into an archive subfolder. However, git didn't recognized that they were renamed.

In general, it was rather hard to review your single commit. It would be helpful if you could split commits into smaller units with a commit message clearly stating what has changed.

@rhaschke rhaschke closed this Oct 9, 2021
@rhaschke rhaschke deleted the pr-modernize-modularize-xacro branch December 13, 2021 18:59
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.

3 participants