Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion src/ompl/geometric/planners/rrt/AOXRRTConnect.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

#include "ompl/datastructures/NearestNeighbors.h"
#include "ompl/base/OptimizationObjective.h"
#include "ompl/base/spaces/RealVectorStateSpace.h"
#include "ompl/geometric/planners/PlannerIncludes.h"
#include <ompl/geometric/planners/rrt/RRTConnect.h>

Expand Down Expand Up @@ -192,9 +193,39 @@ namespace ompl
/** \brief Free the memory allocated by this planner */
void freeMemory();

/** \brief Compute euclidian distance between motions */
/** \brief Compute euclidian distance between motions
*
* For compound state spaces, this extracts the position components and
* computes actual Euclidean distance, rather than using the state space's
* distance() which may return path-based non-metric distances.
*/
double euclideanDistanceFunction(const Motion *a, const Motion *b) const
{
// Try to get actual Euclidean distance for compound state spaces
auto *stateSpace = si_->getStateSpace().get();
if (stateSpace->isCompound())
{
auto *compoundSpace = stateSpace->as<base::CompoundStateSpace>();
// Get the first subspace which should be the position component (RealVectorStateSpace)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not guaranteed. Rephrase as:

Suggested change
// Get the first subspace which should be the position component (RealVectorStateSpace)
// Get the first subspace which should be the position component (RealVectorStateSpace) for state spaces like SE(2) and SE(3).

auto *subspace = compoundSpace->getSubspace(0).get();
if (subspace->getType() == base::STATE_SPACE_REAL_VECTOR)
{
auto *rvSpace = subspace->as<base::RealVectorStateSpace>();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to reimplement RealVectorStateSpace::distance. I think you can just call rvspace->distance(aCompound->as<base::RealVectorStateSpace::StateType>(0), bCompound->as<base::RealVectorStateSpace::StateType>(0))

const auto *aCompound = a->state->as<base::CompoundStateSpace::StateType>();
const auto *bCompound = b->state->as<base::CompoundStateSpace::StateType>();
const double *aVals = aCompound->as<base::RealVectorStateSpace::StateType>(0)->values;
const double *bVals = bCompound->as<base::RealVectorStateSpace::StateType>(0)->values;
unsigned int dim = rvSpace->getDimension();
double dist = 0.0;
for (unsigned int i = 0; i < dim; ++i)
{
double diff = aVals[i] - bVals[i];
dist += diff * diff;
}
return std::sqrt(dist);
}
}
// Fallback to state space distance for non-compound spaces
return si_->distance(a->state, b->state);
}

Expand Down