26#include <SimoxUtility/math/convert/deg_to_rad.h>
27#include <SimoxUtility/math/convert/rad_to_deg.h>
28#include <VirtualRobot/Nodes/RobotNode.h>
29#include <VirtualRobot/RobotNodeSet.h>
30#include <VirtualRobot/math/Helpers.h>
38 side(side), shoulderPos(shoulderPos), scale(scale)
45 Eigen::Vector3f vtgt = targetPos;
49 for (
int i = 1; i < soechtingIterations; i++)
51 Eigen::Vector3f err = targetPos - fwd.
wrist;
60 if (minElbowHeight.has_value() && minElbowHeight.value() > fwd.
elbow.z())
62 float mEH = minElbowHeight.value();
65 Eigen::Vector3f wri_n = (fwd.
wrist - shoulderPos).normalized();
66 Eigen::Vector3f elb = fwd.
elbow;
67 for (
int i = 0; i < 20; i++)
69 float a = (
lo +
hi) / 2;
70 Eigen::AngleAxisf aa(a, wri_n);
71 elb = shoulderPos + aa * (fwd.
elbow - shoulderPos);
92 Eigen::Vector3f targetPos = math::Helpers::Position(targetPose);
109 Eigen::Matrix4f targetPose = math::Helpers::Pose(targetPos, Eigen::Matrix3f::Identity());
127 Eigen::Vector3f targetPos = math::Helpers::Position(targetPose);
144 target = target - shoulderPos;
147 target = target / scale;
149 else if (side ==
"Left")
151 target = target / scale;
152 target(0) = -target(0);
156 throw LocalException(
"Unsupported side: ") << side <<
". supported are Left|Right.";
159 target = target / 10;
164 float R = target.norm();
165 float Chi = simox::math::rad_to_deg(std::atan2(
x, y));
166 float Psi = simox::math::rad_to_deg(std::atan2(z, std::sqrt(
x *
x + y * y)));
179 sa.
SE = -4.0 + 1.10 * R + 0.90 * Psi;
180 sa.
EE = 39.4 + 0.54 * R - 1.06 * Psi;
181 sa.
SY = 13.2 + 0.86 * Chi + 0.11 * Psi;
182 sa.
EY = -10.0 + 1.08 * Chi - 0.35 * Psi;
184 sa.
SE = simox::math::deg_to_rad(sa.
SE);
185 sa.
SY = simox::math::deg_to_rad(sa.
SY);
186 sa.
EE = simox::math::deg_to_rad(sa.
EE);
187 sa.
EY = simox::math::deg_to_rad(sa.
EY);
201 Eigen::AngleAxisf aaSE(sa.
SE, Eigen::Vector3f::UnitX());
202 Eigen::AngleAxisf aaSY(-sa.
SY, Eigen::Vector3f::UnitZ());
203 Eigen::AngleAxisf aaEE(-sa.
EE, Eigen::Vector3f::UnitX());
204 Eigen::AngleAxisf aaEY(-sa.
EY, Eigen::Vector3f::UnitZ());
205 Eigen::Vector3f elb = -Eigen::Vector3f::UnitZ() * upperArmLength;
206 elb = aaSY * aaSE * elb;
207 Eigen::Vector3f wri = Eigen::Vector3f::UnitZ() * lowerArmLength;
208 wri = aaEY * aaEE * wri;
213 res.
elbow = shoulderPos + elb;
214 res.
wrist = shoulderPos + elb + wri;
235 return upperArmLength;
241 upperArmLength = value;
247 return lowerArmLength;
253 lowerArmLength = value;
260 natik(natik), arm(arm), setOri(setOri), params(params)
267 params.diffIKparams.resetRnsValues =
true;
279 const Eigen::VectorXf& startJointValues)
281 params.diffIKparams.resetRnsValues =
false;
282 arm.rns->setJointValues(startJointValues);
static Result CalculateDiffIK(const Eigen::Matrix4f &targetPose, const Eigen::Vector3f &elbowTarget, VirtualRobot::RobotNodeSetPtr rns, VirtualRobot::RobotNodePtr tcp, VirtualRobot::RobotNodePtr elbow, Mode setOri, Parameters params=Parameters())
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 ¶ms=NaturalIK::Parameters())
Eigen::Vector3f getShoulderPos()
NaturalIK::SoechtingForwardPositions solveSoechtingIK(const Eigen::Vector3f &targetPos, std::optional< float > minElbowHeight=std::nullopt)
NaturalDiffIK::Result calculateIK(const Eigen::Matrix4f &targetPose, ArmJoints arm, NaturalIK::Parameters params=NaturalIK::Parameters())
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)
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.
Eigen::VectorXf jointValues
VirtualRobot::RobotNodePtr elbow
VirtualRobot::RobotNodeSetPtr rns
VirtualRobot::RobotNodePtr tcp
NaturalDiffIK::Parameters diffIKparams
std::optional< float > minimumElbowHeight
SoechtingAngles soechtingAngles