GCC Code Coverage Report


Directory: ./
File: unittest/factory/actuation.cpp
Date: 2025-03-26 19:23:43
Exec Total Coverage
Lines: 67 74 90.5%
Branches: 48 99 48.5%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2025, 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/multibody/actuations/floating-base-thrusters.hpp"
15 #include "crocoddyl/multibody/actuations/floating-base.hpp"
16 #include "crocoddyl/multibody/actuations/full.hpp"
17
18 namespace crocoddyl {
19 namespace unittest {
20
21 const std::vector<ActuationModelTypes::Type> ActuationModelTypes::all(
22 ActuationModelTypes::init_all());
23
24 241 std::ostream& operator<<(std::ostream& os, ActuationModelTypes::Type type) {
25
4/6
✓ Branch 0 taken 52 times.
✓ Branch 1 taken 111 times.
✓ Branch 2 taken 28 times.
✓ Branch 3 taken 50 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
241 switch (type) {
26 52 case ActuationModelTypes::ActuationModelFull:
27 52 os << "ActuationModelFull";
28 52 break;
29 111 case ActuationModelTypes::ActuationModelFloatingBase:
30 111 os << "ActuationModelFloatingBase";
31 111 break;
32 28 case ActuationModelTypes::ActuationModelFloatingBaseThrusters:
33 28 os << "ActuationModelFloatingBaseThrusters";
34 28 break;
35 50 case ActuationModelTypes::ActuationModelSquashingFull:
36 50 os << "ActuationModelSquashingFull";
37 50 break;
38 case ActuationModelTypes::NbActuationModelTypes:
39 os << "NbActuationModelTypes";
40 break;
41 default:
42 break;
43 }
44 241 return os;
45 }
46
47 1655 ActuationModelFactory::ActuationModelFactory() {}
48 1655 ActuationModelFactory::~ActuationModelFactory() {}
49
50 std::shared_ptr<crocoddyl::ActuationModelAbstract>
51 1655 ActuationModelFactory::create(ActuationModelTypes::Type actuation_type,
52 StateModelTypes::Type state_type) const {
53 1655 std::shared_ptr<crocoddyl::ActuationModelAbstract> actuation;
54
1/2
✓ Branch 1 taken 1655 times.
✗ Branch 2 not taken.
1655 StateModelFactory factory;
55
1/2
✓ Branch 1 taken 1655 times.
✗ Branch 2 not taken.
1655 std::shared_ptr<crocoddyl::StateAbstract> state = factory.create(state_type);
56 1655 std::shared_ptr<crocoddyl::StateMultibody> state_multibody;
57 // Thruster objects
58 1655 std::vector<crocoddyl::Thruster> ps;
59 1655 const double d_cog = 0.1525;
60 1655 const double cf = 6.6e-5;
61 1655 const double cm = 1e-6;
62
3/6
✓ Branch 1 taken 1655 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1655 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1655 times.
✗ Branch 8 not taken.
1655 pinocchio::SE3 p1(Eigen::Matrix3d::Identity(), Eigen::Vector3d(d_cog, 0, 0));
63
3/6
✓ Branch 1 taken 1655 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1655 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1655 times.
✗ Branch 8 not taken.
1655 pinocchio::SE3 p2(Eigen::Matrix3d::Identity(), Eigen::Vector3d(0, d_cog, 0));
64
3/6
✓ Branch 1 taken 1655 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1655 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1655 times.
✗ Branch 8 not taken.
1655 pinocchio::SE3 p3(Eigen::Matrix3d::Identity(), Eigen::Vector3d(-d_cog, 0, 0));
65
3/6
✓ Branch 1 taken 1655 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1655 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1655 times.
✗ Branch 8 not taken.
1655 pinocchio::SE3 p4(Eigen::Matrix3d::Identity(), Eigen::Vector3d(0, -d_cog, 0));
66
2/4
✓ Branch 2 taken 1655 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1655 times.
✗ Branch 6 not taken.
1655 ps.push_back(crocoddyl::Thruster(p1, cm / cf, crocoddyl::ThrusterType::CCW));
67
2/4
✓ Branch 2 taken 1655 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1655 times.
✗ Branch 6 not taken.
1655 ps.push_back(crocoddyl::Thruster(p2, cm / cf, crocoddyl::ThrusterType::CW));
68
2/4
✓ Branch 2 taken 1655 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1655 times.
✗ Branch 6 not taken.
1655 ps.push_back(crocoddyl::Thruster(p3, cm / cf, crocoddyl::ThrusterType::CW));
69
2/4
✓ Branch 2 taken 1655 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1655 times.
✗ Branch 6 not taken.
1655 ps.push_back(crocoddyl::Thruster(p4, cm / cf, crocoddyl::ThrusterType::CCW));
70 // Actuation Squashing objects
71 1655 std::shared_ptr<crocoddyl::ActuationModelAbstract> act;
72 1655 std::shared_ptr<crocoddyl::SquashingModelSmoothSat> squash;
73
1/2
✓ Branch 1 taken 1655 times.
✗ Branch 2 not taken.
1655 Eigen::VectorXd lb;
74
1/2
✓ Branch 1 taken 1655 times.
✗ Branch 2 not taken.
1655 Eigen::VectorXd ub;
75
4/5
✓ Branch 0 taken 527 times.
✓ Branch 1 taken 677 times.
✓ Branch 2 taken 187 times.
✓ Branch 3 taken 264 times.
✗ Branch 4 not taken.
1655 switch (actuation_type) {
76 527 case ActuationModelTypes::ActuationModelFull:
77 state_multibody =
78 527 std::static_pointer_cast<crocoddyl::StateMultibody>(state);
79 actuation =
80
1/2
✓ Branch 1 taken 527 times.
✗ Branch 2 not taken.
527 std::make_shared<crocoddyl::ActuationModelFull>(state_multibody);
81 527 break;
82 677 case ActuationModelTypes::ActuationModelFloatingBase:
83 state_multibody =
84 677 std::static_pointer_cast<crocoddyl::StateMultibody>(state);
85
1/2
✓ Branch 1 taken 677 times.
✗ Branch 2 not taken.
1354 actuation = std::make_shared<crocoddyl::ActuationModelFloatingBase>(
86 677 state_multibody);
87 677 break;
88 187 case ActuationModelTypes::ActuationModelFloatingBaseThrusters:
89 state_multibody =
90 187 std::static_pointer_cast<crocoddyl::StateMultibody>(state);
91 actuation =
92
1/2
✓ Branch 1 taken 187 times.
✗ Branch 2 not taken.
374 std::make_shared<crocoddyl::ActuationModelFloatingBaseThrusters>(
93 187 state_multibody, ps);
94 187 break;
95 264 case ActuationModelTypes::ActuationModelSquashingFull:
96 state_multibody =
97 264 std::static_pointer_cast<crocoddyl::StateMultibody>(state);
98
99
1/2
✓ Branch 1 taken 264 times.
✗ Branch 2 not taken.
264 act = std::make_shared<crocoddyl::ActuationModelFull>(state_multibody);
100
101
3/6
✓ Branch 2 taken 264 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 264 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 264 times.
✗ Branch 9 not taken.
264 lb = Eigen::VectorXd::Zero(state->get_nv());
102
3/6
✓ Branch 2 taken 264 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 264 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 264 times.
✗ Branch 9 not taken.
264 ub = Eigen::VectorXd::Zero(state->get_nv());
103
1/2
✓ Branch 1 taken 264 times.
✗ Branch 2 not taken.
264 lb.fill(-100.0);
104
1/2
✓ Branch 1 taken 264 times.
✗ Branch 2 not taken.
264 ub.fill(100.0);
105 264 squash = std::make_shared<crocoddyl::SquashingModelSmoothSat>(
106
2/4
✓ Branch 2 taken 264 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 264 times.
✗ Branch 6 not taken.
264 lb, ub, state->get_nv());
107
108 264 actuation = std::make_shared<crocoddyl::ActuationSquashingModel>(
109
2/4
✓ Branch 2 taken 264 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 264 times.
✗ Branch 6 not taken.
264 act, squash, state->get_nv());
110 264 break;
111 default:
112 throw_pretty(__FILE__ ":\n Construct wrong ActuationModelTypes::Type");
113 break;
114 }
115 3310 return actuation;
116 1655 }
117
118 } // namespace unittest
119 } // namespace crocoddyl
120