LiftObject.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::FindAndGraspObjectGroup
19  * @author Valerij Wittenbeck ( valerij dot wittenbeck at student dot kit dot edu )
20  * @date 2014
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #include "LiftObject.h"
26 
27 using namespace armarx;
28 using namespace FindAndGraspObjectGroup;
29 
30 // DO NOT EDIT NEXT LINE
32 
33 
34 
36  XMLStateTemplate < LiftObject > (stateData)
37 {
38 }
39 
41 {
42  ARMARX_VERBOSE << "Entering LiftObject::onEnter()";
43  float timeoutLiftObject = getInput<float>("timeoutLiftObject");
44  condLiftObjectTimeout = setTimeoutEvent(timeoutLiftObject, createEvent<EvLiftObjectTimeout>());
45 
46  //GraspingWithVisualFeedbackContext* context = getContext<GraspingWithVisualFeedbackContext>();
47  FindAndGraspObjectContext* context = getContext<FindAndGraspObjectContext>();
48  FramedPose currentHandPose(context->remoteRobot->getRobotNode(getInput<std::string>("tcpName"))->getGlobalPose(), context->remoteRobot->getRootNode()->getName());
49  Eigen::Matrix4f liftedHandPose = currentHandPose.toEigen();
50  liftedHandPose(2, 3) += 150;
51  FramedPosition targetPosition(liftedHandPose, currentHandPose.frame);
52  FramedOrientation targetOrientation(liftedHandPose, currentHandPose.frame);
53 
54  setLocal("targetTCPPosition", targetPosition);
55  setLocal("targetTCPOrientation", targetOrientation);
56  setLocal("targetPositionDistanceTolerance", 40.0f);
57  setLocal("targetOrientationDistanceTolerance", 3.15f);
58  setLocal("ikWithOrientation", false);
59 
60  setLocal("timeoutInMs", int(timeoutLiftObject));
61  setLocal("jointTargetTolerance", 0.01f);
62  setLocal("kinematicChainName", getInput<std::string>("kinematicChain"));
63  ARMARX_VERBOSE << "Done LiftObject::onEnter()" << flush;
64 }
65 
67 {
68  // set vel to zero
69  ARMARX_DEBUG << "setting joint velocity to zero " << flush;
70 
71  std::string kinChainName = getInput<std::string>("kinematicChain");
72  RobotStatechartContext* context = getContext<RobotStatechartContext>();
73 
74  if (!context)
75  {
76  ARMARX_WARNING << "Need a RobotStatechartContext" << flush;
77  sendEvent<Failure>();
78  }
79 
80  if (!context->robotStateComponent)
81  {
82  ARMARX_WARNING << "No RobotStatechartContext->robotStateComponent" << flush;
83  sendEvent<Failure>();
84  }
85 
87 
88  if (!robot->hasRobotNodeSet(kinChainName))
89  {
90  ARMARX_WARNING << "Robot does not know kinematic chain with name " << kinChainName << flush;
91  sendEvent<Failure>();
92  }
93 
94  VirtualRobot::RobotNodeSetPtr rns = robot->getRobotNodeSet(kinChainName);
95 
96 
97  NameValueMap targetJointVelocities;
98 
99  for (unsigned int i = 0; i < rns->getSize(); i++)
100  {
101  targetJointVelocities[rns->getNode(i)->getName()] = 0;
102  }
103 
104  context->kinematicUnitPrx->setJointVelocities(targetJointVelocities);
105 }
106 
107 
109 {
112  ARMARX_VERBOSE << "Done LiftObject::onExit()";
113 
114  // test: open hand
115  /*
116  RobotStatechartContext *context = getContext<RobotStatechartContext>();
117  HandUnitInterfacePrx handUnitPrx = context->getHandUnit("RightHandUnit");
118  if (handUnitPrx)
119  {
120  ARMARX_INFO << "TEST: open hand" << flush;
121  handUnitPrx->open();
122  ARMARX_INFO << "TEST: set object released: Vitalis" << flush;
123  handUnitPrx->setObjectReleased("Vitalis");
124  }*/
125 
126 }
127 
128 // DO NOT EDIT NEXT FUNCTION
129 std::string LiftObject::GetName()
130 {
131  return "LiftObject";
132 }
133 
134 // DO NOT EDIT NEXT FUNCTION
136 {
137  return XMLStateFactoryBasePtr(new LiftObject(stateData));
138 }
139 
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:180
armarx::FindAndGraspObjectGroup::LiftObject::onExit
void onExit() override
Virtual function, in which the behaviour of state is defined, when it is exited. Can be overridden,...
Definition: LiftObject.cpp:108
armarx::FramedPose
The FramedPose class.
Definition: FramedPose.h:258
armarx::XMLStateConstructorParams
Definition: XMLState.h:50
LiftObject.h
armarx::FindAndGraspObjectGroup::LiftObject::condLiftObjectTimeout
ActionEventIdentifier condLiftObjectTimeout
Definition: LiftObject.h:54
armarx::FindAndGraspObjectContext::remoteRobot
VirtualRobot::RobotPtr remoteRobot
Definition: FindAndGraspObjectContext.h:161
armarx::navigation::platform_controller::platform_global_trajectory::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformGlobalTrajectoryController.h:93
armarx::State::setLocal
void setLocal(std::string const &key, const Variant &value)
setLocal() sets a local parameter.
Definition: State.cpp:417
armarx::FindAndGraspObjectGroup::LiftObject
Definition: LiftObject.h:35
armarx::FindAndGraspObjectContext
Definition: FindAndGraspObjectContext.h:67
armarx::FindAndGraspObjectGroup::LiftObject::GetName
static std::string GetName()
Definition: LiftObject.cpp:129
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::FindAndGraspObjectGroup::LiftObject::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: LiftObject.cpp:135
armarx::RobotStatechartContext
Definition: RobotStatechartContext.h:66
armarx::StateUtility::setTimeoutEvent
ActionEventIdentifier setTimeoutEvent(int timeoutDurationMs, const EventPtr &evt)
Utility function to start a timer on the systemObserver and register an event on the conditionHandler...
Definition: StateUtil.cpp:144
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_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:177
armarx::FramedPosition
The FramedPosition class.
Definition: FramedPose.h:142
armarx::Pose::toEigen
virtual Eigen::Matrix4f toEigen() const
Definition: Pose.cpp:334
armarx::FindAndGraspObjectGroup::LiftObject::Registry
static SubClassRegistry Registry
Definition: LiftObject.h:49
armarx::FramedOrientation
The FramedOrientation class.
Definition: FramedPose.h:199
armarx::FindAndGraspObjectGroup::LiftObject::onEnter
void onEnter() override
Virtual function, in which the behaviour of state is defined, when it is entered. Can be overridden,...
Definition: LiftObject.cpp:40
armarx::FindAndGraspObjectGroup::LiftObject::LiftObject
LiftObject(XMLStateConstructorParams stateData)
Definition: LiftObject.cpp:35
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:65
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:601
armarx::RemoteRobot::createLocalClone
VirtualRobot::RobotPtr createLocalClone()
Clones the structure of this remote robot to a local instance.
Definition: RemoteRobot.cpp:328
armarx::RobotStatechartContext::robotStateComponent
RobotStateComponentInterfacePrx robotStateComponent
Prx for the RobotState.
Definition: RobotStatechartContext.h:96
armarx::FindAndGraspObjectGroup::LiftObject::setJointVelToZero
void setJointVelToZero()
Definition: LiftObject.cpp:66
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::StateUtility::removeTimeoutEvent
void removeTimeoutEvent(const ActionEventIdentifier &id)
Definition: StateUtil.cpp:178
armarx::RobotStatechartContext::kinematicUnitPrx
KinematicUnitInterfacePrx kinematicUnitPrx
Definition: RobotStatechartContext.h:97
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:18