3232# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3333# POSSIBILITY OF SUCH DAMAGE.
3434#
35- # Author: Acorn Pooley, Mike Lautman
35+ # Author: Acorn Pooley, Mike Lautman, Peter Mitrano
3636
3737## BEGIN_SUB_TUTORIAL imports
3838##
4141## and a `RobotCommander`_ class. More on these below. We also import `rospy`_ and some messages that we will use:
4242##
4343
44- # Python 2/3 compatibility imports
45- from __future__ import print_function
46- from six .moves import input
47-
4844import sys
4945import copy
5046import rospy
51- import moveit_commander
47+ from moveit_commander import roscpp_initializer
48+ from moveit .core .conversions import pose_to_list
49+ from moveit .planning_interface import planning_interface
5250import moveit_msgs .msg
5351import geometry_msgs .msg
5452try :
@@ -63,34 +61,38 @@ def dist(p, q):
6361## END_SUB_TUTORIAL
6462
6563
64+
65+ ## END_SUB_TUTORIAL
66+
67+
6668def all_close (goal , actual , tolerance ):
67- """
68- Convenience method for testing if the values in two lists are within a tolerance of each other.
69- For Pose and PoseStamped inputs, the angle between the two quaternions is compared (the angle
70- between the identical orientations q and -q is calculated correctly).
71- @param: goal A list of floats, a Pose or a PoseStamped
72- @param: actual A list of floats, a Pose or a PoseStamped
73- @param: tolerance A float
74- @returns: bool
75- """
76- if type (goal ) is list :
77- for index in range (len (goal )):
78- if abs (actual [index ] - goal [index ]) > tolerance :
79- return False
80-
81- elif type (goal ) is geometry_msgs .msg .PoseStamped :
82- return all_close (goal .pose , actual .pose , tolerance )
83-
84- elif type (goal ) is geometry_msgs .msg .Pose :
85- x0 , y0 , z0 , qx0 , qy0 , qz0 , qw0 = pose_to_list (actual )
86- x1 , y1 , z1 , qx1 , qy1 , qz1 , qw1 = pose_to_list (goal )
87- # Euclidean distance
88- d = dist ((x1 , y1 , z1 ), (x0 , y0 , z0 ))
89- # phi = angle between orientations
90- cos_phi_half = fabs (qx0 * qx1 + qy0 * qy1 + qz0 * qz1 + qw0 * qw1 )
91- return d <= tolerance and cos_phi_half >= cos (tolerance / 2.0 )
92-
93- return True
69+ """
70+ Convenience method for testing if the values in two lists are within a tolerance of each other.
71+ For Pose and PoseStamped inputs, the angle between the two quaternions is compared (the angle
72+ between the identical orientations q and -q is calculated correctly).
73+ @param: goal A list of floats, a Pose or a PoseStamped
74+ @param: actual A list of floats, a Pose or a PoseStamped
75+ @param: tolerance A float
76+ @returns: bool
77+ """
78+ if type (goal ) is list :
79+ for index in range (len (goal )):
80+ if abs (actual [index ] - goal [index ]) > tolerance :
81+ return False
82+
83+ elif type (goal ) is geometry_msgs .msg .PoseStamped :
84+ return all_close (goal .pose , actual .pose , tolerance )
85+
86+ elif type (goal ) is geometry_msgs .msg .Pose :
87+ x0 , y0 , z0 , qx0 , qy0 , qz0 , qw0 = pose_to_list (actual )
88+ x1 , y1 , z1 , qx1 , qy1 , qz1 , qw1 = pose_to_list (goal )
89+ # Euclidean distance
90+ d = dist ((x1 , y1 , z1 ), (x0 , y0 , z0 ))
91+ # phi = angle between orientations
92+ cos_phi_half = fabs (qx0 * qx1 + qy0 * qy1 + qz0 * qz1 + qw0 * qw1 )
93+ return d <= tolerance and cos_phi_half >= cos (tolerance / 2.0 )
94+
95+ return True
9496
9597
9698class MoveGroupPythonInterfaceTutorial (object ):
@@ -175,7 +177,7 @@ def go_to_joint_state(self):
175177 ## Planning to a Joint Goal
176178 ## ^^^^^^^^^^^^^^^^^^^^^^^^
177179 ## The Panda's zero configuration is at a `singularity <https://www.quora.com/Robotics-What-is-meant-by-kinematic-singularity>`_, so the first
178- ## thing we want to do is move it to a slightly better configuration.
180+ ## thing we want to do is move it to a slightly better configuration.
179181 ## We use the constant `tau = 2*pi <https://en.wikipedia.org/wiki/Turn_(angle)#Tau_proposals>`_ for convenience:
180182 # We get the joint values from the group and change some of the values:
181183 joint_goal = move_group .get_current_joint_values ()
@@ -466,55 +468,58 @@ def remove_box(self, timeout=4):
466468
467469
468470def main ():
469- try :
470- print ("" )
471- print ("----------------------------------------------------------" )
472- print ("Welcome to the MoveIt MoveGroup Python Interface Tutorial" )
473- print ("----------------------------------------------------------" )
474- print ("Press Ctrl-D to exit at any time" )
475- print ("" )
476- input ("============ Press `Enter` to begin the tutorial by setting up the moveit_commander ..." )
477- tutorial = MoveGroupPythonInterfaceTutorial ()
471+ try :
472+ print ("" )
473+ print ("----------------------------------------------------------" )
474+ print ("Welcome to the MoveIt MoveGroup Python Interface Tutorial" )
475+ print ("----------------------------------------------------------" )
476+ print ("Press Ctrl-D to exit at any time" )
477+ print ("" )
478+ input ("============ Press `Enter` to begin the tutorial by setting up the moveit_commander ..." )
479+ tutorial = MoveGroupPythonInterfaceTutorial ()
480+
481+ input ("============ Press `Enter` to execute a movement using a joint state goal ..." )
482+ tutorial .go_to_joint_state ()
483+
484+ input ("============ Press `Enter` to execute a movement using a pose goal ..." )
485+ tutorial .go_to_pose_goal ()
478486
479- input ("============ Press `Enter` to execute a movement using a joint state goal ..." )
480- tutorial .go_to_joint_state ()
487+ input ("============ Press `Enter` to plan and display a Cartesian path ..." )
488+ cartesian_plan , fraction = tutorial .plan_cartesian_path ()
481489
482- input ("============ Press `Enter` to execute a movement using a pose goal ..." )
483- tutorial .go_to_pose_goal ( )
490+ input ("============ Press `Enter` to display a saved trajectory (this will replay the Cartesian path) ..." )
491+ tutorial .display_trajectory ( cartesian_plan )
484492
485- input ("============ Press `Enter` to plan and display a Cartesian path ..." )
486- cartesian_plan , fraction = tutorial .plan_cartesian_path ( )
493+ input ("============ Press `Enter` to execute a saved path ..." )
494+ tutorial .execute_plan ( cartesian_plan )
487495
488- input ("============ Press `Enter` to display a saved trajectory (this will replay the Cartesian path) ..." )
489- tutorial .display_trajectory ( cartesian_plan )
496+ input ("============ Press `Enter` to add a box to the planning scene ..." )
497+ tutorial .add_box ( )
490498
491- input ("============ Press `Enter` to execute a saved path ..." )
492- tutorial .execute_plan ( cartesian_plan )
499+ input ("============ Press `Enter` to attach a Box to the Panda robot ..." )
500+ tutorial .attach_box ( )
493501
494- input ("============ Press `Enter` to add a box to the planning scene ..." )
495- tutorial .add_box ()
502+ input ("============ Press `Enter` to plan and execute a path with an attached collision object ..." )
503+ cartesian_plan , fraction = tutorial .plan_cartesian_path (scale = - 1 )
504+ tutorial .execute_plan (cartesian_plan )
496505
497- input ("============ Press `Enter` to attach a Box to the Panda robot ..." )
498- tutorial .attach_box ()
506+ input ("============ Press `Enter` to detach the box from the Panda robot ..." )
507+ tutorial .detach_box ()
499508
500- input ("============ Press `Enter` to plan and execute a path with an attached collision object ..." )
501- cartesian_plan , fraction = tutorial .plan_cartesian_path (scale = - 1 )
502- tutorial .execute_plan (cartesian_plan )
509+ input ("============ Press `Enter` to remove the box from the planning scene ..." )
510+ tutorial .remove_box ()
503511
504- input ("============ Press `Enter` to detach the box from the Panda robot ..." )
505- tutorial .detach_box ()
512+ print ("============ Python tutorial demo complete!" )
506513
507- input ("============ Press `Enter` to remove the box from the planning scene ..." )
508- tutorial .remove_box ()
514+ roscpp_initializer .roscpp_shutdown ()
515+ except rospy .ROSInterruptException :
516+ return
517+ except KeyboardInterrupt :
518+ return
509519
510- print ("============ Python tutorial demo complete!" )
511- except rospy .ROSInterruptException :
512- return
513- except KeyboardInterrupt :
514- return
515520
516521if __name__ == '__main__' :
517- main ()
522+ main ()
518523
519524## BEGIN_TUTORIAL
520525## .. _moveit_commander:
0 commit comments