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