PutAwayLocationPredicateProvider.cpp
Go to the documentation of this file.
1/*
2* This file is part of ArmarX.
3*
4* ArmarX is free software; you can redistribute it and/or modify
5* it under the terms of the GNU General Public License version 2 as
6* published by the Free Software Foundation.
7*
8* ArmarX is distributed in the hope that it will be useful, but
9* WITHOUT ANY WARRANTY; without even the implied warranty of
10* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11* GNU General Public License for more details.
12*
13* You should have received a copy of the GNU General Public License
14* along with this program. If not, see <http://www.gnu.org/licenses/>.
15*
16* @package ArmarX::
17* @author Valerij Wittenbeck ( valerij.wittenbeck at kit dot edu)
18* @date 2014
19* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
20* GNU General Public License
21*/
22
24
26
30
31using namespace memoryx;
32
34 putAwayLocation(PredicateInfo{"putAwayLocation", 2})
35{
36}
37
38void
40{
41 usingProxy("WorkingMemory");
42 usingProxy("PriorKnowledge");
43 usingProxy("LongtermMemory");
44 usingProxy("GraphNodePoseResolver");
45 usingProxy(getProperty<std::string>("CommonPlacesLearnerName").getValue());
46
47 cplSegmentName = getProperty<std::string>("CPLSegmentName").getValue();
48 sceneName = getProperty<std::string>("PlatformGraphSceneName").getValue();
49}
50
51void
53{
54 getProxy(wm, "WorkingMemory");
55 getProxy(prior, "PriorKnowledge");
56 getProxy(ltm, "LongtermMemory");
57 getProxy(psr, "GraphNodePoseResolver");
58 getProxy(cpl, getProperty<std::string>("CommonPlacesLearnerName").getValue());
59
60 cpl->setLTMSegmentName(cplSegmentName);
61 objectInstances = wm->getObjectInstancesSegment();
62 graphSegment = prior->getGraphSegment();
63}
64
65std::string
67{
68 return "PutAwayLocationPredicateProvider";
69}
70
71PredicateInfoList
73{
74 return {putAwayLocation};
75}
76
77PredicateInstanceList
79{
80 PredicateInstanceList result;
81 const std::string predicateName = putAwayLocation.name;
82
83 for (const auto& entity : objectInstances->getAllEntities())
84 {
85 auto entry = getCacheEntry(ObjectInstancePtr::dynamicCast(entity)->getMostProbableClass());
86 if (entry.putAwayNodeRef)
87 {
88 result.push_back(PredicateInstance{
89 predicateName,
90 {objectInstances->getEntityRefById(entity->getId()), entry.putAwayNodeRef},
91 true});
92 }
93 }
94
95 return result;
96}
97
98PutAwayLocationPredicateProvider::CachedCommonPlace
99PutAwayLocationPredicateProvider::getCacheEntry(const std::string& className)
100{
101 auto it = cpCache.find(className);
102 if (it != cpCache.end())
103 {
104 return it->second;
105 }
106
107 if (cplObjects.empty())
108 {
109 cplObjectsSegment = ltm->getCustomInstancesSegment(cplSegmentName, false);
110 if (!cplObjectsSegment)
111 {
112 throw armarx::LocalException("No LTM segment named '") << cplSegmentName << "'";
113 }
114
115 auto entities = cplObjectsSegment->getAllEntities();
116 std::transform(entities.cbegin(),
117 entities.cend(),
118 std::back_inserter(cplObjects),
119 [](const EntityBasePtr& e) { return ObjectInstancePtr::dynamicCast(e); });
120 }
121
122 EntityRefBasePtr nodeRef;
123 for (const auto& cplInstance : cplObjects)
124 {
125 if (cplInstance->getMostProbableClass() == className)
126 {
127 memoryx::Cluster3DList clusterList =
128 cpl->getPositionClustersByComponentCount(cplInstance->getName(), 1);
129 if (!clusterList.empty())
130 {
131 auto cluster = clusterList.front();
132 nodeRef = graphSegment->getEntityRefById(psr->getNearestNodeIdToPosition(
133 sceneName, "putdownlocation", cluster.center.x, cluster.center.y));
134 break;
135 }
136 }
137 }
138
139 if (nodeRef)
140 {
141 ARMARX_IMPORTANT << "caching putaway location for '" << className << "': '"
142 << nodeRef->entityName << "'";
143 }
144
145 CachedCommonPlace result{className, nodeRef};
146 cpCache.insert({className, result});
147 return result;
148}
Property< PropertyType > getProperty(const std::string &name)
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Ice::ObjectPrx getProxy(long timeoutMs=0, bool waitForScheduler=true) const
Returns the proxy of this object (optionally it waits for the proxy)
PredicateInstanceList calcPredicates(const Ice::Current &) override
PredicateInfoList getPredicateInfos(const Ice::Current &c=Ice::emptyCurrent) override
std::string getDefaultName() const override
Retrieve default name of component.
#define ARMARX_IMPORTANT
The logging level for always important information, but expected behaviour (in contrast to ARMARX_WAR...
Definition Logging.h:190
VirtualRobot headers.