aligator  0.9.0
A primal-dual augmented Lagrangian-type solver for nonlinear trajectory optimization.
Loading...
Searching...
No Matches
contact-force.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "./fwd.hpp"
5
6#include <Eigen/src/Core/util/Constants.h>
7#include <proxsuite-nlp/modelling/spaces/multibody.hpp>
8
9#ifdef ALIGATOR_PINOCCHIO_V3
10#include <pinocchio/algorithm/proximal.hpp>
11
12namespace aligator {
13
14template <typename Scalar> struct ContactForceDataTpl;
15
21template <typename _Scalar>
22struct ContactForceResidualTpl : StageFunctionTpl<_Scalar> {
23public:
24 using Scalar = _Scalar;
26 using Base = StageFunctionTpl<Scalar>;
27 using BaseData = typename Base::Data;
28 using Model = pinocchio::ModelTpl<Scalar>;
29 using SE3 = pinocchio::SE3Tpl<Scalar>;
30 using Data = ContactForceDataTpl<Scalar>;
31 using RigidConstraintModelVector = PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(
32 pinocchio::RigidConstraintModel);
33 using RigidConstraintDataVector =
34 PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(pinocchio::RigidConstraintData);
35 using ProxSettings = pinocchio::ProximalSettingsTpl<Scalar>;
36 using Vector3or6 = Eigen::Matrix<Scalar, -1, 1, Eigen::ColMajor, 6, 1>;
37
38 Model pin_model_;
39 MatrixXs actuation_matrix_;
40 RigidConstraintModelVector constraint_models_;
41 ProxSettings prox_settings_;
42 Vector3or6 fref_;
43 long force_size_;
44 int contact_id_;
45
46 ContactForceResidualTpl(const int ndx, const Model &model,
47 const MatrixXs &actuation,
48 const RigidConstraintModelVector &constraint_models,
49 const ProxSettings &prox_settings,
50 const Vector3or6 &fref,
51 const std::string &contact_name)
52 : Base(ndx, (int)actuation.cols(), fref.size()), pin_model_(model),
53 actuation_matrix_(actuation), constraint_models_(constraint_models),
54 prox_settings_(prox_settings), fref_(fref), force_size_(fref.size()) {
55 if (model.nv != actuation.rows()) {
57 fmt::format("actuation matrix should have number of rows = pinocchio "
58 "model nv ({} and {}).",
59 actuation.rows(), model.nv));
60 }
61 contact_id_ = -1;
62 for (std::size_t i = 0; i < constraint_models.size(); i++) {
63 if (constraint_models[i].name == contact_name) {
64 contact_id_ = (int)i;
65 }
66 }
67 if (contact_id_ == -1) {
69 "Contact name is not included in constraint models");
70 }
71 }
72
73 const Vector3or6 &getReference() const { return fref_; }
74 void setReference(const Eigen::Ref<const Vector3or6> &fnew) { fref_ = fnew; }
75
76 void evaluate(const ConstVectorRef &x, const ConstVectorRef &u,
77 BaseData &data) const;
78
79 void computeJacobians(const ConstVectorRef &, const ConstVectorRef &,
80 BaseData &data) const;
81
82 shared_ptr<BaseData> createData() const {
83 return std::make_shared<Data>(this);
84 }
85};
86
87template <typename Scalar>
88struct ContactForceDataTpl : StageFunctionDataTpl<Scalar> {
89 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
90 using Base = StageFunctionDataTpl<Scalar>;
91 using PinData = pinocchio::DataTpl<Scalar>;
92 using VectorXs = typename math_types<Scalar>::VectorXs;
93 using MatrixXs = typename math_types<Scalar>::MatrixXs;
94 using RigidConstraintDataVector =
95 PINOCCHIO_STD_VECTOR_WITH_EIGEN_ALLOCATOR(pinocchio::RigidConstraintData);
96
98 PinData pin_data_;
99 VectorXs tau_;
100
101 RigidConstraintDataVector constraint_datas_;
102 pinocchio::ProximalSettingsTpl<Scalar> settings;
103
104 ContactForceDataTpl(const ContactForceResidualTpl<Scalar> *model);
105};
106
107} // namespace aligator
108
109#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
110#include "aligator/modelling/multibody/contact-force.txx"
111#endif
112
113#endif // ALIGATOR_PINOCCHIO_V3
#define ALIGATOR_RUNTIME_ERROR(...)
Definition exceptions.hpp:7
#define ALIGATOR_DOMAIN_ERROR(msg)
Base definitions for ternary functions.
#define ALIGATOR_DYNAMIC_TYPEDEFS(Scalar)
Definition math.hpp:8
pinocchio::DataTpl< Scalar, Options > PinData
Definition context.hpp:10
Main package namespace.