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();
105 const Eigen::Matrix4f& currentPose = node->getPoseInRootFrame();
106 tcpPoses[tcpName] =
new FramedPose(currentPose, rootFrame, robot->getName());
107 FramedPosePtr::dynamicCast(tcpPoses[tcpName])
108 ->changeFrame(robot, nodesToReport.at(i).second);
118 FramedPoseBaseMap::const_iterator it = poseMap.begin();
120 for (; it != poseMap.end(); it++)
124 const std::string& tcpName = it->first;
145 tcpName,
"qx",
Variant(vec->orientation->qx),
"Quaternion part x");
147 tcpName,
"qy",
Variant(vec->orientation->qy),
"Quaternion part y");
149 tcpName,
"qz",
Variant(vec->orientation->qz),
"Quaternion part z");
151 tcpName,
"qw",
Variant(vec->orientation->qw),
"Quaternion part w");
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);
174 const AMD_RobotStateObserverInterface_getPoseDatafieldPtr& amd,
175 const std::string& nodeName,
176 const Ice::Current&)
const
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();
221 const Eigen::Matrix4f& currentPose =
222 velocityReportRobot->getRobotNode(tcpName)->getGlobalPose();
227 velocityReportRobot->setJointValues(tempJointAngles);
228 velocityReportRobot->setGlobalPose(robot->getGlobalPose());
234 Eigen::VectorXf jointVelocities(jointVel.size());
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)
240 jointVelocities(i) = jointVel.at(rns->getNode(i)->getName());
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);
250 Eigen::VectorXf nodeVel = jac * jointVelocities;
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);
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;
294 const std::string channelName = tcpName +
"Velocities";
298 offerChannel(channelName,
"pose components of " + tcpName);
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);
334 std::unique_lock lock(dataMutex);
337 std::vector<VirtualRobot::RobotNodeSetPtr> robotNodes;
338 robotNodes = robot->getRobotNodeSets();
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()));
360 std::vector<std::string> nodesetNames = simox::alg::split(nodesetsString,
",");
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;
#define TCP_TRANS_VELOCITIES_CHANNEL
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Property< PropertyType > getProperty(const std::string &name)
Checks if the numbers published in the relevant data fields equal a reference value.
Checks if the numbers published in the relevant data fields are within a reference range.
Checks if the numbers published in the relevant data fields are larger than a reference value.
Checks if the numbers published in the relevant data fields are smaller than a reference value.
FramedDirection is a 3 dimensional direction vector with a reference frame.
int getState() const
Retrieve current state of the ManagedIceObject.
bool existsChannel(const std::string &channelName) const
void offerChannel(std::string channelName, std::string description)
Offer a channel.
void offerConditionCheck(std::string checkName, ConditionCheck *conditionCheck)
Offer a condition check.
void updateChannel(const std::string &channelName, const std::set< std::string > &updatedDatafields=std::set< std::string >())
Update all conditions for a channel.
void addWorkerJob(const std::string &name, std::function< void(void)> &&f) const
void setDataFieldsFlatCopy(const std::string &channelName, const StringVariantBaseMap &datafieldValues, bool triggerFilterUpdate=true)
void offerDataFieldWithDefault(std::string channelName, std::string datafieldName, const Variant &defaultValue, std::string description)
Offer a datafield with default value.
bool existsDataField(const std::string &channelName, const std::string &datafieldName) const
DatafieldRefBasePtr getDatafieldRefByName(const std::string &channelName, const std::string &datafieldName) const
void setDataField(const std::string &channelName, const std::string &datafieldName, const Variant &value, bool triggerFilterUpdate=true)
set datafield with datafieldName and in channel channelName
RobotStatePropertyDefinition Property Definitions.
void onConnectObserver() override
Framework hook.
void udpatePoseDatafields(const FramedPoseBaseMap &poseMap)
void updateVelocityDatafields(const FramedDirectionMap &tcpTranslationVelocities, const FramedDirectionMap &tcpOrientationVelocities)
void getPoseDatafield_async(const AMD_RobotStateObserverInterface_getPoseDatafieldPtr &amd, const std::string &nodeName, const Ice::Current &) const override
PropertyDefinitionsPtr createPropertyDefinitions() override
void onInitObserver() override
Framework hook.
void updateNodeVelocities(const NameValueMap &jointVel, long timestampMicroSeconds)
void setRobot(VirtualRobot::RobotPtr robot)
The Variant class is described here: Variants.
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
std::string const GlobalFrame
Variable of the global coordinate system.
std::shared_ptr< class Robot > RobotPtr
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::map< std::string, VariantBasePtr > StringVariantBaseMap
IceInternal::Handle< FramedDirection > FramedDirectionPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
void getMapKeys(const MapType &map, OutputIteratorType it)
IceInternal::Handle< FramedPose > FramedPosePtr
::std::map<::std::string, ::armarx::FramedPoseBasePtr > FramedPoseBaseMap