libmove3d-planners
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Groups Pages
HRICS_MultiHandOver.h
1 #ifndef HRICS_HRICS_MULTIHANDOVER_H
2 #define HRICS_HRICS_MULTIHANDOVER_H
3 
4 #include "HRICS_Workspace.hpp"
5 #include <vector>
6 #include "planner/planner.hpp"
7 #include "utils/multiHandOver/SimpleGraph.h"
8 #include "Grid/HRICS_MultiAgentGrid.hpp"
9 //#include "utils/MultiHandOverUtils.hpp"
10 #include "utils/MultiHandOverAlgos.h"
11 #include "utils/MultiHandOverDisplay.h"
12 #include "Logging/Logger.h"
13 
14 namespace HRICS {
15 
17 {
18  MOVE3D_STATIC_LOGGER;
19 public:
20 
21  //typedef HRICS::MultiHandOverSolution MultiHandOverSolution;
22  typedef enum {NONE,RANDOM_SEARCH,LWA_SEARCH,WA_SEARCH} SearchAlgo_t;
23 
24  MultiHandOver(double cell_size=0.20);
25  virtual ~MultiHandOver();
26 
27  void testForReinit();
28  void createGrid();
29  void dumpVar();
30  void setDefaultEnvVar(void);
31  bool initFromConfXML(std::istream &is);
32  bool initFromConfXML(std::string path);
33 
37  void initToolSet();
38  MHO::ToolSet* getToolSet(){return this->_tool_set;}
42  void setDefaultHandOverTesters(std::vector<std::string> &some_defaults){this->_handover_testers_defaults_set=some_defaults;}
44  unsigned int runScriptFromEnvVar();
46  unsigned int runScript(std::string filename);
47  unsigned int run();
48 
52  unsigned int findAgents();
54  void fetchAgentsConfsInitGoTo();
55  unsigned int findManipulableObjects();
56  unsigned int computeAgentsGraph(void);
57  void initGrid(void);
58  void computeGrid(void);
59  void computeFrontiers(void){_grid->searchAllFrontiers();_progression_state=FRONTIERS_DISTANCE;}
62  void resetAgentsConf(void);
63  void resetManipulablesConf(void);
64 
65  Configuration getAgentTargetConf(unsigned int a);
67  MultiAgentCell* getAgentTargetCell(unsigned int a);
68 
69  Configuration getAgentInitConf(unsigned int a);
70  MultiAgentCell* getAgentInitCell(unsigned int a);
71 
72  void setToComputeHOTraj(bool activate,int solution=-1,int step=0);
73  void computeLongestSolutionDistance();
86  unsigned int computeRawSolutions(float cost_majoration);
87  void clearSolutions(void);
88  void insert_solution_sorted(MHO::MultiHandOverSolution* sol);
89 
101  void searchSolutionLWAstar(bool no_lazy);
102 
103  void postProcessSolution(MHO::MultiHandOverSolution *sol);
113  void searchSolutions(void);
114  bool handOverPossible(unsigned int a1, unsigned int a2);
122  bool handOverFindConfs(MHO::MultiHandOverSolution * solution, int frontier_index=-1);
123  bool handOverFindConfs(FrontierPtr frontier);
124  MHO::MultiHandOverSolution* changeHandOverSolution( MHO::MultiHandOverSolution * solution);
132  double computeNavigationTrajectories(MHO::MultiHandOverSolution * solution, int action_index=-1);
133  void computeHandOverTrajectory(MHO::MultiHandOverSolution * solution, int step=-1);
134  void computeSubTaskTrajectory(MHO::SubTask* sub_task);
135  MHO::MultiHandOverSolution* optimizeSolution(MHO::MultiHandOverSolution *solution);
167  MHO::MultiHandOverSolution* optimizeFrontier(MHO::MultiHandOverSolution *solution, unsigned int action_index, double keep_distance, double min_distance);
168 
180 
181  double navigationRelatedCost(double dist,unsigned int agent);
182  double navigationRelatedCostTime(double dist,unsigned int agent,double &time);
183  double computeSolutionCost(MHO::MultiHandOverSolution * solution);
184 
185  bool getSolutionDataForMHP(std::vector<MHO::MultiHandOverMhpHO> &hand_overs,std::vector<Eigen::Vector3d, Eigen::aligned_allocator<Eigen::Vector3d> > &path, double &cost, double &duration, std::string &main_agent_name);
186 
194  MHO::MultiHandOverSolution * getLowCostRandomSolution(double sigma, int *index=0);
195 
199 
202  typedef enum {DIST_BEST_AGENT =0, BEST_HANDOVER_SERIES} AStarHeuristic_t;
203  void setAstarHeuristic(MultiHandOver::AStarHeuristic_t heuristic){_a_star_heuristic = heuristic;}
204  AStarHeuristic_t getAstarHeuristic(void){return _a_star_heuristic;}
205  void setSearchAlgo(MultiHandOver::SearchAlgo_t algo){_search_algo=algo;}
206  MultiHandOver::SearchAlgo_t getSearchAlgo(){return _search_algo;}
207  double getEpsilonForLWAstar(){return _epsilon;}
209  void setGridCellSize(double size){_cellSize=size;}
210  double getGridCellSize(void){return _cellSize;}
211  void setEpsilonForLWAstar(double e){this->_epsilon=std::max(1.,e);}
212  void setCostsFactors(double dist, double time, double agent_costs, double hri){ _f_dist=dist;_f_time=time;_f_agent_cost=agent_costs;_f_hri=hri;}
213  void getCostsFactors(double &dist, double &time, double &agent_costs, double &hri){ dist=_f_dist;time=_f_time;agent_costs=_f_agent_cost;hri=_f_hri;}
214 
215  void setSearchSolutionStopCondition(int max_it,int overheat,int time_limit_ms){ _max_iterations=max_it;_overheat_temperature=overheat;_time_limit=time_limit_ms;}
216  void getSearchSolutionStopCondition(int &max_it,int &overheat,int &time_limit_ms){ max_it=_max_iterations;overheat=_overheat_temperature;time_limit_ms=_time_limit;}
217 
218  FrontierCells::FrontierCheckStatus getFrontierMaxCheckStatus(){return _max_frontier_check_status;}
219  void setFrontierMaxCheckStatus(FrontierCells::FrontierCheckStatus fcs){_max_frontier_check_status = fcs;}
220 
221  const std::vector<Robot*>& getAgents(void){return this->_agents;}
222  const std::vector<Robot*>& getManipulableObjects(void){return this->_manipulable;}
223 
226  MHO::MultiHandOverAgent *getAgentStruct(unsigned int a){return &_mho_agents[a];}
227 
228  void setFirstAgent(Robot* f){_first_agent=f;setFirstAgentNode();}
229  Robot* getFirstAgent(void){return _first_agent;}
230  void setTargetAgent(Robot* f){_target_agent=f;setTargetAgentNode();}
231  Robot* getTargetAgent(void){return _target_agent;}
232  void setTargetAgent(std::string name);
233  void setFirstAgent(std::string name);
234  void setTargetAgent(p3d_rob* rob);
235  void setFirstAgent(p3d_rob* rob);
236  void setRandomizeFirstTarget(bool b){_random_first_target_agents=b;}
237  void setObject(unsigned int i){setObject(_manipulable[i]);}
238  void setObject(Robot* obj){_object=obj;_object_bb_vects.clear();}
239  Robot *getObject(){return _object;}
240  void setObject(p3d_rob* obj);
241 
242  bool usePostProcess(){return this->_use_post_process;}
243  void usePostProcess(bool b){this->_use_post_process=b;}
244 
245  void setFirstAgentNode(void);
246  void setTargetAgentNode(void);
247 
249 
253  void setAgentUseCost(unsigned int i,double cost){this->_mho_agents[i].use_cost=cost;}//this->_agents_use_costs[i]=cost;}
255  double getAgentUseCost(unsigned int i){return this->_mho_agents[i].use_cost;}//this->_agents_use_costs[i];}
256  double getAgentUseCost(Robot * r);
257  //std::vector<double> const & getAgentUseCost(){return this->_agents_use_costs;}
258  //void setAgentUseCost(std::vector<double> const & costs){this->_agents_use_costs=costs;}
259  void setAgentSpeed(unsigned int i, double speed){this->_mho_agents[i].speed=speed;}//this->_agents_speeds[i]=speed;}
260  double getAgentSpeed(unsigned int i){return this->_mho_agents[i].speed;}//this->_agents_speeds[i];}
261  bool isHuman(unsigned int i){return this->_mho_agents[i].is_human;}
262  //std::vector<double> const & getAgentsSpeeds(){return this->_agents_speeds;}
263  //void setAgentsSpeeds(std::vector<double> const & speeds){this->_agents_speeds=speeds;}
264 
265  double getTimeHO(unsigned int a1,unsigned int a2);
266  void setTimesHO(double rr,double hh,double rh){_r_r_ho_time=rr;_r_h_ho_time=rh;_h_h_ho_time=hh;}
267 
269 
270 
273 
274  void setCheckFrontierBefore(bool b){this->_check_frontier_before=b;}
275  bool getCheckFrontiersBefore(void){return this->_check_frontier_before;}
276 
282  void setUseRrtInFrontierCheck(bool b){_use_rrt_for_frontier_check=b;}
283  void setUseDummySmoothInFrontierCheck(bool b){_use_dummy_smooth_for_frontier_check=b;}
284  double getShoulderHeight(unsigned int agent);
285  Eigen::Vector3d getObjectMainDirection(void);
286  Configuration confForBBAxisAlign(Robot * object, Eigen::Vector3d const & main_dir, Eigen::Vector3d const & second_dir);
287 
295  void setOrientationObjectForHO(Eigen::Vector3d &dir1);
296  void checkAllMetaFrontiersWithObject(void);
297  bool checkMetaFrontiersWithObject(unsigned int a1,unsigned int a2);
298  bool checkMetaFrontierWithObject(unsigned int a1,unsigned int a2,MetaFrontierPtr mf);
308  bool randomCheckFrontiersWithObject(std::tr1::shared_ptr<FrontierCells> & frontier_found, unsigned int a1, unsigned int a2,unsigned int max_it);
322  bool checkFrontierWithObject(FrontierCells &frontier);
324 
328  void printSolutionsForest(void);
330  void printMainTimes(std::vector<double> times);
331  void printLWAStats();
332 
333  void setAgentIndexToDrawGrid(unsigned int index){
334  if(_grid) this->_grid->setAgentIndexToDrawGrid(index);
335  }
336 
337  void setDrawAgentAccessibilityGrid(bool b,bool boundariesOnly=false){if(_grid) this->_grid->setDrawAgentAccessibilityGrid(b,boundariesOnly);}
338  void setDrawFrontiers(bool b,unsigned int i=0,unsigned int j=0){if(_grid) _grid->setDrawFrontiers(b,i,j);}
339 
340  void drawObjectWhenFrontierChecking(bool b){_draw_object_frontiers_checks=b;}
341  void setDrawAgentsDuringSearch(bool b){_draw_agents_holding_conf_during_search=b;}
342  void setDraw2dPaths(bool b){_draw_2d_path=b;}
343  void setDrawAll2dPaths(bool b){_draw_all_2d_pathes=b;}
344  void setDrawLWA(bool b){_draw_lwa=b;if(_display_lwa_in_grid_obj){_display_lwa_in_grid_obj->setDraw(b);}}
345 
346  MHO::MultiHandOverSolution::CostData getSolutionDataStudio(int solution);
354  double setSolutionStepRobotsConfs(int solution, int step, MHO::MultiHandOverSolution::CostData &cost_data);
355  void getConfHandOver(int solution, int step, std::string robot_name, confPtr_t &conf);
356  void draw2dPath(void);
357  void draw2dPath(std::vector<MultiAgentCell*> const & path, int color_id, bool alt=false);
361 #ifdef DRAW_OPTIMIZE_FRONTIER
362  void setDrawOptimizeFrontier(bool b){_draw_optimize_frontier=b;}
363 #else
364  void setDrawOptimizeFrontier(bool b){if(_showText){std::cout<<"DRAW_OPTIMIZE_FRONTIER macro not defined";}}
365 #endif
366 
367  void playTaskStepByStep(MHO::Task* task);
368  void playSolutionTrajSync(MHO::Task *task);
369  bool playSolutionTaskSyncStep(int solution=-1);
370  void computeTaskTrajs(MHO::Task* task);
371  void setSubTaskTrajToRobot(MHO::SubTask* subtask);
372  void playSolutionTask(int solution);
373  void setPlaySolutionTask(int solution);
374  void setPlaySolutionTaskTraj(int solution);
375  void setPlaySolutionSyncStepByStep(int solution);
376  bool isEndPlaySolutionTaskTraj();
378 
379  MultiAgentGrid *getPlanGrid(void){return _grid;}
380 
381 
382 
383 private:
384 
385  enum {INIT, FRONTIERS_DISTANCE,FRONTIERS_OBJECT_PATH,END} _progression_state;
386  std::vector<MHO::MultiHandOverAgent> _mho_agents;
387  std::vector<Robot*> _agents;
388  std::vector<Robot*> _manipulable;
389  mho::SimpleGraph _agents_frontiers_dist_graph;
390  std::vector<mho::Node*> _agents_nodes;
391 
392  double _r_r_ho_time,_r_h_ho_time,_h_h_ho_time;
393 
394  double _f_dist,_f_time,_f_agent_cost,_f_hri;
395  double _max_dist, _max_time,_max_use_cost;
396 
397  bool _use_rrt_for_frontier_check;
398  bool _use_dummy_smooth_for_frontier_check;
399 
400  bool _check_frontier_before;
401 
402  // ///// //////////////////////////////
403  // ///// FOR STATS //////////////////
404  // ///// //////////////////////////////
405  enum STAT_FIELDS {SF_OK,SF_COST,SF_COST_LWA,
406  SF_AGENT_FROM, SF_AGENT_TO,
407  SF_EPSILON,SF_TIME_FACT,SF_AGENT_FACT,SF_HRI_FACT,SF_DIST_FACT,
408  SF_TIME_TOT,SF_TIME_LWA,SF_TIME_POSTPROC,
409  SF_TMP_COST_NB, SF_TMP_COST_MEAN, SF_TMP_COST_STDEV,
410  SF_TRUE_COST_NB, SF_TRUE_COST_MEAN, SF_TRUE_COST_STDEV,
411  SF_HO_COST_NB, SF_HO_COST_MEAN, SF_HO_COST_STDEV,
412  SF_HEURISTIC_NB, SF_HEURISTIC_MEAN, SF_HEURISTIC_STDEV,
413  SF_AGENT_NB,SF_HO_NB,SF_OBJ_DIST,SF_EXEC_TIME,// < stats about the solution
414  SF_SIZE};
415  std::vector< std::vector < double > > _lwa_stats;
416 
417 
418  FrontierCells::FrontierCheckStatus _max_frontier_check_status;
419  MHO::ToolSet *_tool_set;
420  std::vector<std::string> _handover_testers_defaults_set;
421 
422  std::vector<Configuration> _agents_init_confs;
423  std::vector<Configuration> _agents_target_confs;
424  std::vector<Configuration> _manipulables_init_confs;
425 
426  Robot *_first_agent;
427  Robot *_target_agent;
428  bool _random_first_target_agents;
429  Robot *_object;
430  std::vector<Eigen::Vector3d> _object_bb_vects;
431  std::vector<int> _object_directions_sorted_for_ho;
432  mho::Node *_first_agent_node;
436  mho::Node *_target_agent_node;
437 
438  vector<pair<double,vector<mho::NodeInterface*> > > _raw_solution;
439 
440  bool _use_post_process;
441 
442  std::vector<MHO::MultiHandOverSolution*> _solutions;
443  std::vector<MHO::Task*> _solutions_as_tasks;
444  MHO::MultiHandOverSolution * _best_solution;
445  //solution search parameters
446  SearchAlgo_t _search_algo;
447  AStarHeuristic_t _a_star_heuristic;
448  //for LWA*
449  double _epsilon;
450  //for random search
451  int _time_limit;
452  int _max_iterations;
453  int _overheat_temperature;
454 
455  bool _first_run;
456  bool _compute_for_all_robots;
457  bool _compute_traj_only;
458  MHO::MultiHandOverSolution * _solution_to_compute_traj;
459  unsigned int _step_to_compute_traj;
460 
461  //GRID
462  HRICS::MultiAgentGrid * _grid;
463  double _cellSize;
464 
465  bool _showText;
466  bool _draw_object_frontiers_checks;
467  bool _draw_agents_holding_conf_during_search;
468  bool _draw_2d_path;
469  unsigned int _solution_index_to_draw;
470  unsigned int _solution_step_index_to_draw;
471  bool _play_solution_task;
472  bool _play_solution_task_traj;
473  bool _play_solution_sync_step_by_step;
474  bool _draw_all_2d_pathes;
475  bool _draw_lwa;
476  MHO::DisplayLWAstarInGrid* _display_lwa_in_grid_obj;
477  MHO::MultiHandOverDisplay *_mho_display;
478 #ifdef DRAW_OPTIMIZE_FRONTIER
479  bool _draw_optimize_frontier;
480 #endif
481 };
482 
483 } // namespace HRICS
484 
485 #endif // HRICS_HRICS_MULTIHANDOVER_H
double computeNavigationTrajectories(MHO::MultiHandOverSolution *solution, int action_index=-1)
computeNavigationTrajectories
Definition: HRICS_MultiHandOver.cpp:1792
*faster but not conservative *void setUseRrtInFrontierCheck(bool b)
to use an RRT on the object as free flyer to check frontier or not.
Definition: HRICS_MultiHandOver.h:282
MHO::MultiHandOverAgent * getAgentStruct(unsigned int a)
the MHO::MultiHandOverAgent corresponding to agent ID a
Definition: HRICS_MultiHandOver.h:226
Definition: HRICS_MultiHandOver.h:16
Definition: SimpleGraph.h:19
MultiAgentCell * getAgentTargetCell(unsigned int a)
returns 0 if have_final_position is set to false for that agent, a ptr to the cell otherwise...
Definition: HRICS_MultiHandOver.cpp:928
The ToolSet class bundles other tool classes and provides utilities to configure them easily...
Definition: MultiHandOverAlgos.h:67
void initToolSet()
Initialize the tool set for algorithm acording to the settings.
Definition: HRICS_MultiHandOver.cpp:321
bool randomCheckFrontiersWithObject(std::tr1::shared_ptr< FrontierCells > &frontier_found, unsigned int a1, unsigned int a2, unsigned int max_it)
check frontiers with object, stop when one if found to be OK, or max_it checks are made ...
Definition: HRICS_MultiHandOver.cpp:1213
unsigned int run()
Run function.
Definition: HRICS_MultiHandOver.cpp:656
void resetAgentsConf(void)
reset the agents to their initial configuration
Definition: HRICS_MultiHandOver.cpp:902
unsigned int runScriptFromEnvVar()
reads the environment variable $MOVE3D_SCRIPT to get a script/conf file to execute ...
Definition: HRICS_MultiHandOver.cpp:467
Plannar HRI Grid considering multiple agents systems for HRi operations.
Definition: HRICS_MultiAgentGrid.hpp:28
MultiAgentCell * findOptimalCellNullDistanceFrontier(MHO::MultiHandOverSolution *solution, unsigned int action_index)
optimalCellNullDistanceFrontier
Definition: HRICS_MultiHandOver.cpp:1719
This class holds a the robot represented by a kinematic chain.
Definition: robot.hpp:42
MHO::MultiHandOverSolution * getLowCostRandomSolution(double sigma, int *index=0)
get a randomly selected solution, most probably with low cost
Definition: HRICS_MultiHandOver.cpp:2113
This file implements macros to help with the logging, in a way similar to ROS, using log4cxx...
bool handOverFindConfs(MHO::MultiHandOverSolution *solution, int frontier_index=-1)
handOverFindConfs
Definition: HRICS_MultiHandOver.cpp:1526
Definition: MultiHandOverUtils.hpp:92
The MultiHandOverHeuristic class provides an heuristic based on euclidian distance and minimal cost b...
Definition: MultiHandOverUtils.hpp:482
unsigned int runScript(std::string filename)
reads the given script and execute it
Definition: HRICS_MultiHandOver.cpp:478
double setSolutionStepRobotsConfs(int solution, int step, MHO::MultiHandOverSolution::CostData &cost_data)
set the robots to their conf computed in searchSolutions() for the given solution and step ...
Definition: HRICS_MultiHandOver.cpp:2989
Plannar HRI Cell.
Definition: HRICS_MultiAgentGrid.hpp:462
MHO::MultiHandOverSolution * optimizeFrontier(MHO::MultiHandOverSolution *solution, unsigned int action_index, double keep_distance, double min_distance)
optimize a frontier in a solution to minimize the cost.
Definition: HRICS_MultiHandOver.cpp:1703
Definition: MultiHandOverUtils.hpp:141
void setOrientationObjectForHO(Eigen::Vector3d &dir1)
set the orientation of the object for a handover
Definition: HRICS_MultiHandOver.cpp:1308
unsigned int computeRawSolutions(float cost_majoration)
compute possible handover successions
Definition: HRICS_MultiHandOver.cpp:1099
Classe représentant une Configuration d'un Robot.
Definition: configuration.hpp:25
void setDrawOptimizeFrontier(bool b)
sets the option of drawing the frontier optimization process as 2D cells representing the frontier cu...
Definition: HRICS_MultiHandOver.h:362
Definition: MultiHandOverUtils.hpp:248
void setGridCellSize(double size)
set the cell size for discretisation step in the grid
Definition: HRICS_MultiHandOver.h:209
void searchSolutionLWAstar(bool no_lazy)
searchSolutionLWAstar
Definition: HRICS_MultiHandOver.cpp:2382
bool checkFrontierWithObject(FrontierCells &frontier)
checkFrontierWithObject
Definition: HRICS_MultiHandOver.cpp:1328
MHO::MultiHandOverHeuristic * createAstarHeuristic(void)
returns a pointer to newly created Heuristic class for main A* search.
Definition: HRICS_MultiHandOver.cpp:359
void searchSolutions(void)
The core function of this class, it search for an optimal solution.
Definition: HRICS_MultiHandOver.cpp:2188
Definition: Node.h:14
AStarHeuristic_t
available heuristic types for [L][W]A*
Definition: HRICS_MultiHandOver.h:202
Base class for the HRICS motion planners.
Definition: HRICS_Workspace.hpp:37