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
38using namespace armarx;
39using namespace FindAndGraspObjectGroup;
40
41// DO NOT EDIT NEXT LINE
42VisualServoObject::SubClassRegistry VisualServoObject::Registry(VisualServoObject::GetName(),
44
49
50void
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
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
107void
109{
111 context->objectMemoryObserver->releaseObjectClass(
112 getLocal<ChannelRef>("objectChannel")); //which of these do we still need?
113 context->objectMemoryObserver->releaseObjectClass(getLocal<ChannelRef>("markerChannel"));
114}
115
116void
117VisualServoObject::setLocalObjectChannelFromInput(const std::string& objectChannelName,
118 const std::string& inputName)
119{
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
138std::string
140{
141 return "VisualServoObject";
142}
143
144// DO NOT EDIT NEXT FUNCTION
memoryx::PriorKnowledgeInterfacePrx priorMemoryProxy
memoryx::ObjectMemoryObserverInterfacePrx objectMemoryObserver
VisualServoObject(XMLStateConstructorParams stateData)
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,...
void setLocalObjectChannelFromInput(const std::string &objectChannelName, const std::string &inputName)
static XMLStateFactoryBasePtr CreateInstance(XMLStateConstructorParams stateData)
ContextType * getContext() const
Definition StateBase.h:71
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
std::enable_if_t< std::is_base_of_v< VariantDataClass, T >, IceInternal::Handle< T > > getLocal(const std::string &key) const
getLocal can be used to access a specific input parameter.
Definition State.h:653
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
SimoxObjectWrapper offers a simplified access to the Simox ManipulationObject (i.e visualization,...
GridFileManager provides utility functions for working with files in Mongo GridFS and links to them s...
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
#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
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
IceInternal::Handle< SimoxObjectWrapper > SimoxObjectWrapperPtr
IceInternal::Handle< ObjectClass > ObjectClassPtr
Definition ObjectClass.h:35
std::shared_ptr< GridFileManager > GridFileManagerPtr