GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/hpp/rbprm/sampling/heuristic-tools.hh Lines: 0 11 0.0 %
Date: 2024-02-02 12:21:48 Branches: 0 18 0.0 %

Line Branch Exec Source
1
#ifndef HPP_HEURISTIC_TOOLS_HH
2
#define HPP_HEURISTIC_TOOLS_HH
3
4
#include <hpp/core/path.hh>
5
#include <hpp/pinocchio/device.hh>  // way to get the includes of fcl, ...
6
#include <map>
7
8
namespace hpp {
9
namespace rbprm {
10
namespace sampling {
11
12
/// Defines a parameters set for the ZMP-based heuristic
13
struct HeuristicParam {
14
  std::map<std::string, fcl::Vec3f>
15
      contactPositions_;  // to get the others contacts (without the considered
16
                          // sample)
17
  fcl::Vec3f comPosition_;        // The CoM position
18
  fcl::Vec3f comSpeed_;           // The CoM speed
19
  fcl::Vec3f comAcceleration_;    // The CoM acceleration
20
  std::string sampleLimbName_;    // The name of the considered sample
21
  fcl::Transform3f tfWorldRoot_;  // The transform between the world coordinate
22
                                  // system and the root of the robot
23
  core::PathConstPtr_t
24
      comPath_;           // path followed by the CoM (found by planning)
25
  double currentPathId_;  // current id inside comPath (comPath(currentPathId)
26
                          // == comPosition
27
  fcl::Vec3f
28
      limbReferenceOffset_;  // offset between position of the root and position
29
                             // of the end effector in the reference config
30
31
  HeuristicParam() {}
32
  HeuristicParam(const std::map<std::string, fcl::Vec3f>& cp,
33
                 const fcl::Vec3f& comPos, const fcl::Vec3f& comSp,
34
                 const fcl::Vec3f& comAcc, const std::string& sln,
35
                 const fcl::Transform3f& tf);
36
  HeuristicParam(const HeuristicParam& zhp);
37
38
  HeuristicParam& operator=(const HeuristicParam& zhp);
39
};
40
41
/// Computes the transform of a point
42
///
43
/// \param p The considered point
44
/// \param tr The translation to apply
45
/// \param ro The rotation to apply
46
/// \return The transformed point
47
fcl::Vec3f transform(const fcl::Vec3f& p, const fcl::Vec3f& tr,
48
                     const fcl::Matrix3f& ro);
49
50
/// Data structure to store 2-dimensional informations (2D vectors)
51
struct Vec2D {
52
  double x;
53
  double y;
54
  Vec2D() : x(0), y(0) {}
55
  Vec2D(double xx, double yy) : x(xx), y(yy) {}
56
  Vec2D(const Vec2D& c2D) : x(c2D.x), y(c2D.y) {}
57
  Vec2D& operator=(const Vec2D& c);
58
  double operator[](int idx) const;
59
  double& operator[](int idx);
60
  static double euclideanDist(const Vec2D& v1, const Vec2D& v2);
61
};
62
bool operator==(const Vec2D& v1, const Vec2D& v2);
63
bool operator!=(const Vec2D& v1, const Vec2D& v2);
64
std::ostream& operator<<(std::ostream& out, const Vec2D& v);
65
66
/// Function to verify the existence of an element in a std::vector
67
template <typename T>
68
bool contains(const std::vector<T>& vect, const T& val) {
69
  bool found(false);
70
  for (unsigned int i = 0; !found && (i < vect.size()); ++i) {
71
    if (vect[i] == val) found = true;
72
  }
73
  return found;
74
}
75
76
/// Data structure to define a plane corresponding to the following equation :
77
/// ax + by + cz + d = 0
78
struct Plane {
79
  double a;
80
  double b;
81
  double c;
82
  double d;
83
  Plane() : a(0), b(0), c(1), d(0) {}
84
  Plane(double aa, double bb, double cc, double dd)
85
      : a(aa), b(bb), c(cc), d(dd) {}
86
  Plane(const Plane& pe) : a(pe.a), b(pe.b), c(pe.c), d(pe.d) {}
87
  Plane& operator=(const Plane& pe);
88
};
89
90
/// Computes the angle between 2 vectors on the same base point
91
///
92
/// \param center The base point of the vectors
93
/// \param end1 The end point of the first vector
94
/// \param end2 The end point of the second vector
95
/// \return The angle between the two vectors (non oriented)
96
double computeAngle(const Vec2D& center, const Vec2D& end1, const Vec2D& end2);
97
98
/// Computes the support polygon
99
///
100
/// \param contactPositions The map of the contact positions
101
/// \return The support polygon (orthogonal projection of the contact positions
102
/// in the ground plane)
103
std::vector<Vec2D> computeSupportPolygon(
104
    const std::map<std::string, fcl::Vec3f>& contactPositions);
105
106
/// Computes the convex hull of a set
107
///
108
/// \param set The set we want to get the convex hull
109
/// \return The convex hull of the specified set
110
std::vector<Vec2D> convexHull(std::vector<Vec2D> set);
111
112
/// Computes the weighted centroid of a convex polygon
113
/// This is the "real (visual) center" of a polygon (an approximation of it in
114
/// the worst case)
115
///
116
/// \param convexPolygon The convex polygon to whom we want to find the weighted
117
/// centroid \return The weighted centroid of the specified convex polygon
118
Vec2D weightedCentroidConvex2D(const std::vector<Vec2D>& convexPolygon);
119
120
/// Remove the contacts that does not belong to the "ground"
121
///
122
/// \param contacts The considered contacts map
123
void removeNonGroundContacts(std::map<std::string, fcl::Vec3f>& contacts,
124
                             double groundThreshold);
125
126
}  // namespace sampling
127
}  // namespace rbprm
128
}  // namespace hpp
129
130
#endif