CartesianRelativePositionControl.cpp
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2014-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package RobotSkillTemplates::MotionControlGroup
19 * @author Simon Ottenhaus ( simon dot ottenhaus at kit dot edu )
20 * @date 2015
21 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22 * GNU General Public License
23 */
24
26#include <VirtualRobot/RobotNodeSet.h>
27
29
30using namespace armarx;
31using namespace MotionControlGroup;
32
33// DO NOT EDIT NEXT LINE
34CartesianRelativePositionControl::SubClassRegistry
35 CartesianRelativePositionControl::Registry(CartesianRelativePositionControl::GetName(),
37
44
45void
47{
48 if (!in.isTcpRelativeOrientationSet() && !in.isTcpRelativePositionSet())
49 {
50 ARMARX_ERROR << "TcpRelativeOrientation and/or TcpRelativePosition has to be set, but none "
51 "has been set.";
52 emitFailure();
53 return;
54 }
55
57 getContext<MotionControlGroupStatechartContext>();
58 auto robot = context->getRobot();
59 Eigen::Matrix4f currentTcpPose =
60 robot->getRobotNodeSet(in.getKinematicChainName())->getTCP()->getPoseInRootFrame();
61 std::string rootFrameName = robot->getRootNode()->getName();
62 std::string agentName = robot->getName();
63
64 ARMARX_IMPORTANT << "currentTcpPose: " << currentTcpPose;
65
66 auto localRobot = robot->clone();
67 if (in.isTcpRelativePositionSet())
68 {
69 Eigen::Vector3f positionOffset = in.getTcpRelativePosition()->toRootEigen(localRobot);
70 Eigen::Vector3f targetPosition = currentTcpPose.block<3, 1>(0, 3) + positionOffset;
71 FramedPositionPtr targetPositionPtr =
72 new FramedPosition(targetPosition, rootFrameName, agentName);
73 local.setTcpTargetPosition(targetPositionPtr);
74 ARMARX_IMPORTANT << "targetPosition: " << targetPosition;
75 }
76 if (in.isTcpRelativeOrientationSet())
77 {
78 Eigen::Matrix3f orientationOffset = in.getTcpRelativeOrientation()->toRootEigen(localRobot);
79 Eigen::Matrix3f targetOrientation = currentTcpPose.block<3, 3>(0, 0) * orientationOffset;
80 FramedOrientationPtr targetOrientationPtr =
81 new FramedOrientation(targetOrientation, rootFrameName, agentName);
82 local.setTcpTargetOrientation(targetOrientationPtr);
83 }
84}
85
86void
88{
89 // put your user code for the execution-phase here
90 // runs in seperate thread, thus can do complex operations
91 // should check constantly whether isRunningTaskStopped() returns true
92
93 // uncomment this if you need a continous run function. Make sure to use sleep or use blocking wait to reduce cpu load.
94 // while (!isRunningTaskStopped()) // stop run function if returning true
95 // {
96 // // do your calculations
97 // }
98}
99
100void
102{
103 // put your user code for the breaking point here
104 // execution time should be short (<100ms)
105}
106
107void
109{
111 getContext<MotionControlGroupStatechartContext>();
112 auto robot = context->getRobot();
113 Eigen::Matrix4f currentTcpPose =
114 robot->getRobotNodeSet(in.getKinematicChainName())->getTCP()->getPoseInRootFrame();
115
116 ARMARX_IMPORTANT << "final Tcp pose: " << currentTcpPose;
117}
118
119// DO NOT EDIT NEXT FUNCTION
The FramedOrientation class.
Definition FramedPose.h:216
The FramedPosition class.
Definition FramedPose.h:158
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
custom implementation of the StatechartContext for a statechart
Class for legacy to stay compatible with old statecharts.
Definition XMLState.h:147
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#define ARMARX_ERROR
The logging level for unexpected behaviour, that must be fixed.
Definition Logging.h:196
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceInternal::Handle< FramedPosition > FramedPositionPtr
Definition FramedPose.h:149
IceInternal::Handle< FramedOrientation > FramedOrientationPtr
Definition FramedPose.h:207
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64