44 #ifndef IKFAST_HEADER_COMMON 45 #define IKFAST_HEADER_COMMON 48 #define IKFAST_VERSION 61 83 virtual void GetSolution(T *solution,
const T *freevalues)
const = 0;
87 const std::vector<T> &freevalues)
const {
88 solution.resize(GetDOF());
89 GetSolution(&solution.at(0),
90 freevalues.size() > 0 ? &freevalues.at(0) : NULL);
97 virtual const std::vector<int> &GetFree()
const = 0;
100 virtual const int GetDOF()
const = 0;
115 const std::vector<int> &vfree) = 0;
121 virtual size_t GetNumSolutions()
const = 0;
125 virtual void Clear() = 0;
132 : _ComputeIk(NULL), _ComputeFk(NULL), _GetNumFreeParameters(NULL),
133 _GetFreeParameters(NULL), _GetNumJoints(NULL), _GetIkRealSize(NULL),
134 _GetIkFastVersion(NULL), _GetIkType(NULL), _GetKinematicsHash(NULL) {}
136 typedef bool (*ComputeIkFn)(
const T *,
const T *,
const T *,
139 typedef void (*ComputeFkFn)(
const T *, T *, T *);
141 typedef int (*GetNumFreeParametersFn)();
143 typedef int *(*GetFreeParametersFn)();
145 typedef int (*GetNumJointsFn)();
147 typedef int (*GetIkRealSizeFn)();
149 typedef const char *(*GetIkFastVersionFn)();
151 typedef int (*GetIkTypeFn)();
153 typedef const char *(*GetKinematicsHashFn)();
163 const std::vector<int> &vfree) {
168 virtual void GetSolution(T *solution,
const T *freevalues)
const {
169 for (std::size_t i = 0; i < _vbasesol.size(); ++i) {
171 solution[i] = _vbasesol[i].foffset;
173 solution[i] = freevalues[_vbasesol[i].freeind] * _vbasesol[i].fmul +
174 _vbasesol[i].foffset;
175 if (solution[i] > T(3.14159265358979)) {
176 solution[i] -= T(6.28318530717959);
177 }
else if (solution[i] < T(-3.14159265358979)) {
178 solution[i] += T(6.28318530717959);
185 const std::vector<T> &freevalues)
const {
186 solution.resize(GetDOF());
187 GetSolution(&solution.at(0),
188 freevalues.size() > 0 ? &freevalues.at(0) : NULL);
191 virtual const std::vector<int> &
GetFree()
const {
return _vfree; }
193 return static_cast<int>(_vbasesol.size());
197 for (
size_t i = 0; i < _vbasesol.size(); ++i) {
199 throw std::runtime_error(
"max solutions for joint not initialized");
203 throw std::runtime_error(
"index >= max solutions for joint");
205 if (_vbasesol[i].
indices[1] != (
unsigned char)-1 &&
206 _vbasesol[i].
indices[1] >= _vbasesol[i].maxsolutions) {
207 throw std::runtime_error(
"2nd index >= max solutions for joint");
216 for (
int i = (
int)_vbasesol.size() - 1; i >= 0; --i) {
218 _vbasesol[i].maxsolutions > 1) {
219 for (
size_t j = 0; j < v.size(); ++j) {
220 v[j] *= _vbasesol[i].maxsolutions;
222 size_t orgsize = v.size();
223 if (_vbasesol[i].
indices[1] != (
unsigned char)-1) {
224 for (
size_t j = 0; j < orgsize; ++j) {
225 v.push_back(v[j] + _vbasesol[i].
indices[1]);
228 if (_vbasesol[i].
indices[0] != (
unsigned char)-1) {
229 for (
size_t j = 0; j < orgsize; ++j) {
230 v[j] += _vbasesol[i].indices[0];
237 std::vector<IkSingleDOFSolutionBase<T>>
247 const std::vector<int> &vfree) {
248 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 =
258 _listsolutions.begin();
259 std::advance(it, index);
265 virtual void Clear() { _listsolutions.clear(); }
272 #endif // OPENRAVE_IKFAST_HEADER 275 #ifdef IKFAST_HAS_LIBRARY 278 #ifdef IKFAST_CLIBRARY 280 #define IKFAST_API extern "C" __declspec(dllexport) 282 #define IKFAST_API extern "C" 288 #ifdef IKFAST_NAMESPACE 289 namespace IKFAST_NAMESPACE {
293 typedef IKFAST_REAL IkReal;
295 typedef double IkReal;
312 IKFAST_API
bool ComputeIk(
const IkReal *eetrans,
const IkReal *eerot,
318 IKFAST_API
void ComputeFk(
const IkReal *joints, IkReal *eetrans, IkReal *eerot);
342 #ifdef IKFAST_NAMESPACE 346 #endif // IKFAST_HAS_LIBRARY
virtual const IkSolutionBase< T > & GetSolution(size_t index) const
returns the solution pointer
GetFreeParametersFn _GetFreeParameters
std::vector< int > _vfree
virtual void GetSolution(T *solution, const T *freevalues) const
gets a concrete solution
virtual ~IkFastFunctions()
IKFAST_API void ComputeFk(const IkReal *j, IkReal *eetrans, IkReal *eerot)
holds function pointers for all the exported functions of ikfast
virtual size_t GetNumSolutions() const
returns the number of solutions stored
unsigned char maxsolutions
GetIkFastVersionFn _GetIkFastVersion
holds the solution for a single dof
signed char freeind
if >= 0, mimics another joint
The discrete solutions are returned in this structure.
IKFAST_API const char * GetIkFastVersion()
virtual void GetSolutionIndices(std::vector< unsigned int > &v) const
IKFAST_API int GetNumJoints()
virtual void Clear()
clears all current solutions, note that any memory addresses returned from GetSolution will be invali...
IKFAST_API int GetNumFreeParameters()
virtual const int GetDOF() const
the dof of the solution
IKFAST_API int * GetFreeParameters()
IKFAST_API const char * GetKinematicsHash()
GetKinematicsHashFn _GetKinematicsHash
IKFAST_API int GetIkRealSize()
GetNumFreeParametersFn _GetNumFreeParameters
GetNumJointsFn _GetNumJoints
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
Default implementation of IkSolutionBase.
std::list< IkSolution< T > > _listsolutions
IkSolution(const std::vector< IkSingleDOFSolutionBase< T >> &vinfos, const std::vector< int > &vfree)
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...
IKFAST_API bool ComputeIk(const IkReal *eetrans, const IkReal *eerot, const IkReal *pfree, IkSolutionListBase< IkReal > &solutions)
virtual ~IkSolutionBase()
IKFAST_API int GetIkType()
virtual void GetSolution(std::vector< T > &solution, const std::vector< T > &freevalues) const
std::vector version of GetSolution
T foffset
joint value is fmul*sol[freeind]+foffset
std::vector< IkSingleDOFSolutionBase< T > > _vbasesol
solution and their offsets if joints are mimiced
Default implementation of IkSolutionListBase.
virtual ~IkSolutionListBase()
GetIkRealSizeFn _GetIkRealSize
virtual void Validate() const
virtual void GetSolution(std::vector< T > &solution, const std::vector< T > &freevalues) const
std::vector version of GetSolution
IkSingleDOFSolutionBase()
manages all the solutions
unsigned char jointtype
joint type, 0x01 is revolute, 0x11 is slider