Based on a provided URDF (or xacro), it reads all geometries that have a mass
inertial tag, and prints a URDF-ready inertia matrix.
- xacro (pip install xacro)
- numpy-stl (pip install numpy-stl)
- pycollada (pip install pycollada)
- urdf_paser_py (pip install urdf-parser-py)
Install with pip install -r requirements.txt
- 1: URDF file
- Support for Collada (.dae) mesh files (in addition to STL)
- Support for ROS1 AND ROS2. This functionality basically involves looking for mesh files in
package://
tags. (If your urdf/xacro only includesfile://
tags, there is nothing ROS-related to worry about) - Support for ALL kind of geometries (mesh, box, sphere, cylinder)
- Xacro integration for files that use arguments or parameters in fields of interest
- Support for links that have inertia but not a visual tag (collisions only)
python calc_inertia_for_urdf.py /home/gstavrinos/urdfs/model.urdf
Link name: chassis_link_00
Mass: 48.0
Scale: [0.015, 0.015, 0.015]
Mesh: file:///home/gstavrinos/ros2_ws/install/kart_description/share/kart_description/meshes/kart_chassis.stl
---
Calculating inertia...
---
<inertia ixx="107.96846534714074" ixy="0" ixz="0" iyy="279.5263367708269" iyz="0" izz="346.94143021711494" />
Link name: steering_wheel_link_00
Mass: 7.0
Scale: [0.015, 0.015, 0.015]
Mesh: file:///home/gstavrinos/ros2_ws/install/kart_description/share/kart_description/meshes/kart_steering_wheel.stl
---
Calculating inertia...
---
<inertia ixx="1.7008840358588881" ixy="0" ixz="0" iyy="2.939219711456205" iyz="0" izz="3.1101995734940084" />
.
.
.
With an object's STL file and mass, calculate its inertia, based on its bounding box, in mass * dimension * scale. The output is URDF-ready.
- numpy-stl (sudo pip install numpy-stl)
- 1: STL file
- 2: Mass (in kg)
- 3: Scale (in case you are scaling your model before use)(= 0.000001 if stl is in mm)
python calc_inertia.py "/home/gstavrinos/meshes/model.stl" 0.025 1