1#include <SimoxUtility/algorithm/string/string_tools.h>
4#include <VirtualRobot/MathTools.h>
12 tcp_control::arondto::MoveTCPToTargetPoseAcceptedType
13 GetDefaultParameterization()
15 tcp_control::arondto::MoveTCPToTargetPoseAcceptedType ret;
16 ret.orientationalAccuracy = 0.01;
17 ret.positionalAccuracy = 25;
23 .skillId = {.skillName =
"MoveTCPToTargetPose"},
24 .description =
"Move the TCP to a target pose",
25 .rootProfileDefaults = GetDefaultParameterization().toAron(),
27 .parametersType = tcp_control::arondto::MoveTCPToTargetPoseAcceptedType::ToAronType(),
46 tcpControlUnitRequestedOnStart =
true;
49 tcpControlUnitRequestedOnStart =
false;
58 MoveTCPToTargetPose::step(
const SpecializedMainInput& in)
61 robotReader.getSynchronizedRobot(in.parameters.robotName,
63 VirtualRobot::RobotIO::RobotDescription::eStructure);
66 ARMARX_WARNING <<
"Unable to get robot from robotstatememory. Abort.";
70 std::string handRootNodeName =
"Hand L Base";
71 std::string robotAPIHandFileName =
"RobotAPI/robots/Armar3/ArmarIII-LeftHand.xml";
72 if (simox::alg::starts_with(in.parameters.kinematicChainName,
"Right"))
74 handRootNodeName =
"Hand R Base";
75 robotAPIHandFileName =
"RobotAPI/robots/Armar3/ArmarIII-RightHand.xml";
79 robot->getRobotNodeSet(in.parameters.kinematicChainName)->getTCP()->getName();
81 const Eigen::Matrix4f tcpPoseGlobal = robot->getRobotNode(tcpName)->getGlobalPose();
82 const Eigen::Matrix4f handRootPoseGlobal =
83 robot->getRobotNode(handRootNodeName)->getGlobalPose();
84 const Eigen::Matrix4f tcpInHandRoot = handRootPoseGlobal.inverse() * tcpPoseGlobal;
87 auto currentTCPPoseGlobal = robot->getRobotNode(tcpName)->getGlobalPose();
89 const auto tcpTargetPoseGlobal = in.parameters.targetPoseGlobal;
90 const Eigen::Matrix4f handRootTargetPoseGlobal =
91 tcpTargetPoseGlobal * tcpInHandRoot.inverse();
93 const float baseSpeedFactor = 1.5;
94 const float maxTranslationSpeed = baseSpeedFactor * 30;
95 const float minTranslationSpeed = maxTranslationSpeed * 0.1;
96 const float maxRotationSpeed = baseSpeedFactor * 0.7;
97 const float minRotationSpeed = maxRotationSpeed * 0.1;
100 Eigen::Vector3f diffPos =
101 tcpTargetPoseGlobal.block<3, 1>(0, 3) - currentTCPPoseGlobal.block<3, 1>(0, 3);
102 float diffPosError = diffPos.norm();
104 float sig = 1 / (1 + pow(M_E, -diffPos.norm() / 5.f + 1.0));
105 diffPos = baseSpeedFactor * diffPos * sig;
108 if (diffPosError < minTranslationSpeed && diffPosError != 0)
110 diffPos *= (minTranslationSpeed / diffPosError);
113 else if (diffPosError > maxTranslationSpeed && diffPosError != 0)
115 diffPos *= (maxTranslationSpeed / diffPosError);
118 if (diffPosError < in.parameters.positionalAccuracy)
120 diffPos = Eigen::Vector3f::Zero();
127 auto a = armarx::viz::Arrow(
"cartesianVelocity");
128 a.pose(currentTCPPoseGlobal);
129 a.direction(diffPos);
130 a.length(diffPos.norm() * 3);
133 auto b = armarx::viz::Sphere(
"targetPose");
134 b.pose(tcpTargetPoseGlobal);
135 b.radius(diffPos.norm());
138 auto o = armarx::viz::Robot(
"grasp");
139 o.file(
"RobotAPI", robotAPIHandFileName);
140 o.pose(handRootTargetPoseGlobal);
146 Eigen::Vector3f angles(0, 0, 0);
150 Eigen::Matrix3f diffRot = tcpTargetPoseGlobal.block<3, 3>(0, 0) *
151 currentTCPPoseGlobal.block<3, 3>(0, 0).inverse();
152 angles = VirtualRobot::MathTools::eigen3f2rpy(diffRot);
153 float anglesError = angles.norm();
164 if (anglesError < minRotationSpeed && anglesError != 0)
166 angles *= (minRotationSpeed / anglesError);
169 else if (anglesError > maxRotationSpeed && anglesError != 0)
171 angles *= (maxRotationSpeed / anglesError);
174 if (anglesError < in.parameters.orientationalAccuracy)
176 angles = Eigen::Vector3f::Zero();
189 auto cartesianError = diffPosError;
190 auto angleError = anglesError;
193 << (std::to_string(cartesianError) +
" mm, " +
194 std::to_string(angleError * 180 /
M_PI) +
" deg")
198 <<
"Current Thresholds: " << in.parameters.positionalAccuracy <<
"mm, "
199 << in.parameters.orientationalAccuracy * 180.0f /
M_PI <<
"deg";
202 <<
", " << angleVelocity.y <<
", " << angleVelocity.z <<
")\n"
203 <<
"catesian vel: " << cartesianVelocity.x <<
", " << cartesianVelocity.y
204 <<
", " << cartesianVelocity.z <<
")";
206 if (angleError <= in.parameters.orientationalAccuracy &&
207 cartesianError <= in.parameters.positionalAccuracy)
212 context.tcpControlUnitPrx->setTCPVelocity(in.parameters.kinematicChainName,
225 robotReader.getSynchronizedRobot(in.parameters.robotName,
227 VirtualRobot::RobotIO::RobotDescription::eStructure);
230 ARMARX_WARNING <<
"Unable to get robot from robotstatememory. Abort exit method.";
234 std::string tcpName =
235 robot->getRobotNodeSet(in.parameters.kinematicChainName)->getTCP()->getName();
239 if (!tcpControlUnitRequestedOnStart)
241 context.tcpControlUnitPrx->release();
static Duration MilliSeconds(std::int64_t milliSeconds)
Constructs a duration in milliseconds.
SpamFilterDataPtr deactivateSpam(float deactivationDurationSec=10.0f, const std::string &identifier="", bool deactivate=true) const
disables the logging for the current line for the given amount of seconds.
The memory name system (MNS) client.
virtual void connect(armem::client::MemoryNameSystem &memoryNameSystem)
MoveTCPToTargetPose(armem::client::MemoryNameSystem &mns, armarx::viz::Client &arviz, TCPControlSkillContext &context)
static SkillDescription Description
SimplePeriodicSpecializedSkill(const SkillDescription &skillDescription, const armarx::Frequency &frequency)
armarx::core::time::DateTime started
virtual InitResult init()
Override this method with the actual implementation.
virtual ExitResult exit()
Override this method with the actual implementation.
TCPControlSkill(armem::client::MemoryNameSystem &mns, armarx::viz::Client &arviz, const std::string &layerName, TCPControlSkillContext &c)
void stopTCPMovement(const std::string &kinematicChainName, const std::string &tcpName)
TCPControlSkillContext & context
#define ARMARX_INFO
The normal logging level.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
std::string const GlobalFrame
Variable of the global coordinate system.
const VariantTypeId FramedDirection
double a(double t, double a0, double j)
This file is part of ArmarX.
This file offers overloads of toIce() and fromIce() functions for STL container types.
A result struct for skill exit function.
A result struct for skill initialization.
TCPControlUnitInterfacePrx tcpControlUnitPrx
armarx::viz::Client arviz
armem::client::MemoryNameSystem & mns
armem::robot_state::VirtualRobotReader robotReader