diff --git a/include/crocoddyl/core/action-base.hpp b/include/crocoddyl/core/action-base.hpp index 2909018454c6fae93a6c225ded2b620fb59e0a61..7ce25312a279eb568ba3e38931a205a7ab2d14cd 100644 --- a/include/crocoddyl/core/action-base.hpp +++ b/include/crocoddyl/core/action-base.hpp @@ -41,10 +41,10 @@ class ActionModelAbstract { StateAbstract& get_state() const; protected: - unsigned int nu_; //!< Control dimension - unsigned int nr_; //!< Dimension of the cost residual - StateAbstract& state_; //!< Model of the state - Eigen::VectorXd unone_; //!< Neutral state + unsigned int nu_; //!< Control dimension + unsigned int nr_; //!< Dimension of the cost residual + StateAbstract& state_; //!< Model of the state + Eigen::VectorXd unone_; //!< Neutral state #ifdef PYTHON_BINDINGS diff --git a/include/crocoddyl/core/numdiff/action.hpp b/include/crocoddyl/core/numdiff/action.hpp index 0ae52a8975d2df9b428a01fafd47db5e6d675126..2253a9811e49298cb6336ec4a48e0267b45cddc2 100644 --- a/include/crocoddyl/core/numdiff/action.hpp +++ b/include/crocoddyl/core/numdiff/action.hpp @@ -17,13 +17,13 @@ namespace crocoddyl { /** * @brief This class computes the numerical differentiation of an ActionModel. - * + * * It computes the same quantity as a normal model would do but using numerical * differentiation. * The subtility is in the computation of the Hessian of the cost. Let us * concider that the ActionModel owns a cost residual. This means that the cost - * is the square of a residual \f$ l(x,u) = .5 r(x,u)**2 \f$, with - * \f$ r(x,u) \f$ being a vector. Therefore the derivatives of the cost + * is the square of a residual \f$ l(x,u) = .5 r(x,u)**2 \f$, with + * \f$ r(x,u) \f$ being a vector. Therefore the derivatives of the cost * \f$ l \f$ can be expressed in function of the derivatives of the residuals * (jacobians), denoted by \f$ R_x \f$ and \f$ R_u \f$. Which would be: * \f{eqnarray*}{ @@ -49,8 +49,8 @@ class ActionModelNumDiff : public ActionModelAbstract { public: /** * @brief Construct a new ActionModelNumDiff object - * - * @param model + * + * @param model * @param with_gauss_approx defines if we use the Gauss approximation of the * cost hessian or not. */ @@ -60,12 +60,12 @@ class ActionModelNumDiff : public ActionModelAbstract { void calc(const boost::shared_ptr<ActionDataAbstract>& data, const Eigen::Ref<const Eigen::VectorXd>& x, const Eigen::Ref<const Eigen::VectorXd>& u); /** - * @brief calcDiff computes the - * - * @param data - * @param x - * @param u - * @param recalc + * @brief calcDiff computes the + * + * @param data + * @param x + * @param u + * @param recalc */ void calcDiff(const boost::shared_ptr<ActionDataAbstract>& data, const Eigen::Ref<const Eigen::VectorXd>& x, const Eigen::Ref<const Eigen::VectorXd>& u, const bool& recalc = true); @@ -127,14 +127,16 @@ struct ActionDataNumDiff : public ActionDataAbstract { } } - Eigen::MatrixXd Rx; //!< Cost residual jacobian: d r / dx - Eigen::MatrixXd Ru; //!< Cost residual jacobian: d r / du - Eigen::VectorXd dx; //!< State disturbance - Eigen::VectorXd du; //!< Control disturbance - Eigen::VectorXd xp; //!< The integrated state from the disturbance on one DoF "\f$ \int x dx_i \f$" - boost::shared_ptr<ActionDataAbstract> data_0; //!< The data that contains the final results - std::vector<boost::shared_ptr<ActionDataAbstract> > data_x; //!< The temporary data associated with the state variation - std::vector<boost::shared_ptr<ActionDataAbstract> > data_u; //!< The temporary data associated with the control variation + Eigen::MatrixXd Rx; //!< Cost residual jacobian: d r / dx + Eigen::MatrixXd Ru; //!< Cost residual jacobian: d r / du + Eigen::VectorXd dx; //!< State disturbance + Eigen::VectorXd du; //!< Control disturbance + Eigen::VectorXd xp; //!< The integrated state from the disturbance on one DoF "\f$ \int x dx_i \f$" + boost::shared_ptr<ActionDataAbstract> data_0; //!< The data that contains the final results + std::vector<boost::shared_ptr<ActionDataAbstract> > + data_x; //!< The temporary data associated with the state variation + std::vector<boost::shared_ptr<ActionDataAbstract> > + data_u; //!< The temporary data associated with the control variation }; } // namespace crocoddyl diff --git a/src/core/numdiff/action.cpp b/src/core/numdiff/action.cpp index 82418e3bf815f15907bca5419fd89ad038870cb1..de077f566d39f902b16f5c1623ee8d6c6877e586 100644 --- a/src/core/numdiff/action.cpp +++ b/src/core/numdiff/action.cpp @@ -76,7 +76,7 @@ void ActionModelNumDiff::calcDiff(const boost::shared_ptr<ActionDataAbstract>& d model_.get_state().diff(xn0, xn, data_nd->Fu.col(iu)); data->Lu(iu) = (c - c0) / disturbance_; - if (with_gauss_approx_) { + if (with_gauss_approx_) { data_nd->Ru.col(iu) = (data_nd->data_u[iu]->r - data_nd->data_0->r) / disturbance_; } data_nd->du(iu) = 0.0; @@ -87,14 +87,11 @@ void ActionModelNumDiff::calcDiff(const boost::shared_ptr<ActionDataAbstract>& d data->Lxx = data_nd->Rx.transpose() * data_nd->Rx; data->Lxu = data_nd->Rx.transpose() * data_nd->Ru; data->Luu = data_nd->Ru.transpose() * data_nd->Ru; - } - else - { + } else { data->Lxx.fill(0.0); data->Lxu.fill(0.0); data->Luu.fill(0.0); } - } ActionModelAbstract& ActionModelNumDiff::get_model() const { return model_; } diff --git a/unittest/test_actions.cpp b/unittest/test_actions.cpp index c3e44b68eac3fb20e97eb4e9af8338019e5f3ba6..367c9a8181d89eb847b35ae47e8803310d0f5640 100644 --- a/unittest/test_actions.cpp +++ b/unittest/test_actions.cpp @@ -79,7 +79,7 @@ void test_partial_derivatives_against_numdiff(crocoddyl::ActionModelAbstract& mo BOOST_CHECK((data->Lxx - data_num_diff->Lxx).isMuchSmallerThan(1.0, tol)); BOOST_CHECK((data->Lxu - data_num_diff->Lxu).isMuchSmallerThan(1.0, tol)); BOOST_CHECK((data->Luu - data_num_diff->Luu).isMuchSmallerThan(1.0, tol)); - }else{ + } else { BOOST_CHECK((data_num_diff->Lxx).isMuchSmallerThan(1.0, tol)); BOOST_CHECK((data_num_diff->Lxu).isMuchSmallerThan(1.0, tol)); BOOST_CHECK((data_num_diff->Luu).isMuchSmallerThan(1.0, tol));