diff --git a/CMakeLists.txt b/CMakeLists.txt index a6d87d34b87e4bc8a17caf3c55542e175868714e..4b9f48f961d4c31d60556dfd1be106fcdb66aa0f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,7 @@ SET (${PROJECT_NAME}_HEADERS include/hpp/manipulation/robot.hh include/hpp/manipulation/manipulation-planner.hh include/hpp/manipulation/graph-path-validation.hh + include/hpp/manipulation/graph-steering-method.hh include/hpp/manipulation/graph/node.hh include/hpp/manipulation/graph/edge.hh include/hpp/manipulation/graph/node-selector.hh diff --git a/include/hpp/manipulation/graph-steering-method.hh b/include/hpp/manipulation/graph-steering-method.hh index 40cf2b993547f4963f86b7b5cf292cb4d7ad9cb9..0c4dc27e197b8d2c965c515a7b23a07b00e523fe 100644 --- a/include/hpp/manipulation/graph-steering-method.hh +++ b/include/hpp/manipulation/graph-steering-method.hh @@ -19,18 +19,49 @@ # define HPP_MANIPULATION_GRAPH_STEERING_METHOD_HH # include <hpp/core/steering-method.hh> +# include <hpp/core/weighed-distance.hh> +# include <hpp/model/device.hh> -#include "hpp/manipulation/fwd.hh" +# include "hpp/manipulation/fwd.hh" namespace hpp { namespace manipulation { - class GraphSteeringMethod : public SteeringMethod + using core::SteeringMethod; + using core::PathPtr_t; + + class HPP_MANIPULATION_DLLAPI GraphSteeringMethod : public SteeringMethod { public: - GraphSteeringMethod (SteeringMethod) + /// Constructor + GraphSteeringMethod (const DevicePtr_t& robot); + + /// \name Graph of constraints applicable to the robot. + /// \{ + + /// Set constraint graph + void constraintGraph (const graph::GraphPtr_t& graph) + { + graph_ = graph; + } + + /// Get constraint graph + const graph::GraphPtr_t& constraintGraph () const + { + return graph_; + } + /// \} + protected: virtual PathPtr_t impl_compute (ConfigurationIn_t q1, ConfigurationIn_t q2) const; - } + + private: + /// A pointer to the graph of constraint. + graph::GraphPtr_t graph_; + /// Pointer to the Robot. + core::DeviceWkPtr_t robot_; + /// Metric in configuration space. + core::WeighedDistancePtr_t distance_; + }; } // namespace manipulation } // namespace hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6982ee3cd633796a360791faba60d1876acb7787..3e503c66cabac4f90e25a4bd2edc361dd7126f9d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,6 +26,7 @@ ADD_LIBRARY(${LIBRARY_NAME} SHARED robot.cc manipulation-planner.cc graph-path-validation.cc + graph-steering-method.cc graph/node.cc graph/edge.cc diff --git a/src/graph-steering-method.cc b/src/graph-steering-method.cc new file mode 100644 index 0000000000000000000000000000000000000000..d2691d2fd1132400e84ed5fb0f63404337065461 --- /dev/null +++ b/src/graph-steering-method.cc @@ -0,0 +1,49 @@ +// Copyright (c) 2014, LAAS-CNRS +// Authors: Joseph Mirabel (joseph.mirabel@laas.fr) +// +// This file is part of hpp-manipulation. +// hpp-manipulation is free software: you can redistribute it +// and/or modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation, either version +// 3 of the License, or (at your option) any later version. +// +// hpp-manipulation is distributed in the hope that it will be +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Lesser Public License for more details. You should have +// received a copy of the GNU Lesser General Public License along with +// hpp-manipulation. If not, see <http://www.gnu.org/licenses/>. + +#include <hpp/core/straight-path.hh> + +#include "hpp/manipulation/graph/graph.hh" +#include "hpp/manipulation/graph/edge.hh" +#include "hpp/manipulation/graph-steering-method.hh" + +namespace hpp { + namespace manipulation { + GraphSteeringMethod::GraphSteeringMethod (const DevicePtr_t& robot) : + SteeringMethod (), robot_ (robot), + distance_ (core::WeighedDistance::create (robot)) + { + } + + PathPtr_t GraphSteeringMethod::impl_compute (ConfigurationIn_t q1, ConfigurationIn_t q2) const + { + value_type length = (*distance_) (q1,q2); + PathPtr_t path = core::StraightPath::create (robot_.lock(), q1, q2, length); + std::vector< graph::Edges_t > possibleEdges = + graph_->getEdge (graph_->getNode (q1), graph_->getNode (q2)); + ConstraintSetPtr_t constraints; + while (!possibleEdges.empty()) { + constraints = graph_->pathConstraint (possibleEdges.back(), q1); + if (constraints->isSatisfied (q2)) { + path->constraints (constraints); + break; + } + possibleEdges.pop_back (); + } + return path; + } + } // namespace manipulation +} // namespace hpp