hpp_tutorial  5.0.0
Tutorial for humanoid path planner platform.
Tutorial 2 - Plugin

In this tutorial, we are going to implement a new path planning algorithm within a plugin.

Implementing a new path

planning algorithm in a plugin

The code of this tutorial can be found in src/tutorial_2.cc. The compilation and installation instructions can be found in src/CMakeLists.txt.

Implementation of class

Planner

File src/tutorial_2.cc implements class hpp::tutorial::Planner, deriving from abstract class hpp::core::PathPlanner. In this section, we explain some specific parts of the code.

HPP_PREDEF_CLASS (Planner);

is a macro containing the forward declaration of class Planner as well as PlannerWkPtr_t for weak pointer to class Planner. See hpp/util/pointer.hh for details.

static PlannerPtr_t create (const core::Problem& problem,
const core::RoadmapPtr_t& roadmap)

As most classes, hpp::core::PathPlanner and any derived class are manipulated via shared pointers. Users are not allowed to define variables of the type. Instead, they are required to call method create and to store the resulting shared pointer. For this reason, the constructors are all protected.

Note
method create calls protected method init that is explained later on.
virtual void oneStep ()

This method runs one step of our the algorithm. The new algorithm is a basic version of PRM. Notice the compactness of the code.

void init (const PlannerWkPtr_t& weak)

Method init takes as input a weak pointer to a new instance and stores this weak pointer as a private member. This enables any object to create a shared pointer to itself on demand using the following line of code

weakPtr_.lock ();

which is the shared pointer equivalent to this when using simple pointers.

Note
Method init always calls the parent implementation so that the parent part of the object also stores a weak pointer to itself.

Implementation of plugin

tutorial-2.so

Now that the new class hpp::tutorial::Planner has been implemented, we are going to add it via a plugin.

class Plugin : public core::ProblemSolverPlugin {
public:
Plugin() : ProblemSolverPlugin("TutorialPlugin", "0.0") {}
protected:
virtual bool impl_initialize(core::ProblemSolverPtr_t ps) {
ps->pathPlanners.add("TutorialPRM", Planner::create);
return true;
}
}; // class Plugin

class hpp::tutorial::Plugin derives from abstract class hpp::core::ProblemSolverPlugin. Upon loading of the plugin by hppcorbaserver, method impl_initialize is called. This method register our new path planning class with key "TutorialPRM"

HPP_CORE_DEFINE_PLUGIN(hpp::tutorial::Plugin)

This macro register the new plugin.

Compilation and installation

The compilation and installation is done in file src/CMakeLists.txt by the following lines

## Tutorial 2
include(${HPP_CORE_CMAKE_PLUGIN})
# Create and install the plugin
hpp_add_plugin(tutorial-2 SOURCES tutorial_2.cc LINK_DEPENDENCIES
hpp-corbaserver::hpp-corbaserver)

These two lines declare a new plugin the source file of which is tutorial-2.cc and install this plugin into lib/hppPlugins subdirectory of the installation prefix.

Using the plugin and solving a

problem.

To solve a problem with the new path planning algorithm, we simply need to follow the same steps as in tutorial 1, except that we should source script/tutorial_2.py instead of script/tutorial_1.py

loaded = ps.client.problem.loadPlugin("tutorial-2.so")
assert(loaded)
ps.selectPathPlanner("TutorialPRM")

The above lines load the plugin and select the new path planner.