38 #ifndef IKFAST_HEADER_COMMON 39 #define IKFAST_HEADER_COMMON 42 #define IKFAST_VERSION 71 81 virtual void GetSolution(T* solution,
const T* freevalues)
const = 0;
84 virtual void GetSolution(std::vector<T>& solution,
const std::vector<T>& freevalues)
const {
85 solution.resize(GetDOF());
86 GetSolution(&solution.at(0), freevalues.size() > 0 ? &freevalues.at(0) : NULL);
93 virtual const std::vector<int>& GetFree()
const = 0;
96 virtual int GetDOF()
const = 0;
100 template <
typename T>
117 virtual size_t GetNumSolutions()
const = 0;
120 virtual void Clear() = 0;
124 template <
typename T>
128 IkFastFunctions() : _ComputeIk(NULL), _ComputeIk2(NULL), _ComputeFk(NULL), _GetNumFreeParameters(NULL), _GetFreeParameters(NULL), _GetNumJoints(NULL), _GetIkRealSize(NULL), _GetIkFastVersion(NULL), _GetIkType(NULL), _GetKinematicsHash(NULL) {
133 ComputeIkFn _ComputeIk;
135 ComputeIk2Fn _ComputeIk2;
136 typedef void (*ComputeFkFn)(
const T*, T*, T*);
137 ComputeFkFn _ComputeFk;
138 typedef int (*GetNumFreeParametersFn)();
139 GetNumFreeParametersFn _GetNumFreeParameters;
140 typedef int* (*GetFreeParametersFn)();
141 GetFreeParametersFn _GetFreeParameters;
142 typedef int (*GetNumJointsFn)();
143 GetNumJointsFn _GetNumJoints;
144 typedef int (*GetIkRealSizeFn)();
145 GetIkRealSizeFn _GetIkRealSize;
146 typedef const char* (*GetIkFastVersionFn)();
147 GetIkFastVersionFn _GetIkFastVersion;
148 typedef int (*GetIkTypeFn)();
149 GetIkTypeFn _GetIkType;
150 typedef const char* (*GetKinematicsHashFn)();
151 GetKinematicsHashFn _GetKinematicsHash;
157 template <
typename T>
166 virtual void GetSolution(T* solution,
const T* freevalues)
const {
167 for(std::size_t i = 0; i < _vbasesol.size(); ++i) {
169 solution[i] = _vbasesol[i].foffset;
171 solution[i] = freevalues[_vbasesol[i].freeind]*_vbasesol[i].fmul + _vbasesol[i].foffset;
172 if( solution[i] > T(3.14159265358979) ) {
173 solution[i] -= T(6.28318530717959);
175 else if( solution[i] < T(-3.14159265358979) ) {
176 solution[i] += T(6.28318530717959);
182 virtual void GetSolution(std::vector<T>& solution,
const std::vector<T>& freevalues)
const {
183 solution.resize(GetDOF());
184 GetSolution(&solution.at(0), freevalues.size() > 0 ? &freevalues.at(0) : NULL);
187 virtual const std::vector<int>&
GetFree()
const {
191 return static_cast<int>(_vbasesol.size());
194 virtual void Validate()
const {
195 for(
size_t i = 0; i < _vbasesol.size(); ++i) {
197 throw std::runtime_error(
"max solutions for joint not initialized");
201 throw std::runtime_error(
"index >= max solutions for joint");
203 if( _vbasesol[i].
indices[1] != (
unsigned char)-1 && _vbasesol[i].
indices[1] >= _vbasesol[i].maxsolutions ) {
204 throw std::runtime_error(
"2nd index >= max solutions for joint");
207 if( !std::isfinite(_vbasesol[i].
foffset) ) {
208 throw std::runtime_error(
"foffset was not finite");
213 virtual void GetSolutionIndices(std::vector<unsigned int>& v)
const {
216 for(
int i = (
int)_vbasesol.size()-1; i >= 0; --i) {
217 if( _vbasesol[i].
maxsolutions != (
unsigned char)-1 && _vbasesol[i].maxsolutions > 1 ) {
218 for(
size_t j = 0; j < v.size(); ++j) {
219 v[j] *= _vbasesol[i].maxsolutions;
221 size_t orgsize=v.size();
222 if( _vbasesol[i].
indices[1] != (
unsigned char)-1 ) {
223 for(
size_t j = 0; j < orgsize; ++j) {
224 v.push_back(v[j]+_vbasesol[i].
indices[1]);
227 if( _vbasesol[i].
indices[0] != (
unsigned char)-1 ) {
228 for(
size_t j = 0; j < orgsize; ++j) {
229 v[j] += _vbasesol[i].indices[0];
237 std::vector<int> _vfree;
241 template <
typename T>
247 size_t index = _listsolutions.size();
254 if( index >= _listsolutions.size() ) {
255 throw std::runtime_error(
"GetSolution index is invalid");
257 typename std::list< IkSolution<T> >::const_iterator it = _listsolutions.begin();
258 std::advance(it,index);
263 return _listsolutions.size();
267 _listsolutions.clear();
271 std::list< IkSolution<T> > _listsolutions;
276 #endif // OPENRAVE_IKFAST_HEADER 279 #ifdef IKFAST_HAS_LIBRARY 282 #ifdef IKFAST_CLIBRARY 284 #define IKFAST_API extern "C" __declspec(dllexport) 286 #define IKFAST_API extern "C" 292 #ifdef IKFAST_NAMESPACE 293 namespace IKFAST_NAMESPACE {
297 typedef IKFAST_REAL IkReal;
299 typedef double IkReal;
318 IKFAST_API
void ComputeFk(
const IkReal* joints, IkReal* eetrans, IkReal* eerot);
321 IKFAST_API
int GetNumFreeParameters();
324 IKFAST_API
int* GetFreeParameters();
327 IKFAST_API
int GetNumJoints();
330 IKFAST_API
int GetIkRealSize();
333 IKFAST_API
const char* GetIkFastVersion();
336 IKFAST_API
int GetIkType();
339 IKFAST_API
const char* GetKinematicsHash();
341 #ifdef IKFAST_NAMESPACE 345 #endif // IKFAST_HAS_LIBRARY
virtual void GetSolution(std::vector< T > &solution, const std::vector< T > &freevalues) const
std::vector version of GetSolution
Definition: ikfast.h:84
unsigned char indices[5]
unique index of the solution used to keep track on what part it came from. sometimes a solution can b...
Definition: ikfast.h:64
holds function pointers for all the exported functions of ikfast
Definition: ikfast.h:125
unsigned char maxsolutions
max possible indices, 0 if controlled by free index or a free joint itself
Definition: ikfast.h:63
virtual int GetDOF() const
the dof of the solution
Definition: ikfast.h:190
virtual const IkSolutionBase< T > & GetSolution(size_t index) const
returns the solution pointer
Definition: ikfast.h:252
virtual void GetSolution(T *solution, const T *freevalues) const
gets a concrete solution
Definition: ikfast.h:166
holds the solution for a single dof
Definition: ikfast.h:54
signed char freeind
if >= 0, mimics another joint
Definition: ikfast.h:61
The discrete solutions are returned in this structure.
Definition: ikfast.h:72
virtual void Clear()
clears all current solutions, note that any memory addresses returned from GetSolution will be invali...
Definition: ikfast.h:266
std::vector< IkSingleDOFSolutionBase< T > > _vbasesol
solution and their offsets if joints are mimiced
Definition: ikfast.h:236
Default implementation of IkSolutionBase.
Definition: ikfast.h:158
virtual const std::vector< int > & GetFree() const
Gets the indices of the configuration space that have to be preset before a full solution can be retu...
Definition: ikfast.h:187
T foffset
joint value is fmul*sol[freeind]+foffset
Definition: ikfast.h:60
Default implementation of IkSolutionListBase.
Definition: ikfast.h:242
virtual void GetSolution(std::vector< T > &solution, const std::vector< T > &freevalues) const
std::vector version of GetSolution
Definition: ikfast.h:182
manages all the solutions
Definition: ikfast.h:101
virtual size_t GetNumSolutions() const
returns the number of solutions stored
Definition: ikfast.h:262
unsigned char jointtype
joint type, 0x01 is revolute, 0x11 is slider
Definition: ikfast.h:62
virtual size_t AddSolution(const std::vector< IkSingleDOFSolutionBase< T > > &vinfos, const std::vector< int > &vfree)
add one solution and return its index for later retrieval
Definition: ikfast.h:245