moveit2
The MoveIt Motion Planning Framework for ROS 2.
pycollision_detection.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2021, Peter Mitrano
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  * * The name of Peter Mitrano may not be used to endorse or promote
18  * products derived from this software without specific prior
19  * 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: Peter Mitrano */
36 
37 #include <pybind11/pybind11.h>
38 #include <pybind11/stl.h>
39 #include <pybind11/eigen.h>
44 
45 namespace py = pybind11;
46 
47 using namespace collision_detection;
48 
50 {
51  m.doc() = "contains collision detection, the world, and allowed collision matrices";
52  py::enum_<BodyType>(m, "BodyType")
53  .value("ROBOT_ATTACHED", BodyType::ROBOT_ATTACHED)
54  .value("ROBOT_LINK", BodyType::ROBOT_LINK)
55  .value("WORLD_OBJECT", BodyType::WORLD_OBJECT)
56  .export_values();
57  py::class_<Contact>(m, "Contact")
58  .def(py::init<>())
59  .def_readwrite("body_name_1", &Contact::body_name_1)
60  .def_readwrite("body_name_2", &Contact::body_name_2)
61  .def_readwrite("body_type_1", &Contact::body_type_1)
62  .def_readwrite("body_type_2", &Contact::body_type_2)
63  .def_readwrite("depth", &Contact::depth)
64  .def_property_readonly("nearest_points",
65  [](const Contact& contact) {
66  std::vector<Eigen::Vector3d> v{ contact.nearest_points[0], contact.nearest_points[1] };
67  return v;
68  })
69  .def_readwrite("normal", &Contact::normal)
70  .def_readwrite("percent_interpolation", &Contact::percent_interpolation)
71  .def_readwrite("pos", &Contact::pos)
72  //
73  ;
74  py::class_<CollisionRequest>(m, "CollisionRequest")
75  .def(py::init<>())
76  .def_readwrite("contacts", &CollisionRequest::contacts)
77  .def_readwrite("cost", &CollisionRequest::cost)
78  .def_readwrite("distance", &CollisionRequest::distance)
79  .def_readwrite("group_name", &CollisionRequest::group_name)
80  .def_readwrite("is_done", &CollisionRequest::is_done)
81  .def_readwrite("max_contacts", &CollisionRequest::max_contacts)
82  .def_readwrite("max_contacts_per_pair", &CollisionRequest::max_contacts_per_pair)
83  .def_readwrite("max_cost_sources", &CollisionRequest::max_cost_sources)
84  .def_readwrite("verbose", &CollisionRequest::verbose)
85  //
86  ;
87  py::class_<CollisionResult>(m, "CollisionResult")
88  .def(py::init<>())
89  .def_readwrite("collision", &CollisionResult::collision)
90  .def_readwrite("contact_count", &CollisionResult::contact_count)
91  .def_readwrite("contacts", &CollisionResult::contacts)
92  .def_readwrite("cost_sources", &CollisionResult::cost_sources)
93  .def_readwrite("distance", &CollisionResult::distance)
94  .def("clear", &CollisionResult::clear)
95  //
96  ;
97  py::class_<AllowedCollisionMatrix>(m, "AllowedCollisionMatrix")
98  .def(py::init<>())
99  .def("setEntry",
100  py::overload_cast<const std::string&, const std::string&, bool>(&AllowedCollisionMatrix::setEntry))
101  //
102  ;
103  py::class_<World, WorldPtr>(m, "World").def(py::init<>());
104 }
void setEntry(const std::string &name1, const std::string &name2, bool allowed)
Set an entry corresponding to a pair of elements.
@ ROBOT_LINK
A link on the robot.
@ ROBOT_ATTACHED
A body attached to a robot link.
@ WORLD_OBJECT
A body in the environment.
void def_collision_detection_bindings(py::module &m)
std::string group_name
The group name to check collisions for (optional; if empty, assume the complete robot)
bool verbose
Flag indicating whether information about detected collisions should be reported.
std::size_t max_cost_sources
When costs are computed, this value defines how many of the top cost sources should be returned.
bool contacts
If true, compute contacts. Otherwise only a binary collision yes/no is reported.
bool cost
If true, a collision cost is computed.
std::size_t max_contacts
Overall maximum number of contacts to compute.
std::function< bool(const CollisionResult &)> is_done
Function call that decides whether collision detection should stop.
std::size_t max_contacts_per_pair
Maximum number of contacts to compute per pair of bodies (multiple bodies may be in contact at differ...
bool distance
If true, compute proximity distance.
std::set< CostSource > cost_sources
These are the individual cost sources when costs are computed.
double distance
Closest distance between two bodies.
EIGEN_MAKE_ALIGNED_OPERATOR_NEW void clear()
Clear a previously stored result.
bool collision
True if collision was found, false otherwise.
std::size_t contact_count
Number of contacts returned.
Definition of a contact point.
std::string body_name_2
The id of the second body involved in the contact.
double percent_interpolation
The distance percentage between casted poses until collision.
Eigen::Vector3d nearest_points[2]
The two nearest points connecting the two bodies.
std::string body_name_1
The id of the first body involved in the contact.
BodyType body_type_1
The type of the first body involved in the contact.
BodyType body_type_2
The type of the second body involved in the contact.
Eigen::Vector3d normal
normal unit vector at contact
double depth
depth (penetration between bodies)
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Vector3d pos
contact position