aligator  0.9.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
constrained-rnea.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "./fwd.hpp"
4#include "aligator/fwd.hpp"
5
6#include <pinocchio/algorithm/compute-all-terms.hpp>
7#include <pinocchio/algorithm/contact-jacobian.hpp>
8
9#include <Eigen/LU>
10
11namespace aligator {
12
13namespace {
14using pinocchio::DataTpl;
15using pinocchio::ModelTpl;
16using pinocchio::RigidConstraintDataTpl;
17using pinocchio::RigidConstraintModelTpl;
18} // namespace
19
20template <typename Scalar, typename ConfigType, typename VelType,
21 typename MatrixType, typename OutType, int Options>
23 const ModelTpl<Scalar, Options> &model, DataTpl<Scalar, Options> &data,
24 const Eigen::MatrixBase<ConfigType> &q, Eigen::MatrixBase<VelType> const &v,
25 const Eigen::MatrixBase<MatrixType> &actMatrix,
26 const StdVectorEigenAligned<RigidConstraintModelTpl<Scalar, Options>>
27 &constraint_models,
28 StdVectorEigenAligned<RigidConstraintDataTpl<Scalar, Options>>
29 &constraint_datas,
30 const Eigen::MatrixBase<OutType> &res_) {
31 namespace pin = pinocchio;
32 using MatrixXs = Eigen::Matrix<Scalar, -1, -1>;
33 assert(constraint_models.size() == constraint_datas.size() &&
34 "constraint_models and constraint_datas do not have the same size");
35
36 OutType &res = res_.const_cast_derived();
37
38 long nu = actMatrix.cols();
39 long nv = model.nv;
40 assert(nv == actMatrix.rows() && "Actuation matrix dimension inconsistent.");
41
42 pin::computeAllTerms(model, data, q, v);
43 const auto &nle = data.nle;
44
45 int d = 0;
46 for (size_t k = 0; k < constraint_models.size(); ++k) {
47 d += (int)constraint_models[k].size();
48 }
49
50 assert(res.size() == nu + d);
51 MatrixXs work(nv, nu + d);
52
53 work.leftCols(nu) = actMatrix;
54 auto JacT = work.rightCols(d);
55 pin::getConstraintsJacobian(model, data, constraint_models, constraint_datas,
56 JacT.transpose());
57 JacT = -JacT;
58
59 Eigen::ColPivHouseholderQR<MatrixXs> qr(work);
60
61 res = qr.solve(nle);
62}
63
64} // namespace aligator
65
66#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
67#include "./constrained-rnea.txx"
68#endif
Forward declarations.
Main package namespace.
void underactuatedConstrainedInverseDynamics(const ModelTpl< Scalar, Options > &model, DataTpl< Scalar, Options > &data, const Eigen::MatrixBase< ConfigType > &q, Eigen::MatrixBase< VelType > const &v, const Eigen::MatrixBase< MatrixType > &actMatrix, const StdVectorEigenAligned< RigidConstraintModelTpl< Scalar, Options > > &constraint_models, StdVectorEigenAligned< RigidConstraintDataTpl< Scalar, Options > > &constraint_datas, const Eigen::MatrixBase< OutType > &res_)