Skip to content

Commit b89baa4

Browse files
authored
Merge pull request #1455 from cmastalli/topic/actuation-limits
2 parents 1dd24dd + eaa33ee commit b89baa4

File tree

10 files changed

+116
-9
lines changed

10 files changed

+116
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## [Unreleased]
88

9+
* Introduced the actuation limits to handle thrusters and general action models in https://github.com/loco-3d/crocoddyl/pull/1455
910
* Introduced safe difference and integration functions for states in https://github.com/loco-3d/crocoddyl/pull/1448
1011
* ROS: jrl_cmakemodules dependency + kilted CI in https://github.com/loco-3d/crocoddyl/pull/1441
1112

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,12 @@ if(UNIX AND NOT BUILD_STANDALONE_PYTHON_INTERFACE)
292292
${PROJECT_NAME} PUBLIC PINOCCHIO_ENABLE_COMPATIBILITY_WITH_VERSION_2)
293293
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION})
294294

295+
if(BUILD_WITH_CODEGEN_SUPPORT)
296+
# CppAD is header-only but ships cppad_lib for non-header utilities (e.g.
297+
# temp_file)
298+
target_link_libraries(${PROJECT_NAME} ${cppad_LIBRARY})
299+
endif()
300+
295301
if(BUILD_WITH_MULTITHREADS)
296302
target_link_libraries(${PROJECT_NAME} OpenMP::OpenMP_CXX)
297303
endif()

bindings/python/crocoddyl/core/actuation-base.cpp.in

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,15 @@ struct ActuationModelAbstractVisitor
9797
"state",
9898
bp::make_function(&Model::get_state,
9999
bp::return_value_policy<bp::return_by_value>()),
100-
"state");
100+
"state")
101+
.add_property("u_lb",
102+
bp::make_function(&Model::get_u_lb,
103+
bp::return_internal_reference<>()),
104+
&Model::set_u_lb, "lower actuation limits")
105+
.add_property("u_ub",
106+
bp::make_function(&Model::get_u_ub,
107+
bp::return_internal_reference<>()),
108+
&Model::set_u_ub, "upper actuation limits");
101109
}
102110
};
103111

include/crocoddyl/core/actuation-base.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,26 @@ class ActuationModelAbstractTpl : public ActuationModelBase {
155155
*/
156156
const std::shared_ptr<StateAbstract>& get_state() const;
157157

158+
/**
159+
* @brief Return the actuation lower bound
160+
*/
161+
const VectorXs& get_u_lb() const;
162+
163+
/**
164+
* @brief Return the actuation upper bound
165+
*/
166+
const VectorXs& get_u_ub() const;
167+
168+
/**
169+
* @brief Modify the actuation lower bounds
170+
*/
171+
void set_u_lb(const VectorXs& u_lb);
172+
173+
/**
174+
* @brief Modify the actuation upper bounds
175+
*/
176+
void set_u_ub(const VectorXs& u_ub);
177+
158178
/**
159179
* @brief Print information on the actuation model
160180
*/
@@ -172,6 +192,8 @@ class ActuationModelAbstractTpl : public ActuationModelBase {
172192
protected:
173193
std::size_t nu_; //!< Dimension of joint torque inputs
174194
std::shared_ptr<StateAbstract> state_; //!< Model of the state
195+
VectorXs u_lb_; //!< Lower actuation limits
196+
VectorXs u_ub_; //!< Upper actuation limits
175197
ActuationModelAbstractTpl() : nu_(0), state_(nullptr) {};
176198
};
177199

include/crocoddyl/core/actuation-base.hxx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ namespace crocoddyl {
1212
template <typename Scalar>
1313
ActuationModelAbstractTpl<Scalar>::ActuationModelAbstractTpl(
1414
std::shared_ptr<StateAbstract> state, const std::size_t nu)
15-
: nu_(nu), state_(state) {}
15+
: nu_(nu),
16+
state_(state),
17+
u_lb_(MathBase::VectorXs::Constant(
18+
nu, -std::numeric_limits<Scalar>::infinity())),
19+
u_ub_(MathBase::VectorXs::Constant(
20+
nu, std::numeric_limits<Scalar>::infinity())) {}
1621

1722
template <typename Scalar>
1823
std::shared_ptr<ActuationDataAbstractTpl<Scalar> >
@@ -61,6 +66,48 @@ ActuationModelAbstractTpl<Scalar>::get_state() const {
6166
return state_;
6267
}
6368

69+
template <typename Scalar>
70+
const typename MathBaseTpl<Scalar>::VectorXs&
71+
ActuationModelAbstractTpl<Scalar>::get_u_lb() const {
72+
return u_lb_;
73+
}
74+
75+
template <typename Scalar>
76+
const typename MathBaseTpl<Scalar>::VectorXs&
77+
ActuationModelAbstractTpl<Scalar>::get_u_ub() const {
78+
return u_ub_;
79+
}
80+
81+
template <typename Scalar>
82+
void ActuationModelAbstractTpl<Scalar>::set_u_lb(const VectorXs& u_lb) {
83+
if (static_cast<std::size_t>(u_lb.size()) != nu_) {
84+
throw_pretty("Invalid argument: "
85+
<< "control lower bound has wrong dimension (it should be " +
86+
std::to_string(nu_) + ")");
87+
}
88+
u_lb_ = u_lb;
89+
for (std::size_t i = 0; i < nu_; ++i) {
90+
if (u_lb_[i] <= -std::numeric_limits<Scalar>::max()) {
91+
u_lb_[i] = -std::numeric_limits<Scalar>::infinity();
92+
}
93+
}
94+
}
95+
96+
template <typename Scalar>
97+
void ActuationModelAbstractTpl<Scalar>::set_u_ub(const VectorXs& u_ub) {
98+
if (static_cast<std::size_t>(u_ub.size()) != nu_) {
99+
throw_pretty("Invalid argument: "
100+
<< "control upper bound has wrong dimension (it should be " +
101+
std::to_string(nu_) + ")");
102+
}
103+
u_ub_ = u_ub;
104+
for (std::size_t i = 0; i < nu_; ++i) {
105+
if (u_ub_[i] >= std::numeric_limits<Scalar>::max()) {
106+
u_ub_[i] = std::numeric_limits<Scalar>::infinity();
107+
}
108+
}
109+
}
110+
64111
template <typename Scalar>
65112
std::ostream& operator<<(std::ostream& os,
66113
const ActuationModelAbstractTpl<Scalar>& model) {

include/crocoddyl/multibody/actions/contact-fwddyn.hxx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,8 @@ void DifferentialActionModelContactFwdDynamicsTpl<Scalar>::init() {
7373
<< "Costs doesn't have the same control dimension (it should be " +
7474
std::to_string(nu_) + ")");
7575
}
76-
77-
Base::set_u_lb(Scalar(-1.) * pinocchio_->effortLimit.tail(nu_));
78-
Base::set_u_ub(Scalar(+1.) * pinocchio_->effortLimit.tail(nu_));
76+
Base::u_lb_ = actuation_->get_u_lb();
77+
Base::u_ub_ = actuation_->get_u_ub();
7978
}
8079

8180
template <typename Scalar>

include/crocoddyl/multibody/actions/free-fwddyn.hxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ DifferentialActionModelFreeFwdDynamicsTpl<Scalar>::
3333
<< "Costs doesn't have the same control dimension (it should be " +
3434
std::to_string(nu_) + ")");
3535
}
36-
Base::set_u_lb(Scalar(-1.) * pinocchio_->effortLimit.tail(nu_));
37-
Base::set_u_ub(Scalar(+1.) * pinocchio_->effortLimit.tail(nu_));
36+
Base::u_lb_ = actuation_->get_u_lb();
37+
Base::u_ub_ = actuation_->get_u_ub();
3838
}
3939

4040
template <typename Scalar>

include/crocoddyl/multibody/actuations/floating-base-thrusters.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,22 @@ class ActuationModelFloatingBaseThrustersTpl
178178
<< "the first joint has to be a root one (e.g., free-flyer joint)");
179179
}
180180
// Update the joint actuation part
181+
const std::size_t nv_f =
182+
state->get_pinocchio()
183+
->joints[(state->get_pinocchio()->existJointName("root_joint")
184+
? state->get_pinocchio()->getJointId("root_joint")
185+
: 0)]
186+
.nv();
181187
W_thrust_.setZero();
182188
if (nu_ > n_thrusters_) {
183189
W_thrust_.bottomRightCorner(nu_ - n_thrusters_, nu_ - n_thrusters_)
184190
.diagonal()
185191
.setOnes();
192+
Base::u_lb_.tail(nu_ - n_thrusters_) =
193+
Scalar(-1.) *
194+
state->get_pinocchio()->effortLimit.segment(nv_f, nu_ - n_thrusters_);
195+
Base::u_ub_.tail(nu_ - n_thrusters_) =
196+
state->get_pinocchio()->effortLimit.segment(nv_f, nu_ - n_thrusters_);
186197
}
187198
// Update the floating base actuation part
188199
set_thrusters(thrusters_);
@@ -316,6 +327,8 @@ class ActuationModelFloatingBaseThrustersTpl
316327
W_thrust_.template middleRows<3>(3).col(i) -= p.ctorque * f_z;
317328
break;
318329
}
330+
Base::u_lb_(i) = p.min_thrust;
331+
Base::u_ub_(i) = p.max_thrust;
319332
}
320333
// Compute the torque transform matrix from generalized torques to joint
321334
// torque inputs

include/crocoddyl/multibody/actuations/floating-base.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ class ActuationModelFloatingBaseTpl
6060
state->get_pinocchio()->existJointName("root_joint")
6161
? state->get_pinocchio()->getJointId("root_joint")
6262
: 0)]
63-
.nv()) {};
63+
.nv()) {
64+
Base::u_lb_ = Scalar(-1.) * state->get_pinocchio()->effortLimit.tail(nu_);
65+
Base::u_ub_ = state->get_pinocchio()->effortLimit.tail(nu_);
66+
};
6467
virtual ~ActuationModelFloatingBaseTpl() = default;
6568

6669
/**

include/crocoddyl/multibody/actuations/full.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "crocoddyl/core/actuation-base.hpp"
1414
#include "crocoddyl/core/state-base.hpp"
1515
#include "crocoddyl/multibody/fwd.hpp"
16+
#include "crocoddyl/multibody/states/multibody.hpp"
1617

1718
namespace crocoddyl {
1819

@@ -47,7 +48,14 @@ class ActuationModelFullTpl : public ActuationModelAbstractTpl<_Scalar> {
4748
* @param[in] state State of the dynamical system
4849
*/
4950
explicit ActuationModelFullTpl(std::shared_ptr<StateAbstract> state)
50-
: Base(state, state->get_nv()) {};
51+
: Base(state, state->get_nv()) {
52+
StateMultibodyTpl<Scalar>* s =
53+
dynamic_cast<StateMultibodyTpl<Scalar>*>(state.get());
54+
if (s != NULL) {
55+
Base::u_lb_ = Scalar(-1.) * s->get_pinocchio()->effortLimit;
56+
Base::u_ub_ = s->get_pinocchio()->effortLimit;
57+
}
58+
};
5159
virtual ~ActuationModelFullTpl() = default;
5260

5361
/**

0 commit comments

Comments
 (0)