OnTablePredicateProvider.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 
24 
28 //#include <VirtualRobot/BoundingBox.h>
29 
30 using namespace memoryx;
31 
33 {
34 }
35 
36 
38 {
39  usingProxy("WorkingMemory");
40 
41 }
42 
44 {
45  workingMemoryProxy = getProxy<WorkingMemoryInterfacePrx>("WorkingMemory");
46  objectInstancesProxy = workingMemoryProxy->getObjectInstancesSegment();
47 }
48 
50 {
51  return "OnTablePredicateProvider";
52 }
53 
54 PredicateInfo OnTablePredicateProvider::getPredicateInfo(const Ice::Current&)
55 {
56  return PredicateInfo {"ontable", 1};
57 }
58 
59 PredicateInstanceList OnTablePredicateProvider::calcPredicates(const Ice::Current&)
60 {
61  PredicateInstanceList returnPIList;
62 
63  // TODO: only for testing
64  // Ice::StringSeq objs{"nesquik", "table"};
65  // PredicateInstance pI = {"on", Ice::StringSeq{"nesquik", "table"} };
66  //returnPIList.push_back(PredicateInstance{"on", Ice::StringSeq{"nesquik", "table"} } );
67 
68  struct TableDef
69  {
70  std::string name;
71  Eigen::Vector3f min;
72  Eigen::Vector3f max;
73  };
74 
75  std::vector<TableDef> tables;
76  tables.push_back(TableDef {"table1", Eigen::Vector3f(-600, 600, 900), Eigen::Vector3f(600, 1500, 1400)});
77  tables.push_back(TableDef {"table2", Eigen::Vector3f(-600, -1500, 900), Eigen::Vector3f(600, -600, 1400)});
78 
79 
80  // get all currently localized objects and their positions from the working memory
81  EntityIdList objectIds = objectInstancesProxy->getAllEntityIds();
82 
83  for (std::string id : objectIds)
84  {
85  EntityRefBasePtr entityBase = objectInstancesProxy->getEntityRefById(id);
86  const ObjectInstancePtr object = ObjectInstancePtr::dynamicCast(entityBase->getEntity());
87 
88  if (!object)
89  {
90  ARMARX_WARNING << "Something went wrong when getting the object with id " << id << " from working memory";
91  }
92  else
93  {
94  for (TableDef table : tables)
95  {
96  // TODO: assert that positions are in base coordinate frame
97  auto pos = object->getPosition();
98 
99  // assert(pos->getFrame() == "Armar3_Base");
100  if (pos->x > table.min[0] && pos->y > table.min[1] && pos->z > table. min[2]
101  && pos->x < table.max[0] && pos->y < table.max[1] && pos->z < table.max[2])
102  {
103  // returnPIList.push_back(PredicateInstance{"on", Ice::StringSeq{object->getName(), table.name}, true});
104  //@TODO
105  }
106  }
107  }
108  }
109 
110  /*EntityIdList objectIds = objectInstancesProxy->getAllEntityIds();
111  for(EntityIdList::const_iterator it = objectIds.begin(); it != objectIds.end(); it++)
112  {
113  EntityRefBasePtr entityBase = objectInstancesProxy->getEntityRefById(*it);
114  const ObjectInstancePtr object = ObjectInstancePtr::dynamicCast(entityBase->getEntity());
115  if (object)
116  {
117  // TODO: assert that positions are in base coordinate frame
118  auto pos = object->getPosition();
119  // assert(pos->getFrame() == "Armar3_Base");
120  if(pos->x > min[0] && pos->y > min[1] && pos->z > min[2] && pos->x < max[0] && pos->y < max[1] && pos->z < max[2])
121  returnPIList.push_back(PredicateInstance{"on", Ice::StringSeq{object->getName(), "table"}});
122  }
123  else
124  {
125  ARMARX_WARNING << "Something went wrong when getting the object with id " << *it << " from working memory";
126  }
127  }*/
128 
129 
130 
131  return returnPIList;
132 }
memoryx::OnTablePredicateProvider::onInitWorldStateUpdater
void onInitWorldStateUpdater() override
Definition: OnTablePredicateProvider.cpp:37
OnTablePredicateProvider.h
memoryx
VirtualRobot headers.
Definition: CommonPlacesTester.cpp:48
memoryx::OnTablePredicateProvider::calcPredicates
PredicateInstanceList calcPredicates(const Ice::Current &) override
Definition: OnTablePredicateProvider.cpp:59
IceInternal::Handle< ObjectInstance >
memoryx::OnTablePredicateProvider::OnTablePredicateProvider
OnTablePredicateProvider()
Definition: OnTablePredicateProvider.cpp:32
MemoryXCoreObjectFactories.h
max
T max(T t1, T t2)
Definition: gdiam.h:48
memoryx::OnTablePredicateProvider::getDefaultName
std::string getDefaultName() const override
Retrieve default name of component.
Definition: OnTablePredicateProvider.cpp:49
ObjectInstance.h
memoryx::OnTablePredicateProvider::onConnectWorldStateUpdater
void onConnectWorldStateUpdater() override
Definition: OnTablePredicateProvider.cpp:43
MemoryXTypesObjectFactories.h
min
T min(T t1, T t2)
Definition: gdiam.h:42
memoryx::OnTablePredicateProvider::getPredicateInfo
PredicateInfo getPredicateInfo(const Ice::Current &c=Ice::emptyCurrent)
Definition: OnTablePredicateProvider.cpp:54
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::ManagedIceObject::usingProxy
bool usingProxy(const std::string &name, const std::string &endpoints="")
Registers a proxy for retrieval after initialization and adds it to the dependency list.
Definition: ManagedIceObject.cpp:151