Skip to content

Commit 56cdde9

Browse files
author
ipuch
committed
refactor(model-graph-algo): AddJointBetweenBodies
1 parent ae3a65c commit 56cdde9

File tree

2 files changed

+25
-28
lines changed

2 files changed

+25
-28
lines changed

include/pinocchio/multibody/joint/joint-ellipsoid.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ namespace pinocchio
194194
/// @param[out] data Joint data where M will be stored
195195
void computeSpatialTransform(
196196
const Scalar& c0, const Scalar& s0, const Scalar& c1, const Scalar& s1, const Scalar& c2, const Scalar& s2, JointDataDerived & data) const
197-
const
198197
{
199198
// clang-format off
200199
data.M.rotation() << c1 * c2 , -c1 * s2 , s1 ,

src/parsers/graph/model-graph-algo.cpp

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)