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 
27 
28 using namespace armarx;
29 using namespace MotionControlGroup;
30 
31 // DO NOT EDIT NEXT LINE
32 CartesianRelativePositionControl::SubClassRegistry CartesianRelativePositionControl::Registry(CartesianRelativePositionControl::GetName(), &CartesianRelativePositionControl::CreateInstance);
33 
34 
35 
37  XMLStateTemplate<CartesianRelativePositionControl>(stateData), CartesianRelativePositionControlGeneratedBase<CartesianRelativePositionControl>(stateData)
38 {
39 }
40 
42 {
43  if (!in.isTcpRelativeOrientationSet() && !in.isTcpRelativePositionSet())
44  {
45  ARMARX_ERROR << "TcpRelativeOrientation and/or TcpRelativePosition has to be set, but none has been set.";
46  emitFailure();
47  return;
48  }
49 
50  MotionControlGroupStatechartContext* context = getContext<MotionControlGroupStatechartContext>();
51  auto robot = context->getRobot();
52  Eigen::Matrix4f currentTcpPose = robot->getRobotNodeSet(in.getKinematicChainName())->getTCP()->getPoseInRootFrame();
53  std::string rootFrameName = robot->getRootNode()->getName();
54  std::string agentName = robot->getName();
55 
56  ARMARX_IMPORTANT << "currentTcpPose: " << currentTcpPose;
57 
58  auto localRobot = robot->clone();
59  if (in.isTcpRelativePositionSet())
60  {
61  Eigen::Vector3f positionOffset = in.getTcpRelativePosition()->toRootEigen(localRobot);
62  Eigen::Vector3f targetPosition = currentTcpPose.block<3, 1>(0, 3) + positionOffset;
63  FramedPositionPtr targetPositionPtr = new FramedPosition(targetPosition, rootFrameName, agentName);
64  local.setTcpTargetPosition(targetPositionPtr);
65  ARMARX_IMPORTANT << "targetPosition: " << targetPosition;
66  }
67  if (in.isTcpRelativeOrientationSet())
68  {
69  Eigen::Matrix3f orientationOffset = in.getTcpRelativeOrientation()->toRootEigen(localRobot);
70  Eigen::Matrix3f targetOrientation = currentTcpPose.block<3, 3>(0, 0) * orientationOffset;
71  FramedOrientationPtr targetOrientationPtr = new FramedOrientation(targetOrientation, rootFrameName, agentName);
72  local.setTcpTargetOrientation(targetOrientationPtr);
73  }
74 }
75 
77 {
78  // put your user code for the execution-phase here
79  // runs in seperate thread, thus can do complex operations
80  // should check constantly whether isRunningTaskStopped() returns true
81 
82  // uncomment this if you need a continous run function. Make sure to use sleep or use blocking wait to reduce cpu load.
83  // while (!isRunningTaskStopped()) // stop run function if returning true
84  // {
85  // // do your calculations
86  // }
87 
88 }
89 
91 {
92  // put your user code for the breaking point here
93  // execution time should be short (<100ms)
94 }
95 
97 {
98  MotionControlGroupStatechartContext* context = getContext<MotionControlGroupStatechartContext>();
99  auto robot = context->getRobot();
100  Eigen::Matrix4f currentTcpPose = robot->getRobotNodeSet(in.getKinematicChainName())->getTCP()->getPoseInRootFrame();
101 
102  ARMARX_IMPORTANT << "final Tcp pose: " << currentTcpPose;
103 }
104 
105 
106 // DO NOT EDIT NEXT FUNCTION
108 {
110 }
111 
armarx::MotionControlGroup::CartesianRelativePositionControl::CartesianRelativePositionControl
CartesianRelativePositionControl(const XMLStateConstructorParams &stateData)
Definition: CartesianRelativePositionControl.cpp:36
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
armarx::MotionControlGroup::MotionControlGroupStatechartContext
Definition: MotionControlGroupStatechartContext.h:66
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
armarx::MotionControlGroup::CartesianRelativePositionControl::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: CartesianRelativePositionControl.cpp:107
armarx::MotionControlGroup::CartesianRelativePositionControl::Registry
static SubClassRegistry Registry
Definition: CartesianRelativePositionControl.h:45
armarx::MotionControlGroup::CartesianRelativePositionControl::onExit
void onExit() override
Definition: CartesianRelativePositionControl.cpp:96
IceInternal::Handle< FramedPosition >
armarx::MotionControlGroup::MotionControlGroupStatechartContext::getRobot
const std::shared_ptr< RemoteRobot > getRobot()
Definition: MotionControlGroupStatechartContext.h:79
armarx::MotionControlGroup::CartesianRelativePositionControl::onBreak
void onBreak() override
Definition: CartesianRelativePositionControl.cpp:90
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:137
armarx::MotionControlGroup::CartesianRelativePositionControl
Definition: CartesianRelativePositionControl.h:31
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:189
MotionControlGroupStatechartContext.h
armarx::MotionControlGroup::CartesianRelativePositionControl::run
void run() override
Definition: CartesianRelativePositionControl.cpp:76
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:600
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::VariantType::FramedOrientation
const VariantTypeId FramedOrientation
Definition: FramedPose.h:40
CartesianRelativePositionControl.h
armarx::MotionControlGroup::CartesianRelativePositionControl::onEnter
void onEnter() override
Definition: CartesianRelativePositionControl.cpp:41
armarx::VariantType::FramedPosition
const VariantTypeId FramedPosition
Definition: FramedPose.h:39
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28