- 3.0.2 rigid body dynamics module.
InverseKinematicsBase.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 
10 
11 namespace ct {
12 namespace rbd {
13 
14 
16 {
18  size_t maxNumTrials_;
21 };
22 
23 
24 template <size_t NJOINTS, typename SCALAR = double>
26 {
27 public:
28  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
29 
31  using JointPositionsVector_t = std::vector<JointPosition_t, Eigen::aligned_allocator<JointPosition_t>>;
33 
35  InverseKinematicsBase() = default;
36 
38  InverseKinematicsBase(const InverseKinematicsSettings& settings) : settings_(settings) {}
40  virtual ~InverseKinematicsBase() = default;
41 
49  virtual bool computeInverseKinematics(JointPositionsVector_t& ikSolutions,
50  const RigidBodyPoseTpl& eeBasePose,
51  const std::vector<size_t>& freeJoints) = 0;
52 
61  virtual bool computeInverseKinematics(JointPositionsVector_t& ikSolutions,
62  const RigidBodyPoseTpl& eeWorldPose,
63  const RigidBodyPoseTpl& baseWorldPose,
64  const std::vector<size_t>& freeJoints) = 0;
65 
66 
76  const RigidBodyPoseTpl& eeWorldPose,
77  const RigidBodyPoseTpl& baseWorldPose,
78  const JointPosition_t& queryJointPositions,
79  const std::vector<size_t>& freeJoints = std::vector<size_t>())
80  {
81  // compute all inverse kinematics solutions
82  JointPositionsVector_t solutions;
83  bool hasSolution = computeInverseKinematics(solutions, eeWorldPose, baseWorldPose, freeJoints);
84 
85  if (!hasSolution)
86  return false; // no IK solution was found
87 
88  // loop through all solution candidates and return the one which is closest to the "queryJointPositions"
89  ikSolution = solutions[0];
90  double minNorm = (ikSolution - queryJointPositions).norm();
91 
92  for (size_t i = 1; i < solutions.size(); ++i)
93  {
94  if ((solutions[i] - queryJointPositions).norm() < minNorm)
95  {
96  minNorm = (solutions[i] - queryJointPositions).norm();
97  ikSolution = solutions[i];
98  }
99  }
100  return true;
101  }
102 
111  const RigidBodyPoseTpl& eeBasePose,
112  const JointPosition_t& queryJointPositions,
113  const std::vector<size_t>& freeJoints = std::vector<size_t>())
114  {
115  // set base world pose as identity, herewith eeBasePose = eeWorldPose
116  RigidBodyPoseTpl identityWorldPose;
117  identityWorldPose.setIdentity();
118  return computeInverseKinematicsCloseTo(
119  ikSolution, eeBasePose, identityWorldPose, queryJointPositions, freeJoints);
120  }
121 
122  const InverseKinematicsSettings& getSettings() const { return settings_; }
123  void updateSettings(const InverseKinematicsSettings& settings) { settings_ = settings; }
124 protected:
126 };
127 
128 } /* namespace rbd */
129 } /* namespace ct */
InverseKinematicsSettings settings_
Definition: InverseKinematicsBase.h:125
size_t maxNumTrials_
Definition: InverseKinematicsBase.h:18
Pose of a single rigid body.
Definition: RigidBodyPose.h:29
joint state and joint velocity
Definition: JointState.h:21
InverseKinematicsSettings()
Definition: InverseKinematicsBase.h:17
const InverseKinematicsSettings & getSettings() const
Definition: InverseKinematicsBase.h:122
InverseKinematicsBase(const InverseKinematicsSettings &settings)
constructor with additional settings
Definition: InverseKinematicsBase.h:38
void setIdentity()
Sets orientation to identity and position to (0, 0, 0)
Definition: RigidBodyPose.h:390
Definition: InverseKinematicsBase.h:25
Definition: InverseKinematicsBase.h:15
for i
bool randomizeInitialGuess_
Definition: InverseKinematicsBase.h:19
typename JointState< NJOINTS, SCALAR >::Position JointPosition_t
Definition: InverseKinematicsBase.h:30
virtual bool computeInverseKinematicsCloseTo(JointPosition_t &ikSolution, const RigidBodyPoseTpl &eeWorldPose, const RigidBodyPoseTpl &baseWorldPose, const JointPosition_t &queryJointPositions, const std::vector< size_t > &freeJoints=std::vector< size_t >())
compute inverse kinematics for an end-effector
Definition: InverseKinematicsBase.h:75
void updateSettings(const InverseKinematicsSettings &settings)
Definition: InverseKinematicsBase.h:123
virtual bool computeInverseKinematicsCloseTo(JointPosition_t &ikSolution, const RigidBodyPoseTpl &eeBasePose, const JointPosition_t &queryJointPositions, const std::vector< size_t > &freeJoints=std::vector< size_t >())
compute inverse kinematics for an end-effector
Definition: InverseKinematicsBase.h:110
std::vector< JointPosition_t, Eigen::aligned_allocator< JointPosition_t > > JointPositionsVector_t
Definition: InverseKinematicsBase.h:31
double validationTol_
Definition: InverseKinematicsBase.h:20