Line |
Branch |
Exec |
Source |
1 |
|
|
|
2 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
3 |
|
|
// BSD 3-Clause License |
4 |
|
|
// |
5 |
|
|
// Copyright (C) 2019-2025, LAAS-CNRS, University of Edinburgh |
6 |
|
|
// Copyright note valid unless otherwise stated in individual files. |
7 |
|
|
// All rights reserved. |
8 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
9 |
|
|
|
10 |
|
|
#ifndef BINDINGS_PYTHON_CROCODDYL_CORE_ACTUATION_BASE_HPP_ |
11 |
|
|
#define BINDINGS_PYTHON_CROCODDYL_CORE_ACTUATION_BASE_HPP_ |
12 |
|
|
|
13 |
|
|
#include "crocoddyl/core/actuation-base.hpp" |
14 |
|
|
#include "python/crocoddyl/core/core.hpp" |
15 |
|
|
|
16 |
|
|
namespace crocoddyl { |
17 |
|
|
namespace python { |
18 |
|
|
|
19 |
|
|
template <typename Scalar> |
20 |
|
|
class ActuationModelAbstractTpl_wrap |
21 |
|
|
: public ActuationModelAbstractTpl<Scalar>, |
22 |
|
|
public bp::wrapper<ActuationModelAbstractTpl<Scalar>> { |
23 |
|
|
public: |
24 |
|
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW |
25 |
|
✗ |
CROCODDYL_DERIVED_CAST(ActuationModelBase, ActuationModelAbstractTpl_wrap) |
26 |
|
|
|
27 |
|
|
typedef typename crocoddyl::ActuationModelAbstractTpl<Scalar> ActuationModel; |
28 |
|
|
typedef typename crocoddyl::ActuationDataAbstractTpl<Scalar> ActuationData; |
29 |
|
|
typedef typename ActuationModel::StateAbstract State; |
30 |
|
|
typedef typename ActuationModel::VectorXs VectorXs; |
31 |
|
|
using ActuationModel::nu_; |
32 |
|
|
using ActuationModel::state_; |
33 |
|
|
|
34 |
|
6 |
ActuationModelAbstractTpl_wrap(std::shared_ptr<State> state, |
35 |
|
|
const std::size_t nu) |
36 |
1/2
✓ Branch 2 taken 3 times.
✗ Branch 3 not taken.
|
6 |
: ActuationModel(state, nu), bp::wrapper<ActuationModel>() {} |
37 |
|
|
|
38 |
|
✗ |
void calc(const std::shared_ptr<ActuationData>& data, |
39 |
|
|
const Eigen::Ref<const VectorXs>& x, |
40 |
|
|
const Eigen::Ref<const VectorXs>& u) override { |
41 |
|
✗ |
if (static_cast<std::size_t>(x.size()) != state_->get_nx()) { |
42 |
|
✗ |
throw_pretty( |
43 |
|
|
"Invalid argument: " << "x has wrong dimension (it should be " + |
44 |
|
|
std::to_string(state_->get_nx()) + ")"); |
45 |
|
|
} |
46 |
|
✗ |
if (static_cast<std::size_t>(u.size()) != nu_) { |
47 |
|
✗ |
throw_pretty( |
48 |
|
|
"Invalid argument: " << "u has wrong dimension (it should be " + |
49 |
|
|
std::to_string(nu_) + ")"); |
50 |
|
|
} |
51 |
|
✗ |
return bp::call<void>(this->get_override("calc").ptr(), data, (VectorXs)x, |
52 |
|
✗ |
(VectorXs)u); |
53 |
|
|
} |
54 |
|
|
|
55 |
|
✗ |
void calcDiff(const std::shared_ptr<ActuationData>& data, |
56 |
|
|
const Eigen::Ref<const VectorXs>& x, |
57 |
|
|
const Eigen::Ref<const VectorXs>& u) override { |
58 |
|
✗ |
if (static_cast<std::size_t>(x.size()) != state_->get_nx()) { |
59 |
|
✗ |
throw_pretty( |
60 |
|
|
"Invalid argument: " << "x has wrong dimension (it should be " + |
61 |
|
|
std::to_string(state_->get_nx()) + ")"); |
62 |
|
|
} |
63 |
|
✗ |
if (static_cast<std::size_t>(u.size()) != nu_) { |
64 |
|
✗ |
throw_pretty( |
65 |
|
|
"Invalid argument: " << "u has wrong dimension (it should be " + |
66 |
|
|
std::to_string(nu_) + ")"); |
67 |
|
|
} |
68 |
|
✗ |
return bp::call<void>(this->get_override("calcDiff").ptr(), data, |
69 |
|
✗ |
(VectorXs)x, (VectorXs)u); |
70 |
|
|
} |
71 |
|
|
|
72 |
|
✗ |
void commands(const std::shared_ptr<ActuationData>& data, |
73 |
|
|
const Eigen::Ref<const VectorXs>& x, |
74 |
|
|
const Eigen::Ref<const VectorXs>& tau) override { |
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>(tau.size()) != state_->get_nv()) { |
81 |
|
✗ |
throw_pretty( |
82 |
|
|
"Invalid argument: " << "tau has wrong dimension (it should be " + |
83 |
|
|
std::to_string(state_->get_nv()) + ")"); |
84 |
|
|
} |
85 |
|
✗ |
return bp::call<void>(this->get_override("commands").ptr(), data, |
86 |
|
✗ |
(VectorXs)x, (VectorXs)tau); |
87 |
|
|
} |
88 |
|
|
|
89 |
|
✗ |
void torqueTransform(const std::shared_ptr<ActuationData>& data, |
90 |
|
|
const Eigen::Ref<const VectorXs>& x, |
91 |
|
|
const Eigen::Ref<const VectorXs>& u) override { |
92 |
|
✗ |
if (boost::python::override torqueTransform = |
93 |
|
|
this->get_override("torqueTransform")) { |
94 |
|
✗ |
if (static_cast<std::size_t>(x.size()) != state_->get_nx()) { |
95 |
|
✗ |
throw_pretty( |
96 |
|
|
"Invalid argument: " << "x has wrong dimension (it should be " + |
97 |
|
|
std::to_string(state_->get_nx()) + ")"); |
98 |
|
|
} |
99 |
|
✗ |
if (static_cast<std::size_t>(u.size()) != nu_) { |
100 |
|
✗ |
throw_pretty( |
101 |
|
|
"Invalid argument: " << "u has wrong dimension (it should be " + |
102 |
|
|
std::to_string(nu_) + ")"); |
103 |
|
|
} |
104 |
|
✗ |
return bp::call<void>(torqueTransform.ptr(), data, (VectorXs)x, |
105 |
|
✗ |
(VectorXs)u); |
106 |
|
|
} |
107 |
|
✗ |
return ActuationModel::torqueTransform(data, x, u); |
108 |
|
|
} |
109 |
|
|
|
110 |
|
✗ |
void default_torqueTransform(const std::shared_ptr<ActuationData>& data, |
111 |
|
|
const Eigen::Ref<const VectorXs>& x, |
112 |
|
|
const Eigen::Ref<const VectorXs>& u) { |
113 |
|
✗ |
return this->ActuationModel::torqueTransform(data, x, u); |
114 |
|
|
} |
115 |
|
|
|
116 |
|
✗ |
std::shared_ptr<ActuationData> createData() override { |
117 |
|
✗ |
enableMultithreading() = false; |
118 |
|
✗ |
if (boost::python::override createData = this->get_override("createData")) { |
119 |
|
✗ |
return bp::call<std::shared_ptr<ActuationData>>(createData.ptr()); |
120 |
|
|
} |
121 |
|
✗ |
return ActuationModel::createData(); |
122 |
|
|
} |
123 |
|
|
|
124 |
|
12 |
std::shared_ptr<ActuationData> default_createData() { |
125 |
|
12 |
return this->ActuationModel::createData(); |
126 |
|
|
} |
127 |
|
|
|
128 |
|
|
template <typename NewScalar> |
129 |
|
✗ |
ActuationModelAbstractTpl_wrap<NewScalar> cast() const { |
130 |
|
|
typedef ActuationModelAbstractTpl_wrap<NewScalar> ReturnType; |
131 |
|
|
typedef StateAbstractTpl<NewScalar> StateType; |
132 |
|
✗ |
ReturnType ret( |
133 |
|
✗ |
std::static_pointer_cast<StateType>(state_->template cast<NewScalar>()), |
134 |
|
✗ |
nu_); |
135 |
|
✗ |
return ret; |
136 |
|
|
} |
137 |
|
|
}; |
138 |
|
|
|
139 |
|
|
} // namespace python |
140 |
|
|
} // namespace crocoddyl |
141 |
|
|
|
142 |
|
|
#endif // BINDINGS_PYTHON_CROCODDYL_CORE_ACTUATION_BASE_HPP_ |
143 |
|
|
|