kinematics-dynamics
ConfigurationSelector.hpp
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 #ifndef __CONFIGURATION_SELECTOR_HPP__
4 #define __CONFIGURATION_SELECTOR_HPP__
5 
6 #include <vector>
7 
8 #include <kdl/frames.hpp>
9 #include <kdl/jntarray.hpp>
10 
11 namespace roboticslab
12 {
13 
20 {
21 public:
28  ConfigurationSelector(const KDL::JntArray & qMin, const KDL::JntArray & qMax)
29  : _qMin(qMin),
30  _qMax(qMax)
31  {}
32 
34  virtual ~ConfigurationSelector() = default;
35 
44  virtual bool configure(const std::vector<KDL::JntArray> & solutions);
45 
53  virtual bool findOptimalConfiguration(const KDL::JntArray & qGuess) = 0;
54 
60  virtual void retrievePose(KDL::JntArray & q) const
61  {
62  q = *optimalConfig.retrievePose();
63  }
64 
65 protected:
70  {
71  public:
74  : q(nullptr),
75  valid(false)
76  {}
77 
79  void store(const KDL::JntArray * q)
80  { this->q = q; }
81 
83  void validate(const KDL::JntArray & qMin, const KDL::JntArray & qMax);
84 
86  const KDL::JntArray * retrievePose() const
87  { return q; }
88 
90  bool isValid() const
91  { return valid; }
92 
94  void invalidate()
95  { valid = false; }
96 
97  private:
98  const KDL::JntArray * q;
99  bool valid;
100  };
101 
102  KDL::JntArray _qMin, _qMax;
103 
104  Configuration optimalConfig;
105 
106  std::vector<Configuration> configs;
107 };
108 
122 {
123 public:
130  ConfigurationSelectorLeastOverallAngularDisplacement(const KDL::JntArray & qMin, const KDL::JntArray & qMax)
131  : ConfigurationSelector(qMin, qMax),
132  lastValid(INVALID_CONFIG)
133  {}
134 
135  bool findOptimalConfiguration(const KDL::JntArray & qGuess) override;
136 
137 protected:
139  std::vector<double> getDiffs(const KDL::JntArray & qGuess, const Configuration & config);
140 
141  int lastValid;
142 
143  static const int INVALID_CONFIG = -1;
144 };
145 
155 {
156 public:
163  ConfigurationSelectorHumanoidGait(const KDL::JntArray & qMin, const KDL::JntArray & qMax)
165  {}
166 
167  bool findOptimalConfiguration(const KDL::JntArray & qGuess) override;
168 
169 private:
171  bool applyConstraints(const Configuration & config);
172 };
173 
183 {
184 public:
190  virtual ConfigurationSelector * create() const = 0;
191  virtual ~ConfigurationSelectorFactory() = default;
192 
193 protected:
200  ConfigurationSelectorFactory(const KDL::JntArray & qMin, const KDL::JntArray & qMax)
201  : _qMin(qMin), _qMax(qMax)
202  {}
203 
204  KDL::JntArray _qMin, _qMax;
205 };
206 
215 {
216 public:
223  ConfigurationSelectorLeastOverallAngularDisplacementFactory(const KDL::JntArray & qMin, const KDL::JntArray & qMax)
224  : ConfigurationSelectorFactory(qMin, qMax)
225  {}
226 
227  ConfigurationSelector * create() const override
228  {
230  }
231 };
232 
241 {
242 public:
249  ConfigurationSelectorHumanoidGaitFactory(const KDL::JntArray & qMin, const KDL::JntArray & qMax)
250  : ConfigurationSelectorFactory(qMin, qMax)
251  {}
252 
253  ConfigurationSelector * create() const override
254  {
255  if (_qMin.rows() == 6 && _qMax.rows() == 6)
256  {
257  return new ConfigurationSelectorHumanoidGait(_qMin, _qMax);
258  }
259  else
260  {
261  return nullptr;
262  }
263  }
264 };
265 
266 } // namespace roboticslab
267 
268 #endif // __CONFIGURATION_SELECTOR_HPP__
Base factory class for ConfigurationSelector.
Definition: ConfigurationSelector.hpp:183
ConfigurationSelectorFactory(const KDL::JntArray &qMin, const KDL::JntArray &qMax)
Constructor.
Definition: ConfigurationSelector.hpp:200
virtual ConfigurationSelector * create() const =0
Creates an instance of the concrete class.
Implementation factory class for ConfigurationSelectorHumanoidGait.
Definition: ConfigurationSelector.hpp:241
ConfigurationSelectorHumanoidGaitFactory(const KDL::JntArray &qMin, const KDL::JntArray &qMax)
Constructor.
Definition: ConfigurationSelector.hpp:249
ConfigurationSelector * create() const override
Creates an instance of the concrete class.
Definition: ConfigurationSelector.hpp:253
IK solver configuration strategy selector based on human walking.
Definition: ConfigurationSelector.hpp:155
bool applyConstraints(const Configuration &config)
Determines whether the configuration is valid according to this selector's premises.
Definition: ConfigurationSelectorHumanoidGait.cpp:29
bool findOptimalConfiguration(const KDL::JntArray &qGuess) override
Analyzes available configurations and selects the optimal one.
Definition: ConfigurationSelectorHumanoidGait.cpp:11
ConfigurationSelectorHumanoidGait(const KDL::JntArray &qMin, const KDL::JntArray &qMax)
Constructor.
Definition: ConfigurationSelector.hpp:163
Implementation factory class for ConfigurationSelectorLeastOverallAngularDisplacement.
Definition: ConfigurationSelector.hpp:215
ConfigurationSelector * create() const override
Creates an instance of the concrete class.
Definition: ConfigurationSelector.hpp:227
ConfigurationSelectorLeastOverallAngularDisplacementFactory(const KDL::JntArray &qMin, const KDL::JntArray &qMax)
Constructor.
Definition: ConfigurationSelector.hpp:223
IK solver configuration strategy selector based on the overall displacement of all joints.
Definition: ConfigurationSelector.hpp:122
ConfigurationSelectorLeastOverallAngularDisplacement(const KDL::JntArray &qMin, const KDL::JntArray &qMax)
Constructor.
Definition: ConfigurationSelector.hpp:130
std::vector< double > getDiffs(const KDL::JntArray &qGuess, const Configuration &config)
Obtains vector of differences between current and desired joint values.
Definition: ConfigurationSelectorLeastOverallAngularDisplacement.cpp:58
bool findOptimalConfiguration(const KDL::JntArray &qGuess) override
Analyzes available configurations and selects the optimal one.
Definition: ConfigurationSelectorLeastOverallAngularDisplacement.cpp:12
Helper class to store a specific robot configuration.
Definition: ConfigurationSelector.hpp:70
const KDL::JntArray * retrievePose() const
Retrieves stored joint values.
Definition: ConfigurationSelector.hpp:86
Configuration()
Constructor.
Definition: ConfigurationSelector.hpp:73
void validate(const KDL::JntArray &qMin, const KDL::JntArray &qMax)
Checks reachability against provided joint limits.
Definition: ConfigurationSelector.cpp:39
void store(const KDL::JntArray *q)
Initializes joint values.
Definition: ConfigurationSelector.hpp:79
bool isValid() const
Whether this configuration is attainable or not.
Definition: ConfigurationSelector.hpp:90
void invalidate()
Mark this configuration as invalid.
Definition: ConfigurationSelector.hpp:94
Abstract base class for a robot configuration strategy selector.
Definition: ConfigurationSelector.hpp:20
ConfigurationSelector(const KDL::JntArray &qMin, const KDL::JntArray &qMax)
Constructor.
Definition: ConfigurationSelector.hpp:28
virtual bool findOptimalConfiguration(const KDL::JntArray &qGuess)=0
Analyzes available configurations and selects the optimal one.
virtual ~ConfigurationSelector()=default
Destructor.
virtual bool configure(const std::vector< KDL::JntArray > &solutions)
Stores initial values for a specific pose.
Definition: ConfigurationSelector.cpp:21
virtual void retrievePose(KDL::JntArray &q) const
Queries computed joint values for the optimal configuration.
Definition: ConfigurationSelector.hpp:60
The main, catch-all namespace for Robotics Lab UC3M.
Definition: groups.dox:6