VisualServoObject.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 "VisualServoObject.h"
26 
27 #include <VirtualRobot/Grasping/GraspSet.h>
28 
31 #include <MemoryX/interface/components/PriorKnowledgeInterface.h>
32 #include <MemoryX/interface/observers/ObjectMemoryObserverInterface.h>
37 
38 using namespace armarx;
39 using namespace FindAndGraspObjectGroup;
40 
41 // DO NOT EDIT NEXT LINE
42 VisualServoObject::SubClassRegistry VisualServoObject::Registry(VisualServoObject::GetName(),
44 
47 {
48 }
49 
50 void
52 {
53  setLocalObjectChannelFromInput("objectChannel", "objectName"); //still need this?
54  setLocalObjectChannelFromInput("markerChannel", "markerName"); //still need this?
55 
56  //NEW: grasp definition
57  // get grasp definition - Taken from GraspingWithVisualFeedback
58  FindAndGraspObjectContext* context = getContext<FindAndGraspObjectContext>();
59  memoryx::PersistentObjectClassSegmentBasePrx classesSegmentPrx =
60  context->priorMemoryProxy->getObjectClassesSegment();
61  memoryx::CommonStorageInterfacePrx databasePrx = context->priorMemoryProxy->getCommonStorage();
62  memoryx::GridFileManagerPtr fileManager(new memoryx::GridFileManager(databasePrx));
63  memoryx::EntityBasePtr entity =
64  classesSegmentPrx->getEntityByName(getInput<std::string>("objectName"));
65  memoryx::ObjectClassPtr objectClass = memoryx::ObjectClassPtr::dynamicCast(entity);
67  objectClass->addWrapper(new memoryx::EntityWrappers::SimoxObjectWrapper(fileManager));
68  VirtualRobot::ManipulationObjectPtr mo = simoxWrapper->getManipulationObject();
69 
70  // // TODO: remove when grasp definitions can be saved/edited in MemoryX
71  // VirtualRobot::ManipulationObjectPtr mo;
72 
73  // std::string armarx_home;
74  // if(std::getenv("ArmarXHome_DIR")){
75  // armarx_home = std::getenv("ArmarXHome_DIR");
76  // mo = VirtualRobot::ObjectIO::loadManipulationObject(armarx_home + "Armar3/data/scene/Vitalis.xml");
77  // }
78  // else
79  // ARMARX_LOG << eERROR << "Problem with ManipulationObject file for StatechartVisualServoingExample!" << flush;
80 
81 
82  //TODO: Get graspSetName and graspName from the configFile! (in order to try various grasps, in case we chose an unreachable one...)
83 
84  std::string graspSetName = getInput<std::string>("graspSetName");
85  VirtualRobot::GraspSetPtr gs = mo->getGraspSet(graspSetName);
86 
87  if (gs)
88  {
89  std::string graspName = getInput<std::string>("graspName");
90  context->graspDefinition = gs->getGrasp(graspName);
91  ARMARX_DEBUG << "VisualServoObject: getting grasp with name: " << graspName << flush;
92 
93  if (!context->graspDefinition)
94  {
95  ARMARX_WARNING << "No grasp with name " << graspName << " found! " << flush;
96  }
97  }
98  else
99  {
100  ARMARX_WARNING << "No grasp set with name " << graspSetName << " found! " << flush;
101  }
102 
103 
104  ARMARX_VERBOSE << "Done VisualServoObject::onEnter()" << flush;
105 }
106 
107 void
109 {
110  FindAndGraspObjectContext* context = getContext<FindAndGraspObjectContext>();
111  context->objectMemoryObserver->releaseObjectClass(
112  getLocal<ChannelRef>("objectChannel")); //which of these do we still need?
113  context->objectMemoryObserver->releaseObjectClass(getLocal<ChannelRef>("markerChannel"));
114 }
115 
116 void
117 VisualServoObject::setLocalObjectChannelFromInput(const std::string& objectChannelName,
118  const std::string& inputName)
119 {
120  FindAndGraspObjectContext* context = getContext<FindAndGraspObjectContext>();
121  std::string objectName = getInput<std::string>(inputName);
122  ChannelRefBasePtr objectChannel =
123  context->objectMemoryObserver->requestObjectClassRepeated(objectName, 30);
124 
125  if (objectChannel)
126  {
127  setLocal(objectChannelName, objectChannel);
128  ARMARX_DEBUG << "setLocal() for objectName: " << objectName
129  << "; objectChannelName: " << objectChannelName;
130  }
131  else
132  {
133  ARMARX_IMPORTANT << "Unknown Object Class: " << objectName;
134  }
135 }
136 
137 // DO NOT EDIT NEXT FUNCTION
138 std::string
140 {
141  return "VisualServoObject";
142 }
143 
144 // DO NOT EDIT NEXT FUNCTION
147 {
148  return XMLStateFactoryBasePtr(new VisualServoObject(stateData));
149 }
ARMARX_VERBOSE
#define ARMARX_VERBOSE
Definition: Logging.h:187
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:190
armarx::FindAndGraspObjectContext::priorMemoryProxy
memoryx::PriorKnowledgeInterfacePrx priorMemoryProxy
Definition: FindAndGraspObjectContext.h:177
armarx::XMLStateConstructorParams
Definition: XMLState.h:49
GridFileManager.h
ObjectClass.h
armarx::State::setLocal
void setLocal(std::string const &key, const Variant &value)
setLocal() sets a local parameter.
Definition: State.cpp:464
armarx::FindAndGraspObjectGroup::VisualServoObject::GetName
static std::string GetName()
Definition: VisualServoObject.cpp:139
armarx::FindAndGraspObjectContext::objectMemoryObserver
memoryx::ObjectMemoryObserverInterfacePrx objectMemoryObserver
Definition: FindAndGraspObjectContext.h:176
armarx::XMLStateFactoryBasePtr
IceInternal::Handle< XMLStateFactoryBase > XMLStateFactoryBasePtr
Definition: XMLState.h:64
armarx::FindAndGraspObjectContext
Definition: FindAndGraspObjectContext.h:81
IceInternal::Handle< ObjectClass >
armarx::XMLStateTemplate
Class for legacy to stay compatible with old statecharts.
Definition: XMLState.h:146
armarx::FindAndGraspObjectGroup::VisualServoObject
Definition: VisualServoObject.h:35
armarx::FindAndGraspObjectGroup::VisualServoObject::Registry
static SubClassRegistry Registry
Definition: VisualServoObject.h:51
armarx::flush
const LogSender::manipulator flush
Definition: LogSender.h:251
ARMARX_DEBUG
#define ARMARX_DEBUG
Definition: Logging.h:184
MemoryXCoreObjectFactories.h
memoryx::EntityWrappers::SimoxObjectWrapper
SimoxObjectWrapper offers a simplified access to the Simox ManipulationObject (i.e visualization,...
Definition: SimoxObjectWrapper.h:46
MotionModelAttachedToOtherObject.h
armarx::FindAndGraspObjectGroup::VisualServoObject::CreateInstance
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
Definition: VisualServoObject.cpp:146
armarx::FindAndGraspObjectGroup::VisualServoObject::VisualServoObject
VisualServoObject(XMLStateConstructorParams stateData)
Definition: VisualServoObject.cpp:45
armarx::FindAndGraspObjectGroup::VisualServoObject::onEnter
void onEnter() override
Virtual function, in which the behaviour of state is defined, when it is entered. Can be overridden,...
Definition: VisualServoObject.cpp:51
SimoxObjectWrapper.h
memoryx::GridFileManagerPtr
std::shared_ptr< GridFileManager > GridFileManagerPtr
Definition: AbstractEntityWrapper.h:33
armarx::FindAndGraspObjectGroup::VisualServoObject::onExit
void onExit() override
Virtual function, in which the behaviour of state is defined, when it is exited. Can be overridden,...
Definition: VisualServoObject.cpp:108
memoryx::GridFileManager
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
Definition: GridFileManager.h:41
MemoryXTypesObjectFactories.h
VisualServoObject.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:193
armarx::FindAndGraspObjectGroup::VisualServoObject::setLocalObjectChannelFromInput
void setLocalObjectChannelFromInput(const std::string &objectChannelName, const std::string &inputName)
Definition: VisualServoObject.cpp:117
armarx::FindAndGraspObjectContext::graspDefinition
VirtualRobot::GraspPtr graspDefinition
Definition: FindAndGraspObjectContext.h:178
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:27