libmove3d-planners
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Groups Pages
facts.hpp
1 #ifndef FACTS_HPP
2 #define FACTS_HPP
3 
4 #include "P3d-pkg.h"
5 #include "move3d-headless.h"
6 #include "Planner-pkg.h"
7 
8 #include "Device/robot.hpp"
9 #include "scene.hpp"
10 
11 
12 
13 
14 
15 class WorldStateFacts;
16 class Fact;
17 //class Scene;
18 
19 typedef struct struct_fact_id{
20  std::string factType;
21  std::string factSubType;
22  bool isMainAnAgent;
23 } fact_id;
24 
25 
35 {
36  MOVE3D_STATIC_LOGGER;
37 public:
38  FactsManager();
39  FactsManager(Scene *scen);
40  ~FactsManager();
41 
42  void initAll();
43  bool disableFacts(std::string s);
44  bool enableFacts(std::string s);
45  bool isFactEnabled(std::string s);
46 
47  bool computeVisibility(WorldStateFacts* WS,Robot* mainEntity, Robot* targetEntity, bool forceRecompute);
48  bool computeReachability(WorldStateFacts* WS,Robot* mainEntity, Robot* targetEntity, bool forceRecompute);
49  bool computeIsOn(WorldStateFacts* WS,Robot* mainEntity, Robot* targetEntity, bool forceRecompute);
50  bool computeIsIn(WorldStateFacts* WS,Robot* mainEntity, Robot* targetEntity, bool forceRecompute);
51  bool computeIsNextTo(WorldStateFacts* WS,Robot* mainEntity, Robot* targetEntity, bool forceRecompute);
52  bool computeSize(WorldStateFacts* WS,Robot* mainEntity, Robot* targetEntity, bool forceRecompute);
53  bool computeClutter(WorldStateFacts* WS,Robot* mainEntity, Robot* targetEntity, bool forceRecompute);
54 
55 
56  bool computeRobotVisibility(WorldStateFacts* WS, Robot* mainEntity, bool forceRecompute);
57  bool computeRobotReachability(WorldStateFacts* WS, Robot* mainEntity, bool forceRecompute);
58  bool computeRobotIsOn(WorldStateFacts* WS, Robot* mainEntity, bool forceRecompute);
59  bool computeRobotIsIn(WorldStateFacts* WS, Robot* mainEntity, bool forceRecompute);
60  bool computeRobotIsNextTo(WorldStateFacts* WS, Robot* mainEntity, bool forceRecompute);
61  bool computeRobotSize(WorldStateFacts* WS, Robot* mainEntity, bool forceRecompute);
62  bool computeRobotClutter(WorldStateFacts* WS, Robot* mainEntity, bool forceRecompute);
63 
64 
65  bool computeAllVisibilities(WorldStateFacts* WS, bool forceRecompute);
66  bool computeAllReachabilities(WorldStateFacts* WS, bool forceRecompute);
67  bool computeAllIsOn(WorldStateFacts* WS, bool forceRecompute);
68  bool computeAllIsIn(WorldStateFacts* WS, bool forceRecompute);
69  bool computeAllIsNextTo(WorldStateFacts* WS, bool forceRecompute);
70  bool computeAllSize(WorldStateFacts* WS, bool forceRecompute);
71  bool computeAllClutter(WorldStateFacts* WS, bool forceRecompute);
72 
73  bool computeFacts(WorldStateFacts* WS, bool forceRecompute);
74  bool computeFacts(int WSid, bool forceRecompute);
75  int computeFacts(bool forceRecompute);
76 
77 
78  int findWorldStateFacts(WorldStateFacts* WS);
79  int findOrAddWorldStateFacts(WorldStateFacts* WS);
80  int findCurWorldStateFacts();
81 
82  void setFactToFalse(WorldStateFacts* WS, fact_id ft, Robot* mainEntity, Robot* targetEntity);
83 
84  bool cleanWSList();
85 
86  bool computeOneFact(WorldStateFacts* WSF, std::string fact, Robot *mainEntity);
87  std::vector<Fact> computeAndGetFact(std::string fact, Robot *mainEntity);
88  Fact computeAndGetFact(std::string fact, std::string factSubType, Robot *mainEntity, Robot* targetEntity);
89 
90  WorldStateFacts* getWSFromId(int WSid);
91 
92  std::vector<fact_id> getFactList() {return factList;}
93 
94 private:
95  static std::vector<fact_id> factList;
96  std::vector<std::pair<int, WorldStateFacts*> > WSlist;
97  int WSlistId;
98  Scene* sce;
99 
100  std::vector<std::string> disabledFacts;
101 
102 };
103 
104 
105 
106 class Fact
107 {
108  MOVE3D_STATIC_LOGGER;
109 public:
110  Fact();
111  Fact(fact_id fact_type);
112 
113  bool compareFactsDescr(Fact f);
114  bool compareFactsDescr(fact_id FI, Robot* main, Robot* target);
115  bool compareFactsValue(Fact f);
116 
117  fact_id getType();
118 
119  Robot* getMainEntity();
120  Robot* getTargetEntity();
121 
122  void setMainEntity(Robot* r);
123  void setTargetEntity(Robot* r);
124 
125  bool isItComputed();
126  void setIsComputed(bool t);
127 
128  int getValueType();
129  void setValueType(int v);
130 
131  bool getBoolValue();
132  void setBoolValue(bool v);
133 
134  double getSpecValue();
135  void setSpecValue(double v);
136 
137  void printFact();
138 
139  std::string getFactDescr();
140 
141 
142 private:
143  fact_id fType;
144 
145  Robot* mainEntity;
146  Robot* targetEntity;
147 
148  bool isComputed;
149 
150  int value_type; //0 for bool, 1 for specificValue
151 
152  bool boolValue;
153  double specificValue;
154 
155 
156 };
157 
158 
159 
161 {
162  MOVE3D_STATIC_LOGGER;
163 public:
164  WorldStateFacts();
165 
166  WorldStateFacts(Scene *scen);
167  WorldStateFacts(std::vector<confPtr_t> confs );
168  std::vector<Robot*> compareWS(WorldStateFacts* WS);
169 
170  void printAllFacts();
171  void printAllComputedFacts();
172  void printFacts(std::vector<Fact> fp);
173 
174  bool initFacts(std::vector<fact_id> factList);
175 
176 
177  std::vector<Fact> getFacts();
178  std::vector<Fact> getMeaningfulFacts();
179  std::vector<Fact> getUpdatedFacts(WorldStateFacts* WS);
180  void setFacts(std::vector<Fact> Facts);
181 
182  std::vector<Fact> getFactFromMain(std::string factType, std::string main);
183  std::vector<Fact> getFactFromTarget(std::string factType, std::string target);
184 
185  Fact getFact(fact_id Fact_Id, Robot* main, Robot* target);
186  Fact getFact(std::string factType, std::string main, std::string target);
187  void setFact(Fact fact);
188 
189  std::vector<confPtr_t> getRobotsConfs();
190 
191  confPtr_t getRobotConf(Robot* robot);
192 
193  confPtr_t getRobotConfById(int robot_id);
194 
195  void setConfigurations(std::vector<confPtr_t> robVect) { robotsConfs = robVect;}
196  void setConfiguration(confPtr_t conf);
197 
198 private:
199  std::vector<confPtr_t> robotsConfs;
200  std::vector<Fact> facts;
201 
202  Scene* sce;
203 };
204 
205 
206 
207 
208 #endif // FACTS_HPP
bool computeReachability(WorldStateFacts *WS, Robot *mainEntity, Robot *targetEntity, bool forceRecompute)
the hand will be stocked in the sepecific value 2 hand considered
Definition: facts.cpp:416
Definition: facts.hpp:106
bool computeVisibility(WorldStateFacts *WS, Robot *mainEntity, Robot *targetEntity, bool forceRecompute)
computing visibility fact for now, it is done roughly a first loop check if the center of mass of the...
Definition: facts.cpp:252
This class holds a the robot represented by a kinematic chain.
Definition: robot.hpp:42
bool computeIsOn(WorldStateFacts *WS, Robot *mainEntity, Robot *targetEntity, bool forceRecompute)
computation of is On fact an object A is On another one B in the next conditions: The center of A is ...
Definition: facts.cpp:676
Definition: facts.hpp:19
Class that represents a Scene, Described by a p3d file.
Definition: scene.hpp:22
bool computeIsIn(WorldStateFacts *WS, Robot *mainEntity, Robot *targetEntity, bool forceRecompute)
Compute is insinde fact is in means at least half of the mainobject is in the OBB of the target objec...
Definition: facts.cpp:789
Definition: facts.hpp:160
Definition: facts.hpp:34
bool computeIsNextTo(WorldStateFacts *WS, Robot *mainEntity, Robot *targetEntity, bool forceRecompute)
computation of is next to fact an object is next to another if the closest distance between those two...
Definition: facts.cpp:1064