- 3.0.2 models module.
HyAInverseKinematics.h
Go to the documentation of this file.
1 /**********************************************************************************************************************
2 This file is part of the Control Toolbox (https://github.com/ethz-adrl/control-toolbox), copyright by ETH Zurich
3 Licensed under the BSD-2 license (see LICENSE file in main directory)
4 **********************************************************************************************************************/
5 
6 #pragma once
7 
8 #define IKFAST_HAS_LIBRARY
9 #define IKFAST_NAMESPACE hya_ik
10 #include <ikfast.h>
11 #include <ct/core/core.h>
14 
16 
17 using namespace ikfast;
18 
19 namespace ct {
20 namespace rbd {
21 
22 template <typename SCALAR = double>
24 {
25 public:
26  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
27 
32 
33  HyAInverseKinematics() = default;
34 
35  ~HyAInverseKinematics() = default;
36 
38  const RigidBodyPoseTpl& eeBasePose,
39  const std::vector<size_t>& freeJoints = std::vector<size_t>()) override
40  {
41  res.clear();
42  IkSolutionList<double> solutions;
43 
44  if (size_t(hya_ik::GetNumFreeParameters()) != freeJoints.size())
45  throw std::runtime_error("Error specifying free joints in HyAInverseKinematics");
46 
47  // Data needs to be in row-major form.
48  Eigen::Matrix<SCALAR, 3, 3, Eigen::RowMajor> eeBaseRotationRowMajor =
49  eeBasePose.getRotationMatrix().toImplementation();
50  const std::vector<double> freeJoints_ikf(freeJoints.begin(), freeJoints.end());
51  hya_ik::ComputeIk(eeBasePose.position().toImplementation().data(), eeBaseRotationRowMajor.data(),
52  freeJoints_ikf.size() > 0 ? freeJoints_ikf.data() : nullptr, solutions);
53 
54  size_t num_solutions = solutions.GetNumSolutions();
55 
56  if (num_solutions == 0)
57  return false; // no solution found
58 
59  // filter for joint limit violations
60  JointState<6> sol;
61  for (size_t i = 0; i < num_solutions; i++)
62  {
63  const IkSolutionBase<double>& solution = solutions.GetSolution(i);
64  solution.GetSolution(
65  sol.getPositions().data(), freeJoints_ikf.size() > 0 ? freeJoints_ikf.data() : nullptr);
68  res.push_back(sol.getPositions());
69  }
70 
71  if(res.size() == 0)
72  return false; // no viable solution after filtering for joint limits
73 
74  return true;
75  }
76 
78  const RigidBodyPoseTpl& eeWorldPose,
79  const RigidBodyPoseTpl& baseWorldPose,
80  const std::vector<size_t>& freeJoints = std::vector<size_t>()) override
81  {
82  return computeInverseKinematics(res, eeWorldPose.inReferenceFrame(baseWorldPose), freeJoints);
83  }
84 };
85 } /* namespace rbd */
86 } /* namespace ct */
const ct::rbd::JointState< 6, SCALAR >::Position & jointLowerLimit()
Definition: HyAJointLimits.h:13
IKFAST_API int GetNumFreeParameters()
Definition: transform6d.cpp:373
Definition: HyAInverseKinematics.h:23
bool computeInverseKinematics(JointPositionsVector_t &res, const RigidBodyPoseTpl &eeBasePose, const std::vector< size_t > &freeJoints=std::vector< size_t >()) override
Definition: HyAInverseKinematics.h:37
virtual const IkSolutionBase< T > & GetSolution(size_t index) const
typename BASE::JointPosition_t JointPosition_t
Definition: HyAInverseKinematics.h:29
bool computeInverseKinematics(JointPositionsVector_t &res, const RigidBodyPoseTpl &eeWorldPose, const RigidBodyPoseTpl &baseWorldPose, const std::vector< size_t > &freeJoints=std::vector< size_t >()) override
Definition: HyAInverseKinematics.h:77
typename BASE::RigidBodyPoseTpl RigidBodyPoseTpl
Definition: HyAInverseKinematics.h:31
IKFAST_API bool ComputeIk(const IkReal *eetrans, const IkReal *eerot, const IkReal *pfree, IkSolutionListBase< IkReal > &solutions)
Definition: transform6d.cpp:25689
for i
const ct::rbd::JointState< 6, SCALAR >::Position & jointUpperLimit()
Definition: HyAJointLimits.h:22
typename JointState< 6, SCALAR >::Position JointPosition_t
virtual void GetSolution(T *solution, const T *freevalues) const=0
void toUniquePosition(T lowerLimitVec, double tolerance=0.0)
typename BASE::JointPositionsVector_t JointPositionsVector_t
Definition: HyAInverseKinematics.h:30
JointPositionBlock getPositions()
virtual size_t GetNumSolutions() const
bool checkPositionLimits(const T lowerLimit, const T upperLimit, const double tolerance=0.0)
std::vector< JointPosition_t, Eigen::aligned_allocator< JointPosition_t > > JointPositionsVector_t