LEMUR Packages: ompl_lemur or_lemur pr_bgl prpy_lemur
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Groups Pages
module_family.h
Go to the documentation of this file.
1 
7 namespace or_lemur
8 {
9 
34 class FamilyModule : public OpenRAVE::ModuleBase
35 {
36 private:
37  struct Set; // opaque type for module users
38 
39 public:
40  // types
41  // setptrs are unique w.r.t. what checks they entail
42  typedef boost::shared_ptr<Set> SetPtr;
43 
44  // first:antecedents, second:consequent
45  // C > A1 n A2 n A2
46  typedef std::pair< std::set<SetPtr>, SetPtr > Relation;
47 
48  struct Family
49  {
50  std::set<SetPtr> sets;
51  std::set<Relation> relations;
52  };
53 
54  typedef boost::function<bool (const std::vector<OpenRAVE::dReal> & values)> Indicator;
55 
56  FamilyModule(OpenRAVE::EnvironmentBasePtr penv);
57  ~FamilyModule();
58 
59  std::string GetInstanceId();
60 
61  void SetCostPerIlc(double cost_per_ilc);
62 
63  // on environment add/remove
64  // arguments:
65  // --robot-name
66  // --use-baked-checker (optional) (can be on,yes,1,true
67  // or off,no,0,false)
68  int main(const std::string & cmd);
69  void Destroy();
70 
71  std::string GetFamilyId();
72 
73  // note: these will generate the new set and put it in _sets_all,
74  // but it's unnamed, so on next cleanup() it will be removed
75  // if the pointer is destroyed
76 
77  SetPtr GetCurrentSet();
78 
79  SetPtr GetSetFromExpression(std::string input);
80 
81  // returns nothing if literal not bound
82  SetPtr GetSet(std::string literal);
83 
84  void Let(std::string literal, SetPtr set);
85 
86  void Del(std::string literal);
87 
88  std::string GetHeaderFromSet(SetPtr set);
89 
90  SetPtr GetSetFromHeader(std::string set_header);
91 
92  // returns all currently named sets,
93  // as well as other sets need for all of their relations
94  Family GetCurrentFamily(std::set<SetPtr> sets_ext = std::set<SetPtr>());
95 
96  // should return a map from SetPtr -> bool (*)(vec<dReal> q)
97  // internally, this delegates to something else?
98  // these indicators are only valid if the env is unchanged exernally!
99  // this ignores the relations
100  std::map< SetPtr, std::pair<double,Indicator> > GetIndicators(const Family & family);
101 
102  // makes up names for unbound sets
103  std::map<SetPtr,std::string> GetCanonicalNames(const Family & family);
104 
105  bool CmdGetInstanceId(std::ostream & soutput, std::istream & sinput);
106 
107  bool CmdGetRobotName(std::ostream & soutput, std::istream & sinput);
108 
109  bool CmdSetCostPerIlc(std::ostream & soutput, std::istream & sinput);
110 
111  bool CmdGetFamilyId(std::ostream & soutput, std::istream & sinput);
112 
113  // assignment statement
114  // Let A = $live
115  // Let B = $file{something.txt}
116  // Let C = A \ B
117  // Let D = (A u C) n B
118  bool CmdLet(std::ostream & soutput, std::istream & sinput);
119 
120  // input: expression
121  bool CmdNamesOf(std::ostream & soutput, std::istream & sinput);
122 
123  bool CmdPrintCurrentFamily(std::ostream & soutput, std::istream & sinput);
124 
125  // input: expression
126  bool CmdGetHeaderFromSet(std::ostream & soutput, std::istream & sinput);
127 
128 private:
129 
131  bool _initialized;
132  bool _has_use_baked_checker; // whether it was passed
133  bool _use_baked_checker;
134  boost::weak_ptr<OpenRAVE::RobotBase> _robot;
135  bool _robot_nonempty;
136  std::vector<int> _active_dofs;
137  std::string _id;
138  std::vector<int> _proxidxs;
139 
140  // this scales the call costs returned by GetIndicators()
141  double _cost_per_ilc;
142 
143  // types
144 
145  // these are deduplicated, between in-memory and on-disk!
146  // (this is a hard problem in itself; what if two processes generate
147  // slightly different ones? simultaneously?)
148  // a posed link is relative to a proxidx link (relative to this family only)
149  struct PosedLink
150  {
151  int proxidx;
152  std::string geomhash;
153  OpenRAVE::Transform pose;
154  };
155 
159  typedef std::pair<PosedLink *, PosedLink *> Check;
160 
161  struct Atom
162  {
163  std::set<Check> checks; // set of checks this atom entails
164  };
165 
166  struct Set
167  {
168  std::set<std::string> literals; // how everyone pointing to me from _sets_bound
169  std::set<Check> checks; // set of checks this set entails; doesnt change
170  std::set<Atom *> atoms;
171  };
172 
173  // the family module owns everything!
174  // it's sure to deduplicate stuff too
175  // this owns PosedLinks
176  //
177  // the family ONLY maintains posedlinks needed by existing sets!
178  std::map< std::pair<int,std::string>, std::set<PosedLink *> > _posedlinks;
179 
180  // this owns the Atoms
181  std::set<Atom *> _atoms;
182 
183  // all sets (but may still be bound to literals)
184  // when this is the only pointer, we can clean up
185  std::set<SetPtr> _sets_all;
186 
187  // sets we want to own
188  // we delete from here
189  // sets currently bound to a literal
190  std::map<std::string, SetPtr> _sets_bound;
191 
192  // this function considers all links in the environment
193  // (enabled or not)
194  // and finds an existing matching posedlink if it exists
195  // (we dont add them cause they might not be used)
196  std::map<PosedLink *, OpenRAVE::KinBody::LinkPtr> live_links();
197 
198  SetPtr set_from_checks(const std::set<Check> & checks);
199 
200 };
201 
202 } // namespace or_lemur
Definition: module_family.h:34
Definition: module_family.h:48