3#ifdef ALIGATOR_PINOCCHIO_V3
8#include <Eigen/src/Core/util/Constants.h>
9#include <proxsuite-nlp/modelling/spaces/multibody.hpp>
10#include <pinocchio/algorithm/proximal.hpp>
14template <
typename Scalar>
struct ContactForceDataTpl;
21template <
typename _Scalar>
22struct ContactForceResidualTpl : StageFunctionTpl<_Scalar> {
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>;
39 MatrixXs actuation_matrix_;
40 RigidConstraintModelVector constraint_models_;
41 ProxSettings prox_settings_;
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));
62 for (std::size_t i = 0; i < constraint_models.size(); i++) {
63 if (constraint_models[i].name == contact_name) {
67 if (contact_id_ == -1) {
69 "Contact name is not included in constraint models");
73 const Vector3or6 &getReference()
const {
return fref_; }
74 void setReference(
const Eigen::Ref<const Vector3or6> &fnew) { fref_ = fnew; }
76 void evaluate(
const ConstVectorRef &x,
const ConstVectorRef &u,
77 BaseData &data)
const;
79 void computeJacobians(
const ConstVectorRef &,
const ConstVectorRef &,
80 BaseData &data)
const;
82 shared_ptr<BaseData> createData()
const {
83 return std::make_shared<Data>(
this);
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);
101 RigidConstraintDataVector constraint_datas_;
102 pinocchio::ProximalSettingsTpl<Scalar> settings;
104 ContactForceDataTpl(
const ContactForceResidualTpl<Scalar> *model);
109#ifdef ALIGATOR_ENABLE_TEMPLATE_INSTANTIATION
110#include "aligator/modelling/multibody/contact-force.txx"
#define ALIGATOR_RUNTIME_ERROR(...)
#define ALIGATOR_DOMAIN_ERROR(msg)
Base definitions for ternary functions.
#define ALIGATOR_DYNAMIC_TYPEDEFS(Scalar)
pinocchio::DataTpl< Scalar, Options > PinData