NaturalIK.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T),
5 * Karlsruhe Institute of Technology (KIT), all rights reserved.
6 *
7 * ArmarX is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * ArmarX is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * @author Simon Ottenhaus (simon dot ottenhaus at kit dot edu)
20 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
21 * GNU General Public License
22 */
23
24#pragma once
25
26#include <memory>
27
28//#include <RobotAPI/libraries/core/SimpleDiffIK.h>
29
30#include <optional>
31
32#include <VirtualRobot/VirtualRobot.h>
33
36
37namespace armarx
38{
39 using NaturalIKPtr = std::shared_ptr<class NaturalIK>;
40
41 /**
42 * @brief The NaturalIK class
43 *
44 * Calculates natural looking IK solutions by
45 * 1. Calculate Soechting angles
46 * 2. Calculate ForwardKinematics with Soechting angles
47 * 3. Use calculated elbow position as a nullspace target for the robot's elbow during diffik
48 *
49 * WARNING: Only works if robot model is facing forward in Y-direction (like ARMAR-III, ARMAR-IV, ARMAR-6)
50 * WARNING2: Soechting model is not valid for all targets. However, elbow position seems to extrapolate fine.
51 */
53 {
54 public:
56 {
58 {
59 }
60
62 std::optional<float> minimumElbowHeight = std::nullopt;
63 };
64
65 struct ArmJoints
66 {
67 VirtualRobot::RobotNodeSetPtr rns;
68 VirtualRobot::RobotNodePtr elbow;
69 VirtualRobot::RobotNodePtr shoulder;
70 VirtualRobot::RobotNodePtr tcp;
71 };
72
74 {
75 float SE;
76 float SY;
77 float EE;
78 float EY;
79
80
81 static constexpr float MMM_LS2LE = 0.188;
82 static constexpr float MMM_LE2LW = 0.145;
83 static constexpr float MMM_L = 1700;
84 static constexpr float MMM_UPPER_ARM_LENGTH = MMM_LS2LE * MMM_L;
85 static constexpr float MMM_LOWER_ARM_LENGTH = MMM_LE2LW * MMM_L;
86
87 static constexpr float MMM_LSC2LS = 0.023;
88 static constexpr float MMM_BT2LSC = 0.087;
89
90 static constexpr float MMM_CLAVICULAR_WIDTH = MMM_BT2LSC * MMM_L;
91 static constexpr float MMM_SHOULDER_POS = (MMM_LSC2LS + MMM_BT2LSC) * MMM_L;
92 };
93
95 {
96 Eigen::Vector3f shoulder;
97 Eigen::Vector3f elbow;
98 Eigen::Vector3f wrist;
100 };
101
102 public:
103 NaturalIK(std::string side,
104 Eigen::Vector3f shoulderPos = Eigen::Vector3f::Zero(),
105 float scale = 1);
106
108 solveSoechtingIK(const Eigen::Vector3f& targetPos,
109 std::optional<float> minElbowHeight = std::nullopt);
110 NaturalDiffIK::Result calculateIK(const Eigen::Matrix4f& targetPose,
111 ArmJoints arm,
114 calculateIKpos(const Eigen::Vector3f& targetPos,
115 ArmJoints arm,
117
118 NaturalDiffIK::Result calculateIK(const Eigen::Matrix4f& targetPose,
119 ArmJoints arm,
120 NaturalDiffIK::Mode setOri,
122
123 //static SimpleDiffIK::Result CalculateNaturalIK(const Eigen::Matrix4f targetPose, ArmJoints armjoints, Parameters params = Parameters());
124
125 Eigen::Vector3f getShoulderPos();
126
127 /**
128 * @brief NaturalIK::CalculateSoechtingAngles
129 * @param target Pointing target in mm, relative to the soulder position. X: right, Y: forward, Z: up
130 * @param side: Left or Right
131 * @param scale: scale factor to match the robots arm length to the human arm length
132 * @return Angles described in Soechting and Flanders "Errors in Pointing are Due to Approximations in Sensorimotor Transformations"
133 */
134 SoechtingAngles CalculateSoechtingAngles(Eigen::Vector3f target);
135
137
138 void setScale(float scale);
139 float getScale();
140
141
142 float getUpperArmLength() const;
143 void setUpperArmLength(float value);
144
145 float getLowerArmLength() const;
146 void setLowerArmLength(float value);
147
148 private:
149 std::string side;
150 Eigen::Vector3f shoulderPos;
151 float scale;
152
153 int soechtingIterations = 2;
154
155 float upperArmLength = SoechtingAngles::MMM_UPPER_ARM_LENGTH;
156 float lowerArmLength = SoechtingAngles::MMM_LOWER_ARM_LENGTH;
157 };
158
160 {
161 public:
162 NaturalIKProvider(const NaturalIK& natik,
163 const NaturalIK::ArmJoints& arm,
164 const NaturalDiffIK::Mode& setOri,
166 DiffIKResult SolveAbsolute(const Eigen::Matrix4f& targetPose);
167 DiffIKResult SolveRelative(const Eigen::Matrix4f& targetPose,
168 const Eigen::VectorXf& startJointValues);
169
170 private:
171 NaturalIK natik;
173 NaturalDiffIK::Mode setOri;
175 };
176} // namespace armarx
DiffIKResult SolveAbsolute(const Eigen::Matrix4f &targetPose)
DiffIKResult SolveRelative(const Eigen::Matrix4f &targetPose, const Eigen::VectorXf &startJointValues)
NaturalIKProvider(const NaturalIK &natik, const NaturalIK::ArmJoints &arm, const NaturalDiffIK::Mode &setOri, const NaturalIK::Parameters &params=NaturalIK::Parameters())
The NaturalIK class.
Definition NaturalIK.h:53
Eigen::Vector3f getShoulderPos()
NaturalIK::SoechtingForwardPositions solveSoechtingIK(const Eigen::Vector3f &targetPos, std::optional< float > minElbowHeight=std::nullopt)
Definition NaturalIK.cpp:43
NaturalDiffIK::Result calculateIK(const Eigen::Matrix4f &targetPose, ArmJoints arm, NaturalIK::Parameters params=NaturalIK::Parameters())
Definition NaturalIK.cpp:88
NaturalDiffIK::Result calculateIKpos(const Eigen::Vector3f &targetPos, ArmJoints arm, NaturalIK::Parameters params=NaturalIK::Parameters())
NaturalIK(std::string side, Eigen::Vector3f shoulderPos=Eigen::Vector3f::Zero(), float scale=1)
Definition NaturalIK.cpp:37
float getUpperArmLength() const
SoechtingForwardPositions forwardKinematics(SoechtingAngles sa)
SoechtingAngles CalculateSoechtingAngles(Eigen::Vector3f target)
NaturalIK::CalculateSoechtingAngles.
void setUpperArmLength(float value)
float getLowerArmLength() const
void setLowerArmLength(float value)
void setScale(float scale)
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::shared_ptr< class NaturalIK > NaturalIKPtr
Definition NaturalIK.h:39
VirtualRobot::RobotNodePtr elbow
Definition NaturalIK.h:68
VirtualRobot::RobotNodePtr shoulder
Definition NaturalIK.h:69
VirtualRobot::RobotNodeSetPtr rns
Definition NaturalIK.h:67
VirtualRobot::RobotNodePtr tcp
Definition NaturalIK.h:70
NaturalDiffIK::Parameters diffIKparams
Definition NaturalIK.h:61
std::optional< float > minimumElbowHeight
Definition NaturalIK.h:62
static constexpr float MMM_LOWER_ARM_LENGTH
Definition NaturalIK.h:85
static constexpr float MMM_CLAVICULAR_WIDTH
Definition NaturalIK.h:90
static constexpr float MMM_LSC2LS
Definition NaturalIK.h:87
static constexpr float MMM_LE2LW
Definition NaturalIK.h:82
static constexpr float MMM_SHOULDER_POS
Definition NaturalIK.h:91
static constexpr float MMM_LS2LE
Definition NaturalIK.h:81
static constexpr float MMM_L
Definition NaturalIK.h:83
static constexpr float MMM_BT2LSC
Definition NaturalIK.h:88
static constexpr float MMM_UPPER_ARM_LENGTH
Definition NaturalIK.h:84