libmove3d-planners
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Groups Pages
trajectory.hpp
1 /*
2  * trajectory.hpp
3  *
4  * Created on: Jun 17, 2009
5  * Author: jmainpri
6  */
7 
8 #ifndef TRAJECTORY_HPP_
9 #define TRAJECTORY_HPP_
10 
11 #include "API/Device/robot.hpp"
12 #include "API/ConfigSpace/configuration.hpp"
13 #include "API/ConfigSpace/localpath.hpp"
14 
15 #ifndef _TRAJ_H
16 struct traj;
17 #endif
18 
24 {
25  double length;
26  double max;
27  double sum;
28  double average;
29  double integral;
30  double mecha_work;
31  bool is_valid;
32 };
33 
38 namespace API
39 {
40  class Trajectory
41  {
42  public:
43  //---------------------------------------------------------
44  // Constructors
45  Trajectory();
46  Trajectory(Robot* R);
47  Trajectory(Robot* R,traj* t);
48  Trajectory(std::vector<confPtr_t>& C);
49  Trajectory(const Trajectory& T);
50  ~Trajectory();
51 
52  Trajectory& operator= (const Trajectory& t);
53 
54  bool operator == ( const Trajectory& t ) const;
55  bool operator != ( const Trajectory& t ) const;
56 
57  //---------------------------------------------------------
58  // Operations
59  void copyPaths( std::vector<LocalPath*>& vect );
60 
61  std::vector< std::tr1::shared_ptr<Configuration> > getTowConfigurationAtParam( double param1, double param2,
62  uint& lp1, uint& lp2 );
63 
64  std::pair<bool,std::vector<LocalPath*> > extractSubPortion(double param1,double param2,unsigned int& first,unsigned int& last, bool check_for_coll = true);
65  Trajectory extractSubTrajectoryOfLocalPaths(unsigned int id_start, unsigned int id_end);
66  Trajectory extractSubTrajectory(double param1,double param2, bool check_for_coll = true);
67 
68  bool concat(const Trajectory& traj);
69 
70  bool replacePortionOfLocalPaths(unsigned int id1,unsigned int id2,std::vector<LocalPath*> paths, bool freeMemory = true );
71  bool replacePortion(double param1,double param2,std::vector<LocalPath*> paths , bool freeMemory = true );
72 
73  bool replaceBegin(double param, const std::vector<LocalPath*>& paths );
74  bool replaceEnd(double param, const std::vector<LocalPath*>& paths );
75 
76  bool cutTrajInSmallLP(unsigned int nLP);
77  bool cutTrajInSmallLPSimple(unsigned int nLP);
78  uint cutPortionInSmallLP(std::vector<LocalPath*>& portion, uint nLP);
79 
80  void push_back(confPtr_t q);
81  bool push_back(std::tr1::shared_ptr<LocalPath> path);
82 
83  //---------------------------------------------------------
84  // Cost
85  double collisionCost();
86 
87  std::vector< std::pair<double,double > > getCostProfile();
88  double computeSubPortionIntergralCost(std::vector<LocalPath*>& portion);
89  double computeSubPortionCost(std::vector<LocalPath*>& portion);
90  double computeSubPortionCost(std::vector<LocalPath*>::iterator first, std::vector<LocalPath*>::iterator last);
91  double computeSubPortionMaxCost(std::vector<LocalPath*>& portion);
92  double ReComputeSubPortionCost(std::vector<LocalPath*>& portion, int& nb_cost_tests);
93  double computeSubPortionCostVisib( std::vector<LocalPath*>& portion );
94  double costOfPortion(double param1,double param2);
95  double extractCostPortion(double param1, double param2);
96 
97  double cost();
98  double computeCostComplete();
99  double costComplete();
100  double costNoRecompute();
101  double costRecomputed();
102  double costStatistics( TrajectoryStatistics& stat );
103  double costDeltaAlongTraj();
104  double costNPoints(const int n_points);
105  double costSum();
106 
107  std::vector<double> getCostAlongTrajectory(int nbSample);
108  void resetCostComputed();
109 
110  //---------------------------------------------------------
111  // Basic
112  bool isEmpty();
113 
114  void clear();
115 
116  confPtr_t operator [] ( const int &i ) const;
117  confPtr_t configAtParam(double param, unsigned int* id_localpath=NULL) const;
118  double paramAtConfig(confPtr_t config, double step = -1) const;
119  LocalPath* getLocalPathPtrOf(confPtr_t conf) const;
120  double distanceToTraj(confPtr_t config, double step = -1);
121 
122  std::vector<confPtr_t> getNConfAtParam(double delta);
123  std::vector<confPtr_t> getVectorOfConfiguration();
124 
125  uint getIdOfPathAt(double param);
126  LocalPath* getLocalPathPtrAt(unsigned int id) const;
127  int getNbOfPaths() const;
128  int getNbOfViaPoints() const;
129 
130  bool isValid();
131  void resetIsValid();
132 
133  void updateRange();
134  double computeSubPortionRange(const std::vector<LocalPath*>& portion) const;
135 
136  bool replaceP3dTraj();
137  p3d_traj* replaceP3dTraj(p3d_traj* trajPt);
138  p3d_traj* replaceHumanP3dTraj(Robot*rob, p3d_traj* trajPt);
139 
140  void printAllLocalpathCost();
141  void draw(int nbKeyFrame);
142  void print();
143 
144  int meanCollTest();
145 
146  //---------------------------------------------------------
147  // B-Spline
148  bool makeBSplineTrajectory();
149 
150 
151  //---------------------------------------------------------
152  // Getters & Setters
153 
154  void setColor(int col) {mColor=col;}
155 
156  unsigned int getHighestCostId() const
157  {
158  return HighestCostId;
159  }
160 
161  Robot* getRobot() const
162  {
163  return m_Robot;
164  }
165 
166  int size() const
167  {
168  return m_Courbe.size();
169  }
170 
171  confPtr_t getBegin() const
172  {
173  return m_Source;
174  }
175 
176  confPtr_t getEnd() const
177  {
178  return m_Target;
179  }
180 
181  std::vector<LocalPath*> getCourbe() const
182  {
183  return m_Courbe;
184  }
185  std::vector<LocalPath*> &getCourbe()
186  {
187  return m_Courbe;
188  }
189 
190  double getRangeMax() const {
191  return computeSubPortionRange(m_Courbe);
192  }
193 
194  //---------------------------------------------------------
195  // Members
196  protected:
197  /* Robot */
198  Robot* m_Robot;
199 
200  unsigned int HighestCostId;
201  bool isHighestCostIdSet;
202 
203  private:
204  std::vector<LocalPath*> m_Courbe;
205 
206  /* name of trajectory */
207  std::string name;
208 
209  /* Name of the file */
210  std::string file;
211 
212  int mColor;
213 
214  /* Start and Goal (should never change) */
215  confPtr_t m_Source;
216  confPtr_t m_Target;
217  };
218 }
219 
220 //#if defined( QT_LIBRARY )
221 #include <vector>
222 namespace API { class Trajectory; }
223 extern std::vector<API::Trajectory> trajToDraw;
224 void draw_traj_debug();
225 //#endif
226 
227 #endif /* TRAJECTORY_HPP_ */
Definition: trajectory.hpp:23
Classe représentant un chemin local.
Definition: localpath.hpp:15
This class holds a the robot represented by a kinematic chain.
Definition: robot.hpp:42
Definition: trajectory.hpp:40
Trajectory extractSubTrajectoryOfLocalPaths(unsigned int id_start, unsigned int id_end)
Extract sub trajectory.
Definition: trajectory.cpp:1560