9 #ifndef CROCODDYL_MULTIBODY_ACTIONS_FREE_INVDYN_HPP_
10 #define CROCODDYL_MULTIBODY_ACTIONS_FREE_INVDYN_HPP_
14 #include "crocoddyl/core/actuation-base.hpp"
15 #include "crocoddyl/core/constraints/constraint-manager.hpp"
16 #include "crocoddyl/core/costs/cost-sum.hpp"
17 #include "crocoddyl/core/diff-action-base.hpp"
18 #include "crocoddyl/core/residual-base.hpp"
19 #include "crocoddyl/core/utils/exception.hpp"
20 #include "crocoddyl/multibody/data/multibody.hpp"
21 #include "crocoddyl/multibody/fwd.hpp"
22 #include "crocoddyl/multibody/states/multibody.hpp"
41 template <
typename _Scalar>
45 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
47 typedef _Scalar Scalar;
58 typedef typename MathBase::VectorXs VectorXs;
71 boost::shared_ptr<StateMultibody> state,
72 boost::shared_ptr<ActuationModelAbstract> actuation,
73 boost::shared_ptr<CostModelSum> costs);
84 boost::shared_ptr<StateMultibody> state,
85 boost::shared_ptr<ActuationModelAbstract> actuation,
86 boost::shared_ptr<CostModelSum> costs,
87 boost::shared_ptr<ConstraintModelManager> constraints);
101 const boost::shared_ptr<DifferentialActionDataAbstract>& data,
102 const Eigen::Ref<const VectorXs>& x,
const Eigen::Ref<const VectorXs>& u);
110 const boost::shared_ptr<DifferentialActionDataAbstract>& data,
111 const Eigen::Ref<const VectorXs>& x);
127 const boost::shared_ptr<DifferentialActionDataAbstract>& data,
128 const Eigen::Ref<const VectorXs>& x,
const Eigen::Ref<const VectorXs>& u);
136 const boost::shared_ptr<DifferentialActionDataAbstract>& data,
137 const Eigen::Ref<const VectorXs>& x);
144 virtual boost::shared_ptr<DifferentialActionDataAbstract>
createData();
151 const boost::shared_ptr<DifferentialActionDataAbstract>& data);
167 const boost::shared_ptr<DifferentialActionDataAbstract>& data,
168 Eigen::Ref<VectorXs> u,
const Eigen::Ref<const VectorXs>& x,
169 const std::size_t maxiter = 100,
const Scalar tol = Scalar(1e-9));
199 const boost::shared_ptr<CostModelSum>&
get_costs()
const;
216 virtual void print(std::ostream& os)
const;
227 void init(
const boost::shared_ptr<StateMultibody>& state);
228 boost::shared_ptr<ActuationModelAbstract> actuation_;
229 boost::shared_ptr<CostModelSum> costs_;
230 boost::shared_ptr<ConstraintModelManager> constraints_;
231 pinocchio::ModelTpl<Scalar>& pinocchio_;
248 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
250 typedef _Scalar Scalar;
257 typedef typename MathBase::VectorXs VectorXs;
258 typedef typename MathBase::MatrixXs MatrixXs;
267 const std::size_t nu)
268 :
Base(state, state->get_nv() - nu, state->get_nv(), true, true, true),
279 virtual void calc(
const boost::shared_ptr<ResidualDataAbstract>& data,
280 const Eigen::Ref<const VectorXs>&,
281 const Eigen::Ref<const VectorXs>&) {
285 std::size_t nrow = 0;
286 for (std::size_t k = 0;
287 k < static_cast<std::size_t>(d->
actuation->tau_set.size()); ++k) {
299 virtual void calc(
const boost::shared_ptr<ResidualDataAbstract>& data,
300 const Eigen::Ref<const VectorXs>&) {
311 virtual void calcDiff(
const boost::shared_ptr<ResidualDataAbstract>& data,
312 const Eigen::Ref<const VectorXs>&,
313 const Eigen::Ref<const VectorXs>&) {
316 std::size_t nrow = 0;
317 const std::size_t nv =
state_->get_nv();
318 d->dtau_dx.leftCols(nv) = d->
pinocchio->dtau_dq;
319 d->dtau_dx.rightCols(nv) = d->
pinocchio->dtau_dv;
321 for (std::size_t k = 0;
322 k < static_cast<std::size_t>(d->
actuation->tau_set.size()); ++k) {
324 d->
Rx.row(nrow) = d->dtau_dx.row(k);
336 virtual void calcDiff(
const boost::shared_ptr<ResidualDataAbstract>& data,
337 const Eigen::Ref<const VectorXs>&) {
349 return boost::allocate_shared<typename Data::ResidualDataActuation>(
350 Eigen::aligned_allocator<typename Data::ResidualDataActuation>(),
359 virtual void print(std::ostream& os)
const {
360 os <<
"ResidualModelActuation {nx=" <<
state_->get_nx()
361 <<
", ndx=" <<
state_->get_ndx() <<
", nu=" <<
nu_ <<
", na=" <<
na_
372 template <
typename _Scalar>
375 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
376 typedef _Scalar Scalar;
384 typedef typename MathBase::VectorXs VectorXs;
386 template <
template <
typename Scalar>
class Model>
389 pinocchio(pinocchio::DataTpl<Scalar>(model->get_pinocchio())),
391 &
pinocchio, model->get_actuation()->createData(),
392 boost::make_shared<JointDataAbstract>(
393 model->get_state(), model->get_actuation(), model->get_nu())),
397 const std::size_t nv = model->get_state()->get_nv();
398 Fu.leftCols(nv).diagonal().setOnes();
399 multibody.joint->da_du.leftCols(nv).diagonal().setOnes();
400 costs->shareMemory(
this);
407 boost::shared_ptr<CostDataSum>
costs;
423 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
425 typedef _Scalar Scalar;
431 typedef typename MathBase::MatrixXs MatrixXs;
433 template <
template <
typename Scalar>
class Model>
437 dtau_dx(model->get_state()->get_nv(), model->get_state()->get_ndx()) {
444 "Invalid argument: the shared data should be derived from "
445 "DataCollectorActMultibody");
468 #include <crocoddyl/multibody/actions/free-invdyn.hxx>
Abstract class for the actuation-mapping model.
Residual-based constraint.
Abstract class for differential action model.
VectorXs g_ub_
Lower bound of the inequality constraints.
boost::shared_ptr< StateAbstract > state_
Model of the state.
std::size_t nu_
Control dimension.
std::size_t nh_
Number of equality constraints.
VectorXs g_lb_
Lower bound of the inequality constraints.
std::size_t ng_
Number of inequality constraints.
std::size_t na_
Dimension of the joint torques.
virtual void print(std::ostream &os) const
Print relevant information of the actuation residual model.
virtual void calcDiff(const boost::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &, const Eigen::Ref< const VectorXs > &)
Compute the derivatives of the actuation residual.
ResidualModelActuation(boost::shared_ptr< StateMultibody > state, const std::size_t nu)
Initialize the actuation residual model.
boost::shared_ptr< StateAbstract > state_
State description.
std::size_t nu_
Control dimension.
virtual boost::shared_ptr< ResidualDataAbstract > createData(DataCollectorAbstract *const data)
Create the actuation residual data.
virtual void calc(const boost::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &)
virtual void calc(const boost::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &, const Eigen::Ref< const VectorXs > &)
Compute the actuation residual.
virtual void calcDiff(const boost::shared_ptr< ResidualDataAbstract > &data, const Eigen::Ref< const VectorXs > &)
Differential action model for free inverse dynamics in multibody systems.
DifferentialActionModelFreeInvDynamicsTpl(boost::shared_ptr< StateMultibody > state, boost::shared_ptr< ActuationModelAbstract > actuation, boost::shared_ptr< CostModelSum > costs, boost::shared_ptr< ConstraintModelManager > constraints)
Initialize the free inverse-dynamics action model.
pinocchio::ModelTpl< Scalar > & get_pinocchio() const
Return the Pinocchio model.
virtual void calc(const boost::shared_ptr< DifferentialActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
virtual std::size_t get_ng() const
Return the number of inequality constraints.
virtual void calcDiff(const boost::shared_ptr< DifferentialActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the derivatives of the dynamics, cost and constraint functions.
virtual std::size_t get_nh() const
Return the number of equality constraints.
virtual boost::shared_ptr< DifferentialActionDataAbstract > createData()
Create the free inverse-dynamics data.
virtual void print(std::ostream &os) const
Print relevant information of the free inverse-dynamics model.
virtual const VectorXs & get_g_lb() const
Return the lower bound of the inequality constraints.
const boost::shared_ptr< CostModelSum > & get_costs() const
Return the cost model.
virtual void calc(const boost::shared_ptr< DifferentialActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x, const Eigen::Ref< const VectorXs > &u)
Compute the system acceleration, cost value and constraint residuals.
DifferentialActionModelFreeInvDynamicsTpl(boost::shared_ptr< StateMultibody > state, boost::shared_ptr< ActuationModelAbstract > actuation, boost::shared_ptr< CostModelSum > costs)
Initialize the free inverse-dynamics action model.
const boost::shared_ptr< ConstraintModelManager > & get_constraints() const
Return the constraint model manager.
virtual void quasiStatic(const boost::shared_ptr< DifferentialActionDataAbstract > &data, Eigen::Ref< VectorXs > u, const Eigen::Ref< const VectorXs > &x, const std::size_t maxiter=100, const Scalar tol=Scalar(1e-9))
Computes the quasic static commands.
const boost::shared_ptr< ActuationModelAbstract > & get_actuation() const
Return the actuation model.
virtual bool checkData(const boost::shared_ptr< DifferentialActionDataAbstract > &data)
Checks that a specific data belongs to the free inverse-dynamics model.
virtual const VectorXs & get_g_ub() const
Return the upper bound of the inequality constraints.
virtual void calcDiff(const boost::shared_ptr< DifferentialActionDataAbstract > &data, const Eigen::Ref< const VectorXs > &x)
Abstract class for residual models.
boost::shared_ptr< StateAbstract > state_
State description.
std::size_t nu_
Control dimension.
State multibody representation.
MatrixXs Fx
Jacobian of the dynamics w.r.t. the state .
MatrixXs Fu
Jacobian of the dynamics w.r.t. the control .
MatrixXs Luu
Hessian of the cost w.r.t. the control .
VectorXs Lx
Jacobian of the cost w.r.t. the state .
MatrixXs Lxx
Hessian of the cost w.r.t. the state .
VectorXs Lu
Jacobian of the cost w.r.t. the control .
VectorXs xout
evolution state
MatrixXs Ru
Jacobian of the residual vector with respect the control.
MatrixXs Rx
Jacobian of the residual vector with respect the state.
boost::shared_ptr< ActuationDataAbstract > actuation
Actuation data.
DataCollectorAbstract * shared
Shared data allocated by the action model.
VectorXs r
Residual vector.
pinocchio::DataTpl< Scalar > * pinocchio
Pinocchio data.
MatrixXs Fu
Jacobian of the dynamics w.r.t. the control .
VectorXs tmp_xstatic
State point used for computing the quasi-static input.
DataCollectorJointActMultibody multibody
Multibody data.
pinocchio::DataTpl< Scalar > pinocchio
Pinocchio data.
boost::shared_ptr< CostDataSum > costs
Costs data.
boost::shared_ptr< ConstraintDataManager > constraints
Constraints data.
MatrixXs Ru
Jacobian of the residual vector with respect the control.
MatrixXs Rx
Jacobian of the residual vector with respect the state.
DataCollectorAbstract * shared
Shared data allocated by the action model.
VectorXs r
Residual vector.