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(const std::string& ns = "")
59  : py_bindings_tools::ROScppInitializer(), PlanningSceneInterface(ns)
60  {
61  }
62 
63  bp::list getKnownObjectNamesPython(bool with_type = false)
64  {
65  return py_bindings_tools::listFromString(getKnownObjectNames(with_type));
66  }
67 
68  bp::list getKnownObjectNamesInROIPython(double minx, double miny, double minz, double maxx, double maxy, double maxz,
69  bool with_type = false)
70  {
71  return py_bindings_tools::listFromString(getKnownObjectNamesInROI(minx, miny, minz, maxx, maxy, maxz, with_type));
72  }
73 
74  bp::dict getObjectPosesPython(const bp::list& object_ids)
75  {
76  std::map<std::string, geometry_msgs::Pose> ops = getObjectPoses(py_bindings_tools::stringFromList(object_ids));
77  std::map<std::string, py_bindings_tools::ByteString> ser_ops;
78  for (std::map<std::string, geometry_msgs::Pose>::const_iterator it = ops.begin(); it != ops.end(); ++it)
79  ser_ops[it->first] = py_bindings_tools::serializeMsg(it->second);
80 
81  return py_bindings_tools::dictFromType(ser_ops);
82  }
83 
84  bp::dict getObjectsPython(const bp::list& object_ids)
85  {
86  std::map<std::string, moveit_msgs::CollisionObject> objs =
87  getObjects(py_bindings_tools::stringFromList(object_ids));
88  std::map<std::string, py_bindings_tools::ByteString> ser_objs;
89  for (std::map<std::string, moveit_msgs::CollisionObject>::const_iterator it = objs.begin(); it != objs.end(); ++it)
90  ser_objs[it->first] = py_bindings_tools::serializeMsg(it->second);
91 
92  return py_bindings_tools::dictFromType(ser_objs);
93  }
94 
95  bp::dict getAttachedObjectsPython(const bp::list& object_ids)
96  {
97  std::map<std::string, moveit_msgs::AttachedCollisionObject> aobjs =
98  getAttachedObjects(py_bindings_tools::stringFromList(object_ids));
99  std::map<std::string, py_bindings_tools::ByteString> ser_aobjs;
100  for (std::map<std::string, moveit_msgs::AttachedCollisionObject>::const_iterator it = aobjs.begin();
101  it != aobjs.end(); ++it)
102  ser_aobjs[it->first] = py_bindings_tools::serializeMsg(it->second);
103 
104  return py_bindings_tools::dictFromType(ser_aobjs);
105  }
106 
107  py_bindings_tools::ByteString getPlanningScenePython(const uint32_t components)
108  {
109  moveit_msgs::PlanningScene msg = getPlanningSceneMsg(components);
111  }
112 
113  bool applyPlanningScenePython(const py_bindings_tools::ByteString& ps_str)
114  {
115  moveit_msgs::PlanningScene ps_msg;
116  py_bindings_tools::deserializeMsg(ps_str, ps_msg);
117  return applyPlanningScene(ps_msg);
118  }
119 };
120 
121 static void wrap_planning_scene_interface()
122 {
123  bp::class_<PlanningSceneInterfaceWrapper> planning_scene_class("PlanningSceneInterface",
124  bp::init<bp::optional<std::string>>());
125 
126  planning_scene_class.def("get_known_object_names", &PlanningSceneInterfaceWrapper::getKnownObjectNamesPython);
127  planning_scene_class.def("get_known_object_names_in_roi",
128  &PlanningSceneInterfaceWrapper::getKnownObjectNamesInROIPython);
129  planning_scene_class.def("get_object_poses", &PlanningSceneInterfaceWrapper::getObjectPosesPython);
130  planning_scene_class.def("get_objects", &PlanningSceneInterfaceWrapper::getObjectsPython);
131  planning_scene_class.def("get_attached_objects", &PlanningSceneInterfaceWrapper::getAttachedObjectsPython);
132  planning_scene_class.def("get_planning_scene", &PlanningSceneInterfaceWrapper::getPlanningScenePython);
133  planning_scene_class.def("apply_planning_scene", &PlanningSceneInterfaceWrapper::applyPlanningScenePython);
134  planning_scene_class.def("clear", &PlanningSceneInterfaceWrapper::clear);
135 }
136 } // namespace planning_interface
137 } // namespace moveit
138 
139 BOOST_PYTHON_MODULE(_moveit_planning_scene_interface)
140 {
141  using namespace moveit::planning_interface;
142  wrap_planning_scene_interface();
143 }
144 
boost::python
roscpp_initializer.h
BOOST_PYTHON_MODULE
BOOST_PYTHON_MODULE(_moveit_roscpp_initializer)
Definition: wrap_python_roscpp_initializer.cpp:50
moveit::py_bindings_tools::listFromString
boost::python::list listFromString(const std::vector< std::string > &v)
Definition: py_conversions.h:155
moveit::py_bindings_tools::stringFromList
std::vector< std::string > stringFromList(const boost::python::object &values)
Definition: py_conversions.h:145
py_conversions.h
serialize_msg.h
moveit::py_bindings_tools::dictFromType
boost::python::dict dictFromType(const std::map< std::string, T > &v)
Definition: py_conversions.h:132
planning_scene_interface.h
moveit
planning_interface
moveit::py_bindings_tools::deserializeMsg
void deserializeMsg(const ByteString &data, T &msg)
Convert a Python Bytestring to a ROS message.
Definition: serialize_msg.h:174
moveit::planning_interface
Simple interface to MoveIt components.
moveit::py_bindings_tools::serializeMsg
ByteString serializeMsg(const T &msg)
Convert a ROS message to a Python Bytestring.
Definition: serialize_msg.h:167


planning_interface
Author(s): Ioan Sucan
autogenerated on Thu Apr 18 2024 02:25:17