37 #ifndef IKFAST_HEADER_COMMON 38 #define IKFAST_HEADER_COMMON 41 #define IKFAST_VERSION 61 47 class IkSingleDOFSolutionBase
68 virtual ~IkSolutionBase() {
74 virtual void GetSolution(T* solution,
const T* freevalues)
const = 0;
77 virtual void GetSolution(std::vector<T>& solution,
const std::vector<T>& freevalues)
const {
78 solution.resize(GetDOF());
79 GetSolution(&solution.at(0), freevalues.size() > 0 ? &freevalues.at(0) : NULL);
85 virtual const std::vector<int>& GetFree()
const = 0;
88 virtual const int GetDOF()
const = 0;
93 class IkSolutionListBase
96 virtual ~IkSolutionListBase() {
103 virtual size_t AddSolution(
const std::vector<IkSingleDOFSolutionBase<T> >& vinfos,
const std::vector<int>& vfree) = 0;
106 virtual const IkSolutionBase<T>& GetSolution(
size_t index)
const = 0;
109 virtual size_t GetNumSolutions()
const = 0;
112 virtual void Clear() = 0;
116 template <
typename T>
117 class IkFastFunctions
120 IkFastFunctions() : _ComputeIk(NULL), _ComputeFk(NULL), _GetNumFreeParameters(NULL), _GetFreeParameters(NULL), _GetNumJoints(NULL), _GetIkRealSize(NULL), _GetIkFastVersion(NULL), _GetIkType(NULL), _GetKinematicsHash(NULL) {
122 virtual ~IkFastFunctions() {
124 typedef bool (*ComputeIkFn)(
const T*,
const T*,
const T*, IkSolutionListBase<T>&);
125 ComputeIkFn _ComputeIk;
126 typedef void (*ComputeFkFn)(
const T*, T*, T*);
127 ComputeFkFn _ComputeFk;
128 typedef int (*GetNumFreeParametersFn)();
129 GetNumFreeParametersFn _GetNumFreeParameters;
130 typedef int* (*GetFreeParametersFn)();
131 GetFreeParametersFn _GetFreeParameters;
132 typedef int (*GetNumJointsFn)();
133 GetNumJointsFn _GetNumJoints;
134 typedef int (*GetIkRealSizeFn)();
135 GetIkRealSizeFn _GetIkRealSize;
136 typedef const char* (*GetIkFastVersionFn)();
137 GetIkFastVersionFn _GetIkFastVersion;
138 typedef int (*GetIkTypeFn)();
139 GetIkTypeFn _GetIkType;
140 typedef const char* (*GetKinematicsHashFn)();
141 GetKinematicsHashFn _GetKinematicsHash;
147 template <
typename T>
148 class IkSolution :
public IkSolutionBase<T>
151 IkSolution(
const std::vector<IkSingleDOFSolutionBase<T> >& vinfos,
const std::vector<int>& vfree) {
156 virtual void GetSolution(T* solution,
const T* freevalues)
const {
157 for(std::size_t i = 0; i < _vbasesol.size(); ++i) {
159 solution[i] = _vbasesol[i].foffset;
161 solution[i] = freevalues[_vbasesol[i].freeind]*_vbasesol[i].fmul + _vbasesol[i].foffset;
162 if( solution[i] > T(3.14159265358979) ) {
163 solution[i] -= T(6.28318530717959);
165 else if( solution[i] < T(-3.14159265358979) ) {
166 solution[i] += T(6.28318530717959);
172 virtual void GetSolution(std::vector<T>& solution,
const std::vector<T>& freevalues)
const {
173 solution.resize(GetDOF());
174 GetSolution(&solution.at(0), freevalues.size() > 0 ? &freevalues.at(0) : NULL);
177 virtual const std::vector<int>& GetFree()
const {
180 virtual const int GetDOF()
const {
181 return static_cast<int>(_vbasesol.size());
184 virtual void Validate()
const {
185 for(
size_t i = 0; i < _vbasesol.size(); ++i) {
187 throw std::runtime_error(
"max solutions for joint not initialized");
191 throw std::runtime_error(
"index >= max solutions for joint");
193 if( _vbasesol[i].
indices[1] != (
unsigned char)-1 && _vbasesol[i].
indices[1] >= _vbasesol[i].maxsolutions ) {
194 throw std::runtime_error(
"2nd index >= max solutions for joint");
200 virtual void GetSolutionIndices(std::vector<unsigned int>& v)
const {
203 for(
int i = (
int)_vbasesol.size()-1; i >= 0; --i) {
204 if( _vbasesol[i].
maxsolutions != (
unsigned char)-1 && _vbasesol[i].maxsolutions > 1 ) {
205 for(
size_t j = 0; j < v.size(); ++j) {
206 v[j] *= _vbasesol[i].maxsolutions;
208 size_t orgsize=v.size();
209 if( _vbasesol[i].
indices[1] != (
unsigned char)-1 ) {
210 for(
size_t j = 0; j < orgsize; ++j) {
211 v.push_back(v[j]+_vbasesol[i].
indices[1]);
214 if( _vbasesol[i].
indices[0] != (
unsigned char)-1 ) {
215 for(
size_t j = 0; j < orgsize; ++j) {
216 v[j] += _vbasesol[i].indices[0];
223 std::vector< IkSingleDOFSolutionBase<T> > _vbasesol;
224 std::vector<int> _vfree;
228 template <
typename T>
229 class IkSolutionList :
public IkSolutionListBase<T>
232 virtual size_t AddSolution(
const std::vector<IkSingleDOFSolutionBase<T> >& vinfos,
const std::vector<int>& vfree)
234 size_t index = _listsolutions.size();
235 _listsolutions.push_back(IkSolution<T>(vinfos,vfree));
239 virtual const IkSolutionBase<T>& GetSolution(
size_t index)
const 241 if( index >= _listsolutions.size() ) {
242 throw std::runtime_error(
"GetSolution index is invalid");
244 typename std::list< IkSolution<T> >::const_iterator it = _listsolutions.begin();
245 std::advance(it,index);
249 virtual size_t GetNumSolutions()
const {
250 return _listsolutions.size();
253 virtual void Clear() {
254 _listsolutions.clear();
258 std::list< IkSolution<T> > _listsolutions;
263 #endif // OPENRAVE_IKFAST_HEADER 266 #ifdef IKFAST_HAS_LIBRARY 269 #ifdef IKFAST_CLIBRARY 271 #define IKFAST_API extern "C" __declspec(dllexport) 273 #define IKFAST_API extern "C" 279 #ifdef IKFAST_NAMESPACE 280 namespace IKFAST_NAMESPACE {
284 typedef IKFAST_REAL IkReal;
286 typedef double IkReal;
301 IKFAST_API
void ComputeFk(
const IkReal* joints, IkReal* eetrans, IkReal* eerot);
316 IKFAST_API
const char* GetIkFastVersion();
319 IKFAST_API
int GetIkType();
322 IKFAST_API
const char* GetKinematicsHash();
324 #ifdef IKFAST_NAMESPACE 328 #endif // IKFAST_HAS_LIBRARY
IKFAST_API int * GetFreeParameters()
unsigned char indices[5]
unique index of the solution used to keep track on what part it came from. sometimes a solution can b...
unsigned char maxsolutions
max possible indices, 0 if controlled by free index or a free joint itself
signed char freeind
if >= 0, mimics another joint
IKFAST_API void ComputeFk(const IkReal *j, IkReal *eetrans, IkReal *eerot)
IKFAST_API bool ComputeIk(const IkReal *eetrans, const IkReal *eerot, const IkReal *pfree, IkSolutionListBase< IkReal > &solutions)
IKFAST_API int GetNumJoints()
T foffset
joint value is fmul*sol[freeind]+foffset
IKFAST_API int GetNumFreeParameters()
IKFAST_API int GetIkRealSize()
IkSingleDOFSolutionBase()
manages all the solutions
unsigned char jointtype
joint type, 0x01 is revolute, 0x11 is slider