5 #ifndef __pinocchio_algorithm_contact_solver_utils_hpp__
6 #define __pinocchio_algorithm_contact_solver_utils_hpp__
8 #include "pinocchio/math/fwd.hpp"
9 #include "pinocchio/math/comparison-operators.hpp"
10 #include "pinocchio/algorithm/constraints/coulomb-friction-cone.hpp"
11 #include "pinocchio/algorithm/delassus-operator-base.hpp"
22 typename ConstraintAllocator,
23 typename VectorLikeIn,
24 typename VectorLikeOut>
27 const Eigen::DenseBase<VectorLikeIn> & x,
28 const Eigen::DenseBase<VectorLikeOut> & x_proj_)
30 assert(x.size() == x_proj_.size());
31 Eigen::DenseIndex index = 0;
32 VectorLikeOut & x_proj = x_proj_.const_cast_derived();
33 for (
const auto & cone : cones)
35 x_proj.template segment<3>(index) = cone.project(x.template segment<3>(index));
36 assert(cone.isInside(x_proj.template segment<3>(index), Scalar(1e-12)));
44 typename ConstraintAllocator,
45 typename VectorLikeIn,
46 typename VectorLikeOut>
49 const Eigen::DenseBase<VectorLikeIn> & x,
50 const Eigen::DenseBase<VectorLikeOut> & x_proj_)
52 assert(x.size() == x_proj_.size());
53 Eigen::DenseIndex index = 0;
54 VectorLikeOut & x_proj = x_proj_.const_cast_derived();
55 for (
const auto & cone : cones)
57 x_proj.template segment<3>(index) = cone.dual().project(x.template segment<3>(index));
58 assert(cone.dual().isInside(x_proj.template segment<3>(index), Scalar(1e-12)));
65 typename ConstraintAllocator,
66 typename VectorLikeVelocity,
67 typename VectorLikeForce>
68 Scalar computeConicComplementarity(
70 const Eigen::DenseBase<VectorLikeVelocity> & velocities,
71 const Eigen::DenseBase<VectorLikeForce> & forces)
73 assert(velocities.size() == forces.size());
74 Eigen::DenseIndex index = 0;
75 Scalar complementarity = 0;
76 for (
const auto & cone : cones)
78 const Scalar cone_complementarity = cone.computeConicComplementarity(
79 velocities.template segment<3>(index), forces.template segment<3>(index));
80 complementarity = math::max(complementarity, cone_complementarity);
84 return complementarity;
89 typename ConstraintAllocator,
90 typename VectorLikeIn,
91 typename VectorLikeOut>
92 void computeComplementarityShift(
93 const std::vector<CoulombFrictionConeTpl<Scalar>, ConstraintAllocator> & cones,
94 const Eigen::DenseBase<VectorLikeIn> & velocities,
95 const Eigen::DenseBase<VectorLikeOut> & shift_)
97 assert(velocities.size() == shift_.size());
98 Eigen::DenseIndex index = 0;
99 VectorLikeOut & shift = shift_.const_cast_derived();
100 for (
const auto & cone : cones)
102 shift.template segment<3>(index) =
103 cone.computeNormalCorrection(velocities.template segment<3>(index));
108 template<
typename Scalar,
typename Constra
intAllocator,
typename VectorLikeIn>
109 Scalar computePrimalFeasibility(
110 const std::vector<CoulombFrictionConeTpl<Scalar>, ConstraintAllocator> & cones,
111 const Eigen::DenseBase<VectorLikeIn> & forces)
113 typedef CoulombFrictionConeTpl<Scalar> Cone;
114 typedef typename Cone::Vector3 Vector3;
116 Eigen::DenseIndex index = 0;
118 for (
const auto & cone : cones)
120 const Vector3 df_projected =
121 cone.project(forces.template segment<3>(index)) - forces.template segment<3>(index);
122 norm = math::max(norm, df_projected.norm());
131 typename ConstraintAllocator,
132 typename ForceVector,
133 typename VelocityVector>
134 Scalar computeReprojectionError(
135 const std::vector<CoulombFrictionConeTpl<Scalar>, ConstraintAllocator> & cones,
136 const Eigen::DenseBase<ForceVector> & forces,
137 const Eigen::DenseBase<VelocityVector> & velocities)
139 typedef CoulombFrictionConeTpl<Scalar> Cone;
140 typedef typename Cone::Vector3 Vector3;
142 Eigen::DenseIndex index = 0;
144 for (
const auto & cone : cones)
146 const Vector3 df_projected =
147 forces.template segment<3>(index)
148 - cone.project(forces.template segment<3>(index) - velocities.template segment<3>(index));
149 norm = math::max(norm, df_projected.norm());
void computeDualConeProjection(const std::vector< CoulombFrictionConeTpl< Scalar >, ConstraintAllocator > &cones, const Eigen::DenseBase< VectorLikeIn > &x, const Eigen::DenseBase< VectorLikeOut > &x_proj_)
Project a vector x on the dual of the cones contained in the vector of cones.
void computeConeProjection(const std::vector< CoulombFrictionConeTpl< Scalar >, ConstraintAllocator > &cones, const Eigen::DenseBase< VectorLikeIn > &x, const Eigen::DenseBase< VectorLikeOut > &x_proj_)
Project a vector x on the vector of cones.
Main pinocchio namespace.