Skip to content

Commit 1acf72e

Browse files
committed
examples: add orientation path constraint
constrained.py: constrain orientation of attached object pickplace.py: keep object upright during transport
1 parent 69b4606 commit 1acf72e

File tree

2 files changed

+48
-13
lines changed

2 files changed

+48
-13
lines changed

demo/scripts/constrained.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,35 @@
3838

3939
mps = stages.ModifyPlanningScene("modify planning scene")
4040
mps.addObject(co)
41+
42+
co.id = "object"
43+
co.primitives[0].type = SolidPrimitive.BOX
44+
co.primitives[0].dimensions = [0.1, 0.05, 0.03]
45+
pose = co.primitive_poses[0]
46+
pose.position.x = 0.30702
47+
pose.position.y = 0.0
48+
pose.position.z = 0.485
49+
pose.orientation.x = pose.orientation.w = 0.70711 # 90° about x
50+
mps.addObject(co)
51+
mps.attachObjects(["object"], "panda_hand")
52+
4153
task.add(mps)
4254

4355
move = stages.MoveRelative("y +0.4", planner)
56+
move.timeout = 5
4457
move.group = group
4558
header = Header(frame_id="world")
4659
move.setDirection(Vector3Stamped(header=header, vector=Vector3(0, 0.4, 0)))
4760

4861
constraints = Constraints()
4962
oc = OrientationConstraint()
63+
oc.parameterization = oc.ROTATION_VECTOR
5064
oc.header.frame_id = "world"
51-
oc.link_name = "panda_hand"
52-
oc.orientation.x = 1.0
53-
oc.absolute_x_axis_tolerance = 0.01
54-
oc.absolute_y_axis_tolerance = 0.01
55-
oc.absolute_z_axis_tolerance = 0.01
65+
oc.link_name = "object"
66+
oc.orientation.x = oc.orientation.w = 0.70711 # 90° about x
67+
oc.absolute_x_axis_tolerance = 0.1
68+
oc.absolute_y_axis_tolerance = 0.1
69+
oc.absolute_z_axis_tolerance = 3.14
5670
oc.weight = 1.0
5771
constraints.orientation_constraints.append(oc)
5872
move.path_constraints = constraints

demo/scripts/pickplace.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
from moveit.task_constructor import core, stages
66
from moveit_commander import PlanningSceneInterface
77
from geometry_msgs.msg import PoseStamped, TwistStamped
8-
import time
8+
from moveit_msgs.msg import Constraints, OrientationConstraint
9+
import math, time
910

1011
roscpp_init("mtc_tutorial")
1112

@@ -17,7 +18,7 @@
1718

1819
# [pickAndPlaceTut2]
1920
# Specify object parameters
20-
object_name = "grasp_object"
21+
object_name = "object"
2122
object_radius = 0.02
2223

2324
# Start with a clear planning scene
@@ -28,7 +29,7 @@
2829
# Grasp object properties
2930
objectPose = PoseStamped()
3031
objectPose.header.frame_id = "world"
31-
objectPose.pose.orientation.x = 1.0
32+
objectPose.pose.orientation.w = 1.0
3233
objectPose.pose.position.x = 0.30702
3334
objectPose.pose.position.y = 0.0
3435
objectPose.pose.position.z = 0.285
@@ -56,15 +57,15 @@
5657
planners = [(arm, pipeline)]
5758

5859
# Connect the two stages
59-
task.add(stages.Connect("connect1", planners))
60+
task.add(stages.Connect("connect", planners))
6061
# [initAndConfigConnect]
6162
# [pickAndPlaceTut4]
6263

6364
# [pickAndPlaceTut5]
6465
# [initAndConfigGenerateGraspPose]
6566
# The grasp generator spawns a set of possible grasp poses around the object
6667
grasp_generator = stages.GenerateGraspPose("Generate Grasp Pose")
67-
grasp_generator.angle_delta = 0.2
68+
grasp_generator.angle_delta = math.pi / 2
6869
grasp_generator.pregrasp = "open"
6970
grasp_generator.grasp = "close"
7071
grasp_generator.setMonitoredStage(task["current"]) # Generate solutions for all initial states
@@ -78,7 +79,8 @@
7879
# Set frame for IK calculation in the center between the fingers
7980
ik_frame = PoseStamped()
8081
ik_frame.header.frame_id = "panda_hand"
81-
ik_frame.pose.position.z = 0.1034
82+
ik_frame.pose.position.z = 0.1034 # tcp between fingers
83+
ik_frame.pose.orientation.x = 1.0 # grasp from top
8284
simpleGrasp.setIKFrame(ik_frame)
8385
# [initAndConfigSimpleGrasp]
8486
# [pickAndPlaceTut6]
@@ -109,16 +111,35 @@
109111
# [initAndConfigPick]
110112
# [pickAndPlaceTut8]
111113

114+
# Define orientation constraint to keep the object upright
115+
oc = OrientationConstraint()
116+
oc.parameterization = oc.ROTATION_VECTOR
117+
oc.header.frame_id = "world"
118+
oc.link_name = "object"
119+
oc.orientation.w = 1
120+
oc.absolute_x_axis_tolerance = 0.1
121+
oc.absolute_y_axis_tolerance = 0.1
122+
oc.absolute_z_axis_tolerance = math.pi
123+
oc.weight = 1.0
124+
125+
constraints = Constraints()
126+
constraints.name = "object:upright"
127+
constraints.orientation_constraints.append(oc)
128+
112129
# [pickAndPlaceTut9]
113130
# Connect the Pick stage with the following Place stage
114-
task.add(stages.Connect("connect2", planners))
131+
con = stages.Connect("connect", planners)
132+
con.path_constraints = constraints
133+
task.add(con)
115134
# [pickAndPlaceTut9]
116135

117136
# [pickAndPlaceTut10]
118137
# [initAndConfigGeneratePlacePose]
119138
# Define the pose that the object should have after placing
120139
placePose = objectPose
121-
placePose.pose.position.y += 0.2 # shift object by 20cm along y axis
140+
placePose.pose.position.x = -0.2
141+
placePose.pose.position.y = -0.6
142+
placePose.pose.position.z = 0.0
122143

123144
# Generate Cartesian place poses for the object
124145
place_generator = stages.GeneratePlacePose("Generate Place Pose")

0 commit comments

Comments
 (0)