GithubHelp home page GithubHelp logo

vonunwerth / meshlabinertiatourdf Goto Github PK

View Code? Open in Web Editor NEW
30.0 2.0 3.0 38 KB

Calculating inertial tensor for roboitc links with pymeshlab for Gazebo robots

License: GNU General Public License v3.0

Python 100.00%
urdf urdf-descriptions inertia

meshlabinertiatourdf's People

Contributors

vonunwerth avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

meshlabinertiatourdf's Issues

Scaling operation is unnecessary

Nothing wrong with the final result, but fyi, the scaling operation is redundant. The problem with using Meshlab UI is that it doesn't print enough precision nor does it use exponential format, but in your code the tensor is as a ndarray with floats therefor the precision is maintained without scaling. Since you've increased the precision of the printing, it works the same.

So, get rid of the scaling operation, and just change:

        tensor = geom['inertia_tensor'] / pow(scale_factor, 2) * self.mass / volume

to this, where the volume is the original unscaled volume:

        tensor = geom['inertia_tensor'] * self.mass / volume

I've verified the output results are the same numbers. Also, I use this function to export the numbers, it chooses to output non-exponential notation for simple numbers, but switches to exponential notation for small quantities. Feel free to use. Technically, you don't even need the middle 0.001 comparison because the 'g' format will switch between simple and exponential notation based on the precision specifier...this is just my personal preference.

# converts a single float to a string
def export_float(f: float, precision: int = 5):
    if f == 0:
        return "0"
    elif abs(f) < 0.001:
        return f"{f:.{precision}e}"
    else:
        return f"{f:.{precision}g}"

# build a function for converting each element of a numpy array to a string
export_tensor = numpy.vectorize(export_float)

Then later in your processing function, you can use the vectorized exporter:

# convert each float element of the tensor to a string with our desired precision/format
tensor_str = export_tensor(tensor)

# convert to XML   (snipped sections with ... that are unchanged)
# we don't need to format the elements now since they are already strings
inertia_xml = f'<inertia ixx="{tensor_str[0, 0]}" ixy="{tensor[1, 0]}"  ...etc... />'

P.S. Wonderful piece of code you wrote! This was so helpful in my case. If I met you, I'd buy you a buy - or few. :)

Center of mass instead of barycenter ?

Thank you for the nice tool,
I was wondering why you are using the barycenter instead of the center of mass when computing the center of mass.
Cause I know pymeshlab computes both and they are different in my case.

Thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.