@@ -266,18 +266,10 @@ namespace pinocchio
266266 , model(model_)
267267 {
268268 }
269-
270- template <typename JointGraph, typename FrameGraph>
271- void operator ()(const JointGraph & /* joint*/ , const FrameGraph & /* f_*/ )
272- {
273- PINOCCHIO_THROW_PRETTY (
274- std::invalid_argument,
275- " Graph - Invalid joint between non body frames. Non body frames can "
276- " only be added with Fixed joint" );
277- }
278-
269+
270+ // Default implementation for adding a joint between two body frames
279271 template <typename JointGraph>
280- void operator () (const JointGraph & joint, const BodyFrame & b_f)
272+ void addJointBetweenBodies (const JointGraph & joint, const BodyFrame & b_f)
281273 {
282274 if (boost::get<BodyFrame>(&source_vertex.frame ) == nullptr )
283275 {
@@ -295,14 +287,30 @@ namespace pinocchio
295287 edge.jlimit .friction , edge.jlimit .damping );
296288
297289 model.addJointFrame (j_id);
298- model.appendBodyToJoint (j_id, b_f.inertia ); // check this
290+ model.appendBodyToJoint (j_id, b_f.inertia );
299291 model.addBodyFrame (target_vertex.name , j_id, body_pose);
300292
301293 // armature
302294 model.armature .segment (model.joints [j_id].idx_v (), model.joints [j_id].nv ()) =
303295 edge.jlimit .armature ;
304296 }
305297
298+ template <typename JointGraph, typename FrameGraph>
299+ void operator ()(const JointGraph & /* joint*/ , const FrameGraph & /* f_*/ )
300+ {
301+ PINOCCHIO_THROW_PRETTY (
302+ std::invalid_argument,
303+ " Graph - Invalid joint between non body frames. Non body frames can "
304+ " only be added with Fixed joint" );
305+ }
306+
307+ template <typename JointGraph>
308+ void operator ()(const JointGraph & joint, const BodyFrame & b_f)
309+ {
310+ // Call default implementation
311+ addJointBetweenBodies (joint, b_f);
312+ }
313+
306314 template <typename FrameGraph>
307315 void operator ()(const JointFixed & joint, const FrameGraph & f_)
308316 {
@@ -344,27 +352,17 @@ namespace pinocchio
344352 model.appendBodyToJoint (j_id, b_f.inertia ); // check this
345353 model.addBodyFrame (target_vertex.name , j_id, body_pose);
346354 }
347-
355+
348356 void operator ()(const JointEllipsoid & joint, const BodyFrame & b_f)
349357 {
350358 if (!edge.forward )
351359 PINOCCHIO_THROW_PRETTY (
352360 std::invalid_argument, " Graph - JointEllipsoid cannot be reversed yet." );
361+ // The ellipsoid joint cannot be reversed because of the way the motion subspace is defined.
362+ // The motion subspace is defined in the parent frame,
363+ // So reversing the joint would require to change the motion subspace accordingly.
353364
354- if (boost::get<BodyFrame>(&source_vertex.frame ) == nullptr )
355- PINOCCHIO_THROW_PRETTY (
356- std::invalid_argument, " Graph - Invalid joint between a body and a non body frame." );
357-
358- const SE3 & joint_pose = edge.source_to_joint ;
359- const SE3 & body_pose = edge.joint_to_target ;
360-
361- const Frame previous_body = model.frames [model.getFrameId (source_vertex.name , BODY)];
362- JointIndex j_id = model.addJoint (
363- previous_body.parentJoint , cjm (joint), previous_body.placement * joint_pose, edge.name );
364-
365- model.addJointFrame (j_id);
366- model.appendBodyToJoint (j_id, b_f.inertia ); // check this
367- model.addBodyFrame (target_vertex.name , j_id, body_pose);
365+ addJointBetweenBodies (joint, b_f);
368366 }
369367
370368 void operator ()(const JointFixed & joint, const BodyFrame & b_f)
0 commit comments