5 #ifndef __pinocchio_multibody_liegroup_cartesian_product_operation_hpp__ 6 #define __pinocchio_multibody_liegroup_cartesian_product_operation_hpp__ 8 #include <pinocchio/multibody/liegroup/liegroup-base.hpp> 12 template<
int dim1,
int dim2>
15 enum { value = dim1 + dim2 };
21 enum { value = Eigen::Dynamic };
27 enum { value = Eigen::Dynamic };
30 template<
typename LieGroup1,
typename LieGroup2>
33 template<
typename LieGroup1,
typename LieGroup2>
43 template<
typename LieGroup1,
typename LieGroup2>
57 return lg1_.nq () + lg2_.nq ();
63 return lg1_.nv () + lg2_.nv ();
70 Qo1(n) = lg1_.neutral ();
71 Qo2(n) = lg2_.neutral ();
75 std::string
name ()
const 77 std::ostringstream oss; oss << lg1_.name () <<
"*" << lg2_.name ();
81 template <
class ConfigL_t,
class ConfigR_t,
class Tangent_t>
82 void difference_impl(
const Eigen::MatrixBase<ConfigL_t> & q0,
83 const Eigen::MatrixBase<ConfigR_t> & q1,
84 const Eigen::MatrixBase<Tangent_t> & d)
const 86 lg1_.difference(Q1(q0), Q1(q1), Vo1(d));
87 lg2_.difference(Q2(q0), Q2(q1), Vo2(d));
90 template <ArgumentPosition arg,
class ConfigL_t,
class ConfigR_t,
class JacobianOut_t>
91 void dDifference_impl(
const Eigen::MatrixBase<ConfigL_t> & q0,
92 const Eigen::MatrixBase<ConfigR_t> & q1,
93 const Eigen::MatrixBase<JacobianOut_t> & J)
const 98 lg1_.template dDifference<arg> (Q1(q0), Q1(q1), J11(J));
99 lg2_.template dDifference<arg> (Q2(q0), Q2(q1), J22(J));
102 template <
class ConfigIn_t,
class Velocity_t,
class ConfigOut_t>
103 void integrate_impl(
const Eigen::MatrixBase<ConfigIn_t> & q,
104 const Eigen::MatrixBase<Velocity_t> & v,
105 const Eigen::MatrixBase<ConfigOut_t> & qout)
const 107 lg1_.integrate(Q1(q), V1(v), Qo1(qout));
108 lg2_.integrate(Q2(q), V2(v), Qo2(qout));
111 template <
class Config_t,
class Jacobian_t>
112 void integrateCoeffWiseJacobian_impl(
const Eigen::MatrixBase<Config_t> & q,
113 const Eigen::MatrixBase<Jacobian_t> & J)
const 115 assert(J.rows() ==
nq() && J.cols() ==
nv() &&
"J is not of the right dimension");
116 Jacobian_t & J_ = PINOCCHIO_EIGEN_CONST_CAST(Jacobian_t,J);
117 J_.topRightCorner(lg1_.nq(),lg2_.nv()).setZero();
118 J_.bottomLeftCorner(lg2_.nq(),lg1_.nv()).setZero();
120 lg1_.integrateCoeffWiseJacobian(Q1(q),
121 J_.topLeftCorner(lg1_.nq(),lg1_.nv()));
122 lg2_.integrateCoeffWiseJacobian(Q2(q), J_.bottomRightCorner(lg2_.nq(),lg2_.nv()));
125 template <
class Config_t,
class Tangent_t,
class JacobianOut_t>
126 void dIntegrate_dq_impl(
const Eigen::MatrixBase<Config_t > & q,
127 const Eigen::MatrixBase<Tangent_t> & v,
128 const Eigen::MatrixBase<JacobianOut_t> & J,
129 const AssignmentOperatorType op=SETTO)
const 136 lg1_.dIntegrate_dq(Q1(q), V1(v), J11(J),SETTO);
137 lg2_.dIntegrate_dq(Q2(q), V2(v), J22(J),SETTO);
140 lg1_.dIntegrate_dq(Q1(q), V1(v), J11(J),ADDTO);
141 lg2_.dIntegrate_dq(Q2(q), V2(v), J22(J),ADDTO);
144 lg1_.dIntegrate_dq(Q1(q), V1(v), J11(J),RMTO);
145 lg2_.dIntegrate_dq(Q2(q), V2(v), J22(J),RMTO);
148 assert(
false &&
"Wrong Op requesed value");
153 template <
class Config_t,
class Tangent_t,
class JacobianOut_t>
154 void dIntegrate_dv_impl(
const Eigen::MatrixBase<Config_t > & q,
155 const Eigen::MatrixBase<Tangent_t> & v,
156 const Eigen::MatrixBase<JacobianOut_t> & J,
157 const AssignmentOperatorType op=SETTO)
const 164 lg1_.dIntegrate_dv(Q1(q), V1(v), J11(J),SETTO);
165 lg2_.dIntegrate_dv(Q2(q), V2(v), J22(J),SETTO);
168 lg1_.dIntegrate_dv(Q1(q), V1(v), J11(J),ADDTO);
169 lg2_.dIntegrate_dv(Q2(q), V2(v), J22(J),ADDTO);
172 lg1_.dIntegrate_dv(Q1(q), V1(v), J11(J),RMTO);
173 lg2_.dIntegrate_dv(Q2(q), V2(v), J22(J),RMTO);
176 assert(
false &&
"Wrong Op requesed value");
181 template <
class Config_t,
class Tangent_t,
class JacobianIn_t,
class JacobianOut_t>
182 void dIntegrateTransport_dq_impl(
const Eigen::MatrixBase<Config_t > & q,
183 const Eigen::MatrixBase<Tangent_t> & v,
184 const Eigen::MatrixBase<JacobianIn_t> & J_in,
185 const Eigen::MatrixBase<JacobianOut_t> & J_out)
const 187 JacobianOut_t& Jout = PINOCCHIO_EIGEN_CONST_CAST(JacobianOut_t,J_out);
188 JacobianOut_t& Jin = PINOCCHIO_EIGEN_CONST_CAST(JacobianIn_t,J_in);
189 lg1_.dIntegrateTransport_dq(Q1(q), V1(v), Jin.template topRows<LieGroup1::NV>(),Jout.template topRows<LieGroup1::NV>());
190 lg2_.dIntegrateTransport_dq(Q2(q), V2(v), Jin.template bottomRows<LieGroup2::NV>(),Jout.template bottomRows<LieGroup2::NV>());
193 template <
class Config_t,
class Tangent_t,
class JacobianIn_t,
class JacobianOut_t>
194 void dIntegrateTransport_dv_impl(
const Eigen::MatrixBase<Config_t > & q,
195 const Eigen::MatrixBase<Tangent_t> & v,
196 const Eigen::MatrixBase<JacobianIn_t> & J_in,
197 const Eigen::MatrixBase<JacobianOut_t> & J_out)
const 199 JacobianOut_t& Jout = PINOCCHIO_EIGEN_CONST_CAST(JacobianOut_t,J_out);
200 JacobianOut_t& Jin = PINOCCHIO_EIGEN_CONST_CAST(JacobianIn_t,J_in);
201 lg1_.dIntegrateTransport_dv(Q1(q), V1(v), Jin.template topRows<LieGroup1::NV>(),Jout.template topRows<LieGroup1::NV>());
202 lg2_.dIntegrateTransport_dv(Q2(q), V2(v), Jin.template bottomRows<LieGroup2::NV>(),Jout.template bottomRows<LieGroup2::NV>());
206 template <
class Config_t,
class Tangent_t,
class Jacobian_t>
207 void dIntegrateTransport_dq_impl(
const Eigen::MatrixBase<Config_t > & q,
208 const Eigen::MatrixBase<Tangent_t> & v,
209 const Eigen::MatrixBase<Jacobian_t> & Jin)
const 211 Jacobian_t& J = PINOCCHIO_EIGEN_CONST_CAST(Jacobian_t,Jin);
212 lg1_.dIntegrateTransport_dq(Q1(q), V1(v), J.template topRows<LieGroup1::NV>());
213 lg2_.dIntegrateTransport_dq(Q2(q), V2(v), J.template bottomRows<LieGroup2::NV>());
216 template <
class Config_t,
class Tangent_t,
class Jacobian_t>
217 void dIntegrateTransport_dv_impl(
const Eigen::MatrixBase<Config_t > & q,
218 const Eigen::MatrixBase<Tangent_t> & v,
219 const Eigen::MatrixBase<Jacobian_t> & Jin)
const 221 Jacobian_t& J = PINOCCHIO_EIGEN_CONST_CAST(Jacobian_t,Jin);
222 lg1_.dIntegrateTransport_dv(Q1(q), V1(v), J.template topRows<LieGroup1::NV>());
223 lg2_.dIntegrateTransport_dv(Q2(q), V2(v), J.template bottomRows<LieGroup2::NV>());
226 template <
class ConfigL_t,
class ConfigR_t>
227 Scalar squaredDistance_impl(
const Eigen::MatrixBase<ConfigL_t> & q0,
228 const Eigen::MatrixBase<ConfigR_t> & q1)
const 230 return lg1_.squaredDistance(Q1(q0), Q1(q1))
231 + lg2_.squaredDistance(Q2(q0), Q2(q1));
234 template <
class Config_t>
235 void normalize_impl (
const Eigen::MatrixBase<Config_t>& qout)
const 237 lg1_.normalize(Qo1(qout));
238 lg2_.normalize(Qo2(qout));
241 template <
class Config_t>
242 void random_impl (
const Eigen::MatrixBase<Config_t>& qout)
const 244 lg1_.random(Qo1(qout));
245 lg2_.random(Qo2(qout));
248 template <
class ConfigL_t,
class ConfigR_t,
class ConfigOut_t>
249 void randomConfiguration_impl(
const Eigen::MatrixBase<ConfigL_t> & lower,
250 const Eigen::MatrixBase<ConfigR_t> & upper,
251 const Eigen::MatrixBase<ConfigOut_t> & qout)
254 lg1_.randomConfiguration(Q1(lower), Q1(upper), Qo1(qout));
255 lg2_.randomConfiguration(Q2(lower), Q2(upper), Qo2(qout));
258 template <
class ConfigL_t,
class ConfigR_t>
259 bool isSameConfiguration_impl(
const Eigen::MatrixBase<ConfigL_t> & q0,
260 const Eigen::MatrixBase<ConfigR_t> & q1,
261 const Scalar & prec)
const 263 return lg1_.isSameConfiguration(Q1(q0), Q1(q1), prec)
264 && lg2_.isSameConfiguration(Q2(q0), Q2(q1), prec);
272 #if EIGEN_VERSION_AT_LEAST(3,2,1) 273 # define REMOVE_IF_EIGEN_TOO_LOW(x) x 275 # define REMOVE_IF_EIGEN_TOO_LOW(x) 278 template <
typename Config >
typename Config ::template ConstFixedSegmentReturnType<LieGroup1::NQ>::Type Q1 (
const Eigen::MatrixBase<Config >& q)
const {
return q.derived().template head<LieGroup1::NQ>(REMOVE_IF_EIGEN_TOO_LOW(lg1_.nq())); }
279 template <
typename Config >
typename Config ::template ConstFixedSegmentReturnType<LieGroup2::NQ>::Type Q2 (
const Eigen::MatrixBase<Config >& q)
const {
return q.derived().template tail<LieGroup2::NQ>(REMOVE_IF_EIGEN_TOO_LOW(lg2_.nq())); }
280 template <
typename Tangent>
typename Tangent::template ConstFixedSegmentReturnType<LieGroup1::NV>::Type V1 (
const Eigen::MatrixBase<Tangent>& v)
const {
return v.derived().template head<LieGroup1::NV>(REMOVE_IF_EIGEN_TOO_LOW(lg1_.nv())); }
281 template <
typename Tangent>
typename Tangent::template ConstFixedSegmentReturnType<LieGroup2::NV>::Type V2 (
const Eigen::MatrixBase<Tangent>& v)
const {
return v.derived().template tail<LieGroup2::NV>(REMOVE_IF_EIGEN_TOO_LOW(lg2_.nv())); }
283 template <
typename Config >
typename Config ::template FixedSegmentReturnType<LieGroup1::NQ>::Type Qo1 (
const Eigen::MatrixBase<Config >& q)
const {
return PINOCCHIO_EIGEN_CONST_CAST(Config,q).template head<LieGroup1::NQ>(REMOVE_IF_EIGEN_TOO_LOW(lg1_.nq())); }
284 template <
typename Config >
typename Config ::template FixedSegmentReturnType<LieGroup2::NQ>::Type Qo2 (
const Eigen::MatrixBase<Config >& q)
const {
return PINOCCHIO_EIGEN_CONST_CAST(Config,q).template tail<LieGroup2::NQ>(REMOVE_IF_EIGEN_TOO_LOW(lg2_.nq())); }
285 template <
typename Tangent>
typename Tangent::template FixedSegmentReturnType<LieGroup1::NV>::Type Vo1 (
const Eigen::MatrixBase<Tangent>& v)
const {
return PINOCCHIO_EIGEN_CONST_CAST(Tangent,v).template head<LieGroup1::NV>(REMOVE_IF_EIGEN_TOO_LOW(lg1_.nv())); }
286 template <
typename Tangent>
typename Tangent::template FixedSegmentReturnType<LieGroup2::NV>::Type Vo2 (
const Eigen::MatrixBase<Tangent>& v)
const {
return PINOCCHIO_EIGEN_CONST_CAST(Tangent,v).template tail<LieGroup2::NV>(REMOVE_IF_EIGEN_TOO_LOW(lg2_.nv())); }
288 template <
typename Jac> Eigen::Block<Jac, LieGroup1::NV, LieGroup1::NV> J11 (
const Eigen::MatrixBase<Jac>& J)
const {
return PINOCCHIO_EIGEN_CONST_CAST(Jac,J).template topLeftCorner<LieGroup1::NV, LieGroup1::NV>(lg1_.nv(),lg1_.nv()); }
289 template <
typename Jac> Eigen::Block<Jac, LieGroup1::NV, LieGroup2::NV> J12 (
const Eigen::MatrixBase<Jac>& J)
const {
return PINOCCHIO_EIGEN_CONST_CAST(Jac,J).template topRightCorner<LieGroup1::NV, LieGroup2::NV>(lg1_.nv(),lg2_.nv()); }
290 template <
typename Jac> Eigen::Block<Jac, LieGroup2::NV, LieGroup1::NV> J21 (
const Eigen::MatrixBase<Jac>& J)
const {
return PINOCCHIO_EIGEN_CONST_CAST(Jac,J).template bottomLeftCorner<LieGroup2::NV, LieGroup1::NV>(lg2_.nv(),lg1_.nv()); }
291 template <
typename Jac> Eigen::Block<Jac, LieGroup2::NV, LieGroup2::NV> J22 (
const Eigen::MatrixBase<Jac>& J)
const {
return PINOCCHIO_EIGEN_CONST_CAST(Jac,J).template bottomRightCorner<LieGroup2::NV, LieGroup2::NV>(lg2_.nv(),lg2_.nv()); }
292 #undef REMOVE_IF_EIGEN_TOO_LOW 298 #endif // ifndef __pinocchio_multibody_liegroup_cartesian_product_operation_hpp__ int nv(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointNvVisitor to get the dimension of the joint tangent space...
int nq(const JointModelTpl< Scalar, Options, JointCollectionTpl > &jmodel)
Visit a JointModelTpl through JointNqVisitor to get the dimension of the joint configuration space...
std::string name(const LieGroupGenericTpl< LieGroupCollection > &lg)
Visit a LieGroupVariant to get the name of it.
Main pinocchio namespace.
void neutral(const ModelTpl< Scalar, Options, JointCollectionTpl > &model, const Eigen::MatrixBase< ReturnType > &qout)
Return the neutral configuration element related to the model configuration space.
Common traits structure to fully define base classes for CRTP.