1 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
2 |
|
|
// BSD 3-Clause License |
3 |
|
|
// |
4 |
|
|
// Copyright (C) 2019-2023, University of Edinburgh, LAAS-CNRS, |
5 |
|
|
// Heriot-Watt University |
6 |
|
|
// Copyright note valid unless otherwise stated in individual files. |
7 |
|
|
// All rights reserved. |
8 |
|
|
/////////////////////////////////////////////////////////////////////////////// |
9 |
|
|
|
10 |
|
|
#include "impulse.hpp" |
11 |
|
|
|
12 |
|
|
#include "crocoddyl/core/utils/exception.hpp" |
13 |
|
|
#include "crocoddyl/multibody/impulses/impulse-3d.hpp" |
14 |
|
|
#include "crocoddyl/multibody/impulses/impulse-6d.hpp" |
15 |
|
|
|
16 |
|
|
namespace crocoddyl { |
17 |
|
|
namespace unittest { |
18 |
|
|
|
19 |
|
|
const std::vector<ImpulseModelTypes::Type> ImpulseModelTypes::all( |
20 |
|
|
ImpulseModelTypes::init_all()); |
21 |
|
|
|
22 |
|
30 |
std::ostream& operator<<(std::ostream& os, |
23 |
|
|
const ImpulseModelTypes::Type& type) { |
24 |
✓✓✓✓ ✓✓✗✗
|
30 |
switch (type) { |
25 |
|
5 |
case ImpulseModelTypes::ImpulseModel3D_LOCAL: |
26 |
|
5 |
os << "ImpulseModel3D_LOCAL"; |
27 |
|
5 |
break; |
28 |
|
5 |
case ImpulseModelTypes::ImpulseModel3D_WORLD: |
29 |
|
5 |
os << "ImpulseModel3D_WORLD"; |
30 |
|
5 |
break; |
31 |
|
5 |
case ImpulseModelTypes::ImpulseModel3D_LWA: |
32 |
|
5 |
os << "ImpulseModel3D_LWA"; |
33 |
|
5 |
break; |
34 |
|
5 |
case ImpulseModelTypes::ImpulseModel6D_LOCAL: |
35 |
|
5 |
os << "ImpulseModel6D_LOCAL"; |
36 |
|
5 |
break; |
37 |
|
5 |
case ImpulseModelTypes::ImpulseModel6D_WORLD: |
38 |
|
5 |
os << "ImpulseModel6D_WORLD"; |
39 |
|
5 |
break; |
40 |
|
5 |
case ImpulseModelTypes::ImpulseModel6D_LWA: |
41 |
|
5 |
os << "ImpulseModel6D_LWA"; |
42 |
|
5 |
break; |
43 |
|
|
case ImpulseModelTypes::NbImpulseModelTypes: |
44 |
|
|
os << "NbImpulseModelTypes"; |
45 |
|
|
break; |
46 |
|
|
default: |
47 |
|
|
os << "Unknown type"; |
48 |
|
|
break; |
49 |
|
|
} |
50 |
|
30 |
return os; |
51 |
|
|
} |
52 |
|
|
|
53 |
|
391 |
ImpulseModelFactory::ImpulseModelFactory() {} |
54 |
|
391 |
ImpulseModelFactory::~ImpulseModelFactory() {} |
55 |
|
|
|
56 |
|
391 |
boost::shared_ptr<crocoddyl::ImpulseModelAbstract> ImpulseModelFactory::create( |
57 |
|
|
ImpulseModelTypes::Type impulse_type, PinocchioModelTypes::Type model_type, |
58 |
|
|
const std::string frame_name) const { |
59 |
|
391 |
boost::shared_ptr<crocoddyl::ImpulseModelAbstract> impulse; |
60 |
✓✗ |
782 |
PinocchioModelFactory model_factory(model_type); |
61 |
|
|
boost::shared_ptr<crocoddyl::StateMultibody> state = |
62 |
✓✗✓✗
|
782 |
boost::make_shared<crocoddyl::StateMultibody>(model_factory.create()); |
63 |
|
391 |
boost::shared_ptr<crocoddyl::ContactModelAbstract> contact; |
64 |
|
391 |
std::size_t frame_id = 0; |
65 |
✓✓ |
391 |
if (frame_name == "") { |
66 |
✓✗ |
189 |
frame_id = model_factory.get_frame_ids()[0]; |
67 |
|
|
} else { |
68 |
✓✗ |
202 |
frame_id = state->get_pinocchio()->getFrameId(frame_name); |
69 |
|
|
} |
70 |
✓✓✓✓ ✓✓✗ |
391 |
switch (impulse_type) { |
71 |
|
107 |
case ImpulseModelTypes::ImpulseModel3D_LOCAL: |
72 |
|
107 |
impulse = boost::make_shared<crocoddyl::ImpulseModel3D>( |
73 |
✓✗ |
107 |
state, frame_id, pinocchio::ReferenceFrame::LOCAL); |
74 |
|
107 |
break; |
75 |
|
48 |
case ImpulseModelTypes::ImpulseModel3D_WORLD: |
76 |
|
48 |
impulse = boost::make_shared<crocoddyl::ImpulseModel3D>( |
77 |
✓✗ |
48 |
state, frame_id, pinocchio::ReferenceFrame::WORLD); |
78 |
|
48 |
break; |
79 |
|
48 |
case ImpulseModelTypes::ImpulseModel3D_LWA: |
80 |
|
48 |
impulse = boost::make_shared<crocoddyl::ImpulseModel3D>( |
81 |
✓✗ |
48 |
state, frame_id, pinocchio::ReferenceFrame::LOCAL_WORLD_ALIGNED); |
82 |
|
48 |
break; |
83 |
|
97 |
case ImpulseModelTypes::ImpulseModel6D_LOCAL: |
84 |
|
97 |
impulse = boost::make_shared<crocoddyl::ImpulseModel6D>( |
85 |
✓✗ |
97 |
state, frame_id, pinocchio::ReferenceFrame::LOCAL); |
86 |
|
97 |
break; |
87 |
|
66 |
case ImpulseModelTypes::ImpulseModel6D_WORLD: |
88 |
|
66 |
impulse = boost::make_shared<crocoddyl::ImpulseModel6D>( |
89 |
✓✗ |
66 |
state, frame_id, pinocchio::ReferenceFrame::WORLD); |
90 |
|
66 |
break; |
91 |
|
25 |
case ImpulseModelTypes::ImpulseModel6D_LWA: |
92 |
|
25 |
impulse = boost::make_shared<crocoddyl::ImpulseModel6D>( |
93 |
✓✗ |
25 |
state, frame_id, pinocchio::ReferenceFrame::LOCAL_WORLD_ALIGNED); |
94 |
|
25 |
break; |
95 |
|
|
default: |
96 |
|
|
throw_pretty(__FILE__ ": Wrong ImpulseModelTypes::Type given"); |
97 |
|
|
break; |
98 |
|
|
} |
99 |
|
782 |
return impulse; |
100 |
|
|
} |
101 |
|
|
|
102 |
|
39 |
boost::shared_ptr<crocoddyl::ImpulseModelAbstract> create_random_impulse() { |
103 |
|
|
static bool once = true; |
104 |
✓✓ |
39 |
if (once) { |
105 |
|
1 |
srand((unsigned)time(NULL)); |
106 |
|
1 |
once = false; |
107 |
|
|
} |
108 |
|
39 |
boost::shared_ptr<crocoddyl::ImpulseModelAbstract> impulse; |
109 |
✓✗ |
78 |
ImpulseModelFactory factory; |
110 |
✓✓ |
39 |
if (rand() % 2 == 0) { |
111 |
✓✗✓✗
|
56 |
impulse = factory.create(ImpulseModelTypes::ImpulseModel3D_LOCAL, |
112 |
|
28 |
PinocchioModelTypes::RandomHumanoid); |
113 |
|
|
} else { |
114 |
✓✗✓✗
|
22 |
impulse = factory.create(ImpulseModelTypes::ImpulseModel6D_LOCAL, |
115 |
|
11 |
PinocchioModelTypes::RandomHumanoid); |
116 |
|
|
} |
117 |
|
78 |
return impulse; |
118 |
|
|
} |
119 |
|
|
|
120 |
|
|
} // namespace unittest |
121 |
|
|
} // namespace crocoddyl |