wrap_python_planning_scene_interface.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2013, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
41 
42 #include <boost/function.hpp>
43 #include <boost/python.hpp>
44 #include <Python.h>
45 
48 namespace bp = boost::python;
49 
50 namespace moveit
51 {
52 namespace planning_interface
53 {
54 class PlanningSceneInterfaceWrapper : protected py_bindings_tools::ROScppInitializer, public PlanningSceneInterface
55 {
56 public:
57  // ROSInitializer is constructed first, and ensures ros::init() was called, if needed
58  PlanningSceneInterfaceWrapper() : py_bindings_tools::ROScppInitializer(), PlanningSceneInterface()
59  {
60  }
61 
62  bp::list getKnownObjectNamesPython(bool with_type = false)
63  {
64  return py_bindings_tools::listFromString(getKnownObjectNames(with_type));
65  }
66 
67  bp::list getKnownObjectNamesInROIPython(double minx, double miny, double minz, double maxx, double maxy, double maxz,
68  bool with_type = false)
69  {
70  return py_bindings_tools::listFromString(getKnownObjectNamesInROI(minx, miny, minz, maxx, maxy, maxz, with_type));
71  }
72 
73  bp::dict getObjectPosesPython(bp::list object_ids)
74  {
75  std::map<std::string, geometry_msgs::Pose> ops = getObjectPoses(py_bindings_tools::stringFromList(object_ids));
76  std::map<std::string, std::string> ser_ops;
77  for (std::map<std::string, geometry_msgs::Pose>::const_iterator it = ops.begin(); it != ops.end(); ++it)
78  ser_ops[it->first] = py_bindings_tools::serializeMsg(it->second);
79 
80  return py_bindings_tools::dictFromType(ser_ops);
81  }
82 
83  bp::dict getObjectsPython(bp::list object_ids)
84  {
85  std::map<std::string, moveit_msgs::CollisionObject> objs =
86  getObjects(py_bindings_tools::stringFromList(object_ids));
87  std::map<std::string, std::string> ser_objs;
88  for (std::map<std::string, moveit_msgs::CollisionObject>::const_iterator it = objs.begin(); it != objs.end(); ++it)
89  ser_objs[it->first] = py_bindings_tools::serializeMsg(it->second);
90 
91  return py_bindings_tools::dictFromType(ser_objs);
92  }
93 
94  bp::dict getAttachedObjectsPython(const bp::list& object_ids)
95  {
96  std::map<std::string, moveit_msgs::AttachedCollisionObject> aobjs =
97  getAttachedObjects(py_bindings_tools::stringFromList(object_ids));
98  std::map<std::string, std::string> ser_aobjs;
99  for (std::map<std::string, moveit_msgs::AttachedCollisionObject>::const_iterator it = aobjs.begin();
100  it != aobjs.end(); ++it)
101  ser_aobjs[it->first] = py_bindings_tools::serializeMsg(it->second);
102 
103  return py_bindings_tools::dictFromType(ser_aobjs);
104  }
105 };
106 
107 static void wrap_planning_scene_interface()
108 {
109  bp::class_<PlanningSceneInterfaceWrapper> PlanningSceneClass("PlanningSceneInterface");
110 
111  PlanningSceneClass.def("get_known_object_names", &PlanningSceneInterfaceWrapper::getKnownObjectNamesPython);
112  PlanningSceneClass.def("get_known_object_names_in_roi",
113  &PlanningSceneInterfaceWrapper::getKnownObjectNamesInROIPython);
114  PlanningSceneClass.def("get_object_poses", &PlanningSceneInterfaceWrapper::getObjectPosesPython);
115  PlanningSceneClass.def("get_objects", &PlanningSceneInterfaceWrapper::getObjectsPython);
116  PlanningSceneClass.def("get_attached_objects", &PlanningSceneInterfaceWrapper::getAttachedObjectsPython);
117 }
118 }
119 }
120 
121 BOOST_PYTHON_MODULE(_moveit_planning_scene_interface)
122 {
123  using namespace moveit::planning_interface;
124  wrap_planning_scene_interface();
125 }
126 
boost::python::dict dictFromType(const std::map< std::string, T > &v)
BOOST_PYTHON_MODULE(_moveit_roscpp_initializer)
std::vector< std::string > stringFromList(const boost::python::object &values)
Simple interface to MoveIt! components.
boost::python::list listFromString(const std::vector< std::string > &v)
std::string serializeMsg(const T &msg)
Convert a ROS message to a string.
Definition: serialize_msg.h:48


planning_interface
Author(s): Ioan Sucan
autogenerated on Mon Jan 15 2018 03:52:20