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
27using namespace armarx;
28using namespace FindAndGraspObjectGroup;
29
30// DO NOT EDIT NEXT LINE
31LiftObject::SubClassRegistry LiftObject::Registry(LiftObject::GetName(),
33
38
39void
41{
42 ARMARX_VERBOSE << "Entering LiftObject::onEnter()";
43 float timeoutLiftObject = getInput<float>("timeoutLiftObject");
45
46 //GraspingWithVisualFeedbackContext* context = getContext<GraspingWithVisualFeedbackContext>();
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
68void
70{
71 // set vel to zero
72 ARMARX_DEBUG << "setting joint velocity to zero " << flush;
73
74 std::string kinChainName = getInput<std::string>("kinematicChain");
76
77 if (!context)
78 {
79 ARMARX_WARNING << "Need a RobotStatechartContext" << flush;
81 }
82
83 if (!context->robotStateComponent)
84 {
85 ARMARX_WARNING << "No RobotStatechartContext->robotStateComponent" << flush;
87 }
88
90
91 if (!robot->hasRobotNodeSet(kinChainName))
92 {
93 ARMARX_WARNING << "Robot does not know kinematic chain with name " << kinChainName << flush;
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
110void
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
131std::string
133{
134 return "LiftObject";
135}
136
137// DO NOT EDIT NEXT FUNCTION
ActionEventIdentifier condLiftObjectTimeout
Definition LiftObject.h:54
void onEnter() override
Virtual function, in which the behaviour of state is defined, when it is entered. Can be overridden,...
void onExit() override
Virtual function, in which the behaviour of state is defined, when it is exited. Can be overridden,...
LiftObject(XMLStateConstructorParams stateData)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
The FramedOrientation class.
Definition FramedPose.h:216
The FramedPose class.
Definition FramedPose.h:281
The FramedPosition class.
Definition FramedPose.h:158
virtual Eigen::Matrix4f toEigen() const
Definition Pose.cpp:334
VirtualRobot::RobotPtr createLocalClone()
Clones the structure of this remote robot to a local instance.
RobotStateComponentInterfacePrx robotStateComponent
Prx for the RobotState.
KinematicUnitInterfacePrx kinematicUnitPrx
ContextType * getContext() const
Definition StateBase.h:71
void removeTimeoutEvent(const ActionEventIdentifier &id)
ActionEventIdentifier setTimeoutEvent(int timeoutDurationMs, const EventPtr &evt)
Utility function to start a timer on the systemObserver and register an event on the conditionHandler...
EventPtr createEvent()
Utility function to create a new Event.
Definition StateUtil.h:63
void sendEvent(const EventPtr event, StateBasePtr eventProcessor=nullptr)
Function to send an event to a specific state from an onEnter()-function. Must not be called anywhere...
Definition StateUtil.cpp:40
std::enable_if_t< std::is_base_of_v< VariantDataClass, T >, IceInternal::Handle< T > > getInput(const std::string &key) const
getInput can be used to access a specific input parameter.
Definition State.h:620
void setLocal(std::string const &key, const Variant &value)
setLocal() sets a local parameter.
Definition State.cpp:464
XMLStateTemplate(const XMLStateConstructorParams &params)
Definition XMLState.h:149
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
Definition Logging.h:184
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
#define ARMARX_VERBOSE
The logging level for verbose information.
Definition Logging.h:187
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
const LogSender::manipulator flush
Definition LogSender.h:251
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition XMLState.h:64