@@ -127,7 +127,7 @@ namespace pinocchio
127
127
ret.minConfig = Vector::Constant (Nq, -1.01 );
128
128
ret.friction = Vector::Constant (Nv, 0 .);
129
129
ret.damping = Vector::Constant (Nv, 0 .);
130
- ret.armature = armature;
130
+ ret.armature = Vector::Constant (Nv, armature[ 0 ]) ;
131
131
ret.frictionLoss = frictionLoss;
132
132
ret.springStiffness = springStiffness;
133
133
ret.springReference = springReference;
@@ -160,6 +160,10 @@ namespace pinocchio
160
160
ret.springReference .tail (1 ) = range.springReference ;
161
161
ret.springStiffness .conservativeResize (springStiffness.size () + 1 );
162
162
ret.springStiffness .tail (1 ) = range.springStiffness ;
163
+
164
+ ret.armature .conservativeResize (armature.size () + Nv);
165
+ ret.armature .tail (Nv) = range.armature ;
166
+
163
167
return ret;
164
168
}
165
169
@@ -208,7 +212,7 @@ namespace pinocchio
208
212
209
213
value = el.get_optional <double >(" <xmlattr>.armature" );
210
214
if (value)
211
- range.armature = *value;
215
+ range.armature [ 0 ] = *value;
212
216
213
217
// friction loss
214
218
value = el.get_optional <double >(" <xmlattr>.frictionloss" );
@@ -251,7 +255,13 @@ namespace pinocchio
251
255
// Placement
252
256
jointPlacement = currentGraph.convertPosition (el);
253
257
254
- // ChildClass < Class < Real Joint
258
+ // default < ChildClass < Class < Real Joint
259
+ if (currentGraph.mapOfClasses .find (" mujoco_default" ) != currentGraph.mapOfClasses .end ())
260
+ {
261
+ const MjcfClass & classD = currentGraph.mapOfClasses .at (" mujoco_default" );
262
+ if (auto joint_p = classD.classElement .get_child_optional (" joint" ))
263
+ goThroughElement (*joint_p, use_limit, currentGraph.compilerInfo );
264
+ }
255
265
// childClass
256
266
if (currentBody.childClass != " " )
257
267
{
@@ -545,7 +555,13 @@ namespace pinocchio
545
555
else
546
556
throw std::invalid_argument (" Material was given without a name" );
547
557
548
- // Class < Attributes
558
+ // default < Class < Attributes
559
+ if (mapOfClasses.find (" mujoco_default" ) != mapOfClasses.end ())
560
+ {
561
+ const MjcfClass & classD = mapOfClasses.at (" mujoco_default" );
562
+ if (auto mat_p = classD.classElement .get_child_optional (" material" ))
563
+ mat.goThroughElement (*mat_p);
564
+ }
549
565
auto cl_s = el.get_optional <std::string>(" <xmlattr>.class" );
550
566
if (cl_s)
551
567
{
@@ -600,9 +616,10 @@ namespace pinocchio
600
616
}
601
617
}
602
618
603
- void MjcfGraph::parseDefault (ptree & el, const ptree & parent)
619
+ void MjcfGraph::parseDefault (ptree & el, const ptree & parent, const std::string & parentTag )
604
620
{
605
621
boost::optional<std::string> nameClass;
622
+ // Classes
606
623
for (ptree::value_type & v : el)
607
624
{
608
625
if (v.first == " <xmlattr>" )
@@ -619,8 +636,15 @@ namespace pinocchio
619
636
else
620
637
throw std::invalid_argument (" Class does not have a name. Cannot parse model." );
621
638
}
622
- if (v.first == " default" )
623
- parseDefault (v.second , el);
639
+ else if (v.first == " default" )
640
+ parseDefault (v.second , el, v.first );
641
+ else if (parentTag == " mujoco" && v.first != " <xmlattr>" )
642
+ {
643
+ MjcfClass classDefault;
644
+ classDefault.className = " mujoco_default" ;
645
+ classDefault.classElement = el;
646
+ mapOfClasses.insert (std::make_pair (" mujoco_default" , classDefault));
647
+ }
624
648
}
625
649
}
626
650
@@ -808,7 +832,7 @@ namespace pinocchio
808
832
parseCompiler (el.get_child (" compiler" ));
809
833
810
834
if (v.first == " default" )
811
- parseDefault (el.get_child (" default" ), el);
835
+ parseDefault (el.get_child (" default" ), el, " mujoco " );
812
836
813
837
if (v.first == " asset" )
814
838
parseAsset (el.get_child (" asset" ));
@@ -898,7 +922,9 @@ namespace pinocchio
898
922
899
923
// Add armature info
900
924
JointIndex j_id = urdfVisitor.getJointId (joint.jointName );
901
- urdfVisitor.model .armature [static_cast <Eigen::Index>(j_id) - 1 ] = range.armature ;
925
+ urdfVisitor.model .armature .segment (
926
+ urdfVisitor.model .joints [j_id].idx_v (), urdfVisitor.model .joints [j_id].nv ()) =
927
+ range.armature ;
902
928
}
903
929
904
930
void MjcfGraph::fillModel (const std::string & nameOfBody)
@@ -912,7 +938,7 @@ namespace pinocchio
912
938
if (!currentBody.bodyParent .empty ())
913
939
parentFrameId = urdfVisitor.getBodyId (currentBody.bodyParent );
914
940
915
- const Frame & frame = urdfVisitor.model .frames [parentFrameId];
941
+ Frame frame = urdfVisitor.model .frames [parentFrameId];
916
942
// get body pose in body parent
917
943
const SE3 bodyPose = currentBody.bodyPlacement ;
918
944
Inertia inert = currentBody.bodyInertia ;
@@ -1007,7 +1033,9 @@ namespace pinocchio
1007
1033
FrameIndex jointFrameId = urdfVisitor.model .addJointFrame (joint_id, (int )parentFrameId);
1008
1034
urdfVisitor.appendBodyToJoint (jointFrameId, inert, bodyInJoint, nameOfBody);
1009
1035
1010
- urdfVisitor.model .armature [static_cast <Eigen::Index>(joint_id) - 1 ] = rangeCompo.armature ;
1036
+ urdfVisitor.model .armature .segment (
1037
+ urdfVisitor.model .joints [joint_id].idx_v (), urdfVisitor.model .joints [joint_id].nv ()) =
1038
+ rangeCompo.armature ;
1011
1039
}
1012
1040
1013
1041
FrameIndex previousFrameId = urdfVisitor.model .frames .size ();
0 commit comments