Skip to content

Instantly share code, notes, and snippets.

@contradict
Created February 21, 2015 21:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save contradict/0c4589a0ff83c3c13c29 to your computer and use it in GitHub Desktop.
Save contradict/0c4589a0ff83c3c13c29 to your computer and use it in GitHub Desktop.
compile with
g++ -I/opt/ros/indigo/include -I/usr/include/python2.7 python_costmap2d.cpp -fPIC --shared -L/opt/ros/indigo/lib -lcostmap_2d -lpython2.7 -lboost_python -o costmap2d_ext.so
import costmap2d_ext
layerloader = costmap2d_ext.LayerLoader("costmap_2d", "costmap_2d::Layer")
obstacle_layer = ll.createInstance('costmap_2d::VoxelLayer')
layered_costmap = costmap2d_ext.LayeredCostmap("map",True, True)
layered_costmap.addPlugin(obstacle_layer)
# this crashes on exit, likely because the plugins are not properly unloaded
#include <boost/python.hpp>
#include <boost/python/suite/indexing/vector_indexing_suite.hpp>
#include <costmap_2d/costmap_2d.h>
#include <costmap_2d/layer.h>
#include <costmap_2d/layered_costmap.h>
#include <pluginlib/class_loader.h>
namespace bp = boost::python;
namespace c2 = costmap_2d;
namespace pl = pluginlib;
BOOST_PYTHON_MODULE(costmap2d_ext)
{
bp::class_<std::vector<std::string> >("ListOfString")
.def(bp::vector_indexing_suite<std::vector<std::string> >() )
;
bp::class_<boost::shared_ptr<c2::Layer> >("SharedPointerToLayer")
;
bp::class_<c2::LayeredCostmap> ("LayeredCostmap",
bp::init<std::string, bool, bool>())
.def("addPlugin", &c2::LayeredCostmap::addPlugin)
;
bp::class_<pl::ClassLoader<c2::Layer>, boost::noncopyable >("LayerLoader",
bp::init<std::string, std::string, bp::optional<std::string, std::vector<std::string> > >())
.def("getDeclaredClasses", &pl::ClassLoader<c2::Layer>::getDeclaredClasses)
.def("createInstance", &pl::ClassLoader<c2::Layer>::createInstance)
//boost::shared_ptr<T> createInstance(const std::string& lookup_name);
;
bp::class_<c2::Costmap2D>("Costmap2D",
bp::init<unsigned int, unsigned int, double, double, double, bp::optional<unsigned char> >())
;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment