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
31 LiftObject::SubClassRegistry LiftObject::Registry(LiftObject::GetName(),
33 
35  XMLStateTemplate<LiftObject>(stateData)
36 {
37 }
38 
39 void
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(
49  context->remoteRobot->getRobotNode(getInput<std::string>("tcpName"))->getGlobalPose(),
50  context->remoteRobot->getRootNode()->getName());
51  Eigen::Matrix4f liftedHandPose = currentHandPose.toEigen();
52  liftedHandPose(2, 3) += 150;
53  FramedPosition targetPosition(liftedHandPose, currentHandPose.frame);
54  FramedOrientation targetOrientation(liftedHandPose, currentHandPose.frame);
55 
56  setLocal("targetTCPPosition", targetPosition);
57  setLocal("targetTCPOrientation", targetOrientation);
58  setLocal("targetPositionDistanceTolerance", 40.0f);
59  setLocal("targetOrientationDistanceTolerance", 3.15f);
60  setLocal("ikWithOrientation", false);
61 
62  setLocal("timeoutInMs", int(timeoutLiftObject));
63  setLocal("jointTargetTolerance", 0.01f);
64  setLocal("kinematicChainName", getInput<std::string>("kinematicChain"));
65  ARMARX_VERBOSE << "Done LiftObject::onEnter()" << flush;
66 }
67 
68 void
70 {
71  // set vel to zero
72  ARMARX_DEBUG << "setting joint velocity to zero " << flush;
73 
74  std::string kinChainName = getInput<std::string>("kinematicChain");
75  RobotStatechartContext* context = getContext<RobotStatechartContext>();
76 
77  if (!context)
78  {
79  ARMARX_WARNING << "Need a RobotStatechartContext" << flush;
80  sendEvent<Failure>();
81  }
82 
83  if (!context->robotStateComponent)
84  {
85  ARMARX_WARNING << "No RobotStatechartContext->robotStateComponent" << flush;
86  sendEvent<Failure>();
87  }
88 
90 
91  if (!robot->hasRobotNodeSet(kinChainName))
92  {
93  ARMARX_WARNING << "Robot does not know kinematic chain with name " << kinChainName << flush;
94  sendEvent<Failure>();
95  }
96 
97  VirtualRobot::RobotNodeSetPtr rns = robot->getRobotNodeSet(kinChainName);
98 
99 
100  NameValueMap targetJointVelocities;
101 
102  for (unsigned int i = 0; i < rns->getSize(); i++)
103  {
104  targetJointVelocities[rns->getNode(i)->getName()] = 0;
105  }
106 
107  context->kinematicUnitPrx->setJointVelocities(targetJointVelocities);
108 }
109 
110 void
112 {
115  ARMARX_VERBOSE << "Done LiftObject::onExit()";
116 
117  // test: open hand
118  /*
119  RobotStatechartContext *context = getContext<RobotStatechartContext>();
120  HandUnitInterfacePrx handUnitPrx = context->getHandUnit("RightHandUnit");
121  if (handUnitPrx)
122  {
123  ARMARX_INFO << "TEST: open hand" << flush;
124  handUnitPrx->open();
125  ARMARX_INFO << "TEST: set object released: Vitalis" << flush;
126  handUnitPrx->setObjectReleased("Vitalis");
127  }*/
128 }
129 
130 // DO NOT EDIT NEXT FUNCTION
131 std::string
133 {
134  return "LiftObject";
135 }
136 
137 // DO NOT EDIT NEXT FUNCTION
140 {
141  return XMLStateFactoryBasePtr(new LiftObject(stateData));
142 }
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:187
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:111
armarx::FramedPose
The FramedPose class.
Definition: FramedPose.h:280
GfxTL::Matrix4f
MatrixXX< 4, 4, float > Matrix4f
Definition: MatrixXX.h:650
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
LiftObject.h
armarx::FindAndGraspObjectGroup::LiftObject::condLiftObjectTimeout
ActionEventIdentifier condLiftObjectTimeout
Definition: LiftObject.h:54
armarx::FindAndGraspObjectContext::remoteRobot
VirtualRobot::RobotPtr remoteRobot
Definition: FindAndGraspObjectContext.h:185
armarx::State::setLocal
void setLocal(std::string const &key, const Variant &value)
setLocal() sets a local parameter.
Definition: State.cpp:464
armarx::FindAndGraspObjectGroup::LiftObject
Definition: LiftObject.h:37
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
armarx::FindAndGraspObjectContext
Definition: FindAndGraspObjectContext.h:81
armarx::FindAndGraspObjectGroup::LiftObject::GetName
static std::string GetName()
Definition: LiftObject.cpp:132
IceInternal::Handle
Definition: forward_declarations.h:8
armarx::FindAndGraspObjectGroup::LiftObject::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: LiftObject.cpp:139
armarx::RobotStatechartContext
Definition: RobotStatechartContext.h:79
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:162
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_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:184
armarx::FramedPosition
The FramedPosition class.
Definition: FramedPose.h:157
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:215
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:34
armarx::control::njoint_controller::platform::platform_follower_controller::NameValueMap
std::map< std::string, float > NameValueMap
Definition: PlatformFollowerController.h:88
armarx::RemoteRobot::createLocalClone
VirtualRobot::RobotPtr createLocalClone()
Clones the structure of this remote robot to a local instance.
Definition: RemoteRobot.cpp:381
armarx::RobotStatechartContext::robotStateComponent
RobotStateComponentInterfacePrx robotStateComponent
Prx for the RobotState.
Definition: RobotStatechartContext.h:111
armarx::FindAndGraspObjectGroup::LiftObject::setJointVelToZero
void setJointVelToZero()
Definition: LiftObject.cpp:69
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::StateUtility::removeTimeoutEvent
void removeTimeoutEvent(const ActionEventIdentifier &id)
Definition: StateUtil.cpp:203
armarx::RobotStatechartContext::kinematicUnitPrx
KinematicUnitInterfacePrx kinematicUnitPrx
Definition: RobotStatechartContext.h:112
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27
VirtualRobot::RobotPtr
std::shared_ptr< class Robot > RobotPtr
Definition: Bus.h:19