@@ -479,12 +479,14 @@ def test_resolveauto_inertialsWithMultipleCollisions(self):
479
479
link .inertial ().mass_matrix ().diagonal_moments ())
480
480
481
481
def test_inertial_values_given_with_auto_set_to_true (self ):
482
+ # The inertia matrix is specified but should be ignored.
483
+ # <mass> is not speicifed so the inertial values should be computed
484
+ # based on the collision density value.
482
485
sdf = "<?xml version=\" 1.0\" ?>" + \
483
486
"<sdf version=\" 1.11\" >" + \
484
487
" <model name='compound_model'>" + \
485
488
" <link name='compound_link'>" + \
486
489
" <inertial auto='True'>" + \
487
- " <mass>4.0</mass>" + \
488
490
" <pose>1 1 1 2 2 2</pose>" + \
489
491
" <inertia>" + \
490
492
" <ixx>1</ixx>" + \
@@ -515,11 +517,169 @@ def test_inertial_values_given_with_auto_set_to_true(self):
515
517
root .resolve_auto_inertials (errors , sdfParserConfig )
516
518
self .assertEqual (len (errors ), 0 )
517
519
518
- self .assertNotEqual ( 4 .0 , link .inertial ().mass_matrix ().mass ())
520
+ self .assertEqual ( 2 .0 , link .inertial ().mass_matrix ().mass ())
519
521
self .assertEqual (Pose3d .ZERO , link .inertial ().pose ())
520
522
self .assertEqual (Vector3d (0.33333 , 0.33333 , 0.33333 ),
521
523
link .inertial ().mass_matrix ().diagonal_moments ())
522
524
525
+ def test_resolveauto_inertialsWithMass (self ):
526
+ # The inertia matrix is specified but should be ignored.
527
+ # <mass> is speicifed - the auto computed inertial values should
528
+ # be scaled based on the desired mass.
529
+ sdf = "<?xml version=\" 1.0\" ?>" + \
530
+ "<sdf version=\" 1.11\" >" + \
531
+ " <model name='compound_model'>" + \
532
+ " <link name='compound_link'>" + \
533
+ " <inertial auto='True'>" + \
534
+ " <mass>4.0</mass>" + \
535
+ " <pose>1 1 1 2 2 2</pose>" + \
536
+ " <inertia>" + \
537
+ " <ixx>1</ixx>" + \
538
+ " <iyy>1</iyy>" + \
539
+ " <izz>1</izz>" + \
540
+ " </inertia>" + \
541
+ " </inertial>" + \
542
+ " <collision name='box_collision'>" + \
543
+ " <density>2.0</density>" + \
544
+ " <geometry>" + \
545
+ " <box>" + \
546
+ " <size>1 1 1</size>" + \
547
+ " </box>" + \
548
+ " </geometry>" + \
549
+ " </collision>" + \
550
+ " </link>" + \
551
+ " </model>" + \
552
+ " </sdf>"
553
+
554
+ root = Root ()
555
+ sdfParserConfig = ParserConfig ()
556
+ errors = root .load_sdf_string (sdf , sdfParserConfig )
557
+ self .assertEqual (errors , None )
558
+
559
+ model = root .model ()
560
+ link = model .link_by_index (0 )
561
+ errors = []
562
+ root .resolve_auto_inertials (errors , sdfParserConfig )
563
+ self .assertEqual (len (errors ), 0 )
564
+
565
+ self .assertEqual (4.0 , link .inertial ().mass_matrix ().mass ())
566
+ self .assertEqual (Pose3d .ZERO , link .inertial ().pose ())
567
+ self .assertEqual (Vector3d (0.66666 , 0.66666 , 0.66666 ),
568
+ link .inertial ().mass_matrix ().diagonal_moments ())
569
+
570
+ def test_resolveauto_inertialsWithMassAndMultipleCollisions (self ):
571
+ # The inertia matrix is specified but should be ignored.
572
+ # <mass> is speicifed - the auto computed inertial values should
573
+ # be scaled based on the desired mass.
574
+ sdf = "<?xml version=\" 1.0\" ?>" + \
575
+ "<sdf version=\" 1.11\" >" + \
576
+ " <model name='compound_model'>" + \
577
+ " <link name='compound_link'>" + \
578
+ " <inertial auto='True'>" + \
579
+ " <mass>12.0</mass>" + \
580
+ " <pose>1 1 1 2 2 2</pose>" + \
581
+ " <inertia>" + \
582
+ " <ixx>1</ixx>" + \
583
+ " <iyy>1</iyy>" + \
584
+ " <izz>1</izz>" + \
585
+ " </inertia>" + \
586
+ " </inertial>" + \
587
+ " <collision name='cube_collision'>" + \
588
+ " <pose>0.0 0.0 0.5 0 0 0</pose>" + \
589
+ " <density>4.0</density>" + \
590
+ " <geometry>" + \
591
+ " <box>" + \
592
+ " <size>1 1 1</size>" + \
593
+ " </box>" + \
594
+ " </geometry>" + \
595
+ " </collision>" + \
596
+ " <collision name='box_collision'>" + \
597
+ " <pose>0.0 0.0 -1.0 0 0 0</pose>" + \
598
+ " <density>1.0</density>" + \
599
+ " <geometry>" + \
600
+ " <box>" + \
601
+ " <size>1 1 2</size>" + \
602
+ " </box>" + \
603
+ " </geometry>" + \
604
+ " </collision>" + \
605
+ " </link>" + \
606
+ " </model>" + \
607
+ "</sdf>"
608
+
609
+ root = Root ()
610
+ sdfParserConfig = ParserConfig ()
611
+ errors = root .load_sdf_string (sdf , sdfParserConfig )
612
+ self .assertEqual (errors , None )
613
+
614
+ model = root .model ()
615
+ link = model .link_by_index (0 )
616
+ errors = []
617
+ root .resolve_auto_inertials (errors , sdfParserConfig )
618
+ self .assertEqual (len (errors ), 0 )
619
+
620
+ self .assertEqual (12.0 , link .inertial ().mass_matrix ().mass ())
621
+ self .assertEqual (Pose3d .ZERO ,
622
+ link .inertial ().pose ())
623
+ self .assertEqual (Vector3d (9.0 , 9.0 , 2.0 ),
624
+ link .inertial ().mass_matrix ().diagonal_moments ())
625
+
626
+ def test_resolveauto_inertialsWithMassAndDefaultDensity (self ):
627
+ # The inertia matrix is specified but should be ignored.
628
+ # <mass> is speicifed - the auto computed inertial values should
629
+ # be scaled based on the desired mass.
630
+ # Density is not specified for the bottom collision - it should
631
+ # use the default value
632
+ sdf = "<?xml version=\" 1.0\" ?>" + \
633
+ "<sdf version=\" 1.11\" >" + \
634
+ " <model name='compound_model'>" + \
635
+ " <link name='compound_link'>" + \
636
+ " <inertial auto='True'>" + \
637
+ " <mass>12000.0</mass>" + \
638
+ " <pose>1 1 1 2 2 2</pose>" + \
639
+ " <inertia>" + \
640
+ " <ixx>1</ixx>" + \
641
+ " <iyy>1</iyy>" + \
642
+ " <izz>1</izz>" + \
643
+ " </inertia>" + \
644
+ " </inertial>" + \
645
+ " <collision name='cube_collision'>" + \
646
+ " <pose>0.0 0.0 0.5 0 0 0</pose>" + \
647
+ " <density>4000.0</density>" + \
648
+ " <geometry>" + \
649
+ " <box>" + \
650
+ " <size>1 1 1</size>" + \
651
+ " </box>" + \
652
+ " </geometry>" + \
653
+ " </collision>" + \
654
+ " <collision name='box_collision'>" + \
655
+ " <pose>0.0 0.0 -1.0 0 0 0</pose>" + \
656
+ " <geometry>" + \
657
+ " <box>" + \
658
+ " <size>1 1 2</size>" + \
659
+ " </box>" + \
660
+ " </geometry>" + \
661
+ " </collision>" + \
662
+ " </link>" + \
663
+ " </model>" + \
664
+ "</sdf>"
665
+
666
+ root = Root ()
667
+ sdfParserConfig = ParserConfig ()
668
+ errors = root .load_sdf_string (sdf , sdfParserConfig )
669
+ self .assertEqual (errors , None )
670
+
671
+ model = root .model ()
672
+ link = model .link_by_index (0 )
673
+ errors = []
674
+ root .resolve_auto_inertials (errors , sdfParserConfig )
675
+ self .assertEqual (len (errors ), 0 )
676
+
677
+ self .assertEqual (12000.0 , link .inertial ().mass_matrix ().mass ())
678
+ self .assertEqual (Pose3d .ZERO ,
679
+ link .inertial ().pose ())
680
+ self .assertEqual (Vector3d (9000.0 , 9000.0 , 2000.0 ),
681
+ link .inertial ().mass_matrix ().diagonal_moments ())
682
+
523
683
def test_resolveauto_inertialsCalledWithAutoFalse (self ):
524
684
sdf = "<?xml version=\" 1.0\" ?>" + \
525
685
" <sdf version=\" 1.11\" >" + \
0 commit comments