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