GCC Code Coverage Report


Directory: ./
File: unittest/factory/pinocchio_model.hpp
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 6 6 100.0%
Branches: 4 6 66.7%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2019-2022, University of Edinburgh, Heriot-Watt University
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #ifndef CROCODDYL_PINOCCHIO_MODEL_FACTORY_HPP_
10 #define CROCODDYL_PINOCCHIO_MODEL_FACTORY_HPP_
11
12 #include <pinocchio/algorithm/center-of-mass.hpp>
13 #include <pinocchio/algorithm/centroidal-derivatives.hpp>
14 #include <pinocchio/algorithm/centroidal.hpp>
15 #include <pinocchio/algorithm/frames.hpp>
16 #include <pinocchio/algorithm/jacobian.hpp>
17 #include <pinocchio/algorithm/kinematics-derivatives.hpp>
18 #include <pinocchio/algorithm/kinematics.hpp>
19 #include <pinocchio/fwd.hpp>
20 #include <pinocchio/parsers/sample-models.hpp>
21 #include <pinocchio/parsers/srdf.hpp>
22 #include <pinocchio/parsers/urdf.hpp>
23
24 #include "crocoddyl/core/utils/exception.hpp"
25
26 namespace crocoddyl {
27 namespace unittest {
28
29 struct PinocchioModelTypes {
30 enum Type {
31 Hector,
32 TalosArm,
33 HyQ,
34 Talos,
35 RandomHumanoid,
36 NbPinocchioModelTypes
37 };
38 23 static std::vector<Type> init_all() {
39 23 std::vector<Type> v;
40
1/2
✓ Branch 1 taken 23 times.
✗ Branch 2 not taken.
23 v.reserve(NbPinocchioModelTypes);
41
2/2
✓ Branch 0 taken 115 times.
✓ Branch 1 taken 23 times.
138 for (int i = 0; i < NbPinocchioModelTypes; ++i) {
42
1/2
✓ Branch 1 taken 115 times.
✗ Branch 2 not taken.
115 v.push_back((Type)i);
43 }
44 23 return v;
45 }
46 static const std::vector<Type> all;
47 };
48
49 std::ostream& operator<<(std::ostream& os, PinocchioModelTypes::Type type);
50
51 class PinocchioModelFactory {
52 public:
53 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
54
55 PinocchioModelFactory(PinocchioModelTypes::Type type);
56 ~PinocchioModelFactory();
57
58 void construct_model(const std::string& urdf_file = "",
59 const std::string& srdf_file = "",
60 bool free_flyer = true);
61
62 boost::shared_ptr<pinocchio::Model> create() const;
63 std::vector<std::string> get_frame_names() const;
64 std::vector<std::size_t> get_frame_ids() const;
65 std::size_t get_contact_nc() const;
66
67 private:
68 boost::shared_ptr<pinocchio::Model>
69 model_; //!< The pointer to the state in testing
70 std::vector<std::string> frame_name_; //!< Frame name for unittesting
71 std::vector<std::size_t> frame_id_; //!< Frame id for unittesting
72 std::size_t contact_nc_; //!< Dimension of the contact
73 };
74
75 /**
76 * @brief Compute all the pinocchio data needed for the numerical
77 * differentiation. We use the address of the object to avoid a copy from the
78 * "boost::bind".
79 *
80 * @param model[in] Pinocchio model
81 * @param data[out] Pinocchio data
82 * @param x[in] State vector
83 * @param u[in] Control vector
84 */
85 void updateAllPinocchio(pinocchio::Model* const model, pinocchio::Data* data,
86 const Eigen::VectorXd& x,
87 const Eigen::VectorXd& u = Eigen::VectorXd());
88
89 } // namespace unittest
90 } // namespace crocoddyl
91
92 #endif // CROCODDYL_PINOCCHIO_MODEL_FACTORY_HPP_
93