i’am calculating inertia for sphere with mass: 0.01 and radius: 0.008 (using script that course provide)
Here is the python script :
#!/usr/bin/env python
import math
class InertialCalculator(object):
def __init__(self):
print("InertialCaluclator Initialised...")
def start_ask_loop(self):
selection = "START"
while selection != "Q":
print("#############################")
print("Select Geometry to Calculate:")
print("[1]Box width(w)*depth(d)*height(h)")
print("[2]Sphere radius(r)")
print("[3]Cylinder radius(r)*height(h)")
print("[Q]END program")
selection = input(">>")
self.select_action(selection)
print("InertialCaluclator Quit...Thank you")
def select_action(self, selection):
if selection == "1":
mass = float(input("mass>>"))
width = float(input("width>>"))
depth = float(input("depth>>"))
height = float(input("height>>"))
self.calculate_box_inertia(m=mass, w=width, d=depth, h=height)
elif selection == "2":
mass = float(input("mass>>"))
radius = float(input("radius>>"))
self.calculate_sphere_inertia(m=mass, r=radius)
elif selection == "3":
mass = float(input("mass>>"))
radius = float(input("radius>>"))
height = float(input("height>>"))
self.calculate_cylinder_inertia(m=mass, r=radius, h=height)
elif selection == "Q":
print("Selected Quit")
else:
print("Usage: Select one of the give options")
# def calculate_box_inertia(self, m, w, d, h):
# Iw = (m/12.0)*(pow(d,2)+pow(h,2))
# Id = (m / 12.0) * (pow(w, 2) + pow(h, 2))
# Ih = (m / 12.0) * (pow(w, 2) + pow(d, 2))
# print("BOX w*d*h, Iw = "+str(Iw)+",Id = "+str(Id)+",Ih = "+str(Ih))
def calculate_box_inertia(self, m, w, d, h):
Iw = (1.0 / 12.0) * (d**2 + h**2) * m
Id = (1.0 / 12.0) * (w**2 + h**2) * m
Ih = (1.0 / 12.0) * (w**2 + d**2) * m
print ('BOX ixx="' + str(Iw) + '" ixy="0.0" ixz="0.0" iyy="'
+ str(Id) + '" iyz="0.0" izz="' + str(Ih) + '"')
def calculate_sphere_inertia(self, m, r):
I = (2*m*pow(r,2))/5.0
print("SPHERE Ix,y,z = "+str(I))
def calculate_cylinder_inertia(self, m, r, h):
Ix = (m/12.0)*(3*pow(r,2)+pow(h,2))
Iy = Ix
Iz = (m*pow(r,2))/2.0
print("Cylinder Ix,y = "+str(Ix)+",Iz = "+str(Iz))
if __name__ == "__main__":
inertial_object = InertialCalculator()
inertial_object.start_ask_loop()
This the output from the script for sphere:
InertialCaluclator Initialised…
#############################
Select Geometry to Calculate:
[1]Box width(w)*depth(d)*height(h)
[2]Sphere radius(r)
[3]Cylinder radius(r)*height(h)
[Q]END program
2
mass>>0.01
radius>>0.008
SPHERE Ix,y,z = 2.56e-07
#############################
But in solution of the course inertia value is different (1.28e-06):
<link name="footM1_link">
<inertial>
<origin xyz="0 0 0" rpy="0 0 0"/>
<mass value="0.01" />
<inertia ixx="1.28e-06" ixy="0.0" ixz="0.0" iyy="1.28e-06" iyz="0.0" izz="1.28e-06"/>
</inertial>
<collision>
<origin xyz="0 0 0" rpy="0 0 0"/>
<geometry>
<sphere radius="0.008"/>
</geometry>
</collision>
<visual>
<origin rpy="0.0 0 0" xyz="0 0 0"/>
<geometry>
<sphere radius="0.008"/>
</geometry>
</visual>
</link>
I’am misunderstood something or this is mistake in urdf file of course?