22
22
from lxml import etree
23
23
24
24
from dm_control import mjcf
25
- from dm_control .locomotion .walkers .assets .dog_v2 import add_markers as add_markers_func
26
- from dm_control .locomotion .walkers .assets .dog_v2 import (
27
- add_muscles ,
28
- add_torque_actuators ,
29
- add_wrapping_geoms ,
30
- build_back_legs ,
31
- build_front_legs ,
32
- build_neck ,
33
- build_tail ,
34
- build_torso ,
35
- create_skin ,
36
- )
25
+ from dm_control .locomotion .walkers .assets import dog_v2
37
26
from dm_control .utils import io as resources
38
27
39
28
flags .DEFINE_boolean ("make_skin" , True , "Whether to make a new dog_skin.skn" )
78
67
False ,
79
68
"Make slight adjustments to the model to make it compatible for the composer." ,
80
69
)
81
-
70
+ flags .DEFINE_string (
71
+ "output_dir" ,
72
+ os .path .dirname (__file__ ),
73
+ "Output directory for the created dog model"
74
+ )
82
75
83
76
FLAGS = flags .FLAGS
84
77
85
78
BASE_MODEL = "dog_base.xml"
86
79
ASSET_RELPATH = "../../../../suite/dog_assets"
87
80
CURRENT_DIR = os .path .dirname (__file__ )
88
- ASSET_DIR = CURRENT_DIR + "/" + ASSET_RELPATH
81
+ ASSET_DIR = os . path . join ( CURRENT_DIR , ASSET_RELPATH )
89
82
90
83
91
84
def exclude_contacts (model ):
@@ -181,6 +174,7 @@ def main(argv):
181
174
add_markers = FLAGS .add_markers
182
175
lengthrange_from_joints = FLAGS .lengthrange_from_joints
183
176
composer = FLAGS .composer
177
+ output_dir = FLAGS .output_dir
184
178
else :
185
179
lumbar_dofs_per_vert = FLAGS ["lumbar_dofs_per_vertebra" ].default
186
180
cervical_dofs_per_vertebra = FLAGS ["cervical_dofs_per_vertebra" ].default
@@ -193,24 +187,24 @@ def main(argv):
193
187
add_markers = FLAGS ["add_markers" ].default
194
188
lengthrange_from_joints = FLAGS ["lengthrange_from_joints" ].default
195
189
composer = FLAGS ["composer" ].default
190
+ output_dir = FLAGS ["output_dir" ].default
196
191
197
192
print ("Load base model." )
198
193
with open (os .path .join (CURRENT_DIR , BASE_MODEL ), "r" ) as f :
199
194
model = mjcf .from_file (f )
200
195
201
-
202
196
if not composer :
203
197
floor = model .worldbody .add (
204
- "body" , name = "floor" , pos = (0 , 0 , 0 )
205
- )
198
+ "body" , name = "floor" , pos = (0 , 0 , 0 )
199
+ )
206
200
floor .add (
207
- "geom" ,
208
- name = "floor" ,
209
- type = "plane" ,
210
- conaffinity = 1 ,
211
- size = [10 , 10 , 0.1 ],
212
- material = "grid"
213
- )
201
+ "geom" ,
202
+ name = "floor" ,
203
+ type = "plane" ,
204
+ conaffinity = 1 ,
205
+ size = [10 , 10 , 0.1 ],
206
+ material = "grid"
207
+ )
214
208
# Helper constants:
215
209
side_sign = {
216
210
"_L" : np .array ((1.0 , - 1.0 , 1.0 )),
@@ -267,7 +261,7 @@ def main(argv):
267
261
268
262
# Torso
269
263
print ("Torso, lumbar spine, pelvis." )
270
- pelvic_bones , lumbar_joints = build_torso . create_torso (
264
+ pelvic_bones , lumbar_joints = dog_v2 . build_torso (
271
265
model ,
272
266
bones ,
273
267
bone_position ,
@@ -279,7 +273,7 @@ def main(argv):
279
273
280
274
print ("Neck, skull, jaw." )
281
275
# Cervical spine (neck) bodies:
282
- cervical_joints = build_neck . create_neck (
276
+ cervical_joints = dog_v2 . build_neck (
283
277
model ,
284
278
bone_position ,
285
279
cervical_dofs_per_vertebra ,
@@ -290,7 +284,7 @@ def main(argv):
290
284
)
291
285
292
286
print ("Back legs." )
293
- nails , sole_sites = build_back_legs . create_back_legs (
287
+ nails , sole_sites = dog_v2 . build_back_legs (
294
288
model ,
295
289
primary_axis ,
296
290
bone_position ,
@@ -302,7 +296,7 @@ def main(argv):
302
296
)
303
297
304
298
print ("Shoulders, front legs." )
305
- palm_sites = build_front_legs . create_front_legs (
299
+ palm_sites = dog_v2 . build_front_legs (
306
300
nails ,
307
301
model ,
308
302
primary_axis ,
@@ -312,7 +306,7 @@ def main(argv):
312
306
)
313
307
314
308
print ("Tail." )
315
- caudal_joints = build_tail . create_tail (
309
+ caudal_joints = dog_v2 . build_tail (
316
310
caudal_dofs_per_vertebra ,
317
311
bone_size ,
318
312
model ,
@@ -365,9 +359,8 @@ def main(argv):
365
359
exclude_contacts (model )
366
360
367
361
if make_skin :
368
- create_skin .create (
369
- model = model , mesh_file = skin_msh , asset_dir = ASSET_DIR , mesh_name = "dog_skin" , composer = composer
370
- )
362
+ dog_v2 .create_skin (model = model , mesh_file = skin_msh ,
363
+ asset_dir = ASSET_DIR , mesh_name = "dog_skin" , composer = composer )
371
364
372
365
# Add skin from .skn
373
366
print ("Adding Skin." )
@@ -397,7 +390,7 @@ def main(argv):
397
390
muscle_msh = model .asset .add (
398
391
"mesh" , name = filename [:- 4 ], file = ASSET_DIR + "/muscles/" + filename
399
392
)
400
- create_skin . create (
393
+ dog_v2 . create_skin (
401
394
model = model ,
402
395
asset_dir = ASSET_DIR ,
403
396
mesh_file = muscle_msh ,
@@ -426,22 +419,22 @@ def main(argv):
426
419
427
420
if add_markers :
428
421
print ("Add Markers" )
429
- add_markers_func .add_markers (model )
422
+ dog_v2 .add_markers (model )
430
423
431
424
print ("Add Actuators" )
432
425
if use_muscles :
433
426
# Add wrapping geometries
434
- add_wrapping_geoms .add_wrapping_geoms (model )
427
+ dog_v2 .add_wrapping_geoms (model )
435
428
# Add muscles
436
- add_muscles .add_muscles (
429
+ dog_v2 .add_muscles (
437
430
model ,
438
431
muscle_strength_scale ,
439
432
muscle_dynamics ,
440
433
ASSET_DIR ,
441
434
lengthrange_from_joints ,
442
435
)
443
436
else :
444
- actuated_joints = add_torque_actuators . add_motors (
437
+ actuated_joints = dog_v2 . add_torque_actuators (
445
438
physics , model , lumbar_joints , cervical_joints , caudal_joints
446
439
)
447
440
@@ -499,7 +492,7 @@ def main(argv):
499
492
if composer :
500
493
torso = model .find ("body" , "torso" )
501
494
torso .pos = np .zeros (3 )
502
-
495
+
503
496
print ("Finalising and saving model." )
504
497
xml_string = model .to_xml_string ("float" , precision = 4 , zero_threshold = 1e-7 )
505
498
root = etree .XML (xml_string , etree .XMLParser (remove_blank_text = True ))
@@ -548,7 +541,7 @@ def main(argv):
548
541
name = name_prefix + "dog_muscles_{}_{}.xml" .format (
549
542
muscle_strength_scale , muscle_dynamics )
550
543
551
- f = open (os .path .join (CURRENT_DIR , name ), "wb" )
544
+ f = open (os .path .join (output_dir , name ), "wb" )
552
545
f .write (xml_string )
553
546
f .close ()
554
547
0 commit comments