libmove3d-planners
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Groups Pages
HRICS_otpmotionpl.hpp
1 #ifndef HRICS_OTPMOTIONPL_HPP
2 #define HRICS_OTPMOTIONPL_HPP
3 
4 /*
5  * HRICS_CostSpace.h
6  * BioMove3D
7  *
8  * Created by Mamoun Gharbi on 20/04/11.
9  * Copyright 2011 magharbi@laas.fr All rights reserved.
10  *
11  */
12 #include "API/planningAPI.hpp"
13 
14 #include "API/Trajectory/trajectory.hpp"
15 #include "planner/planner.hpp"
16 
17 #include "HRICS_Workspace.hpp"
18 
19 #include "Grid/HRICS_EnvGrid.hpp"
20 #include "Grid/HRICS_TwoDGrid.hpp"
21 #include "utils/OtpUtils.hpp"
22 #include "utils/ConfGenerator.h"
23 
24 #include "LightPlanner-pkg.h"
25 #include "planner/TrajectoryOptim/plannarTrajectorySmoothing.hpp"
26 
27 
28 
29 
30 #include <Eigen/Core>
31 #include <Eigen/StdVector>
32 
33 extern std::string global_ActiveRobotName;
34 extern API::TwoDGrid* API_activeRobotGrid;
35 
36 extern Eigen::Vector3d current_WSPoint;
37 extern std::pair<double,Eigen::Vector3d > current_cost;
38 
39 
40 void hrics_otp_fct();
48 namespace HRICS
49 {
50  class Trajectory;
51 
56  {
57 
58  public:
59  EIGEN_MAKE_ALIGNED_OPERATOR_NEW;
60 
61 
62  OTPMotionPl();
63  OTPMotionPl(Robot* R, Robot* H);
64 
65  ~OTPMotionPl();
66 
67  //getters and setters
68  Robot* getHuman() { return m_Human; }
69  Robot* getRobot() { return _Robot; }
70 
71  EnvGrid* getPlanGrid() { return m_2DGrid; }
72  std::vector<Eigen::Vector3d> getOTPList() { return m_OTPList; }
73  int getNbConf(){ return m_confList.size(); }
74 
75  Eigen::Vector3d getHumanActualPos();
76  Eigen::Vector3d getRobotActualPos();
77 
78  void clearOTPList() { m_OTPList.clear(); }
79 
80  ConfGenerator* getConfGenerator();
81 
82  std::vector<double> getHumanPos(){return m_humanPos;}
83  Eigen::Vector3d getRobotPos(){return m_robotPos;}
84 
85  std::vector<Eigen::Vector2d,Eigen::aligned_allocator<Eigen::Vector2d> > getRobotTraj(){return m_2DPath;}
86  void setRobotTraj(std::vector<Eigen::Vector2d,Eigen::aligned_allocator<Eigen::Vector2d> > traj){m_2DPath = traj;}
87 
88  std::vector<double> getMultipleData(){return m_multipleData;}
89 
90  double getInitTime() {return initTime;}
91  void setInitTime(double d) {initTime = d;}
95  bool finalConfAchieved(double humanError, double robotError);
96 
97 
101  void compteTraj(bool compute);
102 
106  void draw2dPath();
107 
111  bool changeHumanByName(std::string humanName);
112 
113  //##########################################
114  //functions for changing config list #######
115  //##########################################
116 
117  //about the robot
121  bool ComputePR2Gik();
122 
126  void initPR2GiveConf();
127 
131  void placeHuman();
132 
133 
134  // about the OTP list (of point to compute GIK)
135 
136 
140  int loadConfsFromXML(std::string filename, bool isStanding, bool isSlice);
141 
145  int getConfListSize();
146 
150  configPt getRobotConfigAt(int i);
151 
155  std::vector<ConfigHR> getConfList();
156 
157  // after loading confs, computing distances
161  std::pair<double,double> computeHumanRobotDist();
162 
166  double getHumanRobotDist();
167 
168  //##########################################
169  //Tools for Computing OTP ##################
170  //##########################################
171 
172  //initialisation
176  void initGrid();
177 
181  void initAll();
182 
183  //Place from a stored config
188  std::pair<std::tr1::shared_ptr<Configuration>, std::tr1::shared_ptr<Configuration> > setRobotsToConf(int id, bool isStanding);
189 
194  std::pair<std::tr1::shared_ptr<Configuration>, std::tr1::shared_ptr<Configuration> > setRobotsToConf(int id, bool isStanding, double x, double y, double Rz);
195 
196  // saving and reloading a configuration
200  void saveInitConf();
201 
205  void loadInitConf(bool reloadHuman, bool reloadRobot);
206 
210  void clearConfList();
211 
215  int copyConfList();
216 
217  //actual algorithm
221  double ComputePlanarDistancesLineToSegment(Eigen::Vector2d p, Eigen::Vector2d p1, Eigen::Vector2d p2);
222 
226  bool getRandomPoints(double id, Vector3d& vect);
227 
231  bool isAlreadyTested(Eigen::Vector3d p);
232 
236  bool newComputeOTP();
237 
242  OutputConf lookForBestLocalConf(double x, double y, double Rz, double objectNecessity);
243 
247  OutputConf findBestPosForHumanSitConf(double objectNecessity);
248 
249  // redundant call of OTP Computing
254  void getInputs();
255 
259  void setInputs( Eigen::Vector3d humanPos, Eigen::Vector3d robotPos,bool isStanding, double mobility);
260 
264  void addVectorToRealTreajectory(Eigen::Vector2d vect);
265 
269  void setRobotPos();
270 
274  void clearRealTreajectory(){m_2DHumanRealPath.clear();}
275 
279  bool isTheRealNearThePredicted(double threshold);
280 
281  //other
285  void sortConfigList(double nbNode, bool isStanding, bool isSlice);
286 
290  bool testCol(bool isHuman, bool useConf);
291 
297  bool standUp();
298 
299 
300  // Showing the configurations
304  double showConf(unsigned int i);
305 
310 
314  std::tr1::shared_ptr<Configuration> getBestConf();
315 
319  void showBestConfRobOnly();
320 
324  double getConfigCost();
325 
326  //creating trajectories
331 
335  std::vector<Eigen::Vector2d,Eigen::aligned_allocator<Eigen::Vector2d> > smoothTrajectory(
336  std::vector<Eigen::Vector2d,Eigen::aligned_allocator<Eigen::Vector2d> > trajectory);
337 
341  bool testCurrentTraj();
342 
346  void initTrajTest();
347 
351  void navigate();
352 
356  void goToNextStep();
357 
358  // results functions
362  void saveCostsTofile(double cost, double randomCost);
363 
367  void saveAllCostsToFile();
368 
372  void saveAlltimesToFile();
373 
377  void saveCostsTofile(std::string cost);
378 
382  void clearCostsfile();
383 
387  double multipliComputeOtp(int n);
388 
389  //##########################################
390  //Tools for Using from as lib ##############
391  //##########################################
392 
393  //about cells
397  double getDistFromCell(int x, int y, bool isHuman);
398 
402  double getrotFromCell(int x, int y);
403 
404  //about values
408  void dumpCosts();
409 
413  void dumpVar();
414 
415  // using from mhp
419  void setVar();
420 
424  bool getOtp(std::string humanName, Eigen::Vector3d &dockPos, std::vector<SM_TRAJ>& smTraj, configPt& handConf,bool isStanding, double objectNessecity);
425 
426 
430  bool getOtp(std::string humanName, Eigen::Vector3d &dockPos, std::vector<std::pair<double,double> >& traj, configPt& handConf,bool isStanding, double objectNessecity);
431 
435  bool getOtp(std::string humanName, std::vector<std::vector<double> >& traj, configPt& handConf,bool isStanding, double objectNessecity);
436 
437 
441  bool InitMhpObjectTransfert(std::string humanName);
442 
446  bool testTrajectories(bool fullbody);
447 
448 
452  bool getSimplePath(double x, double y, double theta, std::vector<std::vector<double> >& path);
453 
457  bool hasHumanMovedAccordingToPlan(double error);
458 
459  private:
460 
464  Robot* m_Human;
465 
469  EnvGrid* m_2DGrid;
470 
474  std::vector<Eigen::Vector2d,Eigen::aligned_allocator<Eigen::Vector2d> > m_2DPath;
475 
479  std::vector<Eigen::Vector3d,Eigen::aligned_allocator<Eigen::Vector3d> > m_robotTraj3D;
480 
484  std::vector<Eigen::Vector2d,Eigen::aligned_allocator<Eigen::Vector2d> > m_2DHumanPath;
485 
489  std::vector<Eigen::Vector2d,Eigen::aligned_allocator<Eigen::Vector2d> > m_2DHumanRealPath;
490 
494  ManipulationPlanner* m_ManipPl;
495 
499  ManipulationPlanner* m_ManipPlHum;
500 
504  bool m_PathExist;
505 
509  bool m_HumanPathExist;
510 
514  std::vector<Eigen::Vector3d> m_OTPList;
515 
519  std::vector<ConfigHR> m_configList;
520 
524  std::vector<ConfigHR> m_sittingConfigList;
525 
529  std::vector<ConfigHR> m_configListSlice;
530 
534  std::vector<ConfigHR> m_sittingConfigListSlice;
535 
539  OutputConf m_savedConf;
540 
544  std::vector<OutputConf> m_confList;
545 
549  bool m_isInitSiting;
550 
554  Eigen::Vector3d m_sliceVect;
555 
559  bool m_humanCanStand;
560 
564  double m_time;
565 
569  double m_sittingTime;
570 
575  std::vector<double> m_multipleData;
576 
580  Robot* m_simpleChair;
581 
585  std::vector<std::vector<double> > m_multipliComputeCostVector;
586 
590  std::vector<std::vector<double> > m_multipliComputeTimeVector;
591 
595  std::vector<double> m_costVector;
596 
600  std::vector<double> m_timeVector;
601 
605  std::vector<SM_TRAJ> m_smTrajs;
606 
611 
615  std::vector<Eigen::Vector3d,Eigen::aligned_allocator<Eigen::Vector3d> > m_testedVectors;
616 
620 // Eigen::Vector3d m_humanPos;
621  std::vector<double> m_humanPos;
622  Eigen::Vector3d m_robotPos;
623  bool m_isStanding;
624  double m_mobility;
625 
629  ConfGenerator* m_ConfGen;
630 
634  double initTime;
635 
636  bool m_OTPsuceed;
637 
638 
639 
640  };
641 
642 
643 
644 }
645 
646 #endif // HRICS_OTPMOTIONPL_HPP
void saveCostsTofile(double cost, double randomCost)
save the costs to a file
Definition: HRICS_otpmotionpl.cpp:2442
int loadConfsFromXML(std::string filename, bool isStanding, bool isSlice)
load configs from filename and put them, either in sitting or standing list in the correct vector...
Definition: HRICS_otpmotionpl.cpp:355
Definition: OtpUtils.hpp:32
void setRobotPos()
set robotPos to actual pos
Definition: HRICS_otpmotionpl.cpp:828
Robot * _Robot
Le Robot pour lequel la recherche va se faire.
Definition: planner.hpp:174
bool isTheRealNearThePredicted(double threshold)
compare the real trajectory with the predicted trajectory
Definition: HRICS_otpmotionpl.cpp:837
bool standUp()
Put human to a standing position the standing postition is right in from of him if there is no obstac...
Definition: HRICS_otpmotionpl.cpp:2951
void initAll()
called for initialisation
Definition: HRICS_otpmotionpl.cpp:128
void dumpVar()
writing variable
Definition: HRICS_otpmotionpl.cpp:3070
bool ComputePR2Gik()
Compute only PR2 GIK.
Definition: HRICS_otpmotionpl.cpp:268
void getInputs()
getting the inputs from a unique source.
Definition: HRICS_otpmotionpl.cpp:786
std::vector< Eigen::Vector2d, Eigen::aligned_allocator< Eigen::Vector2d > > smoothTrajectory(std::vector< Eigen::Vector2d, Eigen::aligned_allocator< Eigen::Vector2d > > trajectory)
generate a smoothed 2D traj
Definition: HRICS_otpmotionpl.cpp:2800
OutputConf findBestPosForHumanSitConf(double objectNecessity)
if the human is stitting, special features should be than.
Definition: HRICS_otpmotionpl.cpp:1829
bool InitMhpObjectTransfert(std::string humanName)
initialisation of OTP computing for usage in mhp
Definition: HRICS_otpmotionpl.cpp:3181
bool hasHumanMovedAccordingToPlan(double error)
test if the human has moved according to the plan (3d and sitting)
Definition: HRICS_otpmotionpl.cpp:3745
void initTrajTest()
init the class to begin testing
Definition: HRICS_otpmotionpl.cpp:2855
Plannar HRI Grid.
Definition: HRICS_EnvGrid.hpp:14
void sortConfigList(double nbNode, bool isStanding, bool isSlice)
sort configuration stored by confort cost
Definition: HRICS_otpmotionpl.cpp:517
bool testCurrentTraj()
test if current traj is feasable
Definition: HRICS_otpmotionpl.cpp:2840
bool newComputeOTP()
Compute the OTP using the last algorithme.
Definition: HRICS_otpmotionpl.cpp:1232
void clearConfList()
clear the list of confs
Definition: HRICS_otpmotionpl.cpp:402
void showBestConfRobOnly()
show the best computed conf for the robot only
Definition: HRICS_otpmotionpl.cpp:2198
void saveAlltimesToFile()
save all the times computed in multipli conpute OTP in a file
Definition: HRICS_otpmotionpl.cpp:2396
bool isAlreadyTested(Eigen::Vector3d p)
test if the vector has already been computed
Definition: HRICS_otpmotionpl.cpp:3554
double getConfigCost()
getting the true configuration cost (musculoskeletal, dist, Fov)
Definition: HRICS_otpmotionpl.cpp:3736
double showConf(unsigned int i)
show a computed conf from it's number in the list
Definition: HRICS_otpmotionpl.cpp:2138
OutputConf showBestConf()
show the best computed conf
Definition: HRICS_otpmotionpl.cpp:2171
Motion Planing for an object transfert point.
Definition: HRICS_otpmotionpl.hpp:55
void clearCostsfile()
clear the file before saving costs
Definition: HRICS_otpmotionpl.cpp:2467
This class holds a the robot represented by a kinematic chain.
Definition: robot.hpp:42
void initPR2GiveConf()
set Pr2 to a giving configuration
Definition: HRICS_otpmotionpl.cpp:284
OutputConf lookForBestLocalConf(double x, double y, double Rz, double objectNecessity)
Used in newComputeOTP(), this function compoute a conf for human an robot from a position (x...
Definition: HRICS_otpmotionpl.cpp:1621
void saveAllCostsToFile()
save all the costs computed in multipli conpute OTP in a file
Definition: HRICS_otpmotionpl.cpp:2302
void clearRealTreajectory()
clear real trajectory
Definition: HRICS_otpmotionpl.hpp:274
bool getSimplePath(double x, double y, double theta, std::vector< std::vector< double > > &path)
get a simple path
Definition: HRICS_otpmotionpl.cpp:3706
void goToNextStep()
go to the next position of the cylinder
Definition: HRICS_otpmotionpl.cpp:2876
void addVectorToRealTreajectory(Eigen::Vector2d vect)
adding path to real trajectory
Definition: HRICS_otpmotionpl.cpp:3543
double getrotFromCell(int x, int y)
get rotation from human or robot of a cell.
Definition: HRICS_otpmotionpl.cpp:2291
double ComputePlanarDistancesLineToSegment(Eigen::Vector2d p, Eigen::Vector2d p1, Eigen::Vector2d p2)
compute a distance in a planar grid between a point (p) and a segment [p1,p2]
Definition: HRICS_otpmotionpl.cpp:938
std::tr1::shared_ptr< Configuration > getBestConf()
get best conf
Definition: HRICS_otpmotionpl.cpp:2185
double getDistFromCell(int x, int y, bool isHuman)
get distance from human or robot of a cell.
Definition: HRICS_otpmotionpl.cpp:2276
Definition: TwoDGrid.hpp:25
configPt getRobotConfigAt(int i)
return the config at i in the selected config list
Definition: HRICS_otpmotionpl.cpp:2489
Definition: plannarTrajectorySmoothing.hpp:13
double multipliComputeOtp(int n)
compute OTP using newComputeOTP() n time, the returning the average
Definition: HRICS_otpmotionpl.cpp:654
bool createTrajectoryFromOutputConf(OutputConf conf)
create a trajectory from a configuration
Definition: HRICS_otpmotionpl.cpp:2527
void dumpCosts()
write cost of current configList
Definition: HRICS_otpmotionpl.cpp:3432
int getConfListSize()
return the size of the selected config list
Definition: HRICS_otpmotionpl.cpp:2477
bool getRandomPoints(double id, Vector3d &vect)
return the randomly choosed x, y and Rz.
Definition: HRICS_otpmotionpl.cpp:989
bool testTrajectories(bool fullbody)
test pr2Softmotion
Definition: HRICS_otpmotionpl.cpp:3569
bool getOtp(std::string humanName, Eigen::Vector3d &dockPos, std::vector< SM_TRAJ > &smTraj, configPt &handConf, bool isStanding, double objectNessecity)
function to be called from codels for softmotion usage
Definition: HRICS_otpmotionpl.cpp:3271
void saveInitConf()
save the actual robot and human conf to reload it afterwards
Definition: HRICS_otpmotionpl.cpp:2107
bool finalConfAchieved(double humanError, double robotError)
check if the human has reached his destination with an error
Definition: HRICS_otpmotionpl.cpp:3790
double getHumanRobotDist()
return distance between human and robot
Definition: HRICS_otpmotionpl.cpp:2924
bool changeHumanByName(std::string humanName)
Change Human (in case of multiple human in the scenne)
Definition: HRICS_otpmotionpl.cpp:3472
void setInputs(Eigen::Vector3d humanPos, Eigen::Vector3d robotPos, bool isStanding, double mobility)
setting the inputs !!
Definition: HRICS_otpmotionpl.cpp:772
void initGrid()
init the plan grid with the costs and the distances
Definition: HRICS_otpmotionpl.cpp:2205
bool testCol(bool isHuman, bool useConf)
testing collision for human and robot
Definition: HRICS_otpmotionpl.cpp:2068
std::vector< ConfigHR > getConfList()
return the selected config list
Definition: HRICS_otpmotionpl.cpp:2501
std::pair< double, double > computeHumanRobotDist()
return the minimal and maximal dist between human and robot in the loaded configuration ...
Definition: HRICS_otpmotionpl.cpp:2881
Definition: ConfGenerator.h:51
void loadInitConf(bool reloadHuman, bool reloadRobot)
reload the saved human and robot conf
Definition: HRICS_otpmotionpl.cpp:2118
std::pair< std::tr1::shared_ptr< Configuration >, std::tr1::shared_ptr< Configuration > > setRobotsToConf(int id, bool isStanding)
chamge robot configuration to the one with the specified id in the correct list return a pair of the ...
Definition: HRICS_otpmotionpl.cpp:408
Base class for the HRICS motion planners.
Definition: HRICS_Workspace.hpp:37
void draw2dPath()
Draws the 3D path as a yellow line for robot and green one for human.
Definition: HRICS_otpmotionpl.cpp:193
void navigate()
planning using planNavigation
Definition: HRICS_otpmotionpl.cpp:2819
void compteTraj(bool compute)
to compute traj or not
Definition: HRICS_otpmotionpl.cpp:3548
void setVar()
setting variables
Definition: HRICS_otpmotionpl.cpp:3125
void placeHuman()
Compute human GIK.
Definition: HRICS_otpmotionpl.cpp:345
int copyConfList()
copy the list of confs from the confGenerator if possible.
Definition: HRICS_otpmotionpl.cpp:389