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 }
collision_detection::CollisionRequest::cost
bool cost
If true, a collision cost is computed.
Definition: include/moveit/collision_detection/collision_common.h:206
collision_detection::Contact::body_type_1
BodyType body_type_1
The type of the first body involved in the contact.
Definition: include/moveit/collision_detection/collision_common.h:122
collision_detection::Contact::depth
double depth
depth (penetration between bodies)
Definition: include/moveit/collision_detection/collision_common.h:116
pybind_rosmsg_typecasters.h
collision_detection::BodyTypes::WORLD_OBJECT
@ WORLD_OBJECT
A body in the environment.
Definition: include/moveit/collision_detection/collision_common.h:97
world.h
collision_detection::Contact
Definition of a contact point.
Definition: include/moveit/collision_detection/collision_common.h:105
collision_detection::CollisionRequest::is_done
boost::function< bool(const CollisionResult &)> is_done
Function call that decides whether collision detection should stop.
Definition: include/moveit/collision_detection/collision_common.h:222
collision_detection::Contact::body_name_2
std::string body_name_2
The id of the second body involved in the contact.
Definition: include/moveit/collision_detection/collision_common.h:125
collision_detection::Contact::body_type_2
BodyType body_type_2
The type of the second body involved in the contact.
Definition: include/moveit/collision_detection/collision_common.h:128
collision_detection::CollisionRequest::distance
bool distance
If true, compute proximity distance.
Definition: include/moveit/collision_detection/collision_common.h:200
collision_detection::Contact::body_name_1
std::string body_name_1
The id of the first body involved in the contact.
Definition: include/moveit/collision_detection/collision_common.h:119
collision_common.h
collision_detection::Contact::nearest_points
Eigen::Vector3d nearest_points[2]
The two nearest points connecting the two bodies.
Definition: include/moveit/collision_detection/collision_common.h:137
collision_detection::CollisionRequest::max_contacts
std::size_t max_contacts
Overall maximum number of contacts to compute.
Definition: include/moveit/collision_detection/collision_common.h:212
collision_matrix.h
collision_detection::CollisionRequest::verbose
bool verbose
Flag indicating whether information about detected collisions should be reported.
Definition: include/moveit/collision_detection/collision_common.h:225
collision_detection::CollisionRequest::group_name
std::string group_name
The group name to check collisions for (optional; if empty, assume the complete robot)
Definition: include/moveit/collision_detection/collision_common.h:197
collision_detection::BodyTypes::ROBOT_ATTACHED
@ ROBOT_ATTACHED
A body attached to a robot link.
Definition: include/moveit/collision_detection/collision_common.h:94
collision_detection::BodyTypes::ROBOT_LINK
@ ROBOT_LINK
A link on the robot.
Definition: include/moveit/collision_detection/collision_common.h:91
collision_detection::Contact::percent_interpolation
double percent_interpolation
The distance percentage between casted poses until collision.
Definition: include/moveit/collision_detection/collision_common.h:134
collision_detection::CollisionResult::contacts
ContactMap contacts
A map returning the pairs of body ids in contact, plus their contact details.
Definition: include/moveit/collision_detection/collision_common.h:418
collision_detection::Contact::pos
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Eigen::Vector3d pos
contact position
Definition: include/moveit/collision_detection/collision_common.h:110
def_collision_detection_bindings
void def_collision_detection_bindings(py::module &m)
Definition: pycollision_detection.cpp:49
collision_detection::CollisionRequest::contacts
bool contacts
If true, compute contacts. Otherwise only a binary collision yes/no is reported.
Definition: include/moveit/collision_detection/collision_common.h:209
collision_detection::Contact::normal
Eigen::Vector3d normal
normal unit vector at contact
Definition: include/moveit/collision_detection/collision_common.h:113
pybind11
Definition: pybind_rosmsg_typecasters.h:55
collision_detection::CollisionRequest::max_cost_sources
std::size_t max_cost_sources
When costs are computed, this value defines how many of the top cost sources should be returned.
Definition: include/moveit/collision_detection/collision_common.h:219
collision_detection::CollisionResult::collision
bool collision
True if collision was found, false otherwise.
Definition: include/moveit/collision_detection/collision_common.h:406
collision_detection::CollisionResult::cost_sources
std::set< CostSource > cost_sources
These are the individual cost sources when costs are computed.
Definition: include/moveit/collision_detection/collision_common.h:421
collision_detection::CollisionRequest::max_contacts_per_pair
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...
Definition: include/moveit/collision_detection/collision_common.h:216
collision_detection::CollisionResult::clear
EIGEN_MAKE_ALIGNED_OPERATOR_NEW void clear()
Clear a previously stored result.
Definition: include/moveit/collision_detection/collision_common.h:392
collision_detection::CollisionResult::contact_count
std::size_t contact_count
Number of contacts returned.
Definition: include/moveit/collision_detection/collision_common.h:415
collision_detection::CollisionResult::distance
double distance
Closest distance between two bodies.
Definition: include/moveit/collision_detection/collision_common.h:409
collision_detection::AllowedCollisionMatrix::setEntry
void setEntry(const std::string &name1, const std::string &name2, bool allowed)
Set an entry corresponding to a pair of elements.
Definition: collision_matrix.cpp:172
collision_detection
Definition: collision_detector_allocator_allvalid.h:42


moveit_core
Author(s): Ioan Sucan , Sachin Chitta , Acorn Pooley
autogenerated on Sun Nov 3 2024 03:26:15