1 #ifndef MULTIHANDOVERUTILS_HPP
2 #define MULTIHANDOVERUTILS_HPP
7 #include "API/Device/robot.hpp"
8 #include "HRI_costspace/Grid/HRICS_MultiAgentGrid.hpp"
9 #include "multiHandOver/LazyWAstar.h"
10 #include "multiHandOver/SimpleGraph.h"
13 #include "utils/multiHandOver/graphAlgorithms.h"
16 #include "GTP/taskManagerInterface.hpp"
26 class AbstractSolutionTools;
27 class AbstracHandOverObjectCheck;
44 virtual void draw() {}
45 virtual void resetdisp() {}
87 bool configure_from_xml(std::istream & is);
98 std::string shortname;
108 bool have_final_position;
116 bool grabConfIK(configPt &q, confPtr_t robotPos,
const Eigen::Vector3d & grab_point);
126 bool grabConfCheck(configPt &q,
const Eigen::Vector2d robot_pos,
const Eigen::Vector3d & grab_point);
127 bool grabConfIK_human(configPt &q, confPtr_t
const humanPos, Eigen::Vector3d
const & grab_point);
129 bool computeHandOverTrajectory(confPtr_t q_start,confPtr_t q_end);
131 bool computeTrajectory(confPtr_t start_conf,confPtr_t nav_conf, std::vector<Eigen::Vector2d,Eigen::aligned_allocator<Eigen::Vector2d> >
const& path2d, confPtr_t end_conf);
132 bool computePath2dToPath3dShortCut(std::vector<Eigen::Vector2d,Eigen::aligned_allocator<Eigen::Vector2d> >
const& path2d, std::vector<Eigen::Vector3d,Eigen::aligned_allocator<Eigen::Vector3d> > &path3d );
151 static void checkI(
unsigned int i){
if(i>1){
throw(std::invalid_argument(
"argument must be 0 or 1"));}}
154 Robot* robot(
unsigned int i){checkI(i);
return _s->
agents[_f+i]->robot;}
156 std::vector<MultiAgentCell*> & path(
unsigned int i){ checkI(i);
return _s->
navigation_trajs[_f*2+i];}
157 void setPath(
unsigned int i,std::vector<MultiAgentCell*> &path){ checkI(i); _s->
navigation_trajs[_f*2+i]=path;}
162 double dist(
unsigned int i){
return (i<2 ? _s->
nav_dists[_f*2+i]: -1 );}
163 void setDist(
unsigned int i,
double d){(i<2 ? _s->
nav_dists[_f*2+i]=d: -1 );}
164 double startDate(
unsigned int i){checkI(i);
return _s->
nav_start_dates[_f*2+i];}
165 void setStartDate(
unsigned int i,
double date_s){checkI(i); _s->
nav_start_dates[_f*2+i]=date_s;}
170 double navTime(
unsigned int i){checkI(i);
return _s->
nav_times[_f*2+i];}
171 void setNavTime(
unsigned int i,
double time_s){checkI(i); _s->
nav_times[_f*2+i] = time_s;}
172 Configuration & initQ(
unsigned int i){checkI(i);
return _s->initial_confs[_f+i];}
173 FrontierPtr frontier(){
return _s->
frontiers[_f];}
174 MultiHandOverSolution* getSolution(
void){
return _s;}
175 confPtr_t objectPos();
176 confPtr_t agentConf(
unsigned int i);
179 CostData():dist(-1),time(-1),use_cost(-1),handover_cost(-1),handovers(0),marker_is_opt(0),agent_names(0){}
184 double handover_cost;
185 unsigned int handovers;
186 unsigned int go_to_target_nb;
188 std::vector<std::string> agent_names;
194 unsigned int getId(
void){
return _id;}
195 bool addHandOverAction(FrontierPtr frontier);
197 double getTotalDist();
198 double getTotalUseCost();
204 std::vector<Configuration> initial_confs,target_confs;
207 std::vector<Action> actions;
208 std::vector<std::tr1::shared_ptr<FrontierCells> >
frontiers;
224 std::vector<double> nav_dists_to_target;
231 std::string print_long();
234 std::vector<MultiHandOverSolution*> sons;
240 static void printFamiliesTrees(std::vector<MultiHandOverSolution*> &solutions, std::ofstream &output);
241 static void resetID(
void){MultiHandOverSolution::_current_id=0;}
243 static unsigned int _current_id;
250 typedef enum {UNDEF=0, HO_GIVE, HO_GET, NAV_WITH_OBJ, NAV_TO_HO, NAV_TO_TARGET, NAV_SYNC, NAV_OTHER,IDLE} TaskType_t;
259 typedef enum {IS_2D=0, HAS_FULL_TRAJ, COMPLETED, RUNNING, SIZE} MarkerList_t;
265 bool getMarker(MarkerList_t m);
266 void setMarker(MarkerList_t m,
bool b);
268 TaskType_t type()
const ;
271 bool isManip()
const ;
276 void extendToEndDate(
double new_end_date);
277 void extendDuration(
double new_duration);
278 void replan(
double new_begin);
283 std::vector<confPtr_t> & waypoints();
284 std::vector<Eigen::Vector2d> & waypoints2d();
285 void addWaypoint(confPtr_t q);
286 void addWaypoint(Eigen::Vector2d v,
double date=-numeric_limits<double>::infinity());
287 std::vector<double> & waypointDates();
290 void spreadIdlePositionToNext();
292 void addPrevious(
SubTask* prev);
294 std::vector<SubTask*> & getPrev(){
return this->prev;}
295 std::vector<SubTask*> & getNext(){
return this->next;}
296 void substitutePrev(SubTask *prev,SubTask *new_prev);
297 void substituteNext(SubTask *next,SubTask *new_next);
299 unsigned int getId(){
return this->_id;}
300 static bool compareLessBeginDate(SubTask &t1,SubTask &t2){
return t1.beginDate() < t2.beginDate();}
301 static bool compareLessBeginDatePtr(SubTask *t1,SubTask *t2){
return t1->beginDate() < t2->beginDate();}
303 static std::string typeString(SubTask::TaskType_t t);
310 double _begin_date,_end_date;
313 MultiHandOverAgent *_agent;
314 std::vector<confPtr_t> _wp;
315 std::vector<Eigen::Vector2d> _2d_wp;
316 std::vector<double> _dates_wp;
319 std::vector<SubTask*> prev;
320 std::vector<SubTask*> next;
322 std::vector<bool> _markers;
325 static unsigned int _count_id;
335 std::map<MHO::MultiHandOverAgent*,Eigen::Vector2d> & state();
342 bool _is_end_iterator;
344 std::map<MHO::MultiHandOverAgent*,Eigen::Vector2d> _state_current;
346 std::map<MHO::SubTask*,pair<int, double> > _trak;
347 std::map<MHO::SubTask*,pair<int, double> > _next;
348 std::map<MHO::MultiHandOverAgent*,MHO::SubTask*> _sub_task;
354 std::vector<HRICS::MHO::MultiHandOverAgent*>
const & getAgents();
355 std::vector<SubTask *>
const & getSubTasks();
356 void addSubTask(
SubTask* st,
bool no_sort=
false);
370 void fillWithIdle(map<MultiHandOverAgent *, MultiAgentCell *> &state_begin);
373 void refineHandOvers();
376 void setObject(
Robot* obj){_object=obj;}
377 Robot *getObject(){
return _object;}
380 std::vector<SubTask*> _sub_tasks;
381 vector<MultiHandOverAgent*> _agents;
390 std::string robotname;
391 std::vector<int> nexts;
394 std::vector<confPtr_t> wp;
395 SubTask::TaskType_t type;
404 enum {ARM_LEFT,ARM_RIGHT,ARM_UNDEF}
g_arm;
411 std::vector<double> r_arm_conf;
433 double humanRobotDistanceRelatedCost();
436 double getCost(
void)
const;
437 void setCost(
double cost);
438 double getTime(
void)
const;
439 void setTime(
double time_sec);
441 Robot* robot(
unsigned int i);
466 FrontierPtr findFrom2Points();
472 unsigned int _agent1,_agent2;
497 std::vector<double> getTimes(){
return _times;}
503 mho::Node* getAgentNode(
unsigned int i){
return _agents_nodes[i];}
507 std::vector<mho::Node*> _agents_nodes;
510 std::vector<double> _times;
541 Eigen::Vector2d findMinimalFrontier2pt(Eigen::Vector2d c1,
double f1, Eigen::Vector2d c2,
double f2);
542 Eigen::Vector2d findMinimalFrontier3pt(Eigen::Vector2d ci,Eigen::Vector2d cg,
double f1, Eigen::Vector2d c2,
double f2);
543 Eigen::Vector2d findMinimalFrontier4pt(Eigen::Vector2d c1i,Eigen::Vector2d c1g,
double f1, Eigen::Vector2d c2i, Eigen::Vector2d c2g,
double f2);
548 MOVE3D_STATIC_LOGGER;
553 virtual LWANodeInterface *clone();
555 std::vector<LWANodeInterface*> sons();
557 virtual void g(
double g);
558 virtual double computeEndDate();
561 virtual double edgeCostEstimationFrom(LWANodeInterface *parent);
562 virtual double computeHeuristic(LWANodeInterface *goal);
563 virtual double computeTrueCost(LWANodeInterface *parent);
564 virtual bool isSameConf(LWANodeInterface *other);
570 unsigned int agent(){
return _agent;}
571 void agent(
unsigned int a){_agent=a;}
573 LWANodeInterface* parent(){
return mho::LWANodeBase::parent();}
580 std::vector<bool> _agents_in_parents;
581 double _time,_last_computed_time,_last_computed_cost;
594 void onEnd(std::vector<pair<unsigned int,double> > times);
595 void setDraw(
bool b){_draw=b;}
596 std::vector<std::pair<unsigned int,double> > getTimes();
600 bool _marker_is_first_call;
601 bool _showText,_draw;
602 std::vector<MultiAgentCell*> _cells;
604 double count_open,count_closed;
605 std::vector<std::pair<unsigned int,double> > _times;
610 #endif // MULTIHANDOVERUTILS_HPP
std::string r_name
receiver agent name
Definition: MultiHandOverUtils.hpp:408
Definition: graphAlgorithms.h:39
double reach()
the reach distance of the arm of the agent. -inf if not set/known
Definition: MultiHandOverUtils.cpp:234
giver open gripper
Definition: MultiHandOverUtils.hpp:254
The MultiHandOverMhpHO struct defines data for a handover to be exported in MHP.
Definition: MultiHandOverUtils.hpp:399
receiver close gripper
Definition: MultiHandOverUtils.hpp:255
Eigen::Vector3d obj_pose
object 3D position (x,y,z)
Definition: MultiHandOverUtils.hpp:413
The SubTaskMHP struct is to pass results to MHP as simplified SubTask.
Definition: MultiHandOverUtils.hpp:388
void fillWithIdle(map< MultiHandOverAgent *, MultiAgentCell * > &state_begin)
create new IDLE sub tasks when needed manages previous/next relations
Definition: MultiHandOverUtils.cpp:1375
virtual double compute(MultiAgentCell *c1, unsigned int a1, MultiAgentCell *c2, unsigned int a2)
compute
Definition: MultiHandOverUtils.cpp:1832
Definition: HRICS_MultiHandOver.h:16
Definition: MultiHandOverUtils.hpp:143
Definition: SimpleGraph.h:19
MultiAgentCell * to(unsigned int i)
the cell the agent goes to for the next action, if any, 0 otherwise
Definition: MultiHandOverUtils.hpp:161
Eigen::Vector3d g_pose
giver 3d pose (x,y,theta)
Definition: MultiHandOverUtils.hpp:403
virtual double findMinimalFrontier(MultiAgentCell *c1i, MultiAgentCell *c1g, unsigned int a1, MultiAgentCell *c2i, MultiAgentCell *c2g, unsigned int a2)
findMinimalFrontier searches for the frontier between a1 and a2 that minimizes the distance agents ha...
Definition: MultiHandOverUtils.cpp:1994
The ConfigFileParser class parses a stream representing data as an XML file.
Definition: MultiHandOverUtils.hpp:83
bool grabConfCheck(configPt &q, const Eigen::Vector2d robot_pos, const Eigen::Vector3d &grab_point)
given a 2D position for the robot and a 3d position for the object, find a free grabing conf ...
Definition: MultiHandOverUtils.cpp:369
Definition: MultiHandOverUtils.hpp:586
giver disengage its arm
Definition: MultiHandOverUtils.hpp:256
Plannar HRI Grid considering multiple agents systems for HRi operations.
Definition: HRICS_MultiAgentGrid.hpp:28
virtual bool isAgentAlreadyUsed()
returns true if the agent is used by the ancestors of this
Definition: MultiHandOverUtils.cpp:2170
double time
the estimation of the execution time of the plan
Definition: MultiHandOverUtils.hpp:201
receiver extends arm to reach object
Definition: MultiHandOverUtils.hpp:253
friend std::ostream & operator<<(std::ostream &os, const MultiHandOverSolution &sol)
a marker for debug
Definition: MultiHandOverUtils.cpp:726
void plotGanttChart()
use gnuplot to plot the gantt chart of the task (create new independent process/window) ...
Definition: MultiHandOverUtils.cpp:1270
std::vector< double > avail_delay
estimation of the time each agent have to start its plan
Definition: MultiHandOverUtils.hpp:210
This class holds a the robot represented by a kinematic chain.
Definition: robot.hpp:42
The MultiHandOverHO class describes a hand over, and implements method to compute costs and improve a...
Definition: MultiHandOverUtils.hpp:425
MultiAgentCell * from(unsigned int i)
the cell the agent come from (previous action position, if any, 0 otherwise)
Definition: MultiHandOverUtils.hpp:159
Definition: LazyWAstar.h:69
Definition: MultiHandOverUtils.hpp:547
double cost
the cost (estimated) of the solution
Definition: MultiHandOverUtils.hpp:200
Definition: MultiHandOverUtils.hpp:461
double shoulderHeight()
return the shoulder height
Definition: MultiHandOverUtils.cpp:242
std::vector< MultiHandOverAgent * > agents
list of agents used (in the order they have the object)
Definition: MultiHandOverUtils.hpp:206
giver extends arm
Definition: MultiHandOverUtils.hpp:252
This file implements macros to help with the logging, in a way similar to ROS, using log4cxx...
std::vector< std::vector< MultiAgentCell * > > navigation_trajs
the navigation trajectories.
Definition: MultiHandOverUtils.hpp:219
void displayGraph()
uses graphviz (dot) to display the (directed) graph representing the time constraints of the task nod...
Definition: MultiHandOverUtils.cpp:1314
virtual double compute(MultiAgentCell *c1, unsigned int a1, MultiAgentCell *c2, unsigned int a2)
compute
Definition: MultiHandOverUtils.cpp:1900
Definition: taskManagerInterface.hpp:43
Definition: MultiHandOverUtils.hpp:111
std::vector< double > nav_dists
costs for each deplacement made (2 nav costs for each handover, the first is the one of the agent hol...
Definition: MultiHandOverUtils.hpp:220
Definition: MultiHandOverUtils.hpp:92
double handover_comfort_dist
for human only, optimal arm extension distance to get an object (must be in [0..reach]) ...
Definition: MultiHandOverUtils.hpp:102
Definition: LazyWAstar.h:56
Definition: trajectory.hpp:40
std::vector< std::vector< MultiAgentCell * > > navigation_trajs_to_target
the navigation trajectories to reach final target positions.
Definition: MultiHandOverUtils.hpp:223
The MultiHandOverHeuristic class provides an heuristic based on euclidian distance and minimal cost b...
Definition: MultiHandOverUtils.hpp:482
std::string g_name
giver agent name
Definition: MultiHandOverUtils.hpp:402
std::vector< std::pair< double, double > > ho_start_end_dates
start and end dates of each hand over
Definition: MultiHandOverUtils.hpp:216
Plannar HRI Cell.
Definition: HRICS_MultiAgentGrid.hpp:462
Definition: MultiHandOverUtils.hpp:141
double g_torso
giver torso joint
Definition: MultiHandOverUtils.hpp:406
double safe_dist
for human only, the minimal distance to feel safe about surrounding robots
Definition: MultiHandOverUtils.hpp:101
std::vector< double > g_arm_conf
giver arm configuration
Definition: MultiHandOverUtils.hpp:405
std::vector< std::tr1::shared_ptr< FrontierCells > > frontiers
the places (frontiers) where the object is transferred
Definition: MultiHandOverUtils.hpp:208
std::vector< std::pair< double, double > > nav_start_end_times_to_target
nav times of the path to reach final target as begin and end dates in seconds
Definition: MultiHandOverUtils.hpp:225
not a HO task
Definition: MultiHandOverUtils.hpp:251
Classe représentant une Configuration d'un Robot.
Definition: configuration.hpp:25
enum HRICS::MHO::MultiHandOverMhpHO::@3 g_arm
giver arm
void eraseSubTask(SubTask *st)
erase a sub task from the list also delete the existing references to it in the other sub tasks of th...
Definition: MultiHandOverUtils.cpp:1464
Eigen::Vector3d r_pose
receiver 3d pose (x,y,theta)
Definition: MultiHandOverUtils.hpp:409
The AlgoLoggerInterface class defines dummy logging methods that will be used for textual log and dis...
Definition: MultiHandOverUtils.hpp:36
Definition: MultiHandOverUtils.hpp:328
Definition: MultiHandOverUtils.hpp:248
std::vector< double > handover_times
duration of each handover
Definition: MultiHandOverUtils.hpp:217
double computeCost()
compute cost and time duration of the handover
Definition: MultiHandOverUtils.cpp:1681
Definition: MultiHandOverUtils.hpp:178
std::vector< double > nav_start_dates
estimations of the start date (seconds after the 1st nav begining) of each navigation step ...
Definition: MultiHandOverUtils.hpp:215
receiver disengage arm with the object
Definition: MultiHandOverUtils.hpp:257
std::vector< double > handover_hri_costs
HRI related costs of each handover.
Definition: MultiHandOverUtils.hpp:218
std::vector< double > nav_times
the duration of each navigation
Definition: MultiHandOverUtils.hpp:222
Definition: MultiHandOverUtils.hpp:330
Definition: LazyWAstar.h:25
double cumul_time_nav
estimation of cumulated navigation of times of all robots
Definition: MultiHandOverUtils.hpp:202
Definition: MultiHandOverUtils.hpp:514
HandoverStepType_t
Definition: MultiHandOverUtils.hpp:251