GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/hpp/rbprm/rbprm-state.hh Lines: 2 10 20.0 %
Date: 2024-02-02 12:21:48 Branches: 1 14 7.1 %

Line Branch Exec Source
1
//
2
// Copyright (c) 2014 CNRS
3
// Authors: Steve Tonneau (steve.tonneau@laas.fr)
4
//
5
// This file is part of hpp-rbprm.
6
// hpp-rbprm is free software: you can redistribute it
7
// and/or modify it under the terms of the GNU Lesser General Public
8
// License as published by the Free Software Foundation, either version
9
// 3 of the License, or (at your option) any later version.
10
//
11
// hpp-rbprm is distributed in the hope that it will be
12
// useful, but WITHOUT ANY WARRANTY; without even the implied warranty
13
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
// General Lesser Public License for more details.  You should have
15
// received a copy of the GNU Lesser General Public License along with
16
// hpp-core  If not, see
17
// <http://www.gnu.org/licenses/>.
18
19
#ifndef HPP_RBPRM_STATE_HH
20
#define HPP_RBPRM_STATE_HH
21
22
#include <algorithm>
23
#include <hpp/pinocchio/device.hh>
24
#include <hpp/rbprm/config.hh>
25
#include <hpp/rbprm/rbprm-limb.hh>
26
#include <queue>
27
28
namespace hpp {
29
namespace rbprm {
30
struct State;
31
typedef std::vector<State> T_State;
32
typedef T_State::const_iterator CIT_State;
33
typedef std::pair<pinocchio::value_type, rbprm::State> StateFrame;
34
typedef std::vector<StateFrame> T_StateFrame;
35
typedef T_StateFrame::const_iterator CIT_StateFrame;
36
37
/// Helper class that maintains active contacts at a given state, as well as
38
/// their locations can be used to determine contact transition wrt a previous
39
/// State
40
struct HPP_RBPRM_DLLAPI State {
41
153
  State() : nbContacts(0), stable(false) {}
42
  State(const State& other);
43
169
  ~State() {}
44
45
  State& operator=(const State& other);
46
47
  /// Removes an active contact from the State
48
  ///
49
  /// \param contactId name of the contact to remove
50
  /// \return true whether the contact was indeed active
51
  bool RemoveContact(const std::string& contactId);
52
53
  /// Removes the first active contact created
54
  /// in the state.Contact order is maintained in a queue
55
  ///
56
  /// \return empty string if no contact was active, otherwise
57
  /// the id of the removed contact
58
  std::string RemoveFirstContact();
59
60
  /// Given a antecedent State, computes the list of contact changes (creations
61
  /// an destructions)
62
  ///
63
  /// \return the list of all modified contacts between two States
64
  std::vector<std::string> contactVariations(const State& previous) const;
65
66
  /// Given an antecedent State and a list of effectors, computes the list of
67
  /// effectors that were not in contact in any of the two states
68
  ///
69
  /// \return the list of all modified contacts between two States
70
  std::vector<std::string> freeVariations(
71
      const State& previous,
72
      const std::vector<std::string>& allEffectors) const;
73
74
  /// Given an antecedent State and a list of effectors, computes the list of
75
  /// all the effectors that moved between the two States (ie contact was not
76
  /// maintained)
77
  ///
78
  /// \return the list of all modified effectors between two States
79
  std::vector<std::string> allVariations(
80
      const State& previous,
81
      const std::vector<std::string>& allEffectors) const;
82
83
  /// Given a antecedent State, computes the list of Contacts that were
84
  /// maintained between the two States (both active at the same location)
85
  ///
86
  /// \return the list of all preserved contacts between two States
87
  std::vector<std::string> fixedContacts(const State& previous) const;
88
89
  /// Given a antecedent State, computes the list of Contacts that were created
90
  /// between the two States
91
  ///
92
  /// \return the list of all created contacts between two States
93
  void contactCreations(const State& previous,
94
                        std::vector<std::string>& outList) const;
95
96
  /// Given a antecedent State, computes the list of Contacts that were created
97
  /// between the two States
98
  ///
99
  /// \return the list of all created contacts between two States
100
  std::vector<std::string> contactCreations(const State& previous) const;
101
102
  /// Given a antecedent State, computes the list of Contacts that were broken
103
  /// between the two States
104
  ///
105
  /// \return the list of all broken contacts between two States
106
  std::vector<std::string> contactBreaks(const State& previous) const;
107
108
  /// Given a antecedent State, computes the list of Contacts that were broken
109
  /// between the two States
110
  ///
111
  /// \return the list of all broken contacts between two States
112
  void contactBreaks(const State& previous,
113
                     std::vector<std::string>& outList) const;
114
115
  void print() const;
116
  void print(std::stringstream& ss) const;
117
  void print(std::stringstream& ss, const State& previous) const;
118
  void printInternal(std::stringstream& ss) const;
119
120
  hpp::pinocchio::Configuration_t configuration_;
121
  std::map<std::string, bool> contacts_;
122
  std::map<std::string, fcl::Vec3f> contactNormals_;
123
  std::map<std::string, fcl::Vec3f> contactPositions_;
124
  std::map<std::string, fcl::Matrix3f> contactRotation_;
125
  std::queue<std::string> contactOrder_;
126
  std::size_t nbContacts;
127
  bool stable;
128
  double robustness;
129
};  // struct State
130
/// Given two State, compute the contact effectors distance travelled
131
/// between two states
132
HPP_RBPRM_DLLAPI pinocchio::value_type effectorDistance(const State& from,
133
                                                        const State& to);
134
135
/// Given a State and a list of effectors, computes the list of
136
/// all the effectors that moved between the two States (ie contact was not
137
/// maintained)
138
///
139
/// \return the list of all modified effectors between two States
140
template <typename Iter>
141
HPP_RBPRM_DLLAPI std::vector<std::string> freeEffectors(const State& state,
142
                                                        Iter start, Iter end) {
143
  std::vector<std::string> res;
144
  for (Iter it = start; it != end; ++it) {
145
    const std::string& eff = *it;
146
    std::map<std::string, bool>::const_iterator cit = state.contacts_.find(eff);
147
    if (cit == state.contacts_.end() || !cit->second) {
148
      res.push_back(eff);
149
    }
150
  }
151
  return res;
152
}
153
}  // namespace rbprm
154
}  // namespace hpp
155
156
#endif  // HPP_RBPRM_STATE_HH