Skip to content

Commit 623dede

Browse files
authored
Update move_group_python_interface_tutorial.py (#577)
* Update move_group_python_interface_tutorial.py
1 parent ea5ab20 commit 623dede

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

doc/move_group_python_interface/scripts/move_group_python_interface_tutorial.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,17 @@
5151
import moveit_commander
5252
import moveit_msgs.msg
5353
import geometry_msgs.msg
54-
from math import pi
54+
from math import pi, dist, fabs, cos
5555
from std_msgs.msg import String
5656
from moveit_commander.conversions import pose_to_list
5757
## END_SUB_TUTORIAL
5858

5959

6060
def all_close(goal, actual, tolerance):
6161
"""
62-
Convenience method for testing if a list of values are within a tolerance of their counterparts in another list
62+
Convenience method for testing if the values in two lists are within a tolerance of each other.
63+
For Pose and PoseStamped inputs, the angle between the two quaternions is compared (the angle
64+
between the identical orientations q and -q is calculated correctly).
6365
@param: goal A list of floats, a Pose or a PoseStamped
6466
@param: actual A list of floats, a Pose or a PoseStamped
6567
@param: tolerance A float
@@ -74,15 +76,21 @@ def all_close(goal, actual, tolerance):
7476
return all_close(goal.pose, actual.pose, tolerance)
7577

7678
elif type(goal) is geometry_msgs.msg.Pose:
77-
return all_close(pose_to_list(goal), pose_to_list(actual), tolerance)
79+
x0, y0, z0, qx0, qy0, qz0, qw0 = pose_to_list(actual)
80+
x1, y1, z1, qx1, qy1, qz1, qw1 = pose_to_list(goal)
81+
# Euclidean distance
82+
d = dist((x1, y1, z1), (x0, y0, z0))
83+
# phi = angle between orientations
84+
cos_phi_half = fabs(qx0*qx1 + qy0*qy1 + qz0*qz1 + qw0*qw1)
85+
return d <= tolerance and cos_phi_half >= cos(tolerance / 2.0)
7886

7987
return True
8088

8189

82-
class MoveGroupPythonIntefaceTutorial(object):
83-
"""MoveGroupPythonIntefaceTutorial"""
90+
class MoveGroupPythonInterfaceTutorial(object):
91+
"""MoveGroupPythonInterfaceTutorial"""
8492
def __init__(self):
85-
super(MoveGroupPythonIntefaceTutorial, self).__init__()
93+
super(MoveGroupPythonInterfaceTutorial, self).__init__()
8694

8795
## BEGIN_SUB_TUTORIAL setup
8896
##
@@ -459,7 +467,7 @@ def main():
459467
print("Press Ctrl-D to exit at any time")
460468
print("")
461469
input("============ Press `Enter` to begin the tutorial by setting up the moveit_commander ...")
462-
tutorial = MoveGroupPythonIntefaceTutorial()
470+
tutorial = MoveGroupPythonInterfaceTutorial()
463471

464472
input("============ Press `Enter` to execute a movement using a joint state goal ...")
465473
tutorial.go_to_joint_state()

0 commit comments

Comments
 (0)