Line |
Branch |
Exec |
Source |
1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2020-2024, University of Edinburgh, Heriot-Watt University |
5 |
|
|
// Copyright note valid unless otherwise stated in individual files. |
6 |
|
|
// All rights reserved. |
7 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
8 |
|
|
|
9 |
|
|
#ifndef BINDINGS_PYTHON_CROCODDYL_CORE_CONSTRAINT_BASE_HPP_ |
10 |
|
|
#define BINDINGS_PYTHON_CROCODDYL_CORE_CONSTRAINT_BASE_HPP_ |
11 |
|
|
|
12 |
|
|
#include "crocoddyl/core/constraint-base.hpp" |
13 |
|
|
#include "crocoddyl/core/utils/exception.hpp" |
14 |
|
|
#include "python/crocoddyl/core/core.hpp" |
15 |
|
|
|
16 |
|
|
namespace crocoddyl { |
17 |
|
|
namespace python { |
18 |
|
|
|
19 |
|
|
class ConstraintModelAbstract_wrap |
20 |
|
|
: public ConstraintModelAbstract, |
21 |
|
|
public bp::wrapper<ConstraintModelAbstract> { |
22 |
|
|
public: |
23 |
|
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW |
24 |
|
|
using ConstraintModelAbstract::nu_; |
25 |
|
|
using ConstraintModelAbstract::unone_; |
26 |
|
|
|
27 |
|
✗ |
ConstraintModelAbstract_wrap(std::shared_ptr<StateAbstract> state, |
28 |
|
|
std::shared_ptr<ResidualModelAbstract> residual, |
29 |
|
|
const std::size_t ng, const std::size_t nh) |
30 |
|
✗ |
: ConstraintModelAbstract(state, residual, ng, nh), |
31 |
|
✗ |
bp::wrapper<ConstraintModelAbstract>() { |
32 |
|
✗ |
unone_ = NAN * MathBase::VectorXs::Ones(nu_); |
33 |
|
|
} |
34 |
|
|
|
35 |
|
✗ |
ConstraintModelAbstract_wrap(std::shared_ptr<StateAbstract> state, |
36 |
|
|
const std::size_t nu, const std::size_t ng, |
37 |
|
|
const std::size_t nh, const bool T_const = true) |
38 |
|
✗ |
: ConstraintModelAbstract(state, nu, ng, nh, T_const), |
39 |
|
✗ |
bp::wrapper<ConstraintModelAbstract>() { |
40 |
|
✗ |
unone_ = NAN * MathBase::VectorXs::Ones(nu); |
41 |
|
|
} |
42 |
|
|
|
43 |
|
✗ |
ConstraintModelAbstract_wrap(std::shared_ptr<StateAbstract> state, |
44 |
|
|
const std::size_t ng, const std::size_t nh, |
45 |
|
|
const bool T_const = true) |
46 |
|
✗ |
: ConstraintModelAbstract(state, ng, nh, T_const) { |
47 |
|
✗ |
unone_ = NAN * MathBase::VectorXs::Ones(nu_); |
48 |
|
|
} |
49 |
|
|
|
50 |
|
✗ |
void calc(const std::shared_ptr<ConstraintDataAbstract>& data, |
51 |
|
|
const Eigen::Ref<const Eigen::VectorXd>& x, |
52 |
|
|
const Eigen::Ref<const Eigen::VectorXd>& u) { |
53 |
|
✗ |
if (static_cast<std::size_t>(x.size()) != state_->get_nx()) { |
54 |
|
✗ |
throw_pretty( |
55 |
|
|
"Invalid argument: " << "x has wrong dimension (it should be " + |
56 |
|
|
std::to_string(state_->get_nx()) + ")"); |
57 |
|
|
} |
58 |
|
✗ |
if (static_cast<std::size_t>(u.size()) != nu_) { |
59 |
|
✗ |
throw_pretty( |
60 |
|
|
"Invalid argument: " << "u has wrong dimension (it should be " + |
61 |
|
|
std::to_string(nu_) + ")"); |
62 |
|
|
} |
63 |
|
✗ |
if (std::isnan(u.lpNorm<Eigen::Infinity>())) { |
64 |
|
✗ |
return bp::call<void>(this->get_override("calc").ptr(), data, |
65 |
|
✗ |
(Eigen::VectorXd)x); |
66 |
|
|
} else { |
67 |
|
✗ |
return bp::call<void>(this->get_override("calc").ptr(), data, |
68 |
|
✗ |
(Eigen::VectorXd)x, (Eigen::VectorXd)u); |
69 |
|
|
} |
70 |
|
|
} |
71 |
|
|
|
72 |
|
✗ |
void calcDiff(const std::shared_ptr<ConstraintDataAbstract>& data, |
73 |
|
|
const Eigen::Ref<const Eigen::VectorXd>& x, |
74 |
|
|
const Eigen::Ref<const Eigen::VectorXd>& u) { |
75 |
|
✗ |
if (static_cast<std::size_t>(x.size()) != state_->get_nx()) { |
76 |
|
✗ |
throw_pretty( |
77 |
|
|
"Invalid argument: " << "x has wrong dimension (it should be " + |
78 |
|
|
std::to_string(state_->get_nx()) + ")"); |
79 |
|
|
} |
80 |
|
✗ |
if (static_cast<std::size_t>(u.size()) != nu_) { |
81 |
|
✗ |
throw_pretty( |
82 |
|
|
"Invalid argument: " << "u has wrong dimension (it should be " + |
83 |
|
|
std::to_string(nu_) + ")"); |
84 |
|
|
} |
85 |
|
✗ |
if (std::isnan(u.lpNorm<Eigen::Infinity>())) { |
86 |
|
✗ |
return bp::call<void>(this->get_override("calcDiff").ptr(), data, |
87 |
|
✗ |
(Eigen::VectorXd)x); |
88 |
|
|
} else { |
89 |
|
✗ |
return bp::call<void>(this->get_override("calcDiff").ptr(), data, |
90 |
|
✗ |
(Eigen::VectorXd)x, (Eigen::VectorXd)u); |
91 |
|
|
} |
92 |
|
|
} |
93 |
|
|
|
94 |
|
✗ |
std::shared_ptr<ConstraintDataAbstract> createData( |
95 |
|
|
DataCollectorAbstract* const data) { |
96 |
|
✗ |
if (boost::python::override createData = this->get_override("createData")) { |
97 |
|
|
return bp::call<std::shared_ptr<ConstraintDataAbstract> >( |
98 |
|
✗ |
createData.ptr(), boost::ref(data)); |
99 |
|
|
} |
100 |
|
✗ |
return ConstraintModelAbstract::createData(data); |
101 |
|
|
} |
102 |
|
|
|
103 |
|
✗ |
std::shared_ptr<ConstraintDataAbstract> default_createData( |
104 |
|
|
DataCollectorAbstract* const data) { |
105 |
|
✗ |
return this->ConstraintModelAbstract::createData(data); |
106 |
|
|
} |
107 |
|
|
}; |
108 |
|
|
|
109 |
|
|
} // namespace python |
110 |
|
|
} // namespace crocoddyl |
111 |
|
|
|
112 |
|
|
#endif // BINDINGS_PYTHON_CROCODDYL_CORE_CONSTRAINT_BASE_HPP_ |
113 |
|
|
|