Skip to content

Commit c215a78

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

File tree

4 files changed

+31
-31
lines changed

4 files changed

+31
-31
lines changed

examples/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,7 @@ if(BUILD_PYTHON_INTERFACE)
9797
inverse-dynamics-derivatives
9898
model-graph
9999
model-configuration-converter
100-
ellipsoid-joint-kinematics
101-
)
100+
ellipsoid-joint-kinematics)
102101

103102
if(BUILD_WITH_URDF_SUPPORT)
104103
list(

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ namespace pinocchio
112112

113113
}; // struct JointDataEllipsoidTpl
114114

115-
116115
PINOCCHIO_JOINT_CAST_TYPE_SPECIALIZATION(JointModelEllipsoidTpl);
117116
/// \brief Ellipsoid joint - constrains motion to ellipsoid surface with 3-DOF.
118117
///
@@ -193,8 +192,13 @@ namespace pinocchio
193192
/// @param[in] c2, s2 Cosine and sine of q[2]
194193
/// @param[out] data Joint data where M will be stored
195194
void computeSpatialTransform(
196-
const Scalar& c0, const Scalar& s0, const Scalar& c1, const Scalar& s1, const Scalar& c2, const Scalar& s2, JointDataDerived & data) const
197-
const
195+
const Scalar & c0,
196+
const Scalar & s0,
197+
const Scalar & c1,
198+
const Scalar & s1,
199+
const Scalar & c2,
200+
const Scalar & s2,
201+
JointDataDerived & data) const
198202
{
199203
// clang-format off
200204
data.M.rotation() << c1 * c2 , -c1 * s2 , s1 ,

include/pinocchio/multibody/joint/joint-free-flyer.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ namespace pinocchio
256256

257257
}; // struct JointDataFreeFlyerTpl
258258

259-
260259
PINOCCHIO_JOINT_CAST_TYPE_SPECIALIZATION(JointModelFreeFlyerTpl);
261260
/// @brief Free-flyer joint in \f$SE(3)\f$.
262261
///

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

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -267,17 +267,9 @@ namespace pinocchio
267267
{
268268
}
269269

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-
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
{
@@ -350,21 +358,11 @@ namespace pinocchio
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
362+
// defined. The motion subspace is defined in the parent frame, So reversing the joint
363+
// 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)