OnTopPredicateProvider.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 Mirko Waechter ( mirko.waechter 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 
23 #include "OnTopPredicateProvider.h"
24 
28 
29 
30 using namespace memoryx ;
31 
33 {
34 }
35 
36 
37 
39 {
40  usingProxy("WorkingMemory");
41 
42 }
43 
45 {
46  workingMemoryProxy = getProxy<WorkingMemoryInterfacePrx>("WorkingMemory");
47  objectInstancesProxy = workingMemoryProxy->getObjectInstancesSegment();
48 }
49 
51 {
52  return "OnTopPredicateProvider";
53 }
54 
55 PredicateInfo memoryx::OnTopPredicateProvider::getPredicateInfo(const Ice::Current&)
56 {
57  return PredicateInfo {"ontop", 2};
58 }
59 
60 
61 PredicateInstanceList memoryx::OnTopPredicateProvider::calcPredicates(const Ice::Current&)
62 {
63  PredicateInstanceList returnPIList;
64 
65  const float maxDistanceXY = 50;
66  const float minDistanceZ = 40;
67  const float maxDistanceZ = 200;
68 
69  // get all currently localized objects and their positions from the working memory
70  std::map<std::string, armarx::FramedPositionPtr> objectPositions;
71  EntityIdList objectIds = objectInstancesProxy->getAllEntityIds();
72 
73  for (EntityIdList::const_iterator it = objectIds.begin(); it != objectIds.end(); it++)
74  {
75  const EntityBasePtr entityBase = objectInstancesProxy->getEntityById(*it);
76  const ObjectInstancePtr object = ObjectInstancePtr::dynamicCast(entityBase);
77 
78  if (object)
79  {
80  // TODO: assert that positions are in base coordinate frame
81  objectPositions[object->getName()] = object->getPosition();
82  }
83  else
84  {
85  ARMARX_WARNING << "Something went wrong when getting the object with id " << *it << " from working memory";
86  }
87  }
88 
89  // determine which object pairs are standing on one another
90  for (std::map<std::string, armarx::FramedPositionPtr>::iterator i = objectPositions.begin(); i != objectPositions.end(); i++)
91  {
92  Eigen::Vector3f pos1 = i->second->toEigen();
93  ARMARX_IMPORTANT << "Object " << i->first << " at position " << i->second->toEigen();
94  std::map<std::string, armarx::FramedPositionPtr>::iterator j = i;
95  j++;
96 
97  for (; j != objectPositions.end(); j++)
98  {
99  Eigen::Vector3f pos2 = j->second->toEigen();
100 
101  // objects have to be close to each other in the x-y-plane
102  if (sqrtf((pos1(0) - pos2(0)) * (pos1(0) - pos2(0)) + (pos1(1) - pos2(1)) * (pos1(1) - pos2(1))) < maxDistanceXY)
103  {
104  // difference in z coordinate must be between min and max value
105  if (fabs(pos1(2) - pos2(2)) > minDistanceZ && fabs(pos1(2) - pos2(2)) < maxDistanceZ)
106  {
107  if (pos1(2) > pos2(2))
108  {
109  //@TODO
110  // returnPIList.push_back(PredicateInstance{"on", Ice::StringSeq{i->first, j->first}, true});
111  }
112  else
113  {
114  // returnPIList.push_back(PredicateInstance{"on", Ice::StringSeq{j->first, i->first}, true});
115  }
116  }
117  }
118  }
119  }
120 
121  return returnPIList;
122 }
123 
memoryx::OnTopPredicateProvider::onInitWorldStateUpdater
void onInitWorldStateUpdater() override
Definition: OnTopPredicateProvider.cpp:38
OnTopPredicateProvider.h
memoryx::OnTopPredicateProvider::calcPredicates
PredicateInstanceList calcPredicates(const Ice::Current &) override
Definition: OnTopPredicateProvider.cpp:61
ARMARX_IMPORTANT
#define ARMARX_IMPORTANT
Definition: Logging.h:183
memoryx::OnTopPredicateProvider::OnTopPredicateProvider
OnTopPredicateProvider()
Definition: OnTopPredicateProvider.cpp:32
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
IceInternal::Handle< ObjectInstance >
memoryx::OnTopPredicateProvider::onConnectWorldStateUpdater
void onConnectWorldStateUpdater() override
Definition: OnTopPredicateProvider.cpp:44
MemoryXCoreObjectFactories.h
memoryx::OnTopPredicateProvider::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: OnTopPredicateProvider.cpp:50
ObjectInstance.h
memoryx::OnTopPredicateProvider::getPredicateInfo
PredicateInfo getPredicateInfo(const Ice::Current &c=Ice::emptyCurrent)
Definition: OnTopPredicateProvider.cpp:55
MemoryXTypesObjectFactories.h
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186