libmove3d-planners
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Groups Pages
MultiAgentHandOvers.h
1 #ifndef MULTIAGENTHANDOVERS_H
2 #define MULTIAGENTHANDOVERS_H
3 
4 #include "MultiHandOverUtils.hpp"
5 #include "ConfGenerator.h"
6 #include "Chronometer.hpp"
7 #include <map>
8 
9 namespace HRICS {
10 namespace MHO{
16 public:
17  //AbstractHandOverTest();
18  virtual ~AbstractHandOverTest(){}
19  virtual bool check(FrontierPtr frontier)=0;
20  virtual std::string getName()=0;
22  virtual FrontierCells::FrontierCheckStatus getCheckStatusLevel()=0;
24  virtual FrontierCells::FrontierCheckStatus getRequiredCheckStatus()=0;
25 };
26 
28 public:
29  DummyHandOverTest(FrontierCells::FrontierCheckStatus req,FrontierCells::FrontierCheckStatus lvl):
30  _req(req),_lvl(lvl) { }
31  virtual ~DummyHandOverTest(){}
32  virtual bool check(FrontierPtr frontier){
33  bool ok =false;
34  if (frontier->check_status>=_req && frontier->status_ok[_req]){
35  ok= true;
36  }else{
37  ok= false;
38  }
39  frontier->check_status=_lvl;
40  frontier->status_ok[_lvl]=ok;
41  return ok;
42  }
43  virtual std::string getName(){return "dummy";}
45  virtual FrontierCells::FrontierCheckStatus getCheckStatusLevel(){return _lvl;}
47  virtual FrontierCells::FrontierCheckStatus getRequiredCheckStatus(){return _req;}
48 private:
49  FrontierCells::FrontierCheckStatus _req,_lvl;
50 
51 };
52 
61 public:
63  virtual ~FrontierTester();
64  bool test(FrontierPtr frontier,std::string const & method);
71  bool test(FrontierPtr frontier, FrontierCells::FrontierCheckStatus target_status);
78  void addTester(AbstractHandOverTest* tester,bool is_default=false);
80  void addDefault(std::string const & name);
82  AbstractHandOverTest* getDefault(FrontierCells::FrontierCheckStatus target_status);
84  AbstractHandOverTest* getTester(std::string const & name);
85  std::vector< std::pair<std::string,bool> > listTesterNames(bool default_only=false);
86  std::vector< std::pair<AbstractHandOverTest*,bool> > listTesters(bool default_only=false);
87 
88  unsigned int getCheckCount(FrontierCells::FrontierCheckStatus st){return _check_counts[st].first;}
89  double getCheckTime(FrontierCells::FrontierCheckStatus st){return _check_counts[st].second;}
90 private:
93  std::map<std::string,AbstractHandOverTest*> _testers;
98  std::map<FrontierCells::FrontierCheckStatus,std::string> _defaults;
99  std::map<FrontierCells::FrontierCheckStatus,std::pair<unsigned int,double> > _check_counts;
100  Chronometer _chrono;
101 };
102 
107 public:
108  AbstracHandOverObjectCheck(Robot* object,Robot* r1=0,Robot* r2=0):_object(object),
109  _robots(std::make_pair(r1,r2)){
110  setLogger(&_dummy_logger);
111  }
112  virtual ~AbstracHandOverObjectCheck(){}
113  virtual bool check() =0;
116 
118  void timeLimit(double time_limit_ms){_time_limit=time_limit_ms;}
119  double timeLimit(){return _time_limit;}
120  void object(Robot* obj){_object=obj;}
121  Robot* object(void){return _object;}
124  void shoulders(Eigen::Vector3d shoulder1,Eigen::Vector3d shoulder2){this->_shoulder1=shoulder1;this->_shoulder2=shoulder2;}
125  Eigen::Vector3d shoulder1(){return _shoulder1;}
126  Eigen::Vector3d shoulder2(){return _shoulder2;}
127  void reach(double r1,double r2){_reach1=r1;_reach2=r2;}
128  double reach1(){return _reach1;}
129  double reach2(){return _reach2;}
130  void grabs(Eigen::Vector3d& g1,Eigen::Vector3d& g2){_grab1=g1;_grab2=g2;}
131  Eigen::Vector3d& grab1(){return _grab1;}
132  Eigen::Vector3d& grab2(){return _grab2;}
133 
134  void robots(Robot* r1,Robot* r2){_robots=std::make_pair(r1,r2);}
135  inline std::pair<Robot*,Robot*>& robots(){return _robots;}
137  virtual confPtr_t getQMiddle() =0;
138  void setLogger(AlgoLoggerInterface* logger){_logger=logger;}
139  virtual std::string getName()=0;
140 private:
141  AlgoLoggerInterface *_logger;
142  double _time_limit;
143  Robot* _object;
144  std::pair<Robot*,Robot*> _robots;
145  Eigen::Vector3d _shoulder1,_shoulder2;
146  Eigen::Vector3d _grab1,_grab2;
147  double _reach1,_reach2;
148  AlgoLoggerInterface _dummy_logger;
149 };
155 {
156 public:
157  HandOverTestDistance(std::vector<MultiHandOverAgent> * agents);
158  virtual ~HandOverTestDistance(){}
159  virtual bool check(FrontierPtr frontier);
161  virtual bool check(unsigned int a1, unsigned int a2, MultiAgentCell* c1,MultiAgentCell* c2);
162  virtual std::string getName(){return _name;}
163  virtual FrontierCells::FrontierCheckStatus getCheckStatusLevel(){return FrontierCells::FCS_NONE;}
164  virtual FrontierCells::FrontierCheckStatus getRequiredCheckStatus(){return FrontierCells::FCS_NONE;}
165 private:
166  std::vector<MultiHandOverAgent> *_agents;
167  static const std::string _name;
168 };
169 
176 {
177 public:
178  HandOverTestObject(AbstracHandOverObjectCheck* object_check,std::vector<MultiHandOverAgent> *agents);
179  virtual ~HandOverTestObject(){}
180  virtual bool check(FrontierPtr frontier);
181  virtual std::string getName(){return _object_check->getName();}
182  virtual FrontierCells::FrontierCheckStatus getCheckStatusLevel(){return FrontierCells::FCS_OBJECT;}
183  virtual FrontierCells::FrontierCheckStatus getRequiredCheckStatus(){return FrontierCells::FCS_NONE;}
184 
185 private:
186  AbstracHandOverObjectCheck* _object_check;
187  std::vector<MultiHandOverAgent> *_agents;
188 };
189 
195 {
196 public:
197  HandOverTestGrabs(std::vector<MultiHandOverAgent> *agents,Robot **object);
198  virtual ~HandOverTestGrabs(){}
199  virtual bool check(FrontierPtr frontier);
200  virtual std::string getName(){return _name;}
201  virtual FrontierCells::FrontierCheckStatus getCheckStatusLevel(){return FrontierCells::FCS_GRAB_CONFS;}
202  virtual FrontierCells::FrontierCheckStatus getRequiredCheckStatus(){return FrontierCells::FCS_OBJECT;}
203 private:
204  std::vector<MultiHandOverAgent> *_agents;
205  Robot **_object_pt_pt;
206  static const std::string _name;
207 };
208 
209 
215 public:
216  HandOverTestPreDefined(std::vector<MultiHandOverAgent> *agents, std::string file_directory,double grid_discrete_step);
217  virtual ~HandOverTestPreDefined();
218  virtual bool check(FrontierPtr frontier);
219  virtual std::string getName(){return _name;}
220  virtual FrontierCells::FrontierCheckStatus getCheckStatusLevel(){return FrontierCells::FCS_HANDOVER;}
221  virtual FrontierCells::FrontierCheckStatus getRequiredCheckStatus(){return FrontierCells::FCS_GRAB_CONFS;}
222 private:
223 
224  struct _ConfGenAlias{
225  ConfGenerator* conf_generator;
226 
227  std::vector<HRICS::ConfigHR> conf_list;
228  MultiHandOverAgent *alias_human, *alias_robot;
229  bool use_dummy;
231  };
232  _ConfGenAlias *_initGetConfGen(MultiHandOverAgent *a1, MultiHandOverAgent *a2);
233 
234  std::vector<MultiHandOverAgent> *_agents;
235  std::string _file_dir;
236  std::map<pair<MultiHandOverAgent*,MultiHandOverAgent*> , _ConfGenAlias> _conf_generators_alias;
237 
238  std::pair<double,double> _robot_robot_min_max_dists,_human_robot_min_max_dists;
239 
240  static const std::string _name;
241  double _grid_pace;
242 };
243 
245 {
246 public:
247  HandOverTestVisible(std::vector<MultiHandOverAgent> *agents, Robot *object);
248  virtual ~HandOverTestVisible() {}
249  virtual bool check(FrontierPtr frontier);
250  virtual std::string getName() {return _name;}
251  virtual FrontierCells::FrontierCheckStatus getCheckStatusLevel(){return FrontierCells::FCS_HANDOVER;}
252  virtual FrontierCells::FrontierCheckStatus getRequiredCheckStatus(){return FrontierCells::FCS_GRAB_CONFS;}
253 
254 private:
255 
256  std::vector<MultiHandOverAgent> *_agents;
257  Robot *_object_pt;
258  static const std::string _name;
259 };
260 
262 {
263 public:
264  HandOverTestSelection(std::vector<MultiHandOverAgent> *agents, Robot *object,std::string file_directory,double grid_discrete_step);
265  HandOverTestSelection(std::vector<MultiHandOverAgent> *agents, Robot *object,HandOverTestPreDefined* predef,HandOverTestVisible* visib,bool own_tester=false);
266  virtual ~HandOverTestSelection();
267  virtual bool check(FrontierPtr frontier);
268  virtual std::string getName() {return _name;}
269  virtual FrontierCells::FrontierCheckStatus getCheckStatusLevel(){return FrontierCells::FCS_HANDOVER;}
270  virtual FrontierCells::FrontierCheckStatus getRequiredCheckStatus(){return FrontierCells::FCS_GRAB_CONFS;}
271 
272 private:
273  std::vector<MultiHandOverAgent> *_agents;
274  Robot *_object_pt;
275  HandOverTestPreDefined *_test_pre;
276  HandOverTestVisible *_test_vis;
277 
278  static const std::string _name;
279  bool _is_owner;
280 };
281 
283 {
284 public:
285  HandOverTestTrajectory(std::vector<MultiHandOverAgent> *agents);
286  virtual ~HandOverTestTrajectory(){}
287  virtual bool check(FrontierPtr frontier);
288  virtual std::string getName(){return _name;}
289  virtual FrontierCells::FrontierCheckStatus getCheckStatusLevel(){return FrontierCells::FCS_TRAJECTORIES;}
290  virtual FrontierCells::FrontierCheckStatus getRequiredCheckStatus(){return FrontierCells::FCS_HANDOVER;}
291 
292 protected:
293  virtual bool computeTraj(Robot *r,confPtr_t start, confPtr_t target, API::Trajectory *traj);
294 
295 private:
296  std::vector<MultiHandOverAgent> *_agents;
297  static const std::string _name;
298 };
299 }
300 }
301 
302 #endif // MULTIAGENTHANDOVERS_H
The HandOverTestPreSelected class search in predefined configurations for a good handover configurati...
Definition: MultiAgentHandOvers.h:214
virtual FrontierCells::FrontierCheckStatus getRequiredCheckStatus()=0
get the required status level for the class to compute its check.
virtual FrontierCells::FrontierCheckStatus getCheckStatusLevel()
get the status level that the class provides.
Definition: MultiAgentHandOvers.h:163
virtual FrontierCells::FrontierCheckStatus getRequiredCheckStatus()
get the required status level for the class to compute its check.
Definition: MultiAgentHandOvers.h:202
void shoulders(Eigen::Vector3d shoulder1, Eigen::Vector3d shoulder2)
sets the positions of each shoulder.
Definition: MultiAgentHandOvers.h:124
void addTester(AbstractHandOverTest *tester, bool is_default=false)
add tester, the object will own the pointer.
Definition: MultiAgentHandOvers.cpp:20
virtual FrontierCells::FrontierCheckStatus getRequiredCheckStatus()
get the required status level for the class to compute its check.
Definition: MultiAgentHandOvers.h:290
void addDefault(std::string const &name)
sets an already added method as the default for the status level it provides
Definition: MultiAgentHandOvers.cpp:33
virtual FrontierCells::FrontierCheckStatus getRequiredCheckStatus()
get the required status level for the class to compute its check.
Definition: MultiAgentHandOvers.h:252
AbstractHandOverTest * getTester(std::string const &name)
the the tester named name (by the developper of the tester)
Definition: MultiAgentHandOvers.cpp:37
virtual FrontierCells::FrontierCheckStatus getCheckStatusLevel()
get the status level that the class provides.
Definition: MultiAgentHandOvers.h:269
AbstractHandOverTest * getDefault(FrontierCells::FrontierCheckStatus target_status)
get the default method class set for this status level
Definition: MultiAgentHandOvers.cpp:43
virtual FrontierCells::FrontierCheckStatus getCheckStatusLevel()
get the status level that the class provides.
Definition: MultiAgentHandOvers.h:45
Definition: MultiAgentHandOvers.h:27
The HandOverTestDistance class tests if the distance between 2 agents allows them to make a hand over...
Definition: MultiAgentHandOvers.h:154
virtual FrontierCells::FrontierCheckStatus getRequiredCheckStatus()
get the required status level for the class to compute its check.
Definition: MultiAgentHandOvers.h:164
This class holds a the robot represented by a kinematic chain.
Definition: robot.hpp:42
virtual FrontierCells::FrontierCheckStatus getCheckStatusLevel()
get the status level that the class provides.
Definition: MultiAgentHandOvers.h:289
The AbstractHandOverTest class is an abstract class providing the basic interface for a handover/fron...
Definition: MultiAgentHandOvers.h:15
virtual FrontierCells::FrontierCheckStatus getCheckStatusLevel()=0
get the status level that the class provides.
Definition: MultiAgentHandOvers.h:244
The FrontierTester class is a unique interface for all available/desired handover/frontier testers...
Definition: MultiAgentHandOvers.h:60
virtual FrontierCells::FrontierCheckStatus getCheckStatusLevel()
get the status level that the class provides.
Definition: MultiAgentHandOvers.h:220
Definition: MultiHandOverUtils.hpp:92
virtual FrontierCells::FrontierCheckStatus getCheckStatusLevel()
get the status level that the class provides.
Definition: MultiAgentHandOvers.h:182
Definition: trajectory.hpp:40
void timeLimit(double time_limit_ms)
sets the time limit for the motion planner, in milliseconds
Definition: MultiAgentHandOvers.h:118
The HandOverTestGrabs class tests if a grab conf exists for both agent to grasp the object...
Definition: MultiAgentHandOvers.h:194
The HandOverTestObject class tests if ha handover is correct regarding to the object.
Definition: MultiAgentHandOvers.h:175
Definition: MultiAgentHandOvers.h:261
Plannar HRI Cell.
Definition: HRICS_MultiAgentGrid.hpp:462
virtual FrontierCells::FrontierCheckStatus getRequiredCheckStatus()
get the required status level for the class to compute its check.
Definition: MultiAgentHandOvers.h:270
virtual FrontierCells::FrontierCheckStatus getCheckStatusLevel()
get the status level that the class provides.
Definition: MultiAgentHandOvers.h:201
virtual FrontierCells::FrontierCheckStatus getRequiredCheckStatus()
get the required status level for the class to compute its check.
Definition: MultiAgentHandOvers.h:221
The AbstracHandOverObjectCheck class is an abstract class providing tools to check the possibility of...
Definition: MultiAgentHandOvers.h:106
virtual FrontierCells::FrontierCheckStatus getRequiredCheckStatus()
get the required status level for the class to compute its check.
Definition: MultiAgentHandOvers.h:183
Definition: ConfGenerator.h:51
virtual FrontierCells::FrontierCheckStatus getCheckStatusLevel()
get the status level that the class provides.
Definition: MultiAgentHandOvers.h:251
Definition: MultiAgentHandOvers.h:282
Definition: Chronometer.hpp:9
virtual FrontierCells::FrontierCheckStatus getRequiredCheckStatus()
get the required status level for the class to compute its check.
Definition: MultiAgentHandOvers.h:47