icub-tech-iit / urdf-modifiers

BSD 3-Clause "New" or "Revised" License
15 stars 4 forks source link

Existing MULTIPLIER length modifiers with default parameters are not invariant if the scale is set to 1 (feat: propose for new multipliers) #10

Closed traversaro closed 2 years ago

traversaro commented 2 years ago

Hi @CarlottaSartore @GrmanRodriguez @AlexAntn ! For an internal project, I had to work with urdf-modifiers with a model different from ergoCub. As starting step, I wanted to setup the appropriate modifiers for the length.

The model that I used is composed by boxes, but to showcase my problem I prepared a simple model with two links (one cylinder, and one box) for which the length can be changed. The model can be found at https://github.com/traversaro/urdf-modifiers/tree/invariance/examples/models/twoLinks, and the script to showcase the unexpected behavior can be found at https://github.com/traversaro/urdf-modifiers/blob/invariance/examples/generateRandomVariants.py .

In this script, I load a model, and then I generate random variations of it, ideally changing the lenghts of the link1 and link2 links. As a preliminary step, I set all the scale to 1.0 and use the existing modifiers (i.e. setting 1.0 in https://github.com/traversaro/urdf-modifiers/blob/50e9acb5eba57815e6b547b8062cece32cc24872/examples/generateRandomVariants.py#L441/generateRandomVariants.py#L401 and False in https://github.com/traversaro/urdf-modifiers/blob/50e9acb5eba57815e6b547b8062cece32cc24872/examples/generateRandomVariants.py#L371), to make sure that if the length remain the same, the model is the same.

However, the following happens if I run this with the existing LinkModifier and JointModifier (used with default parameters, taking inspiration from @CarlottaSartore's script, but I may be doing something wrong): existing_modifiers_2

(Red is the original model, Black the modified one).

I tried to set some parameters to ensure that the same model was given, but I could not find them, even because I may be missing some logic steps. To avoid being blocked, I instead developed a new modifier (named for now LinkAndJointModifier) that follows the mathematical rules that I will document in a different issue.

GrmanRodriguez commented 2 years ago

Sorry Silvio I don't understand. Is the problem that the axis changes direction?

traversaro commented 2 years ago

Is the problem that the axis changes direction?

The joint axis always point in the same direction, it is the link that change direction, but yes, I would expect that if a relative multiplier is set to 1, the model shape would not change, but perhaps I am misunderstanding something myself. I wanted to fill the issue on the new multiplier I worked on, then we can have a discussion on that issue and also this one.

CarlottaSartore commented 2 years ago

I think this could be due to flip direction value, but anyway let's first wait for the other issue :) https://github.com/icub-tech-iit/urdf-modifiers/blob/23d5517413e1ce765ab5857130f0b30f588b0430/urdfModifiers/core/linkModifier.py#L11

traversaro commented 2 years ago

Thanks, that is probably it! Any clue of why by default is True?

GrmanRodriguez commented 2 years ago

Most weird behavior like this is carryover from the needs of the stickbot. It needs to be more generalized

CarlottaSartore commented 2 years ago

Thanks, that is probably it! Any clue of why by default is True?

I think (as @GrmanRodriguez was pointing out) that this is due to the fact that for the stickbot, if I am not wrong, most of the links need it to be true!

Having a way to automatically generate such entries (as we discussed in #3) could prevent this issue since the needed parameters will be automatically computed

traversaro commented 2 years ago

Thanks, that is probably it! Any clue of why by default is True?

I think (as @GrmanRodriguez was pointing out) that this is due to the fact that for the stickbot, if I am not wrong, most of the links need it to be true!

Yes, that is what is puzzling me, I can't wrap my head on why this needs to be true. Anyhow, no problem, we can discuss about this in the meeting.

traversaro commented 2 years ago

I tried to set some parameters to ensure that the same model was given, but I could not find them, even because I may be missing some logic steps. To avoid being blocked, I instead developed a new modifier (named for now LinkAndJointModifier) that follows the mathematical rules that I will document in a different issue.

New modifier (for now, without hardcoded parameter) described in https://github.com/icub-tech-iit/urdf-modifiers/issues/11 .

GrmanRodriguez commented 2 years ago

Yes, that is what is puzzling me, I can't wrap my head on why this needs to be true. Anyhow, no problem, we can discuss about this in the meeting.

It relates to #7. In the stickbot links in the arms and legs go from the highest one to the lowest one (e.g. in the arm the shoulder is at a higher Z than the hand and in the leg the hip joints are higher than the feet) so we needed the joints to move down when you increase link height.

flip_direction was used around the torso because those joints go from lowest to highest.

Anyways the point is, when we deal with #7 this should be also taken care of.