38 #ifndef IKFAST_HEADER_COMMON 39 #define IKFAST_HEADER_COMMON 43 #define IKFAST_VERSION 0x10000048 76 virtual void GetSolution(T* solution,
const T* freevalues)
const = 0;
79 virtual void GetSolution(std::vector<T>& solution,
const std::vector<T>& freevalues)
const {
80 solution.resize(GetDOF());
81 GetSolution(&solution.at(0), freevalues.size() > 0 ? &freevalues.at(0) : NULL);
88 virtual const std::vector<int>& GetFree()
const = 0;
91 virtual const int GetDOF()
const = 0;
112 virtual size_t GetNumSolutions()
const = 0;
115 virtual void Clear() = 0;
119 template <
typename T>
123 IkFastFunctions() : _ComputeIk(NULL), _ComputeIk2(NULL), _ComputeFk(NULL), _GetNumFreeParameters(NULL), _GetFreeParameters(NULL), _GetNumJoints(NULL), _GetIkRealSize(NULL), _GetIkFastVersion(NULL), _GetIkType(NULL), _GetKinematicsHash(NULL) {
131 typedef void (*ComputeFkFn)(
const T*, T*, T*);
133 typedef int (*GetNumFreeParametersFn)();
135 typedef int* (*GetFreeParametersFn)();
137 typedef int (*GetNumJointsFn)();
139 typedef int (*GetIkRealSizeFn)();
141 typedef const char* (*GetIkFastVersionFn)();
143 typedef int (*GetIkTypeFn)();
145 typedef const char* (*GetKinematicsHashFn)();
152 template <
typename T>
161 virtual void GetSolution(T* solution,
const T* freevalues)
const {
162 for(std::size_t
i = 0;
i < _vbasesol.size(); ++
i) {
164 solution[
i] = _vbasesol[
i].foffset;
166 solution[
i] = freevalues[_vbasesol[
i].freeind]*_vbasesol[
i].fmul + _vbasesol[
i].foffset;
167 if( solution[
i] > T(3.14159265358979) ) {
168 solution[
i] -= T(6.28318530717959);
170 else if( solution[
i] < T(-3.14159265358979) ) {
171 solution[
i] += T(6.28318530717959);
177 virtual void GetSolution(std::vector<T>& solution,
const std::vector<T>& freevalues)
const {
178 solution.resize(GetDOF());
179 GetSolution(&solution.at(0), freevalues.size() > 0 ? &freevalues.at(0) : NULL);
182 virtual const std::vector<int>&
GetFree()
const {
186 return static_cast<int>(_vbasesol.size());
190 for(
size_t i = 0;
i < _vbasesol.size(); ++
i) {
192 throw std::runtime_error(
"max solutions for joint not initialized");
196 throw std::runtime_error(
"index >= max solutions for joint");
198 if( _vbasesol[
i].
indices[1] != (
unsigned char)-1 && _vbasesol[
i].
indices[1] >= _vbasesol[
i].maxsolutions ) {
199 throw std::runtime_error(
"2nd index >= max solutions for joint");
202 if( !std::isfinite(_vbasesol[
i].
foffset) ) {
203 throw std::runtime_error(
"foffset was not finite");
211 for(
int i = (
int)_vbasesol.size()-1;
i >= 0; --
i) {
212 if( _vbasesol[
i].
maxsolutions != (
unsigned char)-1 && _vbasesol[
i].maxsolutions > 1 ) {
213 for(
size_t j = 0; j < v.size(); ++j) {
214 v[j] *= _vbasesol[
i].maxsolutions;
216 size_t orgsize=v.size();
217 if( _vbasesol[
i].
indices[1] != (
unsigned char)-1 ) {
218 for(
size_t j = 0; j < orgsize; ++j) {
219 v.push_back(v[j]+_vbasesol[
i].
indices[1]);
222 if( _vbasesol[
i].
indices[0] != (
unsigned char)-1 ) {
223 for(
size_t j = 0; j < orgsize; ++j) {
224 v[j] += _vbasesol[
i].indices[0];
236 template <
typename T>
242 size_t index = _listsolutions.size();
249 if( index >= _listsolutions.size() ) {
250 throw std::runtime_error(
"GetSolution index is invalid");
252 typename std::list< IkSolution<T> >::const_iterator it = _listsolutions.begin();
253 std::advance(it,index);
258 return _listsolutions.size();
262 _listsolutions.clear();
271 #endif // OPENRAVE_IKFAST_HEADER 274 #ifdef IKFAST_HAS_LIBRARY 277 #ifdef IKFAST_CLIBRARY 279 #define IKFAST_API extern "C" __declspec(dllexport) 281 #define IKFAST_API extern "C" 287 #ifdef IKFAST_NAMESPACE 292 typedef IKFAST_REAL IkReal;
294 typedef double IkReal;
313 IKFAST_API
void ComputeFk(
const IkReal* joints, IkReal* eetrans, IkReal* eerot);
336 #ifdef IKFAST_NAMESPACE 340 #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:79
GetFreeParametersFn _GetFreeParameters
Definition: ikfast.h:136
std::vector< int > _vfree
Definition: ikfast.h:232
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:59
virtual ~IkFastFunctions()
Definition: ikfast.h:125
holds function pointers for all the exported functions of ikfast
Definition: ikfast.h:120
unsigned char maxsolutions
max possible indices, 0 if controlled by free index or a free joint itself
Definition: ikfast.h:58
GetIkFastVersionFn _GetIkFastVersion
Definition: ikfast.h:142
virtual const IkSolutionBase< T > & GetSolution(size_t index) const
returns the solution pointer
Definition: ikfast.h:247
virtual void GetSolution(T *solution, const T *freevalues) const
gets a concrete solution
Definition: ikfast.h:161
holds the solution for a single dof
Definition: ikfast.h:49
signed char freeind
if >= 0, mimics another joint
Definition: ikfast.h:56
The discrete solutions are returned in this structure.
Definition: ikfast.h:67
virtual void GetSolutionIndices(std::vector< unsigned int > &v) const
Definition: ikfast.h:208
virtual void Clear()
clears all current solutions, note that any memory addresses returned from GetSolution will be invali...
Definition: ikfast.h:261
std::vector< IkSingleDOFSolutionBase< T > > _vbasesol
solution and their offsets if joints are mimiced
Definition: ikfast.h:231
GetKinematicsHashFn _GetKinematicsHash
Definition: ikfast.h:146
ComputeFkFn _ComputeFk
Definition: ikfast.h:132
std::list< IkSolution< T > > _listsolutions
Definition: ikfast.h:266
GetNumFreeParametersFn _GetNumFreeParameters
Definition: ikfast.h:134
GetNumJointsFn _GetNumJoints
Definition: ikfast.h:138
Default implementation of IkSolutionBase.
Definition: ikfast.h:153
ComputeIk2Fn _ComputeIk2
Definition: ikfast.h:130
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:182
virtual void Validate() const
Definition: ikfast.h:189
ComputeIkFn _ComputeIk
Definition: ikfast.h:128
virtual ~IkSolutionBase()
Definition: ikfast.h:70
T fmul
Definition: ikfast.h:55
T foffset
joint value is fmul*sol[freeind]+foffset
Definition: ikfast.h:55
Default implementation of IkSolutionListBase.
Definition: ikfast.h:237
GetIkTypeFn _GetIkType
Definition: ikfast.h:144
virtual ~IkSolutionListBase()
Definition: ikfast.h:99
virtual void GetSolution(std::vector< T > &solution, const std::vector< T > &freevalues) const
std::vector version of GetSolution
Definition: ikfast.h:177
GetIkRealSizeFn _GetIkRealSize
Definition: ikfast.h:140
IkSingleDOFSolutionBase()
Definition: ikfast.h:52
manages all the solutions
Definition: ikfast.h:96
virtual size_t GetNumSolutions() const
returns the number of solutions stored
Definition: ikfast.h:257
virtual const int GetDOF() const
the dof of the solution
Definition: ikfast.h:185
unsigned char jointtype
joint type, 0x01 is revolute, 0x11 is slider
Definition: ikfast.h:57
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:240
IkSolution(const std::vector< IkSingleDOFSolutionBase< T > > &vinfos, const std::vector< int > &vfree)
Definition: ikfast.h:156
IkFastFunctions()
Definition: ikfast.h:123