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();
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();
188 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
207 changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
208 Eigen::Vector3f pos =
209 referenceRobot.getRootNode()->getGlobalPose().block<3, 3>(0, 0) *
toEigen();
220 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
235 newDirection->changeToGlobal(referenceRobot);
242 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
264 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
279 newDirection->changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
286 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
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,
317 const VirtualRobot::Robot& robotState)
319 Eigen::Matrix4f toNewFrame;
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)
477 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
483 const std::string& newFrame)
492 if (newFrame == frame)
503 Eigen::Matrix4f oldFrameTransformation = Eigen::Matrix4f::Identity();
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();
525 Eigen::Matrix4f newPose =
526 (referenceRobot.getRobotNode(newFrame)->getPoseInRootFrame().inverse() *
527 oldFrameTransformation) *
531 Eigen::Vector3f pos = newPose.block<3, 1>(0, 3);
534 agent = referenceRobot.getName();
541 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
560 changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
561 Eigen::Matrix4f global = referenceRobot.getRootNode()->getGlobalPose();
562 const Eigen::Matrix4f pose = global *
toEigen();
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();
578 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
593 newPose->changeToGlobal(referenceRobot);
600 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
622 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
637 newPose->changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
644 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
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();
757 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
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";
792 Eigen::Matrix4f oldFrameTransformation = Eigen::Matrix4f::Identity();
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();
809 Eigen::Matrix4f oldPose = Eigen::Matrix4f::Identity();
810 oldPose.block<3, 1>(0, 3) =
toEigen();
811 Eigen::Matrix4f newPose =
812 (referenceRobot.getRobotNode(newFrame)->getPoseInRootFrame().inverse() *
813 oldFrameTransformation) *
816 Eigen::Vector3f pos = newPose.block<3, 1>(0, 3);
820 agent = referenceRobot.getName();
827 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
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);
860 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
875 newPosition->changeToGlobal(referenceRobot);
882 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
904 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
919 newPosition->changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
926 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
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),
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)
1094 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
1101 const std::string& newFrame)
1109 const std::string& newFrame)
1111 if (newFrame == frame)
1122 Eigen::Matrix4f oldFrameTransformation = Eigen::Matrix4f::Identity();
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();
1139 Eigen::Matrix4f oldPose = Eigen::Matrix4f::Identity();
1140 oldPose.block<3, 3>(0, 0) =
toEigen();
1142 Eigen::Matrix4f newPose =
1143 (referenceRobot.getRobotNode(newFrame)->getPoseInRootFrame().inverse() *
1144 oldFrameTransformation) *
1152 agent = referenceRobot.getName();
1159 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
1178 changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
1179 Eigen::Matrix3f rot =
1180 referenceRobot.getRootNode()->getGlobalPose().block<3, 3>(0, 0) *
toEigen();
1193 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
1208 newOrientation->changeToGlobal(referenceRobot);
1209 return newOrientation;
1215 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
1231 return newOrientation.
toEigen();
1237 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
1252 newOrientation->changeFrame(referenceRobot, referenceRobot.getRootNode()->getName());
1253 return newOrientation;
1259 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
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();
1368 Eigen::Matrix4f pose = Eigen::Matrix4f::Identity();
1372 pose.block<3, 3>(0, 0) = orientation->toEigen();
1377 pose.block<3, 1>(0, 3) = position->toEigen();
1387 const std::string& newFrame)
const
1389 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
1390 return toFrame(sharedRobot, newFrame);
1395 const std::string& newFrame)
const
1398 newPose->changeFrame(referenceRobot, newFrame);
1404 const std::string& newFrame)
const
1406 VirtualRobot::RobotConstPtr sharedRobot(
new RemoteRobot(referenceRobot));
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);
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)