4 NAME =
'modelloader-test' 9 import roslib; roslib.load_manifest(
"openhrp3")
13 from omniORB
import CORBA, any, cdrUnmarshal, cdrMarshal
16 import sys, os, socket, subprocess
34 orb = CORBA.ORB_init(sys.argv, CORBA.ORB_ID)
36 nameserver = orb.resolve_initial_references(
"NameService");
37 rootnc = nameserver._narrow(CosNaming.NamingContext)
42 obj = rootnc.resolve([CosNaming.NameComponent(
'ModelLoader',
'')])
43 return obj._narrow(ModelLoader_idl._0_OpenHRP__POA.ModelLoader)
45 print(
"Could not find ModelLoader", sys.exc_info()[0])
49 if type(a) == float
and type(b) == float:
50 return abs(a - b) < tol
51 if type(a) == list
and type(b) == list:
52 return all(
equal(x,y)
for (x,y)
in zip(a,b))
76 s =
'\033[0m' if ok
else '\033[91m' 78 str = s+
"{0:70} {1}".format(fmt, ok)+e
80 self.assertTrue(ok,str)
83 """ Override this method for loading model files from another directory """ 84 openhrp3_prefix=subprocess.check_output(
'pkg-config openhrp3.1 --variable=prefix', shell=
True).rstrip()
85 self.
wrl_url = openhrp3_prefix+
"/share/OpenHRP-3.1/sample/model/"+wrl_file
86 self.
dae_url = openhrp3_prefix+
"/share/OpenHRP-3.1/sample/model/"+dae_file
95 print(
"%16s %16s"%(wrl_file, dae_file))
98 print(
";; %s %d,%d"%(dae_l.name, dae_l.jointId, dae_l.parentIndex));
99 name_ok = wrl_l.name == dae_l.name
100 translation_ok =
equal(wrl_l.translation, dae_l.translation)
101 rotation_ok =
equal(
norm(wrl_l.rotation),
norm(dae_l.rotation))
102 mass_ok =
equal(wrl_l.mass, dae_l.mass)
103 centerOfMass_ok =
equal(wrl_l.centerOfMass, dae_l.centerOfMass)
104 inertia_ok =
equal(wrl_l.inertia, dae_l.inertia)
105 llimit_ok =
equal(wrl_l.llimit, dae_l.llimit)
if wrl_l.parentIndex > 0
else True 106 ulimit_ok =
equal(wrl_l.ulimit, dae_l.ulimit)
if wrl_l.parentIndex > 0
else True 107 lvlimit_ok =
equal(wrl_l.lvlimit, dae_l.lvlimit)
if wrl_l.parentIndex > 0
else True 108 uvlimit_ok =
equal(wrl_l.uvlimit, dae_l.uvlimit)
if wrl_l.parentIndex > 0
else True 109 climit_ok =
equal(wrl_l.climit, dae_l.climit)
if wrl_l.parentIndex > 0
else True 110 torqueConst_ok =
equal(wrl_l.torqueConst, dae_l.torqueConst)
if wrl_l.parentIndex > 0
else True 111 gearRatio_ok =
equal(wrl_l.gearRatio, dae_l.gearRatio)
if wrl_l.parentIndex > 0
else True 112 ret = all([ret, name_ok, translation_ok, rotation_ok, mass_ok, centerOfMass_ok])
113 self.
print_ok(
"name {0:24s} {1:24s} ".format(wrl_l.name, dae_l.name),
True)
114 self.
print_ok(
" tran {0:24} {1:24}".format(wrl_l.translation, dae_l.translation), translation_ok)
115 self.
print_ok(
" rot {0:24} {1:24}".format(wrl_l.rotation, dae_l.rotation), rotation_ok)
116 self.
print_ok(
" mass {0:<24} {1:<24}".format(wrl_l.mass, dae_l.mass), mass_ok)
117 self.
print_ok(
" CoM {0:24} {1:24}".format(wrl_l.centerOfMass, dae_l.centerOfMass), centerOfMass_ok)
118 self.
print_ok(
" iner {0:50}\n {1:50}".format(wrl_l.inertia, dae_l.inertia), inertia_ok)
119 self.
print_ok(
" llim {0:24} {1:24}".format(wrl_l.llimit, dae_l.llimit), llimit_ok)
120 self.
print_ok(
" ulim {0:24} {1:24}".format(wrl_l.ulimit, dae_l.ulimit), ulimit_ok)
121 self.
print_ok(
" lvlim {0:24} {1:24}".format(wrl_l.lvlimit, dae_l.lvlimit), lvlimit_ok)
122 self.
print_ok(
" uvlim {0:24} {1:24}".format(wrl_l.uvlimit, dae_l.uvlimit), uvlimit_ok)
123 self.
print_ok(
" clim {0:24} {1:24}".format(wrl_l.climit, dae_l.climit), climit_ok)
124 self.
print_ok(
" trqcnt {0:24} {1:24}".format(wrl_l.torqueConst, dae_l.torqueConst), torqueConst_ok)
125 self.
print_ok(
" gratio {0:24} {1:24}".format(wrl_l.gearRatio, dae_l.gearRatio), gearRatio_ok)
126 for (wrl_s, dae_s)
in zip(wrl_l.segments, dae_l.segments):
128 name_ok = wrl_s.name == dae_s.name
129 mass_ok =
equal(wrl_s.mass, dae_s.mass)
130 centerOfMass_ok =
equal(wrl_s.centerOfMass, dae_s.centerOfMass)
131 inertia_ok =
equal(wrl_s.inertia, dae_s.inertia)
132 transformMatrix_ok =
equal(wrl_s.transformMatrix, dae_s.transformMatrix)
133 shapeIndices_ok =
equal(wrl_s.shapeIndices, dae_s.shapeIndices)
134 ret = all([ret, name_ok, mass_ok, centerOfMass_ok,inertia_ok, transformMatrix_ok, shapeIndices_ok])
135 self.
print_ok(
" name {0:24s} {1:24s} ".format(wrl_s.name, dae_s.name), name_ok)
136 self.
print_ok(
" mass {0:<24} {1:<24}".format(wrl_s.mass, dae_s.mass), mass_ok)
137 self.
print_ok(
" CoM {0:24} {1:24}".format(wrl_s.centerOfMass, dae_s.centerOfMass), centerOfMass_ok)
138 self.
print_ok(
" iner {0:50}\n {1:50}".format(wrl_s.inertia, dae_s.inertia), inertia_ok)
139 self.
print_ok(
" trans {0:50}\n {1:50}".format(wrl_s.transformMatrix, dae_s.transformMatrix), transformMatrix_ok)
140 self.
print_ok(
" shape {0:24} {1:24}".format(wrl_s.shapeIndices, dae_s.shapeIndices), shapeIndices_ok)
143 print(
"===========\n== ERROR == {0} and {1} differs\n===========".format(wrl_file, dae_file))
147 """ Make class for testing by inheriting TestModelLoaderBase """ 152 self.
checkModels(
"PA10/pa10.main.wrl",
"PA10/pa10.main.dae")
157 if __name__ ==
'__main__':
158 rostest.run(PKG, NAME, TestModelLoader, sys.argv)
png_infop png_charp png_int_32 png_int_32 int * type
def checkModels(self, wrl_file, dae_file)
def print_ok(self, fmt, ok)
def loadFiles(self, wrl_file, dae_file)
def test_sample_models(self)
def equal(a, b, tol=1e-4)