Skip to content

Commit

Permalink
PTGs: small code refactoring; new method inverseMap_WS2TP()
Browse files Browse the repository at this point in the history
  • Loading branch information
jlblancoc committed Dec 28, 2013
1 parent dca29e6 commit 4d04ef5
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 88 deletions.
2 changes: 2 additions & 0 deletions doc/doxygen-pages/changeLog_doc.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
- mrpt::slam::TMatchingExtraResults
- mrpt::slam::CObservationIMU now includes data fields for 3D magnetometers and altimeters. - [(commit)](http://code.google.com/p/mrpt/source/detail?r=3451)
- Method renamed mrpt::utils::CEnhancedMetaFile::selectVectorTextFont() to avoid shadowing mrpt::utils::CCanvas::selectTextFont()
- mrpt::reactivenav::CParameterizedTrajectoryGenerator: New method for inverse look-up of WS to TP space - [(commit)]()
- mrpt::reactivenav::CParameterizedTrajectoryGenerator::inverseMap_WS2TP()
- Deleted classes:
- mrpt::utils::CEvent, which was actually unimplemented (!)
- mrpt::hwdrivers::CInterfaceNI845x has been deleted. It didn't offer features enough to justify a class.
Expand Down
3 changes: 1 addition & 2 deletions libs/reactivenav/include/mrpt/reactivenav/CPTG1.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ namespace mrpt
*/
CPTG1(const TParameters<double> &params );

/** The lambda function. */
void lambdaFunction( float x, float y, int &out_k, float &out_d );
virtual bool inverseMap_WS2TP(float x, float y, int &out_k, float &out_d, float tolerance_dist = 0.10f) const;

/** Gets a short textual description of the PTG and its parameters. */
std::string getDescription() const;
Expand Down
4 changes: 0 additions & 4 deletions libs/reactivenav/include/mrpt/reactivenav/CPTG2.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@ namespace mrpt
*/
CPTG2(const TParameters<double> &params );

/** The lambda function.
*/
void lambdaFunction( float x, float y, int &out_k, float &out_d );

/** Gets a short textual description of the PTG and its parameters.
*/
std::string getDescription() const;
Expand Down
4 changes: 0 additions & 4 deletions libs/reactivenav/include/mrpt/reactivenav/CPTG3.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ namespace mrpt
*/
CPTG3(const TParameters<double> &params );

/** The lambda function.
*/
void lambdaFunction( float x, float y, int &out_k, float &out_d );

/** Gets a short textual description of the PTG and its parameters.
*/
std::string getDescription() const;
Expand Down
4 changes: 0 additions & 4 deletions libs/reactivenav/include/mrpt/reactivenav/CPTG4.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ namespace mrpt
*/
CPTG4(const TParameters<double> &params );

/** The lambda function.
*/
void lambdaFunction( float x, float y, int &out_k, float &out_d );

/** Gets a short textual description of the PTG and its parameters.
*/
std::string getDescription() const;
Expand Down
4 changes: 0 additions & 4 deletions libs/reactivenav/include/mrpt/reactivenav/CPTG5.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ namespace mrpt
*/
CPTG5(const TParameters<double> &params );

/** The lambda function.
*/
void lambdaFunction( float x, float y, int &out_k, float &out_d );

/** Gets a short textual description of the PTG and its parameters.
*/
std::string getDescription() const;
Expand Down
4 changes: 0 additions & 4 deletions libs/reactivenav/include/mrpt/reactivenav/CPTG6.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ namespace mrpt
*/
CPTG6(const TParameters<double> &params );

/** The lambda function.
*/
void lambdaFunction( float x, float y, int &out_k, float &out_d );

/** Gets a short textual description of the PTG and its parameters.
*/
std::string getDescription() const;
Expand Down
4 changes: 0 additions & 4 deletions libs/reactivenav/include/mrpt/reactivenav/CPTG7.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ namespace mrpt
*/
CPTG7(const TParameters<double> &params );

/** The lambda function.
*/
void lambdaFunction( float x, float y, int &out_k, float &out_d );

/** Gets a short textual description of the PTG and its parameters.
*/
std::string getDescription() const;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ namespace mrpt
{
using namespace mrpt::utils;

/** This is the base class for any user defined PTG.
/** This is the base class for any user-defined PTG.
* The class factory interface in CParameterizedTrajectoryGenerator::CreatePTG.
*
* Papers:
* - J.L. Blanco, J. Gonzalez-Jimenez, J.A. Fernandez-Madrigal, "Extending Obstacle Avoidance Methods through Multiple Parameter-Space Transformations", Autonomous Robots, vol. 24, no. 1, 2008. http://ingmec.ual.es/~jlblanco/papers/blanco2008eoa_DRAFT.pdf
*
* Changes history:
* - 30/JUN/2004: Creation (JLBC)
* - 16/SEP/2004: Totally redesigned.
Expand All @@ -39,6 +42,8 @@ namespace mrpt
* - ref_distance: The maximum distance in PTGs
* - resolution: The cell size
* - v_max, w_max: Maximum robot speeds.
*
* See docs of derived classes for additional parameters:
*/
CParameterizedTrajectoryGenerator(const TParameters<double> &params);

Expand Down Expand Up @@ -75,9 +80,22 @@ namespace mrpt
float *out_max_acc_v = NULL,
float *out_max_acc_w = NULL);

/** The "lambda" function, see paper for info. It takes the (a,d) pair that is closest to a given location.
*/
virtual void lambdaFunction( float x, float y, int &out_k, float &out_d );

/** Computes the closest (alpha,d) TP coordinates of the trajectory point closest to the Workspace (WS) Cartesian coordinates (x,y).
* \param[in] x X coordinate of the query point.
* \param[in] y Y coordinate of the query point.
* \param[out] out_k Trajectory parameter index (discretized alpha value, 0-based index).
* \param[out] out_d Trajectory distance, normalized such that D_max becomes 1.
*
* \return true if the distance between (x,y) and the actual trajectory point is below the given tolerance (in meters).
* \note The default implementation in CParameterizedTrajectoryGenerator relies on a look-up-table. Derived classes may redefine this to closed-form expressions, when they exist.
*/
virtual bool inverseMap_WS2TP(float x, float y, int &out_k, float &out_d, float tolerance_dist = 0.10f) const;

/** The "lambda" function, see paper for info. It takes the (a,d) pair that is closest to a given location. */
MRPT_DEPRECATED_PRE("Use inverseMap_WS2TP() instead")
void lambdaFunction( float x, float y, int &out_k, float &out_d );
MRPT_DEPRECATED_POST("Use inverseMap_WS2TP() instead");

/** Converts an "alpha" value (into the discrete set) into a feasible motion command.
*/
Expand Down
15 changes: 7 additions & 8 deletions libs/reactivenav/src/CPTG1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,9 @@ bool CPTG1::PTG_IsIntoDomain( float x, float y )
return true;
}

/*---------------------------------------------------------------
lambdaFunction
---------------------------------------------------------------*/
void CPTG1::lambdaFunction( float x, float y, int &k_out, float &d_out )
bool CPTG1::inverseMap_WS2TP(float x, float y, int &k_out, float &d_out, float tolerance_dist) const
{
MRPT_TODO("Update API to return a bool for approximate results!")

bool is_exact = true;
if (y!=0)
{
double R = (x*x+y*y)/(2*y);
Expand All @@ -83,10 +79,9 @@ void CPTG1::lambdaFunction( float x, float y, int &k_out, float &d_out )
// Distance thru arc:
d_out = (float)(theta * (fabs(R)+turningRadiusReference));

bool is_approx = false;
if (std::abs(R)<Rmin)
{
is_approx=true;
is_exact=false;
R=Rmin*mrpt::utils::sign(R);
}

Expand All @@ -101,11 +96,13 @@ void CPTG1::lambdaFunction( float x, float y, int &k_out, float &d_out )
{
k_out = alpha2index(0);
d_out = x;
is_exact=true;
}
else
{
k_out = alpha2index((float)M_PI);
d_out = 1e+3;
is_exact=false;
}
}

Expand All @@ -114,4 +111,6 @@ void CPTG1::lambdaFunction( float x, float y, int &k_out, float &d_out )

ASSERT_ABOVEEQ_(k_out,0)
ASSERT_BELOW_(k_out,this->m_alphaValuesCount)

return is_exact;
}
7 changes: 0 additions & 7 deletions libs/reactivenav/src/CPTG2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,3 @@ bool CPTG2::PTG_IsIntoDomain( float x, float y )
return true;
}

/*---------------------------------------------------------------
lambdaFunction
---------------------------------------------------------------*/
void CPTG2::lambdaFunction( float x, float y, int &out_k, float &out_d )
{
CParameterizedTrajectoryGenerator::lambdaFunction(x,y,out_k,out_d);
}
7 changes: 0 additions & 7 deletions libs/reactivenav/src/CPTG3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,3 @@ bool CPTG3::PTG_IsIntoDomain( float x, float y )
}
}

/*---------------------------------------------------------------
lambdaFunction
---------------------------------------------------------------*/
void CPTG3::lambdaFunction( float x, float y, int &out_k, float &out_d )
{
CParameterizedTrajectoryGenerator::lambdaFunction(x,y,out_k,out_d);
}
7 changes: 0 additions & 7 deletions libs/reactivenav/src/CPTG4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,3 @@ bool CPTG4::PTG_IsIntoDomain( float x, float y )
}


/*---------------------------------------------------------------
lambdaFunction
---------------------------------------------------------------*/
void CPTG4::lambdaFunction( float x, float y, int &out_k, float &out_d )
{
CParameterizedTrajectoryGenerator::lambdaFunction(x,y,out_k,out_d);
}
8 changes: 0 additions & 8 deletions libs/reactivenav/src/CPTG5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,3 @@ bool CPTG5::PTG_IsIntoDomain( float x, float y )
}
}


/*---------------------------------------------------------------
lambdaFunction
---------------------------------------------------------------*/
void CPTG5::lambdaFunction( float x, float y, int &out_k, float &out_d )
{
CParameterizedTrajectoryGenerator::lambdaFunction(x,y,out_k,out_d);
}
8 changes: 0 additions & 8 deletions libs/reactivenav/src/CPTG6.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,3 @@ bool CPTG6::PTG_IsIntoDomain( float x, float y )
{
return true;
}

/*---------------------------------------------------------------
lambdaFunction
---------------------------------------------------------------*/
void CPTG6::lambdaFunction( float x, float y, int &out_k, float &out_d )
{
CParameterizedTrajectoryGenerator::lambdaFunction(x,y,out_k,out_d);
}
7 changes: 0 additions & 7 deletions libs/reactivenav/src/CPTG7.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,3 @@ bool CPTG7::PTG_IsIntoDomain( float x, float y )
return !( (fabs(y)>M_PI*V_MAX) || (x<M_PI*V_MAX) );
}

/*---------------------------------------------------------------
lambdaFunction
---------------------------------------------------------------*/
void CPTG7::lambdaFunction( float x, float y, int &out_k, float &out_d )
{
CParameterizedTrajectoryGenerator::lambdaFunction(x,y,out_k,out_d);
}
16 changes: 10 additions & 6 deletions libs/reactivenav/src/CParameterizedTrajectoryGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,10 +624,13 @@ bool CParameterizedTrajectoryGenerator::CColisionGrid::loadFromFile( CStream *f,
}
}

/*---------------------------------------------------------------
lambdaFunction
---------------------------------------------------------------*/
void CParameterizedTrajectoryGenerator::lambdaFunction( float x, float y, int &k_out, float &d_out )
// Deprecated:
void CParameterizedTrajectoryGenerator::lambdaFunction( float x, float y, int &out_k, float &out_d )
{
this->inverseMap_WS2TP(x,y,out_k,out_d);
}

bool CParameterizedTrajectoryGenerator::inverseMap_WS2TP( float x, float y, int &k_out, float &d_out, float tolerance_dist ) const
{
ASSERTMSG_(m_alphaValuesCount>0, "Have you called simulateTrajectories() first?")

Expand All @@ -650,7 +653,7 @@ void CParameterizedTrajectoryGenerator::lambdaFunction( float x, float y, int &k
{
for (int cy=cy0-1;cy<=cy0+1;cy++)
{
TCellForLambdaFunction *cell = m_lambdaFunctionOptimizer.cellByIndex(cx,cy);
const TCellForLambdaFunction *cell = m_lambdaFunctionOptimizer.cellByIndex(cx,cy);
if (cell && !cell->isEmpty())
{
if (!at_least_one)
Expand Down Expand Up @@ -702,7 +705,7 @@ void CParameterizedTrajectoryGenerator::lambdaFunction( float x, float y, int &k
{
k_out = selected_k;
d_out = selected_d / refDistance;
return;
return (selected_dist <= square(tolerance_dist));
}

// If not found, compute an extrapolation:
Expand Down Expand Up @@ -730,6 +733,7 @@ void CParameterizedTrajectoryGenerator::lambdaFunction( float x, float y, int &k

k_out = selected_k;
d_out = selected_d / refDistance;
return false;
}


0 comments on commit 4d04ef5

Please sign in to comment.