screw-theory-solvers
Loading...
Searching...
No Matches
ScrewTheoryIkProblem.hpp
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3#ifndef __SCREW_THEORY_IK_PROBLEM_HPP__
4#define __SCREW_THEORY_IK_PROBLEM_HPP__
5
6#include <utility>
7#include <vector>
8
9#include <kdl/frames.hpp>
10#include <kdl/jntarray.hpp>
11
12#include "ProductOfExponentials.hpp"
13
14namespace roboticslab
15{
16
26{
27public:
29 using JointConfig = std::vector<double>;
30
32 using Solutions = std::vector<JointConfig>;
33
35 virtual ~ScrewTheoryIkSubproblem() = default;
36
75 virtual bool solve(const KDL::Frame & rhs, const KDL::Frame & pointTransform, const JointConfig & reference, Solutions & solutions) const = 0;
76
77 virtual bool solve(const KDL::Frame & rhs, const KDL::Frame & pointTransform, const JointConfig & reference, Solutions & solutions, const KDL::Frame & H_S_T, const KDL::JntArray & c_solutions) const
78 {
79 return solve(rhs, pointTransform, reference, solutions);
80 }
81
82 virtual bool solve(const KDL::Frame & rhs, const KDL::Frame & pointTransform, const JointConfig & reference, Solutions & solutions, const KDL::Frame & H_S_T, const KDL::JntArray & c_solutions, const KDL::Frame & H_S_T_0) const
83 {
84 return solve(rhs, pointTransform, reference, solutions);
85 }
86
87 bool solve(const KDL::Frame & rhs, const KDL::Frame & pointTransform, Solutions & _solutions) const
88 {
89 return solve(rhs, pointTransform, JointConfig(solutions()), _solutions);
90 }
91
93 virtual int solutions() const = 0;
94
96 virtual const char * describe() const = 0;
97};
98
109{
110public:
112 using JointIdsToSubproblem = std::pair<std::vector<int>, const ScrewTheoryIkSubproblem *>;
113
115 using Steps = std::vector<JointIdsToSubproblem>;
116
118 using Solutions = std::vector<KDL::JntArray>;
119
122
123 // disable these, avoid issues related to dynamic alloc
125 ScrewTheoryIkProblem & operator=(const ScrewTheoryIkProblem &) = delete;
126
137 std::vector<bool> solve(const KDL::Frame & H_S_T, const KDL::JntArray & reference, Solutions & solutions);
138
139 std::vector<bool> solve(const KDL::Frame & H_S_T, Solutions & solutions)
140 {
141 return solve(H_S_T, KDL::JntArray(poe.size()), solutions);
142 }
143
145 int solutions() const
146 { return soln; }
147
149 const Steps & getSteps() const
150 { return steps; }
151
153 bool isReversed() const
154 { return reversed; }
155
165 static ScrewTheoryIkProblem * create(const PoeExpression & poe, const Steps & steps, bool reversed = false);
166
167private:
168 enum poe_term
169 {
170 EXP_KNOWN,
171 EXP_COMPUTED,
172 EXP_UNKNOWN
173 };
174
175 using Frames = std::vector<KDL::Frame>;
176 using PoeTerms = std::vector<poe_term>;
177
178 // disable instantiation, force users to call builder class
179 ScrewTheoryIkProblem(const PoeExpression & poe, const Steps & steps, bool reversed);
180
181 void recalculateFrames(const Solutions & solutions, Frames & frames, PoeTerms & poeTerms);
182 bool recalculateFrames(const Solutions & solutions, Frames & frames, PoeTerms & poeTerms, bool backwards);
183
184 KDL::Frame transformPoint(const KDL::JntArray & jointValues, const PoeTerms & poeTerms);
185
186 const PoeExpression poe;
187
188 // we own these, resources freed in destructor
189 const Steps steps;
190
191 PoeTerms poeTerms;
192 Frames rhsFrames;
193 std::vector<bool> reachability;
194
195 const bool reversed;
196 const int soln;
197};
198
210{
211public:
213 struct PoeTerm
214 {
215 PoeTerm() : known(false), simplified(false) {}
216 bool known, simplified;
217 };
218
225
232
233private:
234 static std::vector<KDL::Vector> searchPoints(const PoeExpression & poe);
235
236 ScrewTheoryIkProblem::Steps searchSolutions();
237
238 void refreshSimplificationState();
239
240 void simplify(int depth);
241 void simplifyWithPadenKahanOne(const KDL::Vector & point);
242 void simplifyWithPadenKahanThree(const KDL::Vector & point);
243 void simplifyWithPardosOne();
244 void simplifyWithPardosFive();
245 bool simplifyWithPardosThree(MatrixExponential & exp1, MatrixExponential & exp2, KDL::Vector & point);
246
248
249 PoeExpression poe;
250
251 std::vector<KDL::Vector> points;
252 std::vector<KDL::Vector> testPoints;
253
254 std::vector<PoeTerm> poeTerms;
255
256 static const int MAX_SIMPLIFICATION_DEPTH = 2;
257};
258
259} // namespace roboticslab
260
261#endif // __SCREW_THEORY_IK_PROBLEM_HPP__
Abstraction of a term in a product of exponentials (POE) formula.
Definition MatrixExponential.hpp:19
Abstraction of a product of exponentials (POE) formula.
Definition ProductOfExponentials.hpp:28
int size() const
Size of this POE.
Definition ProductOfExponentials.hpp:76
Automated IK solution finder.
Definition ScrewTheoryIkProblem.hpp:210
ScrewTheoryIkProblem * build()
Finds a valid sequence of geometric subproblems that solve a global IK problem.
Definition ScrewTheoryIkProblemBuilder.cpp:232
Proxy IK problem solver class that iterates over a sequence of subproblems.
Definition ScrewTheoryIkProblem.hpp:109
static ScrewTheoryIkProblem * create(const PoeExpression &poe, const Steps &steps, bool reversed=false)
Creates an IK solver instance given a sequence of known subproblems.
Definition ScrewTheoryIkProblem.cpp:294
std::vector< KDL::JntArray > Solutions
Collection of global IK solutions.
Definition ScrewTheoryIkProblem.hpp:118
~ScrewTheoryIkProblem()
Destructor.
Definition ScrewTheoryIkProblem.cpp:71
std::pair< std::vector< int >, const ScrewTheoryIkSubproblem * > JointIdsToSubproblem
Pair of joint ids and an their associated local IK subproblem.
Definition ScrewTheoryIkProblem.hpp:112
const Steps & getSteps() const
Solution of the IK problem (if available)
Definition ScrewTheoryIkProblem.hpp:149
std::vector< bool > solve(const KDL::Frame &H_S_T, const KDL::JntArray &reference, Solutions &solutions)
Find all available solutions.
Definition ScrewTheoryIkProblem.cpp:81
bool isReversed() const
Whether the computed solution is reversed.
Definition ScrewTheoryIkProblem.hpp:153
std::vector< JointIdsToSubproblem > Steps
Ordered sequence of IK subproblems that solve a global IK problem.
Definition ScrewTheoryIkProblem.hpp:115
int solutions() const
Number of global IK solutions.
Definition ScrewTheoryIkProblem.hpp:145
Interface shared by all IK subproblems found in Screw Theory applied to Robotics.
Definition ScrewTheoryIkProblem.hpp:26
virtual bool solve(const KDL::Frame &rhs, const KDL::Frame &pointTransform, const JointConfig &reference, Solutions &solutions) const =0
Finds a closed geometric solution for this IK subproblem.
virtual const char * describe() const =0
Return a human-readable description of this IK subproblem.
virtual int solutions() const =0
Number of local IK solutions.
virtual ~ScrewTheoryIkSubproblem()=default
Destructor.
std::vector< double > JointConfig
Joint configurations.
Definition ScrewTheoryIkProblem.hpp:29
std::vector< JointConfig > Solutions
Collection of local IK solutions.
Definition ScrewTheoryIkProblem.hpp:32
The main, catch-all namespace for RoboticsLab UC3M.
Definition groups.dox:5
Helper structure that holds the state of a POE term.
Definition ScrewTheoryIkProblem.hpp:214