00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef CParameterizedTrajectoryGenerator_H
00029 #define CParameterizedTrajectoryGenerator_H
00030
00031 #include <mrpt/utils/CDynamicGrid.h>
00032 #include <mrpt/utils/CStream.h>
00033 #include <mrpt/utils/TParameters.h>
00034 #include <mrpt/reactivenav/link_pragmas.h>
00035
00036 namespace mrpt
00037 {
00038 namespace reactivenav
00039 {
00040 using namespace mrpt::utils;
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 class REACTIVENAV_IMPEXP CParameterizedTrajectoryGenerator
00053 {
00054 public:
00055 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
00056 protected:
00057
00058
00059
00060
00061
00062
00063 CParameterizedTrajectoryGenerator(const TParameters<double> ¶ms);
00064
00065
00066 void initializeCollisionsGrid(float refDistance,float resolution);
00067
00068 public:
00069
00070
00071
00072
00073
00074
00075
00076
00077 static CParameterizedTrajectoryGenerator * CreatePTG(const TParameters<double> ¶ms);
00078
00079
00080
00081 virtual std::string getDescription() const = 0 ;
00082
00083
00084 virtual ~CParameterizedTrajectoryGenerator() { }
00085
00086
00087
00088 void simulateTrajectories(
00089 uint16_t alfaValuesCount,
00090 float max_time,
00091 float max_dist,
00092 unsigned int max_n,
00093 float diferencial_t,
00094 float min_dist,
00095 float *out_max_acc_v = NULL,
00096 float *out_max_acc_w = NULL);
00097
00098
00099
00100 virtual void lambdaFunction( float x, float y, int &out_k, float &out_d );
00101
00102
00103
00104 void directionToMotionCommand( uint16_t k, float &out_v, float &out_w );
00105
00106 size_t getAlfaValuesCount() { return alfaValuesCount; };
00107 size_t getPointsCountInCPath_k(uint16_t k) { return CPoints[k].size(); };
00108
00109 void getCPointWhen_d_Is ( float d, uint16_t k, float &x, float &y, float &phi, float &t, float *v = NULL, float *w = NULL );
00110
00111 float GetCPathPoint_x( uint16_t k, int n ){ return CPoints[k][n].x; }
00112 float GetCPathPoint_y( uint16_t k, int n ){ return CPoints[k][n].y; }
00113 float GetCPathPoint_phi(uint16_t k, int n ){ return CPoints[k][n].phi; }
00114 float GetCPathPoint_t( uint16_t k, int n ){ return CPoints[k][n].t; }
00115 float GetCPathPoint_d( uint16_t k, int n ){ return CPoints[k][n].dist; }
00116 float GetCPathPoint_v( uint16_t k, int n ){ return CPoints[k][n].v; }
00117 float GetCPathPoint_w( uint16_t k, int n ){ return CPoints[k][n].w; }
00118
00119 void allocMemForVerticesData( int nVertices );
00120
00121 void setVertex_xy( uint16_t k, int n, int m, float x, float y )
00122 {
00123 vertexPoints_x[k][ n*nVertices + m ] = x;
00124 vertexPoints_y[k][ n*nVertices + m ] = y;
00125 }
00126
00127 float getVertex_x( uint16_t k, int n, int m )
00128 {
00129 int idx = n*nVertices + m;
00130
00131 return vertexPoints_x[k][idx];
00132 }
00133
00134 float getVertex_y( uint16_t k, int n, int m )
00135 {
00136 int idx = n*nVertices + m;
00137
00138 return vertexPoints_y[k][idx];
00139 }
00140
00141 float* getVertixesArray_x( uint16_t k, int n )
00142 {
00143 int idx = n*nVertices;
00144 return &vertexPoints_x[k][idx];
00145 }
00146
00147 float* getVertixesArray_y( uint16_t k, int n )
00148 {
00149 int idx = n*nVertices;
00150 return &vertexPoints_y[k][idx];
00151 }
00152
00153 unsigned int getVertixesCount() { return nVertices; }
00154
00155 float getMax_V() { return V_MAX; }
00156 float getMax_W() { return W_MAX; }
00157 float getMax_V_inTPSpace() { return maxV_inTPSpace; }
00158
00159
00160
00161
00162 float index2alfa( uint16_t k )
00163 {
00164 return (float)(M_PI * (-1 + 2 * (k+0.5f) / ((float)alfaValuesCount) ));
00165 }
00166
00167
00168
00169
00170 uint16_t alfa2index( float alfa )
00171 {
00172 if (alfa>M_PI) alfa-=(float)M_2PI;
00173 if (alfa<-M_PI) alfa+=(float)M_2PI;
00174 return (uint16_t)(0.5f*(alfaValuesCount*(1+alfa/M_PI) - 1));
00175 }
00176
00177
00178
00179 void debugDumpInFiles(int nPT);
00180
00181
00182
00183
00184
00185 typedef std::map<uint16_t,float> TCollisionCell;
00186
00187
00188 class REACTIVENAV_IMPEXP CColisionGrid : public mrpt::utils::CDynamicGrid<TCollisionCell>
00189 {
00190 private:
00191 CParameterizedTrajectoryGenerator const * m_parent;
00192
00193 public:
00194 CColisionGrid(float x_min, float x_max,float y_min, float y_max, float resolution, CParameterizedTrajectoryGenerator* parent )
00195 : mrpt::utils::CDynamicGrid<TCollisionCell>(x_min,x_max,y_min,y_max,resolution),
00196 m_parent(parent)
00197 {
00198 }
00199 virtual ~CColisionGrid() { }
00200
00201 bool saveToFile( mrpt::utils::CStream* fil );
00202 bool loadFromFile( mrpt::utils::CStream* fil );
00203
00204
00205
00206 const TCollisionCell & getTPObstacle( const float obsX, const float obsY) const;
00207
00208
00209
00210
00211
00212
00213 void updateCellInfo( const unsigned int icx, const unsigned int icy, const uint16_t k, const float dist );
00214 };
00215
00216
00217 CColisionGrid m_collisionGrid;
00218
00219
00220 bool SaveColGridsToFile( const std::string &filename );
00221 bool LoadColGridsFromFile( const std::string &filename );
00222
00223
00224 float refDistance;
00225
00226
00227
00228 virtual void PTG_Generator( float alfa, float t, float x, float y, float phi, float &v, float &w) = 0;
00229
00230
00231
00232 virtual bool PTG_IsIntoDomain( float x, float y ) = 0;
00233
00234 protected:
00235
00236 float V_MAX, W_MAX;
00237 float TAU, DELAY;
00238
00239 float turningRadiusReference;
00240
00241
00242
00243
00244 struct TCellForLambdaFunction
00245 {
00246 TCellForLambdaFunction()
00247 {
00248 k_min=k_max=n_min=n_max=-1;
00249 }
00250
00251 int k_min,k_max,n_min,n_max;
00252 };
00253
00254
00255
00256 CDynamicGrid<TCellForLambdaFunction> m_lambdaFunctionOptimizer;
00257
00258
00259 float maxV_inTPSpace;
00260
00261 bool flag1, flag2;
00262
00263
00264
00265 unsigned int alfaValuesCount;
00266
00267
00268
00269 struct TCPoint
00270 {
00271 TCPoint( float x,
00272 float y,
00273 float phi,
00274 float t,
00275 float dist,
00276 float v,
00277 float w)
00278 {
00279 this->x = x;
00280 this->y = y;
00281 this->phi = phi;
00282 this->t = t;
00283 this->dist = dist;
00284 this->v = v;
00285 this->w = w;
00286 };
00287
00288 float x, y, phi,t, dist,v,w;
00289 };
00290 typedef std::vector<TCPoint> TCPointVector;
00291 std::vector<TCPointVector> CPoints;
00292
00293
00294
00295 std::vector<vector_float> vertexPoints_x,vertexPoints_y;
00296 int nVertices;
00297
00298
00299
00300 void FreeMemory();
00301
00302 };
00303
00304
00305 typedef std::vector<mrpt::reactivenav::CParameterizedTrajectoryGenerator*> TListPTGs;
00306
00307 }
00308 }
00309
00310
00311 #endif
00312