27#include <Eigen/Geometry>
29#include <VirtualRobot/LinkedCoordinate.h>
30#include <VirtualRobot/Robot.h>
31#include <VirtualRobot/RobotConfig.h>
32#include <VirtualRobot/VirtualRobot.h>
44template class ::IceInternal::Handle<::armarx::FramedPose>;
45template class ::IceInternal::Handle<::armarx::FramedPosition>;
46template class ::IceInternal::Handle<::armarx::FramedDirection>;
47template class ::IceInternal::Handle<::armarx::FramedOrientation>;
53 FramedDirection::FramedDirection() =
default;
57 armarx::Serializable(source),
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();
115 Eigen::Matrix4f rotToNewFrame =
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();
133 const std::string& newFrame)
159 if (!robot.hasRobotNode(newFrame))
161 throw LocalException() <<
"The requested frame '" << newFrame
162 <<
"' does not exist in the robot " << robot.getName();
165 if (frame !=
GlobalFrame && !robot.hasRobotNode(frame))
167 throw LocalException() <<
"The current frame '" << frame
168 <<
"' does not exist in the robot " << robot.getName();
172 Eigen::Matrix4f rotToNewFrame = __GetRotationBetweenFrames(frame, newFrame, robot);
176 Eigen::Vector3f newVec = rotToNewFrame.block(0, 0, 3, 3).inverse() * vecOldFrame;
183 agent = robot.getName();
189 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
208 changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
209 Eigen::Vector3f pos =
210 referenceRobot.getRootNode()->getGlobalPose().block<3, 3>(0, 0) *
toEigen();
221 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
236 newDirection->changeToGlobal(referenceRobot);
243 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
265 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
280 newDirection->changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
287 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
302 newDirection.
changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
311 <<
"frame: " <<
getFrame() << (agent.empty() ?
"" : (
" agent: " + agent));
316 FramedDirection::__GetRotationBetweenFrames(
const std::string& oldFrame,
317 const std::string& newFrame,
318 const VirtualRobot::Robot& robotState)
320 Eigen::Matrix4f toNewFrame;
324 auto node = robotState.getRobotNode(newFrame);
326 toNewFrame = node->getGlobalPose();
330 auto node = robotState.getRobotNode(oldFrame);
332 <<
"old frame: " + oldFrame +
333 ValueToString(robotState.getConfig()->getRobotNodeJointValueMap());
334 auto newNode = robotState.getRobotNode(newFrame);
336 toNewFrame = node->getTransformationTo(newNode);
339 toNewFrame(0, 3) = 0;
340 toNewFrame(1, 3) = 0;
341 toNewFrame(2, 3) = 0;
351 obj->setString(
"frame", frame);
352 obj->setString(
"agent", agent);
360 frame = obj->getString(
"frame");
362 if (obj->hasElement(
"agent"))
364 agent = obj->getString(
"agent");
371 return this->
clone();
395 stream <<
"FramedDirection: " << std::endl << rhs.
output() << std::endl;
406 armarx::Serializable(pose),
407 armarx::VariantDataClass(pose),
409 FramedPoseBase(pose),
415 const Eigen::Vector3f& v,
416 const std::string& s,
417 const std::string& agent) :
425 const std::string& s,
426 const std::string& agent) :
434 const armarx::QuaternionBasePtr ori,
435 const std::string& frame,
436 const std::string& agent) :
445 const std::string& frame,
446 const std::string& agent) :
463 const Eigen::IOFormat
ArmarXEigenFormat(Eigen::StreamPrecision, 4,
" ",
"\n",
"",
"");
465 <<
"frame: " <<
getFrame() << (agent.empty() ?
"" : (
" agent: " + agent));
471 const std::string& newFrame)
473 if (newFrame == frame)
478 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
484 const std::string& newFrame)
493 if (newFrame == frame)
504 Eigen::Isometry3f oldFrameTransformation = Eigen::Isometry3f::Identity();
506 if (frame !=
GlobalFrame and !referenceRobot.hasRobotNode(frame))
508 throw LocalException() <<
"The current frame '" << frame
509 <<
"' does not exists in the robot " << referenceRobot.getName();
511 if (!referenceRobot.hasRobotNode(newFrame))
513 throw LocalException() <<
"The requested frame '" << newFrame
514 <<
"' does not exists in the robot " << referenceRobot.getName();
519 oldFrameTransformation = referenceRobot.getRobotNode(frame)->getPoseInRootFrame();
523 oldFrameTransformation =
524 Eigen::Isometry3f{referenceRobot.getRootNode()->getGlobalPose()}.inverse();
527 Eigen::Isometry3f newPose =
528 (Eigen::Isometry3f{referenceRobot.getRobotNode(newFrame)->getPoseInRootFrame()}
530 oldFrameTransformation) *
533 orientation =
new Quaternion(Eigen::Matrix3f{newPose.linear()});
534 Eigen::Vector3f pos = newPose.translation();
537 agent = referenceRobot.getName();
544 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
563 changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
564 Eigen::Matrix4f global = referenceRobot.getRootNode()->getGlobalPose();
565 const Eigen::Matrix4f pose = global *
toEigen();
566 position->x = pose(0, 3);
567 position->y = pose(1, 3);
568 position->z = pose(2, 3);
570 orientation->qw =
q.w();
571 orientation->qx =
q.x();
572 orientation->qy =
q.y();
573 orientation->qz =
q.z();
581 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
596 newPose->changeToGlobal(referenceRobot);
603 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
625 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
640 newPose->changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
647 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
662 newPose.
changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
678 QuaternionPtr::dynamicCast(this->orientation)->
toEigen(), frame, agent);
688 obj->setString(
"frame", frame);
689 obj->setString(
"agent", agent);
698 frame = obj->getString(
"frame");
700 if (obj->hasElement(
"agent"))
702 agent = obj->getString(
"agent");
712 const std::string& s,
713 const std::string& agent) :
721 const std::string& s,
722 const std::string& agent) :
746 const std::string& newFrame)
748 if (newFrame == frame)
753 if (!referenceRobot->hasRobotNode(newFrame))
755 throw LocalException()
756 <<
"The requested frame '" << newFrame <<
"' does not exists in the robot "
757 << referenceRobot->getName();
760 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
766 const std::string& newFrame)
774 const std::string& newFrame)
776 if (newFrame == frame)
787 if (newFrame.empty())
789 ARMARX_WARNING_S <<
"Frame Conversion: Frame is empty, always set frame names! "
790 "...assuming GlobalFrame";
795 Eigen::Matrix4f oldFrameTransformation = Eigen::Matrix4f::Identity();
797 if (!referenceRobot.hasRobotNode(newFrame))
799 throw LocalException() <<
"The requested frame '" << newFrame
800 <<
"' does not exists in the robot " << referenceRobot.getName();
805 oldFrameTransformation = referenceRobot.getRobotNode(frame)->getPoseInRootFrame();
809 oldFrameTransformation = referenceRobot.getRootNode()->getGlobalPose().inverse();
812 Eigen::Matrix4f oldPose = Eigen::Matrix4f::Identity();
813 oldPose.block<3, 1>(0, 3) =
toEigen();
814 Eigen::Matrix4f newPose =
815 (referenceRobot.getRobotNode(newFrame)->getPoseInRootFrame().inverse() *
816 oldFrameTransformation) *
819 Eigen::Vector3f pos = newPose.block<3, 1>(0, 3);
823 agent = referenceRobot.getName();
830 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
849 changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
850 Eigen::Vector3f pos =
851 referenceRobot.getRootNode()->getGlobalPose().block<3, 3>(0, 0) *
toEigen() +
852 referenceRobot.getRootNode()->getGlobalPose().block<3, 1>(0, 3);
863 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
878 newPosition->changeToGlobal(referenceRobot);
885 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
907 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
922 newPosition->changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
929 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
944 newPosition.
changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
953 <<
"frame: " <<
getFrame() << (agent.empty() ?
"" : (
" agent: " + agent));
959 const ::Ice::Current&
c)
const
964 obj->setString(
"frame", frame);
965 obj->setString(
"agent", agent);
974 frame = obj->getString(
"frame");
976 if (obj->hasElement(
"agent"))
978 agent = obj->getString(
"agent");
984 armarx::Serializable(other),
985 Vector3Base(other.
x, other.y, other.z),
986 FramedPositionBase(other.
x, other.y, other.z, other.frame, other.agent),
1005 return this->
clone();
1029 stream <<
"FramedPosition: " << std::endl << rhs.
output() << std::endl;
1039 const std::string& s,
1040 const std::string& agent) :
1044 this->agent = agent;
1048 const std::string& frame,
1049 const std::string& agent) :
1052 this->frame = frame;
1053 this->agent = agent;
1057 const std::string& s,
1058 const std::string& agent) :
1062 this->agent = agent;
1082 std::stringstream s;
1084 <<
"frame: " <<
getFrame() << (agent.empty() ?
"" : (
" agent: " + agent));
1090 const std::string& newFrame)
1092 if (newFrame == frame)
1097 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
1104 const std::string& newFrame)
1112 const std::string& newFrame)
1114 if (newFrame == frame)
1125 Eigen::Matrix4f oldFrameTransformation = Eigen::Matrix4f::Identity();
1127 if (!referenceRobot.hasRobotNode(newFrame))
1129 throw LocalException() <<
"The requested frame '" << newFrame
1130 <<
"' does not exists in the robot " << referenceRobot.getName();
1135 oldFrameTransformation = referenceRobot.getRobotNode(frame)->getPoseInRootFrame();
1139 oldFrameTransformation = referenceRobot.getRootNode()->getGlobalPose().inverse();
1142 Eigen::Matrix4f oldPose = Eigen::Matrix4f::Identity();
1143 oldPose.block<3, 3>(0, 0) =
toEigen();
1145 Eigen::Matrix4f newPose =
1146 (referenceRobot.getRobotNode(newFrame)->getPoseInRootFrame().inverse() *
1147 oldFrameTransformation) *
1155 agent = referenceRobot.getName();
1162 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
1181 changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
1182 Eigen::Matrix3f rot =
1183 referenceRobot.getRootNode()->getGlobalPose().block<3, 3>(0, 0) *
toEigen();
1196 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
1211 newOrientation->changeToGlobal(referenceRobot);
1212 return newOrientation;
1218 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
1234 return newOrientation.
toEigen();
1240 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
1255 newOrientation->changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
1256 return newOrientation;
1262 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
1277 newOrientation.
changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
1278 return newOrientation.
toEigen();
1283 const ::Ice::Current&
c)
const
1288 obj->setString(
"frame", frame);
1289 obj->setString(
"agent", agent);
1294 const ::Ice::Current&
c)
1299 frame = obj->getString(
"frame");
1301 if (obj->hasElement(
"agent"))
1303 agent = obj->getString(
"agent");
1310 return this->
clone();
1334 stream <<
"FramedOrientation: " << std::endl << rhs.
output() << std::endl;
1338 VirtualRobot::LinkedCoordinate
1343 VirtualRobot::LinkedCoordinate
c(virtualRobot);
1348 frame = position->getFrame();
1352 if (!frame.empty() && frame != orientation->getFrame())
1354 throw armarx::UserException(
"Error: frames mismatch");
1362 armarx::UserException(
1363 "createLinkedCoordinate: orientation and position are both NULL");
1367 frame = orientation->getFrame();
1371 Eigen::Matrix4f pose = Eigen::Matrix4f::Identity();
1375 pose.block<3, 3>(0, 0) = orientation->toEigen();
1380 pose.block<3, 1>(0, 3) = position->toEigen();
1390 const std::string& newFrame)
const
1392 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
1393 return toFrame(sharedRobot, newFrame);
1398 const std::string& newFrame)
const
1401 newPose->changeFrame(referenceRobot, newFrame);
1407 const std::string& newFrame)
const
1409 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
1415 const std::string& newFrame)
const
1417 return toFrame(referenceRobot, newFrame)->toEigen();
1423 return this->
clone();
1447 stream <<
"FramedPose: " << std::endl << rhs.
output() << std::endl;
1454 if (pose1.frame != pose2.frame || pose1.agent != pose2.agent)
1462 return !(pose1 == pose2);
FramedDirectionPtr toGlobal(const SharedRobotInterfacePrx &referenceRobot) const
VariantTypeId getType(const Ice::Current &c=Ice::emptyCurrent) const override
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
Eigen::Vector3f toGlobalEigen(const SharedRobotInterfacePrx &referenceRobot) const
bool validate(const Ice::Current &c=Ice::emptyCurrent) override
static FramedDirectionPtr ChangeFrame(const VirtualRobot::RobotConstPtr &robot, const FramedDirection &framedVec, const std::string &newFrame)
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
void changeToGlobal(const SharedRobotInterfacePrx &referenceRobot)
FramedDirectionPtr toRootFrame(const SharedRobotInterfacePrx &referenceRobot) const
Ice::ObjectPtr ice_clone() const override
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
Eigen::Vector3f toRootEigen(const SharedRobotInterfacePrx &referenceRobot) const
std::string getFrame() const
void changeFrame(const VirtualRobot::RobotConstPtr &robot, const std::string &newFrame)
The FramedOrientation class.
VariantTypeId getType(const Ice::Current &c=Ice::emptyCurrent) const override
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
FramedOrientationPtr toGlobal(const SharedRobotInterfacePrx &referenceRobot) const
VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
FramedOrientationPtr toRootFrame(const SharedRobotInterfacePrx &referenceRobot) const
bool validate(const Ice::Current &c=Ice::emptyCurrent) override
Eigen::Matrix3f toGlobalEigen(const SharedRobotInterfacePrx &referenceRobot) const
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
void changeToGlobal(const SharedRobotInterfacePrx &referenceRobot)
Ice::ObjectPtr ice_clone() const override
Eigen::Matrix3f toRootEigen(const SharedRobotInterfacePrx &referenceRobot) const
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
std::string getFrame() const
void changeFrame(const SharedRobotInterfacePrx &referenceRobot, const std::string &newFrame)
FramedOrientationPtr getOrientation() const
VariantTypeId getType(const Ice::Current &c=Ice::emptyCurrent) const override
FramedPosePtr toRootFrame(const SharedRobotInterfacePrx &referenceRobot) const
Eigen::Matrix4f toGlobalEigen(const SharedRobotInterfacePrx &referenceRobot) const
static VirtualRobot::LinkedCoordinate createLinkedCoordinate(const VirtualRobot::RobotPtr &virtualRobot, const FramedPositionPtr &position, const FramedOrientationPtr &orientation)
Eigen::Matrix4f toRootEigen(const SharedRobotInterfacePrx &referenceRobot) const
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
Eigen::Matrix4f toFrameEigen(const SharedRobotInterfacePrx &referenceRobot, const std::string &newFrame) const
FramedPosePtr toFrame(const SharedRobotInterfacePrx &referenceRobot, const std::string &newFrame) const
bool validate(const Ice::Current &c=Ice::emptyCurrent) override
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
void changeToGlobal(const SharedRobotInterfacePrx &referenceRobot)
FramedPosePtr toGlobal(const SharedRobotInterfacePrx &referenceRobot) const
FramedPositionPtr getPosition() const
Ice::ObjectPtr ice_clone() const override
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
std::string getFrame() const
void changeFrame(const SharedRobotInterfacePrx &referenceRobot, const std::string &newFrame)
The FramedPosition class.
VariantTypeId getType(const Ice::Current &c=Ice::emptyCurrent) const override
FramedPositionPtr toGlobal(const SharedRobotInterfacePrx &referenceRobot) const
std::string output(const Ice::Current &c=Ice::emptyCurrent) const override
VariantDataClassPtr clone(const Ice::Current &c=Ice::emptyCurrent) const override
FramedPosition & operator=(const armarx::FramedPosition &other)
Eigen::Vector3f toGlobalEigen(const SharedRobotInterfacePrx &referenceRobot) const
bool validate(const Ice::Current &c=Ice::emptyCurrent) override
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
void changeToGlobal(const SharedRobotInterfacePrx &referenceRobot)
FramedPositionPtr toRootFrame(const SharedRobotInterfacePrx &referenceRobot) const
Ice::ObjectPtr ice_clone() const override
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
Eigen::Vector3f toRootEigen(const SharedRobotInterfacePrx &referenceRobot) const
std::string getFrame() const
void changeFrame(const SharedRobotInterfacePrx &referenceRobot, const std::string &newFrame)
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
virtual Eigen::Matrix4f toEigen() const
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
Eigen::Matrix3f toEigen() const
Quaternion()
Construct an identity quaternion.
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
Mimics the behaviour of the VirtualRobot::Robot class while redirecting everything to an Ice proxy.
virtual Eigen::Vector3f toEigen() const
void deserialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) override
void serialize(const armarx::ObjectSerializerBasePtr &serializer, const ::Ice::Current &=Ice::emptyCurrent) const override
#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_CHECK_NOT_NULL(ptr)
This macro evaluates whether ptr is not null and if it turns out to be false it will throw an Express...
#define ARMARX_WARNING_S
The logging level for unexpected behaviour, but not a serious problem.
std::string const GlobalFrame
Variable of the global coordinate system.
Quaternion< float, 0 > Quaternionf
std::shared_ptr< class Robot > RobotPtr
const VariantTypeId FramedPosition
const VariantTypeId FramedOrientation
const VariantTypeId FramedPose
const VariantTypeId FramedDirection
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::ostream & operator<<(std::ostream &os, const PythonApplicationManager::Paths &paths)
IceInternal::Handle< FramedDirection > FramedDirectionPtr
bool operator==(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
const Eigen::IOFormat ArmarXEigenFormat(Eigen::StreamPrecision, Eigen::DontAlignCols, " ", "\n", "", "")
IceInternal::Handle< AbstractObjectSerializer > AbstractObjectSerializerPtr
IceInternal::Handle< FramedPosition > FramedPositionPtr
::IceInternal::ProxyHandle<::IceProxy::armarx::SharedRobotInterface > SharedRobotInterfacePrx
IceInternal::Handle< FramedOrientation > FramedOrientationPtr
bool operator!=(const RemoteHandle< PrxTA > &fst, const RemoteHandle< PrxTB > &snd)
IceInternal::Handle< FramedPose > FramedPosePtr
std::string ValueToString(const T &value)