24 #include <RobotAPI/interface/core/RobotState.h>
34 #include <VirtualRobot/VirtualRobot.h>
35 #include <VirtualRobot/RobotNodeSet.h>
36 #include <VirtualRobot/Nodes/RobotNode.h>
37 #include <VirtualRobot/RobotConfig.h>
38 #include <VirtualRobot/VirtualRobot.h>
40 #include <VirtualRobot/IK/DifferentialIK.h>
42 #include <SimoxUtility/algorithm/string/string_tools.h>
44 #define TCP_POSE_CHANNEL "TCPPose"
45 #define TCP_TRANS_VELOCITIES_CHANNEL "TCPVelocities"
86 if (getState() < eManagedIceObjectStarting)
96 std::unique_lock lock(dataMutex);
97 ReadLockPtr lock2 = robot->getReadLock();
99 std::string rootFrame = robot->getRootNode()->getName();
102 for (
unsigned int i = 0; i < nodesToReport.size(); i++)
104 VirtualRobot::RobotNodePtr& node = nodesToReport.at(i).first;
105 const std::string& tcpName = node->getName();
107 tcpPoses[tcpName] =
new FramedPose(currentPose, rootFrame, robot->getName());
108 FramedPosePtr::dynamicCast(tcpPoses[tcpName])->changeFrame(robot, nodesToReport.at(i).second);
112 udpatePoseDatafields(tcpPoses);
119 FramedPoseBaseMap::const_iterator it = poseMap.begin();
121 for (; it != poseMap.end(); it++)
125 const std::string& tcpName = it->first;
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(tcpName,
"qx",
Variant(vec->orientation->qx),
"Quaternion part x");
145 offerDataFieldWithDefault(tcpName,
"qy",
Variant(vec->orientation->qy),
"Quaternion part y");
146 offerDataFieldWithDefault(tcpName,
"qz",
Variant(vec->orientation->qz),
"Quaternion part z");
147 offerDataFieldWithDefault(tcpName,
"qw",
Variant(vec->orientation->qw),
"Quaternion part w");
148 offerDataFieldWithDefault(tcpName,
"frame",
Variant(vec->frame),
"Reference Frame");
153 newValues[
"x"] =
new Variant(vec->position->x);
154 newValues[
"y"] =
new Variant(vec->position->y);
155 newValues[
"z"] =
new Variant(vec->position->z);
156 newValues[
"qx"] =
new Variant(vec->orientation->qx);
157 newValues[
"qy"] =
new Variant(vec->orientation->qy);
158 newValues[
"qz"] =
new Variant(vec->orientation->qz);
159 newValues[
"qw"] =
new Variant(vec->orientation->qw);
160 newValues[
"frame"] =
new Variant(vec->frame);
161 setDataFieldsFlatCopy(tcpName, newValues);
164 updateChannel(tcpName);
170 const AMD_RobotStateObserverInterface_getPoseDatafieldPtr& amd,
171 const std::string& nodeName,
172 const Ice::Current&)
const
174 addWorkerJob(
"RobotStateObserver::getPoseDatafield", [
this, amd, nodeName]
182 if (jointVel.empty())
186 if (getState() < eManagedIceObjectStarting)
191 std::unique_lock lock(dataMutex);
198 ReadLockPtr lock2 = robot->getReadLock();
200 if (!velocityReportRobot)
202 velocityReportRobot = robot->clone(robot->getName());
207 FramedDirectionMap tcpTranslationVelocities;
208 FramedDirectionMap tcpOrientationVelocities;
209 std::string rootFrame = robot->getRootNode()->getName();
210 NameValueMap tempJointAngles = robot->getConfig()->getRobotNodeJointValueMap();
213 for (
unsigned int i = 0; i < nodesToReport.size(); i++)
215 RobotNodePtr node = nodesToReport.at(i).first;
216 const std::string& tcpName = node->getName();
217 const Eigen::Matrix4f& currentPose = velocityReportRobot->getRobotNode(tcpName)->getGlobalPose();
223 velocityReportRobot->setJointValues(tempJointAngles);
224 velocityReportRobot->setGlobalPose(robot->getGlobalPose());
231 auto rootFrameName = velocityReportRobot->getRootNode()->getName();
232 RobotNodeSetPtr rns = RobotNodeSet::createRobotNodeSet(velocityReportRobot,
"All_Nodes", keys, rootFrameName);
233 for (
size_t i = 0; i < rns->getSize(); ++i)
237 DifferentialIKPtr j(
new DifferentialIK(rns));
240 auto robotName = velocityReportRobot->getName();
241 for (
unsigned int i = 0; i < nodesToReport.size(); i++)
243 RobotNodePtr node = velocityReportRobot->getRobotNode(nodesToReport.at(i).first->getName());
244 Eigen::MatrixXf jac = j->getJacobianMatrix(node, IKSolver::All);
247 const std::string tcpName = node->getName();
248 tcpTranslationVelocities[tcpName] =
new FramedDirection(nodeVel.block<3, 1>(0, 0), rootFrameName, robotName);
249 tcpOrientationVelocities[tcpName] =
new FramedDirection(nodeVel.block<3, 1>(3, 0), rootFrameName, robotName);
253 updateVelocityDatafields(tcpTranslationVelocities, tcpOrientationVelocities);
258 FramedDirectionMap::const_iterator it = tcpTranslationVelocities.begin();
260 for (; it != tcpTranslationVelocities.end(); it++)
265 FramedDirectionMap::const_iterator itOri = tcpOrientationVelocities.find(it->first);
267 if (itOri != tcpOrientationVelocities.end())
269 vecOri = FramedDirectionPtr::dynamicCast(itOri->second);
272 const std::string& tcpName = it->first;
286 const std::string channelName = tcpName +
"Velocities";
288 if (!existsChannel(channelName))
290 offerChannel(channelName,
"pose components of " + tcpName);
291 offerDataFieldWithDefault(channelName,
"x",
Variant(vec->x),
"X axis");
292 offerDataFieldWithDefault(channelName,
"y",
Variant(vec->y),
"Y axis");
293 offerDataFieldWithDefault(channelName,
"z",
Variant(vec->z),
"Z axis");
294 offerDataFieldWithDefault(channelName,
"roll",
Variant(vecOri->x),
"Roll");
295 offerDataFieldWithDefault(channelName,
"pitch",
Variant(vecOri->y),
"Pitch");
296 offerDataFieldWithDefault(channelName,
"yaw",
Variant(vecOri->z),
"Yaw");
297 offerDataFieldWithDefault(channelName,
"frame",
Variant(vecOri->frame),
"Reference Frame");
302 newValues[
"x"] =
new Variant(vec->x);
303 newValues[
"y"] =
new Variant(vec->y);
304 newValues[
"z"] =
new Variant(vec->z);
305 newValues[
"roll"] =
new Variant(vecOri->x);
306 newValues[
"pitch"] =
new Variant(vecOri->y);
307 newValues[
"yaw"] =
new Variant(vecOri->z);
308 newValues[
"frame"] =
new Variant(vec->frame);
309 setDataFieldsFlatCopy(channelName, newValues);
312 updateChannel(channelName);
321 getConfigIdentifier()));
326 std::unique_lock lock(dataMutex);
329 std::vector< VirtualRobot::RobotNodeSetPtr > robotNodes;
330 robotNodes = robot->getRobotNodeSets();
332 std::string nodesetsString = getProperty<std::string>(
"TCPsToReport").getValue();
333 nodesToReport.clear();
335 if (!nodesetsString.empty())
337 if (nodesetsString ==
"*")
339 auto nodesets = robot->getRobotNodeSets();
341 for (RobotNodeSetPtr&
set : nodesets)
345 nodesToReport.push_back(std::make_pair(
set->getTCP(), robot->getRootNode()->getName()));
353 for (
auto name : nodesetNames)
355 simox::alg::trim(name);
356 auto node = robot->getRobotNode(name);
360 nodesToReport.push_back(std::make_pair(node, robot->getRootNode()->getName()));
364 ARMARX_ERROR <<
"Could not find node with name: " << name;