Skip to content

Commit 053e9a8

Browse files
author
twill777
committed
De-inhertied RRT-Connect
1 parent ae0d7c4 commit 053e9a8

File tree

4 files changed

+82
-65
lines changed

4 files changed

+82
-65
lines changed

src/ompl/geometric/planners/rrt/AORRTC.h

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace ompl
7575
{
7676
public:
7777
/** \brief Constructor */
78-
AORRTC(const base::SpaceInformationPtr &si, bool addIntermediateStates = false);
78+
AORRTC(const base::SpaceInformationPtr &si);
7979

8080
~AORRTC() override;
8181

@@ -114,20 +114,6 @@ namespace ompl
114114
return psk_;
115115
}
116116

117-
/** \brief Return true if the intermediate states generated along motions are to be added to the tree itself
118-
*/
119-
bool getIntermediateStates() const
120-
{
121-
return addIntermediateStates_;
122-
}
123-
124-
/** \brief Specify whether the intermediate states generated along motions are to be added to the tree
125-
* itself */
126-
void setIntermediateStates(bool addIntermediateStates)
127-
{
128-
addIntermediateStates_ = addIntermediateStates;
129-
}
130-
131117
/** \brief Attempt to simplify the current solution path. Stop computation when \e ptc becomes true at the
132118
* latest. */
133119
void simplifySolution(const base::PathPtr &p, const base::PlannerTerminationCondition &ptc);
@@ -154,9 +140,6 @@ namespace ompl
154140

155141
base::PathPtr bestPath_{nullptr};
156142

157-
/** \brief Flag indicating whether intermediate states are added to the built tree of motions */
158-
bool addIntermediateStates_;
159-
160143
ompl::base::Cost bestCost_{std::numeric_limits<double>::infinity()};
161144

162145
/** \brief Objective we're optimizing */

src/ompl/geometric/planners/rrt/AOXRRTConnect.h

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ namespace ompl
7676
*/
7777

7878
/** \brief Modified RRT-Connect for AORRTC (AOXRRTConnect) */
79-
class AOXRRTConnect : public ompl::geometric::RRTConnect
79+
class AOXRRTConnect : public base::Planner
8080
{
8181
public:
8282
/** \brief Constructor */
83-
AOXRRTConnect(const base::SpaceInformationPtr &si, bool addIntermediateStates = false);
83+
AOXRRTConnect(const base::SpaceInformationPtr &si);
8484

8585
~AOXRRTConnect() override;
8686

@@ -96,6 +96,22 @@ namespace ompl
9696
return foundPath;
9797
}
9898

99+
/** \brief Set the range the planner is supposed to use.
100+
101+
This parameter greatly influences the runtime of the
102+
algorithm. It represents the maximum length of a
103+
motion to be added in the tree of motions. */
104+
void setRange(double distance)
105+
{
106+
maxDistance_ = distance;
107+
}
108+
109+
/** \brief Get the range the planner is using */
110+
double getRange() const
111+
{
112+
return maxDistance_;
113+
}
114+
99115
/** \brief Set a different nearest neighbors datastructure */
100116
template <template <typename T> class NN>
101117
void setNearestNeighbors()
@@ -161,6 +177,20 @@ namespace ompl
161177
bool start;
162178
};
163179

180+
/** \brief The state of the tree after an attempt to extend it */
181+
enum GrowState
182+
{
183+
/// no progress has been made
184+
TRAPPED,
185+
/// progress has been made towards the randomly sampled state
186+
ADVANCED,
187+
/// the randomly sampled state was reached
188+
REACHED
189+
};
190+
191+
/** \brief Free the memory allocated by this planner */
192+
void freeMemory();
193+
164194
/** \brief Compute euclidian distance between motions */
165195
double euclideanDistanceFunction(const Motion *a, const Motion *b) const
166196
{
@@ -195,6 +225,12 @@ namespace ompl
195225
/** \brief The goal tree */
196226
TreeData tGoal_;
197227

228+
/** \brief A flag that toggles between expanding the start tree (true) or goal tree (false). */
229+
bool startTree_{true};
230+
231+
/** \brief The maximum length of a motion to be added to a tree */
232+
double maxDistance_{0.};
233+
198234
/** \brief Maximum allowed cost resampling iterations before moving on */
199235
long int maxResampleAttempts_{100};
200236

@@ -224,6 +260,12 @@ namespace ompl
224260

225261
/** \brief Objective we're optimizing */
226262
base::OptimizationObjectivePtr opt_;
263+
264+
/** \brief The random number generator */
265+
RNG rng_;
266+
267+
/** \brief The pair of states in each tree connected during planning. Used for PlannerData computation */
268+
std::pair<base::State *, base::State *> connectionPoint_;
227269
};
228270
} // namespace geometric
229271
} // namespace ompl

src/ompl/geometric/planners/rrt/src/AORRTC.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@
3939
#include "ompl/base/goals/GoalSampleableRegion.h"
4040
#include "ompl/tools/config/SelfConfig.h"
4141

42-
ompl::geometric::AORRTC::AORRTC(const base::SpaceInformationPtr &si, bool addIntermediateStates)
42+
ompl::geometric::AORRTC::AORRTC(const base::SpaceInformationPtr &si)
4343
: base::Planner(si, "AORRTC")
4444
{
4545
specs_.approximateSolutions = true;
4646
specs_.directed = true;
47-
48-
addIntermediateStates_ = addIntermediateStates;
4947
}
5048

5149
ompl::geometric::AORRTC::~AORRTC()
@@ -73,7 +71,6 @@ void ompl::geometric::AORRTC::setup()
7371
aox_planner->setProblemDefinition(pdef_);
7472
aox_planner->setName("AOXRRTConnect");
7573
aox_planner->setRange(getRange());
76-
aox_planner->setIntermediateStates(getIntermediateStates());
7774

7875
aox_planner->setup();
7976

src/ompl/geometric/planners/rrt/src/AOXRRTConnect.cpp

Lines changed: 36 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,15 @@
4444

4545
#include <stdexcept>
4646

47-
ompl::geometric::AOXRRTConnect::AOXRRTConnect(const base::SpaceInformationPtr &si, bool addIntermediateStates)
48-
: ompl::geometric::RRTConnect(si, addIntermediateStates)
47+
ompl::geometric::AOXRRTConnect::AOXRRTConnect(const base::SpaceInformationPtr &si)
48+
: base::Planner(si, "AOXRRTConnect")
4949
{
5050
specs_.recognizedGoal = base::GOAL_SAMPLEABLE_REGION;
5151
specs_.directed = true;
5252

5353
Planner::declareParam<double>("range", this, &AOXRRTConnect::setRange, &AOXRRTConnect::getRange, "0.:1.:10000.");
54-
Planner::declareParam<bool>("intermediate_states", this, &AOXRRTConnect::setIntermediateStates,
55-
&AOXRRTConnect::getIntermediateStates, "0,1");
5654

5755
connectionPoint_ = std::make_pair<base::State *, base::State *>(nullptr, nullptr);
58-
distanceBetweenTrees_ = std::numeric_limits<double>::infinity();
59-
addIntermediateStates_ = addIntermediateStates;
6056
}
6157

6258
ompl::geometric::AOXRRTConnect::~AOXRRTConnect()
@@ -96,6 +92,33 @@ void ompl::geometric::AOXRRTConnect::setup()
9692
reset(true);
9793
}
9894

95+
void ompl::geometric::AOXRRTConnect::freeMemory()
96+
{
97+
std::vector<Motion *> motions;
98+
99+
if (tStart_)
100+
{
101+
tStart_->list(motions);
102+
for (auto &motion : motions)
103+
{
104+
if (motion->state != nullptr)
105+
si_->freeState(motion->state);
106+
delete motion;
107+
}
108+
}
109+
110+
if (tGoal_)
111+
{
112+
tGoal_->list(motions);
113+
for (auto &motion : motions)
114+
{
115+
if (motion->state != nullptr)
116+
si_->freeState(motion->state);
117+
delete motion;
118+
}
119+
}
120+
}
121+
99122
void ompl::geometric::AOXRRTConnect::reset(bool solvedProblem)
100123
{
101124
tStart_->clear();
@@ -263,42 +286,14 @@ ompl::geometric::AOXRRTConnect::GrowState ompl::geometric::AOXRRTConnect::growTr
263286
}
264287
}
265288

266-
if (addIntermediateStates_)
267-
{
268-
const base::State *astate = tgi.start ? nmotion->state : dstate;
269-
const base::State *bstate = tgi.start ? dstate : nmotion->state;
270-
271-
std::vector<base::State *> states;
272-
const unsigned int count = si_->getStateSpace()->validSegmentCount(astate, bstate);
273-
274-
if (si_->getMotionStates(astate, bstate, states, count, true, true))
275-
si_->freeState(states[0]);
276-
277-
for (std::size_t i = 1; i < states.size(); ++i)
278-
{
279-
auto *motion = new Motion;
280-
motion->state = states[i];
281-
motion->parent = nmotion;
282-
motion->root = nmotion->root;
283-
motion->cost = si_->distance(nmotion->state, motion->state) + nmotion->cost;
284-
tree->add(motion);
285-
286-
nmotion = motion;
287-
}
289+
auto *motion = new Motion(si_);
290+
si_->copyState(motion->state, dstate);
291+
motion->parent = nmotion;
292+
motion->root = nmotion->root;
293+
motion->cost = si_->distance(nmotion->state, motion->state) + nmotion->cost;
294+
tree->add(motion);
288295

289-
tgi.xmotion = nmotion;
290-
}
291-
else
292-
{
293-
auto *motion = new Motion(si_);
294-
si_->copyState(motion->state, dstate);
295-
motion->parent = nmotion;
296-
motion->root = nmotion->root;
297-
motion->cost = si_->distance(nmotion->state, motion->state) + nmotion->cost;
298-
tree->add(motion);
299-
300-
tgi.xmotion = motion;
301-
}
296+
tgi.xmotion = motion;
302297

303298
si_->freeState(root_motion->state);
304299
delete root_motion;

0 commit comments

Comments
 (0)