Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

moveit_cpp: add getter for last plan solution, add missing implementa… #1

Open
wants to merge 31 commits into
base: tmp-multi_query_planners_moveit_cpp
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
659eb38
Copy made
simonGoldstein Jul 31, 2019
e874cde
Renamed and added to Cmake
simonGoldstein Jul 31, 2019
d33557a
Remove impl
simonGoldstein Jul 31, 2019
721a281
Added tests
simonGoldstein Jul 31, 2019
673f771
Clang Format
simonGoldstein Aug 1, 2019
91e6629
Remove depreciated constructor funtions
simonGoldstein Aug 1, 2019
cf396f6
Remove MoveItCpp python wrapper
henningkayser Aug 16, 2019
55c84b5
Rename moveit_cpp.cpp to moveit.cpp
henningkayser Aug 16, 2019
a29339b
Remove previous authors
henningkayser Aug 16, 2019
f70f3e8
Remove non-functional demo
henningkayser Aug 16, 2019
efa7353
Update license headers
henningkayser Aug 16, 2019
877abe5
Remove ! from MoveIt
henningkayser Aug 16, 2019
8110afe
Add TODOs
henningkayser Aug 16, 2019
e86d625
Wrap moveit_cpp function definitions in namespace
henningkayser Aug 16, 2019
9c46f8b
Remove old pick/place actions
henningkayser Aug 20, 2019
2d7d750
Remove constraints storage
henningkayser Aug 20, 2019
3c3179e
Reduce moveit_cpp to minimal core class
henningkayser Aug 20, 2019
6aa20a8
Remove unused headers
henningkayser Aug 20, 2019
eb9c5fd
Remove unused forwards and structs
henningkayser Aug 20, 2019
a4a58a6
Implement plan/execution interface
henningkayser Aug 22, 2019
618767e
Change author in headers
henningkayser Aug 22, 2019
a3627dc
Cleanup + clang
henningkayser Aug 22, 2019
79bd090
Remove debug messages
henningkayser Aug 22, 2019
9976056
Make options accessible + fix TF
henningkayser Aug 30, 2019
e27dc99
Implement CostConvergenceTerminationCondition for OMPL* planners
henningkayser Jul 13, 2019
cf30235
Fix CostConvergenceTerminationCondition
henningkayser Aug 8, 2019
16b6175
Implement support for multi-query planners in OMPL
henningkayser Aug 23, 2019
bc0f153
Support storing/loading roadmaps for PRM variants
henningkayser Sep 4, 2019
44dc6dc
Add separate flag for loading/storing planner data
henningkayser Sep 12, 2019
76c84c8
moveit_cpp: add getter for last plan solution, add missing implementa…
mamoll Sep 19, 2019
9d576b4
moveit_cpp: add getter for PlanningComponent::joint_model_group_
mamoll Sep 19, 2019
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*********************************************************************
* Software License Agreement (BSD License)
*
* Copyright (c) 2019, PickNik LLC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of PickNik LLC nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/

/* Author: Henning Kayser */
/* Description: A termination condition for early-stopping OMPL* planners based on cost-convergence. */

#include <ompl/base/PlannerTerminationCondition.h>
namespace ompl_interface
{
namespace ob = ompl::base;
class CostConvergenceTerminationCondition : public ob::PlannerTerminationCondition
{
public:
CostConvergenceTerminationCondition(size_t solutions_window = 10, double convergence_threshold = 0.9)
: ob::PlannerTerminationCondition([] { return false; })
, solutions_window_(solutions_window)
, convergence_threshold_(convergence_threshold)
{
}

// Compute the running average cost of the last solutions (solution_window) and terminate if the cost of a
// new solution is higher than convergence_threshold times the average cost.
void processNewSolution(const std::vector<const ob::State*>& solution_states, double solution_cost)
{
++solutions_;
size_t solutions = std::min(solutions_, solutions_window_);
double new_cost = ((solutions - 1) * average_cost_ + solution_cost) / solutions;
double cost_ratio = new_cost / average_cost_;
average_cost_ = new_cost;
if (solutions == solutions_window_ && cost_ratio > convergence_threshold_)
{
ROS_DEBUG_NAMED("cost_convergence_termination_condition",
"Cost of optimizing planner converged after %lu solutions", solutions_);
terminate();
}
}

private:
double average_cost_;
size_t solutions_ = 0;

const size_t solutions_window_;
const double convergence_threshold_;
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
/*********************************************************************
* Software License Agreement (BSD License)
*
* Copyright (c) 2019, PickNik LLC
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of PickNik LLC nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/

/* Author: Henning Kayser */
/* Description: Support for storing and loading planner data for PRM-based planners. */

#pragma once

#include <ompl/geometric/planners/prm/PRM.h>
#include <ompl/geometric/planners/prm/LazyPRM.h>
#include <ompl/tools/config/SelfConfig.h>
#include <type_traits>

namespace ompl
{
namespace geometric
{
class PRMPersist : public PRM
{
public:
PRMPersist(const base::PlannerData& data, bool starStrategy = false) : PRM(data.getSpaceInformation(), starStrategy)
{
if (data.numVertices() > 0)
{
std::map<unsigned int, Vertex> vertices;
const auto& si = data.getSpaceInformation();
const auto& getOrCreateVertex = [&](unsigned int vertex_index) {
if (!vertices.count(vertex_index))
{
const auto& data_vertex = data.getVertex(vertex_index);
Vertex graph_vertex = boost::add_vertex(g_);
stateProperty_[graph_vertex] = si->cloneState(data_vertex.getState());
totalConnectionAttemptsProperty_[graph_vertex] = 1;
successfulConnectionAttemptsProperty_[graph_vertex] = 0;
vertices[vertex_index] = graph_vertex;
}
return vertices.at(vertex_index);
};

specs_.multithreaded = false;
nn_.reset(tools::SelfConfig::getDefaultNearestNeighbors<Vertex>(this));
specs_.multithreaded = true;
nn_->setDistanceFunction([this](const Vertex a, const Vertex b) { return distanceFunction(a, b); });

for (size_t vertex_index = 0; vertex_index < data.numVertices(); ++vertex_index)
{
Vertex m = getOrCreateVertex(vertex_index);
std::vector<unsigned int> neighbor_indices;
data.getEdges(vertex_index, neighbor_indices);
if (neighbor_indices.empty())
{
disjointSets_.make_set(m);
}
else
{
for (const unsigned int neighbor_index : neighbor_indices)
{
Vertex n = getOrCreateVertex(neighbor_index);
totalConnectionAttemptsProperty_[n]++;
successfulConnectionAttemptsProperty_[n]++;
base::Cost weight;
data.getEdgeWeight(vertex_index, neighbor_index, &weight);
const Graph::edge_property_type properties(weight);
boost::add_edge(m, n, properties, g_);
uniteComponents(m, n);
}
}
nn_->add(m);
}
}
};
PRMPersist(const base::SpaceInformationPtr& si, bool starStrategy = false) : PRM(si, starStrategy){};
};
class PRMStarPersist : public PRMPersist
{
public:
PRMStarPersist(const base::PlannerData& data) : PRMPersist(data, true){};
PRMStarPersist(const base::SpaceInformationPtr& si) : PRMPersist(si, true){};
};

class LazyPRMPersist : public LazyPRM
{
public:
LazyPRMPersist(const base::PlannerData& data, bool starStrategy = false)
: LazyPRM(data.getSpaceInformation(), starStrategy)
{
if (data.numVertices() > 0)
{
std::map<unsigned int, Vertex> vertices;
const auto& si = data.getSpaceInformation();
const auto& getOrCreateVertex = [&](unsigned int vertex_index) {
if (!vertices.count(vertex_index))
{
const auto& data_vertex = data.getVertex(vertex_index);
Vertex graph_vertex = boost::add_vertex(g_);
stateProperty_[graph_vertex] = si->cloneState(data_vertex.getState());
vertexValidityProperty_[graph_vertex] = VALIDITY_UNKNOWN;
unsigned long int newComponent = componentCount_++;
vertexComponentProperty_[graph_vertex] = newComponent;
vertices[vertex_index] = graph_vertex;
}
return vertices.at(vertex_index);
};

specs_.multithreaded = false;
nn_.reset(tools::SelfConfig::getDefaultNearestNeighbors<Vertex>(this));
specs_.multithreaded = true;
nn_->setDistanceFunction([this](const Vertex a, const Vertex b) { return distanceFunction(a, b); });

for (size_t vertex_index = 0; vertex_index < data.numVertices(); ++vertex_index)
{
Vertex m = getOrCreateVertex(vertex_index);
std::vector<unsigned int> neighbor_indices;
data.getEdges(vertex_index, neighbor_indices);
for (const unsigned int neighbor_index : neighbor_indices)
{
Vertex n = getOrCreateVertex(neighbor_index);
base::Cost weight;
data.getEdgeWeight(vertex_index, neighbor_index, &weight);
const Graph::edge_property_type properties(weight);
const Edge& edge = boost::add_edge(m, n, properties, g_).first;
edgeValidityProperty_[edge] = VALIDITY_UNKNOWN;
uniteComponents(m, n);
}
nn_->add(m);
}
}
};
LazyPRMPersist(const base::SpaceInformationPtr& si, bool starStrategy = false) : LazyPRM(si, starStrategy){};
};
class LazyPRMStarPersist : public LazyPRMPersist
{
public:
LazyPRMStarPersist(const base::PlannerData& data) : LazyPRMPersist(data, true){};
LazyPRMStarPersist(const base::SpaceInformationPtr& si) : LazyPRMPersist(si, true){};
};
}
}
namespace
{
template <typename T>
inline ompl::base::Planner* allocatePersistingPlanner(const ompl::base::PlannerData& data)
{
return NULL;
};
template <>
inline ompl::base::Planner* allocatePersistingPlanner<ompl::geometric::PRMPersist>(const ompl::base::PlannerData& data)
{
return new ompl::geometric::PRMPersist(data);
};
template <>
inline ompl::base::Planner*
allocatePersistingPlanner<ompl::geometric::PRMStarPersist>(const ompl::base::PlannerData& data)
{
return new ompl::geometric::PRMStarPersist(data);
};
template <>
inline ompl::base::Planner*
allocatePersistingPlanner<ompl::geometric::LazyPRMPersist>(const ompl::base::PlannerData& data)
{
return new ompl::geometric::LazyPRMPersist(data);
};
template <>
inline ompl::base::Planner*
allocatePersistingPlanner<ompl::geometric::LazyPRMStarPersist>(const ompl::base::PlannerData& data)
{
return new ompl::geometric::LazyPRMStarPersist(data);
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,8 @@ class ModelBasedPlanningContext : public planning_interface::PlanningContext
virtual void useConfig();
virtual ob::GoalPtr constructGoal();

ob::PlannerTerminationCondition getPlannerTerminationCondition(
double ptc_timeout, const std::shared_ptr<ob::PlannerTerminationCondition>& alternative_ptc = nullptr);
void registerTerminationCondition(const ob::PlannerTerminationCondition& ptc);
void unregisterTerminationCondition();

Expand Down Expand Up @@ -373,6 +375,9 @@ class ModelBasedPlanningContext : public planning_interface::PlanningContext

bool use_state_validity_cache_;

/// clears planners that don't support multi-query use before running solve()
bool multi_query_planning_enabled_;

bool simplify_solutions_;
};
} // namespace ompl_interface
Loading