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 
30 using namespace armarx;
31 using namespace MotionControlGroup;
32 
33 // DO NOT EDIT NEXT LINE
34 CartesianRelativePositionControl::SubClassRegistry
35  CartesianRelativePositionControl::Registry(CartesianRelativePositionControl::GetName(),
37 
39  const XMLStateConstructorParams& stateData) :
41  CartesianRelativePositionControlGeneratedBase<CartesianRelativePositionControl>(stateData)
42 {
43 }
44 
45 void
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 
86 void
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 
100 void
102 {
103  // put your user code for the breaking point here
104  // execution time should be short (<100ms)
105 }
106 
107 void
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
122 {
124 }
armarx::MotionControlGroup::CartesianRelativePositionControl::CartesianRelativePositionControl
CartesianRelativePositionControl(const XMLStateConstructorParams &stateData)
Definition: CartesianRelativePositionControl.cpp:38
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
armarx::MotionControlGroup::MotionControlGroupStatechartContext
Definition: MotionControlGroupStatechartContext.h:75
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
armarx::MotionControlGroup::CartesianRelativePositionControl::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: CartesianRelativePositionControl.cpp:121
armarx::MotionControlGroup::CartesianRelativePositionControl::Registry
static SubClassRegistry Registry
Definition: CartesianRelativePositionControl.h:45
armarx::MotionControlGroup::CartesianRelativePositionControl::onExit
void onExit() override
Definition: CartesianRelativePositionControl.cpp:108
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
IceInternal::Handle< FramedPosition >
armarx::MotionControlGroup::MotionControlGroupStatechartContext::getRobot
const std::shared_ptr< RemoteRobot > getRobot()
Definition: MotionControlGroupStatechartContext.h:90
armarx::MotionControlGroup::CartesianRelativePositionControl::onBreak
void onBreak() override
Definition: CartesianRelativePositionControl.cpp:101
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:146
armarx::MotionControlGroup::CartesianRelativePositionControl
Definition: CartesianRelativePositionControl.h:31
ARMARX_ERROR
#define ARMARX_ERROR
Definition: Logging.h:196
MotionControlGroupStatechartContext.h
armarx::MotionControlGroup::CartesianRelativePositionControl::run
void run() override
Definition: CartesianRelativePositionControl.cpp:87
armarx::VariantType::FramedOrientation
const VariantTypeId FramedOrientation
Definition: FramedPose.h:39
CartesianRelativePositionControl.h
armarx::MotionControlGroup::CartesianRelativePositionControl::onEnter
void onEnter() override
Definition: CartesianRelativePositionControl.cpp:46
GfxTL::Matrix3f
MatrixXX< 3, 3, float > Matrix3f
Definition: MatrixXX.h:649
armarx::VariantType::FramedPosition
const VariantTypeId FramedPosition
Definition: FramedPose.h:38
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27