25 #include <SimoxUtility/algorithm/string/string_tools.h>
26 #include <VirtualRobot/IK/DifferentialIK.h>
27 #include <VirtualRobot/Nodes/RobotNode.h>
28 #include <VirtualRobot/RobotConfig.h>
29 #include <VirtualRobot/RobotNodeSet.h>
30 #include <VirtualRobot/VirtualRobot.h>
39 #include <RobotAPI/interface/core/RobotState.h>
43 #define TCP_POSE_CHANNEL "TCPPose"
44 #define TCP_TRANS_VELOCITIES_CHANNEL "TCPVelocities"
85 if (getState() < eManagedIceObjectStarting)
95 std::unique_lock lock(dataMutex);
96 ReadLockPtr lock2 = robot->getReadLock();
98 std::string rootFrame = robot->getRootNode()->getName();
101 for (
unsigned int i = 0; i < nodesToReport.size(); i++)
103 VirtualRobot::RobotNodePtr& node = nodesToReport.at(i).first;
104 const std::string& tcpName = node->getName();
106 tcpPoses[tcpName] =
new FramedPose(currentPose, rootFrame, robot->getName());
107 FramedPosePtr::dynamicCast(tcpPoses[tcpName])
108 ->changeFrame(robot, nodesToReport.at(i).second);
111 udpatePoseDatafields(tcpPoses);
118 FramedPoseBaseMap::const_iterator it = poseMap.begin();
120 for (; it != poseMap.end(); it++)
124 const std::string& tcpName = it->first;
128 offerDataFieldWithDefault(
138 if (!existsChannel(tcpName))
140 offerChannel(tcpName,
"pose components of " + tcpName);
141 offerDataFieldWithDefault(tcpName,
"x",
Variant(vec->position->x),
"X axis");
142 offerDataFieldWithDefault(tcpName,
"y",
Variant(vec->position->y),
"Y axis");
143 offerDataFieldWithDefault(tcpName,
"z",
Variant(vec->position->z),
"Z axis");
144 offerDataFieldWithDefault(
145 tcpName,
"qx",
Variant(vec->orientation->qx),
"Quaternion part x");
146 offerDataFieldWithDefault(
147 tcpName,
"qy",
Variant(vec->orientation->qy),
"Quaternion part y");
148 offerDataFieldWithDefault(
149 tcpName,
"qz",
Variant(vec->orientation->qz),
"Quaternion part z");
150 offerDataFieldWithDefault(
151 tcpName,
"qw",
Variant(vec->orientation->qw),
"Quaternion part w");
152 offerDataFieldWithDefault(tcpName,
"frame",
Variant(vec->frame),
"Reference Frame");
157 newValues[
"x"] =
new Variant(vec->position->x);
158 newValues[
"y"] =
new Variant(vec->position->y);
159 newValues[
"z"] =
new Variant(vec->position->z);
160 newValues[
"qx"] =
new Variant(vec->orientation->qx);
161 newValues[
"qy"] =
new Variant(vec->orientation->qy);
162 newValues[
"qz"] =
new Variant(vec->orientation->qz);
163 newValues[
"qw"] =
new Variant(vec->orientation->qw);
164 newValues[
"frame"] =
new Variant(vec->frame);
165 setDataFieldsFlatCopy(tcpName, newValues);
168 updateChannel(tcpName);
174 const AMD_RobotStateObserverInterface_getPoseDatafieldPtr& amd,
175 const std::string& nodeName,
176 const Ice::Current&)
const
178 addWorkerJob(
"RobotStateObserver::getPoseDatafield",
179 [
this, amd, nodeName]
186 if (jointVel.empty())
190 if (getState() < eManagedIceObjectStarting)
195 std::unique_lock lock(dataMutex);
202 ReadLockPtr lock2 = robot->getReadLock();
204 if (!velocityReportRobot)
206 velocityReportRobot = robot->clone(robot->getName());
211 FramedDirectionMap tcpTranslationVelocities;
212 FramedDirectionMap tcpOrientationVelocities;
213 std::string rootFrame = robot->getRootNode()->getName();
214 NameValueMap tempJointAngles = robot->getConfig()->getRobotNodeJointValueMap();
217 for (
unsigned int i = 0; i < nodesToReport.size(); i++)
219 RobotNodePtr node = nodesToReport.at(i).first;
220 const std::string& tcpName = node->getName();
222 velocityReportRobot->getRobotNode(tcpName)->getGlobalPose();
227 velocityReportRobot->setJointValues(tempJointAngles);
228 velocityReportRobot->setGlobalPose(robot->getGlobalPose());
235 auto rootFrameName = velocityReportRobot->getRootNode()->getName();
236 RobotNodeSetPtr rns =
237 RobotNodeSet::createRobotNodeSet(velocityReportRobot,
"All_Nodes", keys, rootFrameName);
238 for (
size_t i = 0; i < rns->getSize(); ++i)
242 DifferentialIKPtr j(
new DifferentialIK(rns));
245 auto robotName = velocityReportRobot->getName();
246 for (
unsigned int i = 0; i < nodesToReport.size(); i++)
248 RobotNodePtr node = velocityReportRobot->getRobotNode(nodesToReport.at(i).first->getName());
249 Eigen::MatrixXf jac = j->getJacobianMatrix(node, IKSolver::All);
252 const std::string tcpName = node->getName();
253 tcpTranslationVelocities[tcpName] =
254 new FramedDirection(nodeVel.block<3, 1>(0, 0), rootFrameName, robotName);
255 tcpOrientationVelocities[tcpName] =
256 new FramedDirection(nodeVel.block<3, 1>(3, 0), rootFrameName, robotName);
258 updateVelocityDatafields(tcpTranslationVelocities, tcpOrientationVelocities);
263 const FramedDirectionMap& tcpOrientationVelocities)
265 FramedDirectionMap::const_iterator it = tcpTranslationVelocities.begin();
267 for (; it != tcpTranslationVelocities.end(); it++)
272 FramedDirectionMap::const_iterator itOri = tcpOrientationVelocities.find(it->first);
274 if (itOri != tcpOrientationVelocities.end())
276 vecOri = FramedDirectionPtr::dynamicCast(itOri->second);
279 const std::string& tcpName = it->first;
285 offerDataFieldWithDefault(
294 const std::string channelName = tcpName +
"Velocities";
296 if (!existsChannel(channelName))
298 offerChannel(channelName,
"pose components of " + tcpName);
299 offerDataFieldWithDefault(channelName,
"x",
Variant(vec->x),
"X axis");
300 offerDataFieldWithDefault(channelName,
"y",
Variant(vec->y),
"Y axis");
301 offerDataFieldWithDefault(channelName,
"z",
Variant(vec->z),
"Z axis");
302 offerDataFieldWithDefault(channelName,
"roll",
Variant(vecOri->x),
"Roll");
303 offerDataFieldWithDefault(channelName,
"pitch",
Variant(vecOri->y),
"Pitch");
304 offerDataFieldWithDefault(channelName,
"yaw",
Variant(vecOri->z),
"Yaw");
305 offerDataFieldWithDefault(
306 channelName,
"frame",
Variant(vecOri->frame),
"Reference Frame");
311 newValues[
"x"] =
new Variant(vec->x);
312 newValues[
"y"] =
new Variant(vec->y);
313 newValues[
"z"] =
new Variant(vec->z);
314 newValues[
"roll"] =
new Variant(vecOri->x);
315 newValues[
"pitch"] =
new Variant(vecOri->y);
316 newValues[
"yaw"] =
new Variant(vecOri->z);
317 newValues[
"frame"] =
new Variant(vec->frame);
318 setDataFieldsFlatCopy(channelName, newValues);
321 updateChannel(channelName);
334 std::unique_lock lock(dataMutex);
337 std::vector<VirtualRobot::RobotNodeSetPtr> robotNodes;
338 robotNodes = robot->getRobotNodeSets();
340 std::string nodesetsString = getProperty<std::string>(
"TCPsToReport").getValue();
341 nodesToReport.clear();
343 if (!nodesetsString.empty())
345 if (nodesetsString ==
"*")
347 auto nodesets = robot->getRobotNodeSets();
349 for (RobotNodeSetPtr&
set : nodesets)
353 nodesToReport.push_back(
354 std::make_pair(
set->getTCP(), robot->getRootNode()->getName()));
362 for (
auto name : nodesetNames)
364 simox::alg::trim(name);
365 auto node = robot->getRobotNode(name);
369 nodesToReport.push_back(std::make_pair(node, robot->getRootNode()->getName()));
373 ARMARX_ERROR <<
"Could not find node with name: " << name;