27 #include <Eigen/Geometry>
29 #include <VirtualRobot/LinkedCoordinate.h>
30 #include <VirtualRobot/Robot.h>
31 #include <VirtualRobot/RobotConfig.h>
32 #include <VirtualRobot/VirtualRobot.h>
42 using namespace Eigen;
44 template class ::IceInternal::Handle<::armarx::FramedPose>;
45 template class ::IceInternal::Handle<::armarx::FramedPosition>;
46 template class ::IceInternal::Handle<::armarx::FramedDirection>;
47 template class ::IceInternal::Handle<::armarx::FramedOrientation>;
59 FramedDirectionBase(
source),
65 const std::string& frame,
66 const std::string& agent) :
76 const std::string& frame,
77 const std::string& agent) :
93 const std::string& newFrame)
102 const std::string& newFrame)
104 if (framedVec.
getFrame() == newFrame)
106 return FramedDirectionPtr::dynamicCast(framedVec.
clone());
109 if (!robot.hasRobotNode(newFrame))
111 throw LocalException() <<
"The requested frame '" << newFrame
112 <<
"' does not exists in the robot " << robot.getName();
116 __GetRotationBetweenFrames(framedVec.frame, newFrame, robot);
118 Eigen::Vector3f vecOldFrame = framedVec.Vector3::toEigen();
120 Eigen::Vector3f newVec = rotToNewFrame.block(0, 0, 3, 3).inverse() * vecOldFrame;
123 result->x = newVec(0);
124 result->y = newVec(1);
125 result->z = newVec(2);
126 result->frame = newFrame;
127 result->agent = robot.getName();
158 if (!robot.hasRobotNode(newFrame))
160 throw LocalException() <<
"The requested frame '" << newFrame
161 <<
"' does not exist in the robot " << robot.getName();
164 if (frame !=
GlobalFrame && !robot.hasRobotNode(frame))
166 throw LocalException() <<
"The current frame '" << frame
167 <<
"' does not exist in the robot " << robot.getName();
171 Eigen::Matrix4f rotToNewFrame = __GetRotationBetweenFrames(frame, newFrame, robot);
175 Eigen::Vector3f newVec = rotToNewFrame.block(0, 0, 3, 3).inverse() * vecOldFrame;
182 agent = robot.getName();
207 changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
208 Eigen::Vector3f pos =
209 referenceRobot.getRootNode()->getGlobalPose().block<3, 3>(0, 0) *
toEigen();
235 newDirection->changeToGlobal(referenceRobot);
279 newDirection->changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
301 newDirection.
changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
310 <<
"frame: " <<
getFrame() << (agent.empty() ?
"" : (
" agent: " + agent));
315 FramedDirection::__GetRotationBetweenFrames(
const std::string& oldFrame,
316 const std::string& newFrame,
323 auto node = robotState.getRobotNode(newFrame);
325 toNewFrame = node->getGlobalPose();
329 auto node = robotState.getRobotNode(oldFrame);
331 <<
"old frame: " + oldFrame +
332 ValueToString(robotState.getConfig()->getRobotNodeJointValueMap());
333 auto newNode = robotState.getRobotNode(newFrame);
335 toNewFrame = node->getTransformationTo(newNode);
338 toNewFrame(0, 3) = 0;
339 toNewFrame(1, 3) = 0;
340 toNewFrame(2, 3) = 0;
350 obj->setString(
"frame", frame);
351 obj->setString(
"agent", agent);
359 frame = obj->getString(
"frame");
361 if (obj->hasElement(
"agent"))
363 agent = obj->getString(
"agent");
370 return this->
clone();
394 stream <<
"FramedDirection: " << std::endl << rhs.
output() << std::endl;
405 armarx::Serializable(pose),
406 armarx::VariantDataClass(pose),
408 FramedPoseBase(pose),
414 const Eigen::Vector3f&
v,
415 const std::string&
s,
416 const std::string& agent) :
424 const std::string&
s,
425 const std::string& agent) :
433 const armarx::QuaternionBasePtr ori,
434 const std::string& frame,
435 const std::string& agent) :
444 const std::string& frame,
445 const std::string& agent) :
462 const Eigen::IOFormat
ArmarXEigenFormat(Eigen::StreamPrecision, 4,
" ",
"\n",
"",
"");
464 <<
"frame: " <<
getFrame() << (agent.empty() ?
"" : (
" agent: " + agent));
470 const std::string& newFrame)
472 if (newFrame == frame)
483 const std::string& newFrame)
492 if (newFrame == frame)
505 if (frame !=
GlobalFrame and !referenceRobot.hasRobotNode(frame))
507 throw LocalException() <<
"The current frame '" << frame
508 <<
"' does not exists in the robot " << referenceRobot.getName();
510 if (!referenceRobot.hasRobotNode(newFrame))
512 throw LocalException() <<
"The requested frame '" << newFrame
513 <<
"' does not exists in the robot " << referenceRobot.getName();
518 oldFrameTransformation = referenceRobot.getRobotNode(frame)->getPoseInRootFrame();
522 oldFrameTransformation = referenceRobot.getRootNode()->getGlobalPose().inverse();
526 (referenceRobot.getRobotNode(newFrame)->getPoseInRootFrame().inverse() *
527 oldFrameTransformation) *
531 Eigen::Vector3f pos = newPose.block<3, 1>(0, 3);
534 agent = referenceRobot.getName();
560 changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
561 Eigen::Matrix4f global = referenceRobot.getRootNode()->getGlobalPose();
563 position->x = pose(0, 3);
564 position->y = pose(1, 3);
565 position->z = pose(2, 3);
567 orientation->qw =
q.w();
568 orientation->qx =
q.x();
569 orientation->qy =
q.y();
570 orientation->qz =
q.z();
593 newPose->changeToGlobal(referenceRobot);
637 newPose->changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
659 newPose.
changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
675 QuaternionPtr::dynamicCast(this->orientation)->
toEigen(), frame, agent);
685 obj->setString(
"frame", frame);
686 obj->setString(
"agent", agent);
695 frame = obj->getString(
"frame");
697 if (obj->hasElement(
"agent"))
699 agent = obj->getString(
"agent");
709 const std::string&
s,
710 const std::string& agent) :
718 const std::string&
s,
719 const std::string& agent) :
743 const std::string& newFrame)
745 if (newFrame == frame)
750 if (!referenceRobot->hasRobotNode(newFrame))
752 throw LocalException()
753 <<
"The requested frame '" << newFrame <<
"' does not exists in the robot "
754 << referenceRobot->getName();
763 const std::string& newFrame)
771 const std::string& newFrame)
773 if (newFrame == frame)
784 if (newFrame.empty())
786 ARMARX_WARNING_S <<
"Frame Conversion: Frame is empty, always set frame names! "
787 "...assuming GlobalFrame";
794 if (!referenceRobot.hasRobotNode(newFrame))
796 throw LocalException() <<
"The requested frame '" << newFrame
797 <<
"' does not exists in the robot " << referenceRobot.getName();
802 oldFrameTransformation = referenceRobot.getRobotNode(frame)->getPoseInRootFrame();
806 oldFrameTransformation = referenceRobot.getRootNode()->getGlobalPose().inverse();
810 oldPose.block<3, 1>(0, 3) =
toEigen();
812 (referenceRobot.getRobotNode(newFrame)->getPoseInRootFrame().inverse() *
813 oldFrameTransformation) *
816 Eigen::Vector3f pos = newPose.block<3, 1>(0, 3);
820 agent = referenceRobot.getName();
846 changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
847 Eigen::Vector3f pos =
848 referenceRobot.getRootNode()->getGlobalPose().block<3, 3>(0, 0) *
toEigen() +
849 referenceRobot.getRootNode()->getGlobalPose().block<3, 1>(0, 3);
875 newPosition->changeToGlobal(referenceRobot);
919 newPosition->changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
941 newPosition.
changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
950 <<
"frame: " <<
getFrame() << (agent.empty() ?
"" : (
" agent: " + agent));
956 const ::Ice::Current&
c)
const
961 obj->setString(
"frame", frame);
962 obj->setString(
"agent", agent);
971 frame = obj->getString(
"frame");
973 if (obj->hasElement(
"agent"))
975 agent = obj->getString(
"agent");
981 armarx::Serializable(other),
982 Vector3Base(other.x, other.y, other.z),
983 FramedPositionBase(other.x, other.y, other.z, other.frame, other.agent),
984 Vector3(other.x, other.y, other.z)
1002 return this->
clone();
1026 stream <<
"FramedPosition: " << std::endl << rhs.
output() << std::endl;
1036 const std::string&
s,
1037 const std::string& agent) :
1041 this->agent = agent;
1045 const std::string& frame,
1046 const std::string& agent) :
1049 this->frame = frame;
1050 this->agent = agent;
1054 const std::string&
s,
1055 const std::string& agent) :
1059 this->agent = agent;
1079 std::stringstream
s;
1081 <<
"frame: " <<
getFrame() << (agent.empty() ?
"" : (
" agent: " + agent));
1087 const std::string& newFrame)
1089 if (newFrame == frame)
1101 const std::string& newFrame)
1109 const std::string& newFrame)
1111 if (newFrame == frame)
1124 if (!referenceRobot.hasRobotNode(newFrame))
1126 throw LocalException() <<
"The requested frame '" << newFrame
1127 <<
"' does not exists in the robot " << referenceRobot.getName();
1132 oldFrameTransformation = referenceRobot.getRobotNode(frame)->getPoseInRootFrame();
1136 oldFrameTransformation = referenceRobot.getRootNode()->getGlobalPose().inverse();
1140 oldPose.block<3, 3>(0, 0) =
toEigen();
1143 (referenceRobot.getRobotNode(newFrame)->getPoseInRootFrame().inverse() *
1144 oldFrameTransformation) *
1152 agent = referenceRobot.getName();
1178 changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
1180 referenceRobot.getRootNode()->getGlobalPose().block<3, 3>(0, 0) *
toEigen();
1208 newOrientation->changeToGlobal(referenceRobot);
1209 return newOrientation;
1231 return newOrientation.
toEigen();
1252 newOrientation->changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
1253 return newOrientation;
1274 newOrientation.
changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
1275 return newOrientation.
toEigen();
1280 const ::Ice::Current&
c)
const
1285 obj->setString(
"frame", frame);
1286 obj->setString(
"agent", agent);
1291 const ::Ice::Current&
c)
1296 frame = obj->getString(
"frame");
1298 if (obj->hasElement(
"agent"))
1300 agent = obj->getString(
"agent");
1307 return this->
clone();
1331 stream <<
"FramedOrientation: " << std::endl << rhs.
output() << std::endl;
1335 VirtualRobot::LinkedCoordinate
1340 VirtualRobot::LinkedCoordinate
c(virtualRobot);
1345 frame = position->getFrame();
1349 if (!frame.empty() && frame != orientation->getFrame())
1351 throw armarx::UserException(
"Error: frames mismatch");
1359 armarx::UserException(
1360 "createLinkedCoordinate: orientation and position are both NULL");
1364 frame = orientation->getFrame();
1372 pose.block<3, 3>(0, 0) = orientation->toEigen();
1377 pose.block<3, 1>(0, 3) = position->toEigen();
1387 const std::string& newFrame)
const
1390 return toFrame(sharedRobot, newFrame);
1395 const std::string& newFrame)
const
1398 newPose->changeFrame(referenceRobot, newFrame);
1404 const std::string& newFrame)
const
1412 const std::string& newFrame)
const
1414 return toFrame(referenceRobot, newFrame)->toEigen();
1420 return this->
clone();
1444 stream <<
"FramedPose: " << std::endl << rhs.
output() << std::endl;
1451 if (pose1.frame != pose2.frame || pose1.agent != pose2.agent)
1459 return !(pose1 == pose2);