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

Randomized inertia tensor does not satisfy the triangle inequality #218

Closed
diegoferigo opened this issue Jul 15, 2020 · 4 comments
Closed

Comments

@diegoferigo
Copy link
Collaborator

diegoferigo commented Jul 15, 2020

The recently introduced SDF randomizer #177, part of the bigger randomization plan defined in #41, allows to randomize mostly all entries of an SDF model taking advantage of XPaths.

This is applied also to the inertia parameters that define the inertia matrix. However, sampling the parameters from a random distribution sometimes leads to parameters that do not satisfy the triangle inequality, obtaining an invalid model (check performed in ignition::math::MassMatrix3::ValidMoments.

Refer to test_sdf_randomizer for usage examples.

We should add a new randomization method specific for the inertia tensor that samples from a physically consistent distribution, something like:

randomizer.new_randomization() \
    .at_xpath("*/link/inertial/inertia") \
    .is_inertia(True, only_diagonal=True) \
    .method(Method.Coefficient) \
    .sampled_from(Distribution.Gaussian, GaussianParams(mean=1, variance=0.1)) \
    .add()

so that ixx, iyy and izz are sampled consistently.

@HorvathDawson
Copy link

HorvathDawson commented Oct 13, 2021

I am working on implementing a version of this for my own use that I could create a pull request for after. I have two ideas on how to achieve this without adding bias.

  1. Only allow coefficient scaling. Then scale each principal inertia by this value. (the issue with this is that it will only randomize the inertia magnitude instead of shifting the centre of mass around randomly. This is a bit restrictive.)

  2. To avoid this another option would be to perform some random method to each principal inertia independently then check if these values satisfy the inequality. If they do not satisfy the inequality then repeat until they do. This will have a longer run time but avoids adding accidental bias into the chosen values by forcing the constraints before randomization. (This would need a max number of attempts)

Do either of these options sound like a good way to implement this randomization?

@HorvathDawson
Copy link

I made a small google colab which also includes a randomization using the constraints of the triangle inequalities to avoid permutations. https://colab.research.google.com/drive/1BQRnzZ69jncUPdaVWVzR6ZIeWmAugGf3?usp=sharing

However,I am not convinced this avoids biasing the output to the clipped values... There might be a much more intelligent way to do this.

@AndrejOrsula
Copy link

Hello @HorvathDawson, great to see that someone is looking into this.

I implemented a simple randomization of inertial properties within the context of Gym-Ignition some time ago. I used the approach you described in your first point (my assumption/limitation was that all objects have a uniform density).

  1. Only allow coefficient scaling. Then scale each principal inertia by this value. (the issue with this is that it will only randomize the inertia magnitude instead of shifting the centre of mass around randomly. This is a bit restrictive.)

Therefore, I thought I would share the code. It's an old and messy Python script, but there might be something useful (or not). Here, all links of models are assumed to have a mesh geometry (one or more visual), and trimesh is used for most of the mesh analysis and manipulation.

And then also some other stuff within this context that might be relevant for your application (or not).

@diegoferigo
Copy link
Collaborator Author

Note

Cleaning up old issues and pull requests I opened over the past years that are now outdated or stale. If this is still relevant, feel free to reopen it or create a new one with updated details. Thanks!

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

No branches or pull requests

3 participants