How to send EnvironmentBasePtr from python program to c++?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

How to send EnvironmentBasePtr from python program to c++?

saurabdixit
Hello Everyone,
                      I want to use depth penetration functionality available in c++. I wrote a function in c++ to return a vector after calling it from python. I am using BOOST_PYTHON_MODULE. I want to send EnvironmentBasePtr from python to c++ as input to the function. So far, I am not able to do it. Does anyone know a method for sending the pointer from python to c++? I am not much familiar in c++.

Following is my current method:
#include "openrave-core.h"
#include "ros/ros.h"
#include "std_msgs/String.h"
#include "valid_grasp_generator/GraspSnapshot.h"
#include <iostream>
#include <vector>
#include <boost/python.hpp>
#include <sstream>
using namespace OpenRAVE;
using namespace std;

boost::python::list get_penetration_depth(string env)
{
    vector<double> vec(9,0);
    stringstream ss(env);
    long long unsigned int i;
    ss >> hex >> i;
    EnvironmentBasePtr penv = reinterpret_cast<int *>(i);


    //code for getting penetration value from the openrave

    typename std::vector<double>::iterator iter;
    boost::python::list list;
    for (iter = vec.begin(); iter != vec.end(); ++iter) {
    list.append(*iter);
    }
    return list;
}

BOOST_PYTHON_MODULE(libdepth_penetration){
    using namespace boost::python;
    def("get_penetration", get_penetration_depth);
}



Error given by catkin_make:

/home/saurabh/catkin_ws/src/valid_grasp_generator/src/depth_penetration.cpp: In function ‘boost::python::list get_penetration_depth(std::string)’:
/home/saurabh/catkin_ws/src/valid_grasp_generator/src/depth_penetration.cpp:37:56: error: conversion from ‘int*’ to non-scalar type ‘OpenRAVE::EnvironmentBasePtr {aka boost::shared_ptr<OpenRAVE::EnvironmentBase>}’ requested
     EnvironmentBasePtr penv = reinterpret_cast<int *>(i);
                                                        ^
make[2]: *** [valid_grasp_generator/CMakeFiles/depth_penetration.dir/src/depth_penetration.cpp.o] Error 1
make[1]: *** [valid_grasp_generator/CMakeFiles/depth_penetration.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j8 -l8" failed

Loading...