Skip to content

Commit 120f941

Browse files
committed
continue work on tutorial
1 parent 88db9f0 commit 120f941

File tree

4 files changed

+61
-19
lines changed

4 files changed

+61
-19
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ add_subdirectory(doc/pick_place)
6363
add_subdirectory(doc/planning)
6464
add_subdirectory(doc/planning_scene)
6565
add_subdirectory(doc/planning_scene_ros_api)
66+
add_subdirectory(doc/planning_scene_python)
6667
add_subdirectory(doc/robot_model_and_robot_state)
6768
add_subdirectory(doc/state_display)
6869
add_subdirectory(doc/subframes)

doc/planning_scene_python/CMakeLists.txt

Whitespace-only changes.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Planning Scene Python
2+
==================================
3+
4+
The :planning_scene:`PlanningScene` class provides the main interface that you will use
5+
for collision checking and constraint checking. In this tutorial, we
6+
will explore the Python interface to this class.
7+
8+
Getting Started
9+
---------------
10+
If you haven't already done so, make sure you've completed the steps in `Getting Started <../getting_started/getting_started.html>`_.
11+
12+
The entire code
13+
---------------
14+
The entire code can be seen :codedir:`here in the MoveIt GitHub project<planning_scene>`.
15+
16+
.. tutorial-formatter:: ./src/planning_scene_tutorial.py
17+
18+
Running the code
19+
----------------
20+
Roslaunch the launch file to run the code directly from moveit_tutorials: ::
21+
22+
rosrun moveit_tutorials planning_scene_tutorial.py
23+
24+
Expected Output
25+
---------------
26+
27+
The output should look something like this, though we are using random
28+
joint values so some things may be different. ::
29+
30+
[ INFO] [1615403438.643254533]: Loading robot model 'panda'...
31+
[INFO] [1615403438.700939]: Test 1: Current state is in self collision
32+
[INFO] [1615403438.704516]: Contact between panda_hand and panda_link5
33+
[INFO] [1615403438.706369]: Contact between panda_link5 and panda_link7
34+
[INFO] [1615403459.455112]: Test 2: Current state is in self collision
35+
[INFO] [1615403459.461933]: Test 3: Current state is not in self collision
36+
[INFO] [1615403459.470156]: Test 4: Current state is valid
37+
[INFO] [1615403459.474089]: Test 6: Current state is not in self collision
38+
[INFO] [1615403459.479456]: Test 7: Current state is not in self collision
39+
[INFO] [1615403459.488881]: Test 8: Random state is not constrained
40+
[INFO] [1615403459.496180]: Test 9: Random state is not constrained
41+
[INFO] [1615403459.498652]: Test 10: Random state is not constrained
42+
[INFO] [1615403459.503490]: Test 12: Random state is not valid
43+
44+
**Note:** Don't worry if your output has different ROS console format. You can customize your ROS console logger by following `this blog post <http://dav.ee/blog/notes/archives/898>`_.

doc/planning_scene/src/planning_scene_tutorial.py renamed to doc/planning_scene_python/src/planning_scene_tutorial.py

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1+
#!/usr/bin/env python
12
import sys
23

34
import moveit_commander
45
import numpy as np
56
import rospy
67
from geometry_msgs.msg import PoseStamped
7-
from moveit_msgs.msg import DisplayRobotState
88
from pymoveit import kinematic_constraints, collision_detection, robot_model, random_numbers
99
from pymoveit.planning_scene import PlanningScene
1010

@@ -58,6 +58,21 @@ def main():
5858
planning_scene.checkSelfCollision(collision_request, collision_result)
5959
rospy.loginfo(f"Test 1: Current state is {'in' if collision_result.collision else 'not in'} self collision")
6060

61+
# Now, we can get contact information for any collisions that might
62+
# have happened at a given configuration of the Panda arm. We can ask
63+
# for contact information by filling in the appropriate field in the
64+
# collision request and specifying the maximum number of contacts to
65+
# be returned as a large number.
66+
67+
collision_request.contacts = True
68+
collision_request.max_contacts = 1000
69+
70+
collision_result.clear()
71+
planning_scene.checkSelfCollision(collision_request, collision_result)
72+
for (first_name, second_name), contacts in collision_result.contacts.items():
73+
rospy.loginfo(f"Contact between {first_name} and {second_name}")
74+
75+
6176
# Change the state
6277
# ~~~~~~~~~~~~~~~~
6378
#
@@ -104,21 +119,6 @@ def main():
104119
rospy.loginfo(
105120
f"Test 4: Current state is {'valid' if current_state.satisfiesBounds(joint_model_group) else 'not valid'}")
106121

107-
# Now, we can get contact information for any collisions that might
108-
# have happened at a given configuration of the Panda arm. We can ask
109-
# for contact information by filling in the appropriate field in the
110-
# collision request and specifying the maximum number of contacts to
111-
# be returned as a large number.
112-
113-
collision_request.contacts = True
114-
collision_request.max_contacts = 1000
115-
116-
collision_result.clear()
117-
planning_scene.checkSelfCollision(collision_request, collision_result)
118-
rospy.loginfo(f"Test 5: Current state is {'in' if collision_result.collision else 'not in'} self collision")
119-
for (first_name, second_name), contacts in collision_result.contacts:
120-
rospy.loginfo(f"Contact between {first_name} and {second_name}")
121-
122122
# Modifying the Allowed Collision Matrix
123123
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
124124
#
@@ -218,9 +218,6 @@ def main():
218218
rospy.loginfo(
219219
f"Test 10: Random state is {'constrained' if constraint_eval_result.satisfied else 'not constrained'}")
220220

221-
# User-defined constraints
222-
# ~~~~~~~~~~~~~~~~~~~~~~~~
223-
224221
# Whenever isStateValid is called, three checks are conducted: (a)
225222
# collision checking (b) constraint checking and (c) feasibility
226223
# checking using the user-defined callback.

0 commit comments

Comments
 (0)