CartesianPositionControl.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 Peter Kaiser ( peter dot kaiser at kit dot edu )
20  * @date 2014
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 
31 
32 using namespace armarx;
33 using namespace MotionControlGroup;
34 
35 // DO NOT EDIT NEXT LINE
36 CartesianPositionControl::SubClassRegistry
37  CartesianPositionControl::Registry(CartesianPositionControl::GetName(),
39 
42  CartesianPositionControlGeneratedBase<CartesianPositionControl>(stateData)
43 {
44 }
45 
46 void
48 {
49  // Create and install timeout condition
50  int timeout = in.getTimeout();
51 
52  if (timeout > 0)
53  {
54  setTimeoutEvent(timeout, createEventTimeout());
55  }
56 
57  // Check if position and orientation are given in the same frame
58  if (isInputParameterSet("TcpTargetPosition") && isInputParameterSet("TcpTargetOrientation"))
59  {
60  if (in.getTcpTargetPosition()->frame != in.getTcpTargetOrientation()->frame)
61  {
62  ARMARX_WARNING << "Frame mismatch between target position and target orientation"
63  << flush;
64  emitFailure();
65  }
66  }
67 
68  // Check if at least one type of target is given
69  if (!isInputParameterSet("TcpTargetPosition") && !isInputParameterSet("TcpTargetOrientation"))
70  {
71  ARMARX_WARNING << "Neither position target nor orientation target given for IK" << flush;
72  emitFailure();
73  }
74 }
75 
76 void
78 {
79 }
80 
81 void
83 {
84  if (in.isTcpTargetPositionSet())
85  {
87  getContext<MotionControlGroupStatechartContext>();
88 
89  auto robot = context->getRobot()->clone();
90  Eigen::Vector3f target = in.getTcpTargetPosition()->toRootEigen(robot);
91  Eigen::Vector3f currentTcpPosition = robot->getRobotNodeSet(in.getKinematicChainName())
92  ->getTCP()
93  ->getPoseInRootFrame()
94  .block<3, 1>(0, 3);
95 
96  ARMARX_IMPORTANT << "Remaining error: " << (currentTcpPosition - target).norm()
97  << ", current TCP position: " << currentTcpPosition
98  << ", target: " << target << "(in root frame)";
99  }
100 }
101 
102 // DO NOT EDIT NEXT FUNCTION
105 {
106  return XMLStateFactoryBasePtr(new CartesianPositionControl(stateData));
107 }
armarx::MotionControlGroup::CartesianPositionControl::onExit
void onExit() override
Definition: CartesianPositionControl.cpp:82
CartesianPositionControl.h
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
armarx::MotionControlGroup::MotionControlGroupStatechartContext
Definition: MotionControlGroupStatechartContext.h:75
Pose.h
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
boost::target
Vertex target(const detail::edge_base< Directed, Vertex > &e, const PCG &)
Definition: point_cloud_graph.h:668
armarx::MotionControlGroup::CartesianPositionControl::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: CartesianPositionControl.cpp:104
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
armarx::MotionControlGroup::CartesianPositionControl
Definition: CartesianPositionControl.h:31
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::MotionControlGroup::CartesianPositionControl::CartesianPositionControl
CartesianPositionControl(XMLStateConstructorParams stateData)
Definition: CartesianPositionControl.cpp:40
armarx::MotionControlGroup::MotionControlGroupStatechartContext::getRobot
const std::shared_ptr< RemoteRobot > getRobot()
Definition: MotionControlGroupStatechartContext.h:90
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:146
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
armarx::MotionControlGroup::CartesianPositionControl::onBreak
void onBreak() override
Definition: CartesianPositionControl.cpp:77
MotionControlGroupStatechartContext.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::MotionControlGroup::CartesianPositionControl::onEnter
void onEnter() override
Definition: CartesianPositionControl.cpp:47
armarx::MotionControlGroup::CartesianPositionControl::Registry
static SubClassRegistry Registry
Definition: CartesianPositionControl.h:44
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
norm
double norm(const Point &a)
Definition: point.hpp:102