Skip to content

Commit 88db9f0

Browse files
committed
cleanup tutorial
1 parent dad2cd9 commit 88db9f0

File tree

1 file changed

+16
-41
lines changed

1 file changed

+16
-41
lines changed

doc/planning_scene/src/planning_scene_tutorial.py

Lines changed: 16 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,21 @@
99
from pymoveit.planning_scene import PlanningScene
1010

1111

12-
# BEGIN_SUB_TUTORIAL stateFeasibilityTestExample
13-
#
14-
# User defined constraints can also be specified to the PlanningScene
15-
# class. This is done by specifying a callback using the
16-
# setStateFeasibilityPredicate function. Here's a simple example of a
17-
# user-defined callback that checks whether the "panda_joint1" of
18-
# the Panda robot is at a positive or negative angle:
19-
def stateFeasibilityTestExample(kinematic_state, verbose):
20-
joint_values = kinematic_state.getJointPositions("panda_joint1")
21-
return joint_values[0] > 0.0
22-
23-
24-
# END_SUB_TUTORIAL
25-
2612
def main():
2713
rospy.init_node("planning_scene_tutorial")
2814
moveit_commander.roscpp_initialize(sys.argv)
2915

30-
robot_state_pub = rospy.Publisher("display_robot_state", DisplayRobotState, queue_size=10)
31-
3216
# BEGIN_TUTORIAL
3317
#
3418
# Setup
3519
# ^^^^^
3620
#
3721
# The :planning_scene:`PlanningScene` class can be easily setup and
38-
# configured using a :moveit_core:`RobotModel` or a URDF and
22+
# configured using a URDF and
3923
# SRDF. This is, however, not the recommended way to instantiate a
40-
# PlanningScene. The :planning_scene_monitor:`PlanningSceneMonitor`
41-
# is the recommended method to create and maintain the current
42-
# planning scene (and is discussed in detail in the next tutorial)
24+
# PlanningScene. At the time of writing there are not yet python bindings
25+
# for the PlanningSceneMonitoir, which is is the recommended method to
26+
# create and maintain the current planning scene
4327
# using data from the robot's joints and the sensors on the robot. In
4428
# this tutorial, we will instantiate a PlanningScene class directly,
4529
# but this method of instantiation is only intended for illustration.
@@ -72,7 +56,7 @@ def main():
7256
collision_request = collision_detection.CollisionRequest()
7357
collision_result = collision_detection.CollisionResult()
7458
planning_scene.checkSelfCollision(collision_request, collision_result)
75-
print(f"Test 1: Current state is {'in' if collision_result.collision else 'not in'} self collision")
59+
rospy.loginfo(f"Test 1: Current state is {'in' if collision_result.collision else 'not in'} self collision")
7660

7761
# Change the state
7862
# ~~~~~~~~~~~~~~~~
@@ -89,7 +73,7 @@ def main():
8973

9074
collision_result.clear()
9175
planning_scene.checkSelfCollision(collision_request, collision_result)
92-
print(f"Test 2: Current state is {'in' if collision_result.collision else 'not in'} self collision")
76+
rospy.loginfo(f"Test 2: Current state is {'in' if collision_result.collision else 'not in'} self collision")
9377

9478
# Checking for a group
9579
# ~~~~~~~~~~~~~~~~~~~~
@@ -104,7 +88,7 @@ def main():
10488
current_state.setToRandomPositions(joint_model_group, rng)
10589
collision_result.clear()
10690
planning_scene.checkSelfCollision(collision_request, collision_result)
107-
print(f"Test 3: Current state is {'in' if collision_result.collision else 'not in'} self collision")
91+
rospy.loginfo(f"Test 3: Current state is {'in' if collision_result.collision else 'not in'} self collision")
10892

10993
# Getting Contact Information
11094
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -117,7 +101,7 @@ def main():
117101
joint_values = np.array([0.0, 0.0, 0.0, -2.9, 0.0, 1.4, 0.0])
118102
joint_model_group = current_state.getJointModelGroup("panda_arm")
119103
current_state.setJointGroupPositions(joint_model_group, joint_values)
120-
print(
104+
rospy.loginfo(
121105
f"Test 4: Current state is {'valid' if current_state.satisfiesBounds(joint_model_group) else 'not valid'}")
122106

123107
# Now, we can get contact information for any collisions that might
@@ -131,9 +115,9 @@ def main():
131115

132116
collision_result.clear()
133117
planning_scene.checkSelfCollision(collision_request, collision_result)
134-
print(f"Test 5: Current state is {'in' if collision_result.collision else 'not in'} self collision")
118+
rospy.loginfo(f"Test 5: Current state is {'in' if collision_result.collision else 'not in'} self collision")
135119
for (first_name, second_name), contacts in collision_result.contacts:
136-
print(f"Contact between {first_name} and {second_name}")
120+
rospy.loginfo(f"Contact between {first_name} and {second_name}")
137121

138122
# Modifying the Allowed Collision Matrix
139123
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -159,7 +143,7 @@ def main():
159143
acm.setEntry(first_name, second_name, True)
160144
collision_result.clear()
161145
planning_scene.checkSelfCollision(collision_request, collision_result, copied_state, acm)
162-
print(f"Test 6: Current state is {'in' if collision_result.collision else 'not in'} self collision")
146+
rospy.loginfo(f"Test 6: Current state is {'in' if collision_result.collision else 'not in'} self collision")
163147

164148
# Full Collision Checking
165149
# ~~~~~~~~~~~~~~~~~~~~~~~
@@ -174,7 +158,7 @@ def main():
174158
# from obstacles in the environment.
175159
collision_result.clear()
176160
planning_scene.checkCollision(collision_request, collision_result, copied_state, acm)
177-
print(f"Test 7: Current state is {'in' if collision_result.collision else 'not in'} self collision")
161+
rospy.loginfo(f"Test 7: Current state is {'in' if collision_result.collision else 'not in'} self collision")
178162

179163
# Constraint Checking
180164
# ^^^^^^^^^^^^^^^^^^^
@@ -214,7 +198,7 @@ def main():
214198
copied_state.setToRandomPositions(joint_model_group, rng)
215199
copied_state.update()
216200
constrained = planning_scene.isStateConstrained(copied_state, goal_constraint)
217-
print(f"Test 8: Random state is {'constrained' if constrained else 'not constrained'}")
201+
rospy.loginfo(f"Test 8: Random state is {'constrained' if constrained else 'not constrained'}")
218202

219203
# There's a more efficient way of checking constraints (when you want
220204
# to check the same constraint over and over again, e.g. inside a
@@ -225,33 +209,24 @@ def main():
225209
kinematic_constraint_set = kinematic_constraints.KinematicConstraintSet(kinematic_model)
226210
kinematic_constraint_set.add(goal_constraint, planning_scene.getTransforms())
227211
constrained_2 = planning_scene.isStateConstrained(copied_state, kinematic_constraint_set)
228-
print(f"Test 9: Random state is {'constrained' if constrained_2 else 'not constrained'}")
212+
rospy.loginfo(f"Test 9: Random state is {'constrained' if constrained_2 else 'not constrained'}")
229213

230214
# There's a direct way to do this using the KinematicConstraintSet
231215
# class.
232216

233217
constraint_eval_result = kinematic_constraint_set.decide(copied_state)
234-
print(
218+
rospy.loginfo(
235219
f"Test 10: Random state is {'constrained' if constraint_eval_result.satisfied else 'not constrained'}")
236220

237221
# User-defined constraints
238222
# ~~~~~~~~~~~~~~~~~~~~~~~~
239-
#
240-
# CALL_SUB_TUTORIAL stateFeasibilityTestExample
241-
242-
# Now, whenever isStateFeasible is called, this user-defined callback
243-
# will be called.
244-
245-
# planning_scene.setStateFeasibilityPredicate(stateFeasibilityTestExample)
246-
# state_feasible = planning_scene.isStateFeasible(copied_state)
247-
# print(f"Test 11: Random state is {'feasible' if state_feasible else 'not feasible'}")
248223

249224
# Whenever isStateValid is called, three checks are conducted: (a)
250225
# collision checking (b) constraint checking and (c) feasibility
251226
# checking using the user-defined callback.
252227

253228
state_valid = planning_scene.isStateValid(copied_state, kinematic_constraint_set, "panda_arm")
254-
print(f"Test 12: Random state is {'valid' if state_valid else 'not valid'}")
229+
rospy.loginfo(f"Test 12: Random state is {'valid' if state_valid else 'not valid'}")
255230

256231
# Note that all the planners available through MoveIt and OMPL will
257232
# currently perform collision checking, constraint checking and

0 commit comments

Comments
 (0)