Directory: | ./ |
---|---|
File: | unittest/factory/actuation.cpp |
Date: | 2025-02-24 23:41:29 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 70 | 77 | 90.9% |
Branches: | 46 | 95 | 48.4% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | ||
2 | // BSD 3-Clause License | ||
3 | // | ||
4 | // Copyright (C) 2019-2024, University of Edinburgh, Heriot-Watt University | ||
5 | // Copyright note valid unless otherwise stated in individual files. | ||
6 | // All rights reserved. | ||
7 | /////////////////////////////////////////////////////////////////////////////// | ||
8 | |||
9 | #include "actuation.hpp" | ||
10 | |||
11 | #include "crocoddyl/core/actuation/actuation-squashing.hpp" | ||
12 | #include "crocoddyl/core/actuation/squashing-base.hpp" | ||
13 | #include "crocoddyl/core/actuation/squashing/smooth-sat.hpp" | ||
14 | #include "crocoddyl/core/utils/exception.hpp" | ||
15 | #include "crocoddyl/multibody/actuations/floating-base-thrusters.hpp" | ||
16 | #include "crocoddyl/multibody/actuations/floating-base.hpp" | ||
17 | #include "crocoddyl/multibody/actuations/full.hpp" | ||
18 | |||
19 | namespace crocoddyl { | ||
20 | namespace unittest { | ||
21 | |||
22 | const std::vector<ActuationModelTypes::Type> ActuationModelTypes::all( | ||
23 | ActuationModelTypes::init_all()); | ||
24 | |||
25 | 259 | std::ostream& operator<<(std::ostream& os, ActuationModelTypes::Type type) { | |
26 |
4/6✓ Branch 0 taken 57 times.
✓ Branch 1 taken 116 times.
✓ Branch 2 taken 31 times.
✓ Branch 3 taken 55 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
|
259 | switch (type) { |
27 | 57 | case ActuationModelTypes::ActuationModelFull: | |
28 | 57 | os << "ActuationModelFull"; | |
29 | 57 | break; | |
30 | 116 | case ActuationModelTypes::ActuationModelFloatingBase: | |
31 | 116 | os << "ActuationModelFloatingBase"; | |
32 | 116 | break; | |
33 | 31 | case ActuationModelTypes::ActuationModelFloatingBaseThrusters: | |
34 | 31 | os << "ActuationModelFloatingBaseThrusters"; | |
35 | 31 | break; | |
36 | 55 | case ActuationModelTypes::ActuationModelSquashingFull: | |
37 | 55 | os << "ActuationModelSquashingFull"; | |
38 | 55 | break; | |
39 | ✗ | case ActuationModelTypes::NbActuationModelTypes: | |
40 | ✗ | os << "NbActuationModelTypes"; | |
41 | ✗ | break; | |
42 | ✗ | default: | |
43 | ✗ | break; | |
44 | } | ||
45 | 259 | return os; | |
46 | } | ||
47 | |||
48 | 1709 | ActuationModelFactory::ActuationModelFactory() {} | |
49 | 1709 | ActuationModelFactory::~ActuationModelFactory() {} | |
50 | |||
51 | std::shared_ptr<crocoddyl::ActuationModelAbstract> | ||
52 | 1709 | ActuationModelFactory::create(ActuationModelTypes::Type actuation_type, | |
53 | StateModelTypes::Type state_type) const { | ||
54 | 1709 | std::shared_ptr<crocoddyl::ActuationModelAbstract> actuation; | |
55 |
1/2✓ Branch 1 taken 1709 times.
✗ Branch 2 not taken.
|
1709 | StateModelFactory factory; |
56 |
1/2✓ Branch 1 taken 1709 times.
✗ Branch 2 not taken.
|
1709 | std::shared_ptr<crocoddyl::StateAbstract> state = factory.create(state_type); |
57 | 1709 | std::shared_ptr<crocoddyl::StateMultibody> state_multibody; | |
58 | // Thruster objects | ||
59 | 1709 | std::vector<crocoddyl::Thruster> ps; | |
60 | 1709 | const double d_cog = 0.1525; | |
61 | 1709 | const double cf = 6.6e-5; | |
62 | 1709 | const double cm = 1e-6; | |
63 |
3/6✓ Branch 1 taken 1709 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1709 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1709 times.
✗ Branch 8 not taken.
|
1709 | pinocchio::SE3 p1(Eigen::Matrix3d::Identity(), Eigen::Vector3d(d_cog, 0, 0)); |
64 |
3/6✓ Branch 1 taken 1709 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1709 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1709 times.
✗ Branch 8 not taken.
|
1709 | pinocchio::SE3 p2(Eigen::Matrix3d::Identity(), Eigen::Vector3d(0, d_cog, 0)); |
65 |
3/6✓ Branch 1 taken 1709 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1709 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1709 times.
✗ Branch 8 not taken.
|
1709 | pinocchio::SE3 p3(Eigen::Matrix3d::Identity(), Eigen::Vector3d(-d_cog, 0, 0)); |
66 |
3/6✓ Branch 1 taken 1709 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1709 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1709 times.
✗ Branch 8 not taken.
|
1709 | pinocchio::SE3 p4(Eigen::Matrix3d::Identity(), Eigen::Vector3d(0, -d_cog, 0)); |
67 |
2/4✓ Branch 2 taken 1709 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1709 times.
✗ Branch 6 not taken.
|
1709 | ps.push_back(crocoddyl::Thruster(p1, cm / cf, crocoddyl::ThrusterType::CCW)); |
68 |
2/4✓ Branch 2 taken 1709 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1709 times.
✗ Branch 6 not taken.
|
1709 | ps.push_back(crocoddyl::Thruster(p2, cm / cf, crocoddyl::ThrusterType::CW)); |
69 |
2/4✓ Branch 2 taken 1709 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1709 times.
✗ Branch 6 not taken.
|
1709 | ps.push_back(crocoddyl::Thruster(p3, cm / cf, crocoddyl::ThrusterType::CW)); |
70 |
2/4✓ Branch 2 taken 1709 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1709 times.
✗ Branch 6 not taken.
|
1709 | ps.push_back(crocoddyl::Thruster(p4, cm / cf, crocoddyl::ThrusterType::CCW)); |
71 | // Actuation Squashing objects | ||
72 | 1709 | std::shared_ptr<crocoddyl::ActuationModelAbstract> act; | |
73 | 1709 | std::shared_ptr<crocoddyl::SquashingModelSmoothSat> squash; | |
74 |
1/2✓ Branch 1 taken 1709 times.
✗ Branch 2 not taken.
|
1709 | Eigen::VectorXd lb; |
75 |
1/2✓ Branch 1 taken 1709 times.
✗ Branch 2 not taken.
|
1709 | Eigen::VectorXd ub; |
76 |
4/5✓ Branch 0 taken 542 times.
✓ Branch 1 taken 692 times.
✓ Branch 2 taken 196 times.
✓ Branch 3 taken 279 times.
✗ Branch 4 not taken.
|
1709 | switch (actuation_type) { |
77 | 542 | case ActuationModelTypes::ActuationModelFull: | |
78 | state_multibody = | ||
79 | 542 | std::static_pointer_cast<crocoddyl::StateMultibody>(state); | |
80 | actuation = | ||
81 |
1/2✓ Branch 1 taken 542 times.
✗ Branch 2 not taken.
|
542 | std::make_shared<crocoddyl::ActuationModelFull>(state_multibody); |
82 | 542 | break; | |
83 | 692 | case ActuationModelTypes::ActuationModelFloatingBase: | |
84 | state_multibody = | ||
85 | 692 | std::static_pointer_cast<crocoddyl::StateMultibody>(state); | |
86 |
1/2✓ Branch 1 taken 692 times.
✗ Branch 2 not taken.
|
1384 | actuation = std::make_shared<crocoddyl::ActuationModelFloatingBase>( |
87 | 692 | state_multibody); | |
88 | 692 | break; | |
89 | 196 | case ActuationModelTypes::ActuationModelFloatingBaseThrusters: | |
90 | state_multibody = | ||
91 | 196 | std::static_pointer_cast<crocoddyl::StateMultibody>(state); | |
92 | actuation = | ||
93 |
1/2✓ Branch 1 taken 196 times.
✗ Branch 2 not taken.
|
392 | std::make_shared<crocoddyl::ActuationModelFloatingBaseThrusters>( |
94 | 196 | state_multibody, ps); | |
95 | 196 | break; | |
96 | 279 | case ActuationModelTypes::ActuationModelSquashingFull: | |
97 | state_multibody = | ||
98 | 279 | std::static_pointer_cast<crocoddyl::StateMultibody>(state); | |
99 | |||
100 |
1/2✓ Branch 1 taken 279 times.
✗ Branch 2 not taken.
|
279 | act = std::make_shared<crocoddyl::ActuationModelFull>(state_multibody); |
101 | |||
102 |
2/4✓ Branch 3 taken 279 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 279 times.
✗ Branch 7 not taken.
|
279 | lb = Eigen::VectorXd::Zero(state->get_nv()); |
103 |
2/4✓ Branch 3 taken 279 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 279 times.
✗ Branch 7 not taken.
|
279 | ub = Eigen::VectorXd::Zero(state->get_nv()); |
104 |
1/2✓ Branch 1 taken 279 times.
✗ Branch 2 not taken.
|
279 | lb.fill(-100.0); |
105 |
1/2✓ Branch 1 taken 279 times.
✗ Branch 2 not taken.
|
279 | ub.fill(100.0); |
106 | 279 | squash = std::make_shared<crocoddyl::SquashingModelSmoothSat>( | |
107 |
1/2✓ Branch 3 taken 279 times.
✗ Branch 4 not taken.
|
279 | lb, ub, state->get_nv()); |
108 | |||
109 | 279 | actuation = std::make_shared<crocoddyl::ActuationSquashingModel>( | |
110 |
1/2✓ Branch 3 taken 279 times.
✗ Branch 4 not taken.
|
279 | act, squash, state->get_nv()); |
111 | 279 | break; | |
112 | ✗ | default: | |
113 | ✗ | throw_pretty(__FILE__ ":\n Construct wrong ActuationModelTypes::Type"); | |
114 | break; | ||
115 | } | ||
116 | 3418 | return actuation; | |
117 | 1709 | } | |
118 | |||
119 | 19935 | void updateActuation( | |
120 | const std::shared_ptr<crocoddyl::ActuationModelAbstract>& model, | ||
121 | const std::shared_ptr<crocoddyl::ActuationDataAbstract>& data, | ||
122 | const Eigen::VectorXd& x, const Eigen::VectorXd& u) { | ||
123 |
2/4✓ Branch 3 taken 19935 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 19935 times.
✗ Branch 7 not taken.
|
19935 | model->calc(data, x, u); |
124 | 19935 | } | |
125 | |||
126 | } // namespace unittest | ||
127 | } // namespace crocoddyl | ||
128 |