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