26 #include <VirtualRobot/RobotNodeSet.h>
31 using namespace MotionControlGroup;
34 CalculateRelativePosition::SubClassRegistry
47 if (!in.isTcpRelativeOrientationsSet() && !in.isTcpRelativePositionsSet())
49 ARMARX_ERROR <<
"TcpRelativeOrientations and/or TcpRelativePositions has to be set, but "
54 int index = in.getIndex();
58 getContext<MotionControlGroupStatechartContext>();
60 std::string rootFrameName = robot->getRootNode()->getName();
61 std::string agentName = robot->getName();
63 Eigen::Vector3f positionOffset = Eigen::Vector3f::Zero();
66 bool doPos = in.isTcpRelativePositionsSet();
67 bool doOri = in.isTcpRelativeOrientationsSet();
68 out.setIndex(
index + 1);
70 auto localRobot = robot->clone();
73 std::vector<FramedDirectionPtr> relativePositions = in.getTcpRelativePositions();
75 if (
static_cast<std::size_t
>(
index) >= relativePositions.size())
80 positionOffset = relativePositions.at(
index)->toRootEigen(localRobot);
84 std::vector<FramedOrientationPtr> relativeOrientations = in.getTcpRelativeOrientations();
86 if (
static_cast<std::size_t
>(
index) >= relativeOrientations.size())
91 orientationOffset = relativeOrientations.at(
index)->toRootEigen(localRobot);
94 Eigen::Vector3f referencePosition;
97 if (in.getRelativeMode() ==
"Initial")
99 referencePosition = in.getInitalTcpPosition()->toRootEigen(localRobot);
100 referenceOrientation = in.getInitailTcpOrientation()->toRootEigen(localRobot);
102 else if (in.getRelativeMode() ==
"TCP")
105 robot->getRobotNodeSet(in.getKinematicChainName())->getTCP()->getPoseInRootFrame();
106 referencePosition = currentTcpPose.block<3, 1>(0, 3);
107 referenceOrientation = currentTcpPose.block<3, 3>(0, 0);
109 else if (in.getRelativeMode() ==
"Previous")
112 doPos ? in.getTcpPosition()->toRootEigen(localRobot) : Eigen::Vector3f::Zero();
113 referenceOrientation =
118 ARMARX_ERROR <<
"Invalid RelativeMode '" << in.getRelativeMode()
119 <<
"'. Valid options: 'Initial' 'TCP' 'Previous'";
126 Eigen::Vector3f targetPosition = referencePosition + positionOffset;
129 out.setTcpPosition(targetPositionPtr);
134 Eigen::Matrix3f targetOrientation = referenceOrientation * orientationOffset;
137 out.setTcpOrientation(targetOrientationPtr);
140 emitPositionControl();