CartesianVelocityControl.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 
28 #include <RobotAPI/interface/units/TCPControlUnit.h>
29 
31 
32 using namespace armarx;
33 using namespace MotionControlGroup;
34 
35 // DO NOT EDIT NEXT LINE
36 CartesianVelocityControl::SubClassRegistry
37  CartesianVelocityControl::Registry(CartesianVelocityControl::GetName(),
39 
42  CartesianVelocityControlGeneratedBase<CartesianVelocityControl>(stateData)
43 {
44 }
45 
46 void
48 {
50  getContext<MotionControlGroupStatechartContext>();
51 
52  std::string kinematicChain = in.getKinematicChainName();
53 
54  if (!context->getRobot()->hasRobotNodeSet(kinematicChain))
55  {
56  ARMARX_WARNING << "Kinematic Chain '" << kinematicChain << "' not available" << flush;
57  emitFailure();
58  }
59 
60  std::string endEffectorName =
61  context->getRobot()->getRobotNodeSet(kinematicChain)->getTCP()->getName();
62 
63  FramedDirectionPtr orientationVelocity(new FramedDirection);
64  orientationVelocity->frame = endEffectorName;
65  orientationVelocity->x = orientationVelocity->y = orientationVelocity->z = 0;
66 
67  FramedDirectionPtr positionVelocity(new FramedDirection);
68  positionVelocity->frame = endEffectorName;
69  positionVelocity->x = positionVelocity->y = positionVelocity->z = 0;
70 
71  if (isInputParameterSet("TargetTcpOrientationVelocity"))
72  {
73  orientationVelocity = in.getTargetTcpOrientationVelocity();
74  }
75 
76  if (isInputParameterSet("TargetTcpPositionVelocity"))
77  {
78  positionVelocity = in.getTargetTcpPositionVelocity();
79  }
80 
81  context->getTCPControlUnit()->setCycleTime(in.getCycleTime());
82 
83  // Call request without release to keep the velocities applied after the state is left. Calling release would stop the joints
84  // It is no problem to call request a second time in another unit.
85  context->getTCPControlUnit()->request();
86  context->getTCPControlUnit()->setTCPVelocity(
87  in.getKinematicChainName(), endEffectorName, positionVelocity, orientationVelocity);
88 
89  // wait a custom amount of time until going to next state
90  setTimeoutEvent(in.getWaitTimeUntilTransition(), createEventSuccess());
91 }
92 
93 void
95 {
96 }
97 
98 void
100 {
101 }
102 
103 // DO NOT EDIT NEXT FUNCTION
106 {
107  return XMLStateFactoryBasePtr(new CartesianVelocityControl(stateData));
108 }
armarx::MotionControlGroup::CartesianVelocityControl::onEnter
void onEnter() override
Definition: CartesianVelocityControl.cpp:47
armarx::MotionControlGroup::MotionControlGroupStatechartContext
Definition: MotionControlGroupStatechartContext.h:75
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
armarx::MotionControlGroup::CartesianVelocityControl::CartesianVelocityControl
CartesianVelocityControl(XMLStateConstructorParams stateData)
Definition: CartesianVelocityControl.cpp:40
armarx::MotionControlGroup::MotionControlGroupStatechartContext::getTCPControlUnit
TCPControlUnitInterfacePrx getTCPControlUnit()
Definition: MotionControlGroupStatechartContext.h:138
armarx::MotionControlGroup::CartesianVelocityControl::onBreak
void onBreak() override
Definition: CartesianVelocityControl.cpp:94
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
IceInternal::Handle< FramedDirection >
CartesianVelocityControl.h
armarx::MotionControlGroup::MotionControlGroupStatechartContext::getRobot
const std::shared_ptr< RemoteRobot > getRobot()
Definition: MotionControlGroupStatechartContext.h:90
armarx::MotionControlGroup::CartesianVelocityControl::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: CartesianVelocityControl.cpp:105
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::CartesianVelocityControl::Registry
static SubClassRegistry Registry
Definition: CartesianVelocityControl.h:46
MotionControlGroupStatechartContext.h
armarx::MotionControlGroup::CartesianVelocityControl::onExit
void onExit() override
Definition: CartesianVelocityControl.cpp:99
armarx::FramedDirection
FramedDirection is a 3 dimensional direction vector with a reference frame. The reference frame can b...
Definition: FramedPose.h:86
armarx::MotionControlGroup::CartesianVelocityControl
Definition: CartesianVelocityControl.h:33
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27