Go to the documentation of this file.
41 #ifndef IKFAST_HEADER_COMMON
42 #define IKFAST_HEADER_COMMON
45 #define IKFAST_VERSION 61
51 class IkSingleDOFSolutionBase
79 virtual void GetSolution(T* solution,
const T* freevalues)
const = 0;
82 virtual void GetSolution(std::vector<T>& solution,
const std::vector<T>& freevalues)
const
85 if (freevalues.empty())
94 virtual const std::vector<int>&
GetFree()
const = 0;
97 virtual int GetDOF()
const = 0;
101 template <
typename T>
102 class IkSolutionListBase
112 virtual size_t AddSolution(
const std::vector<IkSingleDOFSolutionBase<T> >& vinfos,
const std::vector<int>& vfree) = 0;
115 virtual const IkSolutionBase<T>&
GetSolution(
size_t index)
const = 0;
122 virtual void Clear() = 0;
126 template <
typename T>
127 class IkFastFunctions
132 using ComputeIkFn = bool (*)(
const T*,
const T*,
const T*, IkSolutionListBase<T>&);
155 template <
typename T>
156 class IkSolution :
public IkSolutionBase<T>
159 IkSolution(
const std::vector<IkSingleDOFSolutionBase<T> >& vinfos,
const std::vector<int>& vfree)
165 void GetSolution(T* solution,
const T* freevalues)
const override
167 for (std::size_t i = 0; i <
_vbasesol.size(); ++i)
173 assert(freevalues !=
nullptr);
175 if (solution[i] > T(3.14159265358979))
177 solution[i] -= T(6.28318530717959);
179 else if (solution[i] < T(-3.14159265358979))
181 solution[i] += T(6.28318530717959);
187 void GetSolution(std::vector<T>& solution,
const std::vector<T>& freevalues)
const override
189 solution.resize(
GetDOF());
190 if (freevalues.empty())
196 const std::vector<int>&
GetFree()
const override {
return _vfree; }
197 int GetDOF()
const override {
return static_cast<int>(
_vbasesol.size()); }
201 for (
size_t i = 0; i <
_vbasesol.size(); ++i)
203 if (
_vbasesol[i].maxsolutions == (
unsigned char)-1)
205 throw std::runtime_error(
"max solutions for joint not initialized");
211 throw std::runtime_error(
"index >= max solutions for joint");
215 throw std::runtime_error(
"2nd index >= max solutions for joint");
225 for (
int i = (
int)
_vbasesol.size() - 1; i >= 0; --i)
229 for (
size_t j = 0; j < v.size(); ++j)
233 size_t orgsize = v.size();
234 if (
_vbasesol[i].indices[1] != (
unsigned char)-1)
236 for (
size_t j = 0; j < orgsize; ++j)
238 v.push_back(v[j] +
_vbasesol[i].indices[1]);
241 if (
_vbasesol[i].indices[0] != (
unsigned char)-1)
243 for (
size_t j = 0; j < orgsize; ++j)
252 std::vector<IkSingleDOFSolutionBase<T> >
_vbasesol;
257 template <
typename T>
258 class IkSolutionList :
public IkSolutionListBase<T>
261 size_t AddSolution(
const std::vector<IkSingleDOFSolutionBase<T> >& vinfos,
const std::vector<int>& vfree)
override
268 const IkSolutionBase<T>&
GetSolution(
size_t index)
const override
272 throw std::runtime_error(
"GetSolution index is invalid");
275 std::advance(it, index);
288 #endif // OPENRAVE_IKFAST_HEADER
291 #ifdef IKFAST_HAS_LIBRARY
294 #ifdef IKFAST_CLIBRARY
296 #define IKFAST_API extern "C" __declspec(dllexport)
298 #define IKFAST_API extern "C" __attribute__((visibility("default")))
304 #ifdef IKFAST_NAMESPACE
305 namespace IKFAST_NAMESPACE
310 typedef IKFAST_REAL IkReal;
312 using IkReal = double;
326 IKFAST_API
bool ComputeIk(
const IkReal* eetrans,
332 IKFAST_API
void ComputeFk(
const IkReal* joints, IkReal* eetrans, IkReal* eerot);
355 #ifdef IKFAST_NAMESPACE
359 #endif // IKFAST_HAS_LIBRARY
unsigned char jointtype
joint type, 0x01 is revolute, 0x11 is slider
IKFAST_API int GetNumJoints()
virtual const IkSolutionBase< T > & GetSolution(size_t index) const=0
GetIkFastVersionFn _GetIkFastVersion
IkSingleDOFSolutionBase()
void(* ComputeFkFn)(const T *, T *, T *)
GetFreeParametersFn _GetFreeParameters
const IKFAST_API char * GetIkFastVersion()
virtual size_t GetNumSolutions() const
std::vector< int > _vfree
virtual void GetSolutionIndices(std::vector< unsigned int > &v) const
T fmul
joint value is fmul*sol[freeind]+foffset
IKFAST_API int GetIkRealSize()
T foffset
joint value is fmul*sol[freeind]+foffset
unsigned char maxsolutions
max possible indices, 0 if controlled by free index or a free joint itself
manages all the solutions
virtual size_t AddSolution(const std::vector< IkSingleDOFSolutionBase< T > > &vinfos, const std::vector< int > &vfree)
GetKinematicsHashFn _GetKinematicsHash
virtual size_t GetNumSolutions() const=0
IKFAST_API int GetIkType()
int(* GetNumFreeParametersFn)()
IKFAST_API int * GetFreeParameters()
GetNumFreeParametersFn _GetNumFreeParameters
virtual const std::vector< int > & GetFree() const
virtual const int GetDOF() const=0
virtual ~IkSolutionBase()
virtual size_t AddSolution(const std::vector< IkSingleDOFSolutionBase< T > > &vinfos, const std::vector< int > &vfree)=0
virtual void Validate() const
virtual const IkSolutionBase< T > & GetSolution(size_t index) const
IKFAST_API void ComputeFk(const IkReal *j, IkReal *eetrans, IkReal *eerot)
const typedef char *(* GetIkFastVersionFn)()
GetNumJointsFn _GetNumJoints
virtual ~IkSolutionListBase()
std::list< IkSolution< T > > _listsolutions
IKFAST_API int GetNumFreeParameters()
GetIkRealSizeFn _GetIkRealSize
const IKFAST_API char * GetKinematicsHash()
virtual ~IkFastFunctions()
const typedef char *(* GetKinematicsHashFn)()
virtual const int GetDOF() const
virtual const std::vector< int > & GetFree() const=0
virtual void GetSolution(std::vector< T > &solution, const std::vector< T > &freevalues) const
std::vector< IkSingleDOFSolutionBase< T > > _vbasesol
solution and their offsets if joints are mimiced
IkSolution(const std::vector< IkSingleDOFSolutionBase< T > > &vinfos, const std::vector< int > &vfree)
signed char freeind
if >= 0, mimics another joint
IKFAST_API bool ComputeIk(const IkReal *eetrans, const IkReal *eerot, const IkReal *pfree, IkSolutionListBase< IkReal > &solutions)
bool(* ComputeIkFn)(const T *, const T *, const T *, IkSolutionListBase< T > &)
int *(* GetFreeParametersFn)()
virtual void GetSolution(std::vector< T > &solution, const std::vector< T > &freevalues) const