Line |
Branch |
Exec |
Source |
1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2019-2025, LAAS-CNRS, University of Edinburgh, |
5 |
|
|
// Heriot-Watt University |
6 |
|
|
// Copyright note valid unless otherwise stated in individual files. |
7 |
|
|
// All rights reserved. |
8 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
9 |
|
|
|
10 |
|
|
#ifndef BINDINGS_PYTHON_CROCODDYL_MULTIBODY_IMPULSE_BASE_HPP_ |
11 |
|
|
#define BINDINGS_PYTHON_CROCODDYL_MULTIBODY_IMPULSE_BASE_HPP_ |
12 |
|
|
|
13 |
|
|
#include "crocoddyl/multibody/impulse-base.hpp" |
14 |
|
|
#include "python/crocoddyl/multibody/multibody.hpp" |
15 |
|
|
|
16 |
|
|
namespace crocoddyl { |
17 |
|
|
namespace python { |
18 |
|
|
|
19 |
|
|
template <typename Scalar> |
20 |
|
|
class ImpulseModelAbstractTpl_wrap |
21 |
|
|
: public ImpulseModelAbstractTpl<Scalar>, |
22 |
|
|
public bp::wrapper<ImpulseModelAbstractTpl<Scalar>> { |
23 |
|
|
public: |
24 |
|
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW |
25 |
|
✗ |
CROCODDYL_DERIVED_CAST(ImpulseModelBase, ImpulseModelAbstractTpl_wrap) |
26 |
|
|
|
27 |
|
|
typedef typename crocoddyl::ImpulseModelAbstractTpl<Scalar> ImpulseModel; |
28 |
|
|
typedef typename crocoddyl::ImpulseDataAbstractTpl<Scalar> ImpulseData; |
29 |
|
|
typedef typename ImpulseModel::VectorXs VectorXs; |
30 |
|
|
typedef typename ImpulseModel::StateMultibody State; |
31 |
|
|
using ImpulseModel::nc_; |
32 |
|
|
using ImpulseModel::state_; |
33 |
|
|
using ImpulseModel::type_; |
34 |
|
|
|
35 |
|
12 |
ImpulseModelAbstractTpl_wrap(std::shared_ptr<State> state, |
36 |
|
|
const pinocchio::ReferenceFrame type, |
37 |
|
|
std::size_t nc) |
38 |
1/2
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
|
12 |
: ImpulseModel(state, type, nc) {} |
39 |
|
|
|
40 |
|
✗ |
ImpulseModelAbstractTpl_wrap(std::shared_ptr<State> state, std::size_t nc) |
41 |
|
✗ |
: ImpulseModel(state, pinocchio::ReferenceFrame::LOCAL, nc) { |
42 |
|
✗ |
std::cerr << "Deprecated: Use constructor that passes the type of contact, " |
43 |
|
|
"this assumes is pinocchio::LOCAL." |
44 |
|
✗ |
<< std::endl; |
45 |
|
|
} |
46 |
|
|
|
47 |
|
✗ |
void calc(const std::shared_ptr<ImpulseData>& data, |
48 |
|
|
const Eigen::Ref<const VectorXs>& x) override { |
49 |
|
✗ |
assert_pretty(static_cast<std::size_t>(x.size()) == state_->get_nx(), |
50 |
|
|
"x has wrong dimension"); |
51 |
|
✗ |
return bp::call<void>(this->get_override("calc").ptr(), data, (VectorXs)x); |
52 |
|
|
} |
53 |
|
|
|
54 |
|
✗ |
void calcDiff(const std::shared_ptr<ImpulseData>& data, |
55 |
|
|
const Eigen::Ref<const VectorXs>& x) override { |
56 |
|
✗ |
assert_pretty(static_cast<std::size_t>(x.size()) == state_->get_nx(), |
57 |
|
|
"x has wrong dimension"); |
58 |
|
✗ |
return bp::call<void>(this->get_override("calcDiff").ptr(), data, |
59 |
|
✗ |
(VectorXs)x); |
60 |
|
|
} |
61 |
|
|
|
62 |
|
✗ |
void updateForce(const std::shared_ptr<ImpulseData>& data, |
63 |
|
|
const VectorXs& force) override { |
64 |
|
✗ |
assert_pretty(static_cast<std::size_t>(force.size()) == nc_, |
65 |
|
|
"force has wrong dimension"); |
66 |
|
✗ |
return bp::call<void>(this->get_override("updateForce").ptr(), data, force); |
67 |
|
|
} |
68 |
|
|
|
69 |
|
✗ |
std::shared_ptr<ImpulseData> createData( |
70 |
|
|
pinocchio::DataTpl<Scalar>* const data) override { |
71 |
|
✗ |
enableMultithreading() = false; |
72 |
|
✗ |
if (boost::python::override createData = this->get_override("createData")) { |
73 |
|
|
return bp::call<std::shared_ptr<ImpulseData>>(createData.ptr(), |
74 |
|
✗ |
boost::ref(data)); |
75 |
|
|
} |
76 |
|
✗ |
return ImpulseModel::createData(data); |
77 |
|
|
} |
78 |
|
|
|
79 |
|
✗ |
std::shared_ptr<ImpulseData> default_createData( |
80 |
|
|
pinocchio::DataTpl<Scalar>* const data) { |
81 |
|
✗ |
return this->ImpulseModel::createData(data); |
82 |
|
|
} |
83 |
|
|
|
84 |
|
|
template <typename NewScalar> |
85 |
|
✗ |
ImpulseModelAbstractTpl_wrap<NewScalar> cast() const { |
86 |
|
|
typedef ImpulseModelAbstractTpl_wrap<NewScalar> ReturnType; |
87 |
|
|
typedef StateMultibodyTpl<NewScalar> StateType; |
88 |
|
✗ |
ReturnType ret( |
89 |
|
✗ |
std::make_shared<StateType>(state_->template cast<NewScalar>()), type_, |
90 |
|
✗ |
nc_); |
91 |
|
✗ |
return ret; |
92 |
|
|
} |
93 |
|
|
}; |
94 |
|
|
|
95 |
|
|
} // namespace python |
96 |
|
|
} // namespace crocoddyl |
97 |
|
|
|
98 |
|
|
#endif // BINDINGS_PYTHON_CROCODDYL_MULTIBODY_IMPULSE_BASE_HPP_ |
99 |
|
|
|