Directory: | ./ |
---|---|
File: | unittest/factory/impulse.cpp |
Date: | 2025-01-16 08:47:40 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 72 | 80 | 90.0% |
Branches: | 34 | 61 | 55.7% |
Line | Branch | Exec | Source |
---|---|---|---|
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 |
6/8✓ Branch 0 taken 5 times.
✓ Branch 1 taken 5 times.
✓ Branch 2 taken 5 times.
✓ Branch 3 taken 5 times.
✓ Branch 4 taken 5 times.
✓ Branch 5 taken 5 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
|
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 | 403 | ImpulseModelFactory::ImpulseModelFactory() {} | |
54 | 403 | ImpulseModelFactory::~ImpulseModelFactory() {} | |
55 | |||
56 | 403 | boost::shared_ptr<crocoddyl::ImpulseModelAbstract> ImpulseModelFactory::create( | |
57 | ImpulseModelTypes::Type impulse_type, PinocchioModelTypes::Type model_type, | ||
58 | const std::string frame_name) const { | ||
59 | 403 | boost::shared_ptr<crocoddyl::ImpulseModelAbstract> impulse; | |
60 |
1/2✓ Branch 1 taken 403 times.
✗ Branch 2 not taken.
|
403 | PinocchioModelFactory model_factory(model_type); |
61 | boost::shared_ptr<crocoddyl::StateMultibody> state = | ||
62 |
2/4✓ Branch 1 taken 403 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 403 times.
✗ Branch 5 not taken.
|
403 | boost::make_shared<crocoddyl::StateMultibody>(model_factory.create()); |
63 | 403 | boost::shared_ptr<crocoddyl::ContactModelAbstract> contact; | |
64 | 403 | std::size_t frame_id = 0; | |
65 |
2/2✓ Branch 1 taken 189 times.
✓ Branch 2 taken 214 times.
|
403 | if (frame_name == "") { |
66 |
1/2✓ Branch 1 taken 189 times.
✗ Branch 2 not taken.
|
189 | frame_id = model_factory.get_frame_ids()[0]; |
67 | } else { | ||
68 |
1/2✓ Branch 4 taken 214 times.
✗ Branch 5 not taken.
|
214 | frame_id = state->get_pinocchio()->getFrameId(frame_name); |
69 | } | ||
70 |
6/7✓ Branch 0 taken 100 times.
✓ Branch 1 taken 50 times.
✓ Branch 2 taken 50 times.
✓ Branch 3 taken 110 times.
✓ Branch 4 taken 68 times.
✓ Branch 5 taken 25 times.
✗ Branch 6 not taken.
|
403 | switch (impulse_type) { |
71 | 100 | case ImpulseModelTypes::ImpulseModel3D_LOCAL: | |
72 | 100 | impulse = boost::make_shared<crocoddyl::ImpulseModel3D>( | |
73 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
100 | state, frame_id, pinocchio::ReferenceFrame::LOCAL); |
74 | 100 | break; | |
75 | 50 | case ImpulseModelTypes::ImpulseModel3D_WORLD: | |
76 | 50 | impulse = boost::make_shared<crocoddyl::ImpulseModel3D>( | |
77 |
1/2✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
|
50 | state, frame_id, pinocchio::ReferenceFrame::WORLD); |
78 | 50 | break; | |
79 | 50 | case ImpulseModelTypes::ImpulseModel3D_LWA: | |
80 | 50 | impulse = boost::make_shared<crocoddyl::ImpulseModel3D>( | |
81 |
1/2✓ Branch 1 taken 50 times.
✗ Branch 2 not taken.
|
50 | state, frame_id, pinocchio::ReferenceFrame::LOCAL_WORLD_ALIGNED); |
82 | 50 | break; | |
83 | 110 | case ImpulseModelTypes::ImpulseModel6D_LOCAL: | |
84 | 110 | impulse = boost::make_shared<crocoddyl::ImpulseModel6D>( | |
85 |
1/2✓ Branch 1 taken 110 times.
✗ Branch 2 not taken.
|
110 | state, frame_id, pinocchio::ReferenceFrame::LOCAL); |
86 | 110 | break; | |
87 | 68 | case ImpulseModelTypes::ImpulseModel6D_WORLD: | |
88 | 68 | impulse = boost::make_shared<crocoddyl::ImpulseModel6D>( | |
89 |
1/2✓ Branch 1 taken 68 times.
✗ Branch 2 not taken.
|
68 | state, frame_id, pinocchio::ReferenceFrame::WORLD); |
90 | 68 | break; | |
91 | 25 | case ImpulseModelTypes::ImpulseModel6D_LWA: | |
92 | 25 | impulse = boost::make_shared<crocoddyl::ImpulseModel6D>( | |
93 |
1/2✓ Branch 1 taken 25 times.
✗ Branch 2 not taken.
|
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 | 806 | return impulse; | |
100 | 403 | } | |
101 | |||
102 | 39 | boost::shared_ptr<crocoddyl::ImpulseModelAbstract> create_random_impulse() { | |
103 | static bool once = true; | ||
104 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 38 times.
|
39 | if (once) { |
105 | 1 | srand((unsigned)time(NULL)); | |
106 | 1 | once = false; | |
107 | } | ||
108 | 39 | boost::shared_ptr<crocoddyl::ImpulseModelAbstract> impulse; | |
109 |
1/2✓ Branch 1 taken 39 times.
✗ Branch 2 not taken.
|
39 | ImpulseModelFactory factory; |
110 |
2/2✓ Branch 1 taken 17 times.
✓ Branch 2 taken 22 times.
|
39 | if (rand() % 2 == 0) { |
111 |
2/4✓ Branch 2 taken 17 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 17 times.
✗ Branch 6 not taken.
|
34 | impulse = factory.create(ImpulseModelTypes::ImpulseModel3D_LOCAL, |
112 | 17 | PinocchioModelTypes::RandomHumanoid); | |
113 | } else { | ||
114 |
2/4✓ Branch 2 taken 22 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 22 times.
✗ Branch 6 not taken.
|
44 | impulse = factory.create(ImpulseModelTypes::ImpulseModel6D_LOCAL, |
115 | 22 | PinocchioModelTypes::RandomHumanoid); | |
116 | } | ||
117 | 78 | return impulse; | |
118 | 39 | } | |
119 | |||
120 | } // namespace unittest | ||
121 | } // namespace crocoddyl | ||
122 |