hpp_tutorial  4.9.0
Tutorial for humanoid path planner platform.
Tutorial 2

Implementing a new path planning algorithm

The code of this tutorial can be found in src/tutorial.cc. The compilation and installation instructions can be found in 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 executable hpp-tutorial-2-server

Now that the new class hpp::tutorial::Planner has been implemented, we are going to use it in a new executable. The new executable is defined by

int main (int argc, const char* argv[])

This executable creates an instance of hpp::core::ProblemSolver,

adds the constructor of class hpp::tutorial::Planner in the map of the ProblemSolver instance with key "PRM",

creates a CORBA server with the ProblemSolver instance,

hpp::corbaServer::Server server (problemSolver, argc, argv, true);

starts the CORBA server, and

server.startCorbaServer ();

process client requests forever.

server.processRequest (true);

Compilation and installation

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

CMAKE_MINIMUM_REQUIRED (VERSION 2.6)
INCLUDE(cmake/base.cmake)
SET(PROJECT_NAME hpp_tutorial)
SET(PROJECT_DESCRIPTION
"Tutorial for humanoid path planner platform."
)
SET(PROJECT_URL "")
SETUP_PROJECT()
ADD_REQUIRED_DEPENDENCY("hpp-corbaserver >= 3")
# Create and install executable running the corba server
ADD_EXECUTABLE (hpp-tutorial-2-server
src/tutorial_2.cc
)
# Link executable with hpp-corbaserver library
PKG_CONFIG_USE_DEPENDENCY (hpp-tutorial-2-server hpp-corbaserver)
# Install executable
INSTALL (TARGETS hpp-tutorial-2-server DESTINATION ${CMAKE_INSTALL_BINDIR})
SETUP_PROJECT_FINALIZE()

Running the server and solving a problem.

To run your executable and solve a problem with your path planning algorithm, you simply need to follow the same steps as in tutorial 1, except that you should start

hpp-tutorial-2-server

instead of hppcorbaserver and source script/tutorial_2.py instead of script/tutorial_1.py, or make sure that you add the following line before solving the problem

ps.selectPathPlanner ("PRM")
Warning
Basic PRM is very inefficient. Resolution can take a long time, especially if you have compiled in debug mode.

Moving the code into an external package

To implement the above executable in an external package, you should do the following steps.

  • create a new directory in src, for instance
    mkdir my-hpp-project
  • create a file README.md describing the new package
    echo "Implementation of a new path planning algorithm embedded in a CORBA server" > my-hpp-project/README.md
  • create an empty Doxyfile.extra.in file
    mkdir my-hpp-project/doc; touch my-hpp-project/doc/Doxyfile.extra.in
  • copy the above cmake code into my-hpp-project/CMakeLists.txt, after replacing names by the names you have chosen,
  • copy file src/tutorial.cc into my-hpp-project/src
    mkdir my-hpp-project/src
    cp hpp_tutorial/src/tutorial.cc my-hpp-project/src/.
    Go into the project directory and initialize git.
    cd my-hpp-project; git init; git add .
    Import the cmake git sub-module
    git submodule add git://github.com/jrl-umi3218/jrl-cmakemodules.git cmake
    Commit this first version.
    git commit -m "My first hpp project"

Installation

The package is ready for installation. Create a build directory

mkdir build; cd build

configure and install

cmake -DCMAKE_INSTALL_PREFIX=${DEVEL_DIR}/install ..
make install

Executable hpp-tutorial-2-server is installed and can be run from the terminal.