33 #include <VirtualRobot/Robot.h>
34 #include <VirtualRobot/LinkedCoordinate.h>
35 #include <VirtualRobot/VirtualRobot.h>
36 #include <VirtualRobot/RobotConfig.h>
39 #include <Eigen/Geometry>
43 using namespace Eigen;
45 template class ::IceInternal::Handle<::armarx::FramedPose>;
46 template class ::IceInternal::Handle<::armarx::FramedPosition>;
47 template class ::IceInternal::Handle<::armarx::FramedDirection>;
48 template class ::IceInternal::Handle<::armarx::FramedOrientation>;
61 FramedDirectionBase(
source),
94 if (framedVec.
getFrame() == newFrame)
96 return FramedDirectionPtr::dynamicCast(framedVec.
clone());
99 if (!robot.hasRobotNode(newFrame))
101 throw LocalException() <<
"The requested frame '" << newFrame <<
"' does not exists in the robot " << robot.getName();
104 Eigen::Matrix4f rotToNewFrame = __GetRotationBetweenFrames(framedVec.frame, newFrame, robot);
106 Eigen::Vector3f vecOldFrame = framedVec.Vector3::toEigen();
108 Eigen::Vector3f newVec = rotToNewFrame.block(0, 0, 3, 3).inverse() * vecOldFrame;
111 result->x = newVec(0);
112 result->y = newVec(1);
113 result->z = newVec(2);
114 result->frame = newFrame;
115 result->agent = robot.getName();
144 if (!robot.hasRobotNode(newFrame))
146 throw LocalException() <<
"The requested frame '" << newFrame <<
"' does not exist in the robot " << robot.getName();
149 if (frame !=
GlobalFrame && !robot.hasRobotNode(frame))
151 throw LocalException() <<
"The current frame '" << frame <<
"' does not exist in the robot " << robot.getName();
155 Eigen::Matrix4f rotToNewFrame = __GetRotationBetweenFrames(frame, newFrame, robot);
159 Eigen::Vector3f newVec = rotToNewFrame.block(0, 0, 3, 3).inverse() * vecOldFrame;
166 agent = robot.getName();
188 changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
189 Eigen::Vector3f pos = referenceRobot.getRootNode()->getGlobalPose().block<3, 3>(0, 0) *
toEigen();
210 newDirection->changeToGlobal(referenceRobot);
244 newDirection->changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
261 newDirection.
changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
278 auto node = robotState.getRobotNode(newFrame);
280 toNewFrame = node->getGlobalPose();
284 auto node = robotState.getRobotNode(oldFrame);
286 auto newNode = robotState.getRobotNode(newFrame);
288 toNewFrame = node->getTransformationTo(newNode);
291 toNewFrame(0, 3) = 0;
292 toNewFrame(1, 3) = 0;
293 toNewFrame(2, 3) = 0;
303 obj->setString(
"frame", frame);
304 obj->setString(
"agent", agent);
312 frame = obj->getString(
"frame");
314 if (obj->hasElement(
"agent"))
316 agent = obj->getString(
"agent");
322 return this->
clone();
342 stream <<
"FramedDirection: " << std::endl << rhs.
output() << std::endl;
355 armarx::Serializable(pose),
356 armarx::VariantDataClass(pose),
358 FramedPoseBase(pose),
378 FramedPose::FramedPose(
const armarx::Vector3BasePtr pos,
const armarx::QuaternionBasePtr ori,
const std::string& frame,
const std::string& agent) :
401 const Eigen::IOFormat
ArmarXEigenFormat(Eigen::StreamPrecision, 4,
" ",
"\n",
"",
"");
408 if (newFrame == frame)
425 if (newFrame == frame)
438 if (frame !=
GlobalFrame and !referenceRobot.hasRobotNode(frame))
440 throw LocalException() <<
"The current frame '" << frame <<
"' does not exists in the robot " << referenceRobot.getName();
442 if (!referenceRobot.hasRobotNode(newFrame))
444 throw LocalException() <<
"The requested frame '" << newFrame <<
"' does not exists in the robot " << referenceRobot.getName();
449 oldFrameTransformation = referenceRobot.getRobotNode(frame)->getPoseInRootFrame();
453 oldFrameTransformation = referenceRobot.getRootNode()->getGlobalPose().inverse();
457 (referenceRobot.getRobotNode(newFrame)->getPoseInRootFrame().inverse() * oldFrameTransformation) *
toEigen();
460 Eigen::Vector3f pos = newPose.block<3, 1>(0, 3);
463 agent = referenceRobot.getName();
485 changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
486 Eigen::Matrix4f global = referenceRobot.getRootNode()->getGlobalPose();
488 position->x = pose(0, 3);
489 position->y = pose(1, 3);
490 position->z = pose(2, 3);
492 orientation->qw =
q.w();
493 orientation->qx =
q.x();
494 orientation->qy =
q.y();
495 orientation->qz =
q.z();
513 newPose->changeToGlobal(referenceRobot);
547 newPose->changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
564 newPose.
changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
586 obj->setString(
"frame", frame);
587 obj->setString(
"agent", agent);
595 frame = obj->getString(
"frame");
597 if (obj->hasElement(
"agent"))
599 agent = obj->getString(
"agent");
639 if (newFrame == frame)
644 if (!referenceRobot->hasRobotNode(newFrame))
646 throw LocalException() <<
"The requested frame '" << newFrame <<
"' does not exists in the robot " << referenceRobot->getName();
661 if (newFrame == frame)
672 if (newFrame.empty())
674 ARMARX_WARNING_S <<
"Frame Conversion: Frame is empty, always set frame names! ...assuming GlobalFrame";
681 if (!referenceRobot.hasRobotNode(newFrame))
683 throw LocalException() <<
"The requested frame '" << newFrame <<
"' does not exists in the robot " << referenceRobot.getName();
688 oldFrameTransformation = referenceRobot.getRobotNode(frame)->getPoseInRootFrame();
692 oldFrameTransformation = referenceRobot.getRootNode()->getGlobalPose().inverse();
696 oldPose.block<3, 1>(0, 3) =
toEigen();
698 (referenceRobot.getRobotNode(newFrame)->getPoseInRootFrame().inverse() * oldFrameTransformation) * oldPose;
700 Eigen::Vector3f pos = newPose.block<3, 1>(0, 3);
704 agent = referenceRobot.getName();
725 changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
726 Eigen::Vector3f pos = referenceRobot.getRootNode()->getGlobalPose().block<3, 3>(0, 0) *
toEigen()
727 + referenceRobot.getRootNode()->getGlobalPose().block<3, 1>(0, 3);
748 newPosition->changeToGlobal(referenceRobot);
782 newPosition->changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
799 newPosition.
changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
815 obj->setString(
"frame", frame);
816 obj->setString(
"agent", agent);
824 frame = obj->getString(
"frame");
826 if (obj->hasElement(
"agent"))
828 agent = obj->getString(
"agent");
834 armarx::Serializable(other),
835 Vector3Base(other.x, other.y, other.z),
836 FramedPositionBase(other.x, other.y, other.z, other.frame, other.agent),
837 Vector3(other.x, other.y, other.z)
853 return this->
clone();
873 stream <<
"FramedPosition: " << std::endl << rhs.
output() << std::endl;
921 s <<
toEigen() << std::endl <<
"frame: " <<
getFrame() << (agent.empty() ?
"" : (
" agent: " + agent));
927 if (newFrame == frame)
945 if (newFrame == frame)
958 if (!referenceRobot.hasRobotNode(newFrame))
960 throw LocalException() <<
"The requested frame '" << newFrame <<
"' does not exists in the robot " << referenceRobot.getName();
965 oldFrameTransformation = referenceRobot.getRobotNode(frame)->getPoseInRootFrame();
969 oldFrameTransformation = referenceRobot.getRootNode()->getGlobalPose().inverse();
973 oldPose.block<3, 3>(0, 0) =
toEigen();
976 (referenceRobot.getRobotNode(newFrame)->getPoseInRootFrame().inverse() * oldFrameTransformation) * oldPose;
983 agent = referenceRobot.getName();
1005 changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
1029 newOrientation->changeToGlobal(referenceRobot);
1030 return newOrientation;
1047 return newOrientation.
toEigen();
1063 newOrientation->changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
1064 return newOrientation;
1080 newOrientation.
changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
1081 return newOrientation.
toEigen();
1089 obj->setString(
"frame", frame);
1090 obj->setString(
"agent", agent);
1098 frame = obj->getString(
"frame");
1100 if (obj->hasElement(
"agent"))
1102 agent = obj->getString(
"agent");
1108 return this->
clone();
1128 stream <<
"FramedOrientation: " << std::endl << rhs.
output() << std::endl;
1135 VirtualRobot::LinkedCoordinate
c(virtualRobot);
1140 frame = position->getFrame();
1144 if (!frame.empty() && frame != orientation->getFrame())
1146 throw armarx::UserException(
"Error: frames mismatch");
1154 armarx::UserException(
"createLinkedCoordinate: orientation and position are both NULL");
1158 frame = orientation->getFrame();
1166 pose.block<3, 3>(0, 0) = orientation->toEigen();
1171 pose.block<3, 1>(0, 3) = position->toEigen();
1182 return toFrame(sharedRobot, newFrame);
1188 newPose->changeFrame(referenceRobot, newFrame);
1202 return toFrame(referenceRobot, newFrame)->toEigen();
1207 return this->
clone();
1227 stream <<
"FramedPose: " << std::endl << rhs.
output() << std::endl;
1233 if (pose1.frame != pose2.frame || pose1.agent != pose2.agent)
return false;
1239 return !(pose1 == pose2);