29 #ifndef HPP_CONSTRAINTS_TOOL_HH
30 #define HPP_CONSTRAINTS_TOOL_HH
32 #include <boost/math/constants/constants.hpp>
34 #include <pinocchio/spatial/se3.hpp>
37 namespace constraints {
39 template <
typename VectorType,
typename MatrixType>
40 static void computeCrossMatrix(
const VectorType& v, MatrixType& m) {
41 m.diagonal().setZero();
59 template <
typename Derived>
61 Eigen::MatrixBase<Derived>
const& result) {
62 Eigen::MatrixBase<Derived>& value =
63 const_cast<Eigen::MatrixBase<Derived>&
>(result);
64 const value_type PI = ::boost::math::constants::pi<value_type>();
71 theta = acos((tr - 1) / 2);
74 if (theta < PI - 1e-2) {
75 const value_type t = ((theta > 1e-6) ? theta / sin(theta) : 1) / 2;
76 value(0) = t * (R(2, 1) - R(1, 2));
77 value(1) = t * (R(0, 2) - R(2, 0));
78 value(2) = t * (R(1, 0) - R(0, 1));
85 const value_type beta = theta * theta / (1 + cphi);
86 const value_type tmp0 = (R(0, 0) + cphi) * beta;
87 const value_type tmp1 = (R(1, 1) + cphi) * beta;
88 const value_type tmp2 = (R(2, 2) + cphi) * beta;
89 value(0) = (R(2, 1) > R(1, 2) ? 1 : -1) * (tmp0 > 0 ? sqrt(tmp0) : 0);
90 value(1) = (R(0, 2) > R(2, 0) ? 1 : -1) * (tmp1 > 0 ? sqrt(tmp1) : 0);
91 value(2) = (R(1, 0) > R(0, 1) ? 1 : -1) * (tmp2 > 0 ? sqrt(tmp2) : 0);
128 template <
typename Derived>
135 const value_type ct = cos(theta), st = sin(theta);
139 Jlog.diagonal().setConstant(theta * st_1mct);
142 Jlog(0, 1) = -log(2);
145 Jlog(2, 0) = -log(1);
146 Jlog(1, 2) = -log(0);
150 const value_type alpha = 1 / (theta * theta) - st_1mct / (2 * theta);
151 Jlog.noalias() += alpha * log * log.transpose();
163 template <
typename Derived>
165 assert(result.size() == 6);
166 Eigen::MatrixBase<Derived>& value =
167 const_cast<Eigen::MatrixBase<Derived>&
>(result);
173 value.segment(3, 3) = r;
175 if (fabs(theta) < 1e-2) {
176 alpha = 1 - theta * theta / 12 - theta * theta * theta * theta / 720;
177 beta = 1. / 12 + theta * theta / 720;
179 alpha = theta * sin(theta) / (2 * (1 - cos(theta)));
180 beta = 1 / (theta * theta) - sin(theta) / (2 * theta * (1 - cos(theta)));
183 computeCrossMatrix(r, rcross);
184 value.segment(0, 3) = alpha * p - .5 * rcross * p + beta * r.dot(p) * r;
187 template <
typename Derived>
189 Eigen::MatrixBase<Derived>& value =
190 const_cast<Eigen::MatrixBase<Derived>&
>(Jlog);
200 if (fabs(theta) < 1e-2) {
201 alpha = 1 - theta * theta / 12 - theta * theta * theta * theta / 720;
202 beta = 1. / 12 + theta * theta / 720;
203 beta_dot_over_theta = 1. / 360.;
205 alpha = theta * sin(theta) / (2 * (1 - cos(theta)));
206 beta = 1 / (theta * theta) - sin(theta) / (2 * theta * (1 - cos(theta)));
207 beta_dot_over_theta =
208 -2 / (theta * theta * theta * theta) +
209 (theta + sin(theta)) / (2 * theta * theta * theta * (1 - cos(theta)));
212 computeCrossMatrix(r, rcross);
213 matrix3_t V(alpha * matrix3_t::Identity() - .5 * rcross +
214 beta * r * r.transpose());
217 computeCrossMatrix(p, pcross);
219 (.5 * pcross + (beta_dot_over_theta * rTp) * r * r.transpose() -
220 (theta * theta * beta_dot_over_theta + 2 * beta) * p * r.transpose() +
221 rTp * beta * matrix3_t::Identity() + beta * r * p.transpose()) *
223 value.block(0, 0, 3, 3) = V * R;
224 value.block(0, 3, 3, 3) = J;
225 Eigen::Block<Derived> b(value.block(3, 0, 3, 3));
227 value.block(3, 3, 3, 3) = Jlog3;
230 template <
typename Derived1,
typename Derived2>
232 Eigen::MatrixBase<Derived2>
const& q) {
233 Derived2& _q =
const_cast<Derived2&
>(q.derived());
235 Eigen::Map<Transform3s::Quaternion> quat(_q.data());
239 template <
typename Derived>
241 Derived& _q =
const_cast<Derived&
>(q.derived());
243 _q.template head<3>() = M.translation();
assert(d.lhs()._blocks()==d.rhs()._blocks())
pinocchio::matrix3_t matrix3_t
Definition: fwd.hh:53
pinocchio::vector3_t vector3_t
Definition: fwd.hh:52
pinocchio::Transform3s Transform3s
Definition: fwd.hh:64
pinocchio::value_type value_type
Definition: fwd.hh:48
Definition: active-set-differentiable-function.hh:36