1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15+ import copy
1516import math
1617
1718from crane_plus_examples_py .utils import plan_and_execute
18- from geometry_msgs .msg import PoseStamped
19+
20+ from geometry_msgs .msg import Point , Pose , PoseStamped , Quaternion
21+
1922from moveit .core .robot_state import RobotState
2023from moveit .planning import (
2124 MoveItPy ,
2225 PlanRequestParameters ,
2326)
2427from moveit_msgs .msg import BoundingVolume , Constraints , OrientationConstraint , PositionConstraint
28+
2529import rclpy
2630from rclpy .logging import get_logger
2731from scipy .spatial .transform import Rotation
2832from shape_msgs .msg import SolidPrimitive
2933
3034
31- def set_goal_constraints (x , y , z , roll , pitch , yaw ):
35+ def set_goal_constraints (pose ):
3236 # 位置姿勢の許容誤差
3337 POSITION_TOLERANCE = 0.00001
3438 ORIENTATION_TOLERANCE = 0.0001
3539
3640 # 目標位置姿勢
3741 target_pose = PoseStamped ()
3842 target_pose .header .frame_id = 'crane_plus_base'
39- target_pose .pose .position .x = x
40- target_pose .pose .position .y = y
41- target_pose .pose .position .z = z
42- rotation = Rotation .from_euler ('xyz' , [roll , pitch , yaw ], degrees = True )
43- quat = rotation .as_quat ()
44- target_pose .pose .orientation .x = quat [0 ]
45- target_pose .pose .orientation .y = quat [1 ]
46- target_pose .pose .orientation .z = quat [2 ]
47- target_pose .pose .orientation .w = quat [3 ]
43+ target_pose .pose = pose
4844
4945 # 目標位置姿勢の制約設定
5046 goal_constraints = Constraints ()
@@ -115,8 +111,28 @@ def main(args=None):
115111 GRIPPER_DEFAULT = 0.0
116112 GRIPPER_OPEN = math .radians (- 30.0 )
117113 GRIPPER_CLOSE = math .radians (10.0 )
118-
114+ # 物体を持ち上げる高さ
115+ LIFTING_HEIGHT = 0.03
116+ # 物体の頭上の位置
117+ gripper_quat = Rotation .from_euler ('xyz' , [0.0 , 90.0 , - 90.0 ], degrees = True ).as_quat ()
118+ gripper_quat_msg = Quaternion (
119+ x = gripper_quat [0 ], y = gripper_quat [1 ], z = gripper_quat [2 ], w = gripper_quat [3 ]
120+ )
121+ ABOVE_POSE = Pose (position = Point (x = 0.0 , y = - 0.21 , z = 0.17 ), orientation = gripper_quat_msg )
122+ # 物体を掴む位置
123+ gripper_quat = Rotation .from_euler ('xyz' , [0.0 , 180.0 , - 90.0 ], degrees = True ).as_quat ()
124+ gripper_quat_msg = Quaternion (
125+ x = gripper_quat [0 ], y = gripper_quat [1 ], z = gripper_quat [2 ], w = gripper_quat [3 ]
126+ )
127+ GRASP_POSE = Pose (position = Point (x = 0.0 , y = - 0.1 , z = 0.02 ), orientation = gripper_quat_msg )
128+ PRE_AND_POST_GRASP_POSE = copy .deepcopy (GRASP_POSE )
129+ PRE_AND_POST_GRASP_POSE .position .z = LIFTING_HEIGHT
119130 # 物体を置く位置
131+ gripper_quat = Rotation .from_euler ('xyz' , [0.0 , 90.0 , 0.0 ], degrees = True ).as_quat ()
132+ gripper_quat_msg = Quaternion (
133+ x = gripper_quat [0 ], y = gripper_quat [1 ], z = gripper_quat [2 ], w = gripper_quat [3 ]
134+ )
135+ RELEASE_POSE = Pose (position = Point (x = 0.25 , y = 0.0 , z = 0.06 ), orientation = gripper_quat_msg )
120136
121137 # SRDF内に定義されている'vertical'の姿勢にする
122138 arm .set_start_state_to_current_state ()
@@ -164,7 +180,7 @@ def main(args=None):
164180
165181 # 物体の上に腕を伸ばす
166182 arm .set_start_state_to_current_state ()
167- goal_constraints = set_goal_constraints (0.0 , - 0.21 , 0.17 , 0.0 , 90.0 , - 90.0 )
183+ goal_constraints = set_goal_constraints (ABOVE_POSE )
168184 arm .set_goal_state (motion_plan_constraints = [goal_constraints ])
169185 plan_and_execute (
170186 crane_plus ,
@@ -173,7 +189,7 @@ def main(args=None):
173189 single_plan_parameters = arm_plan_request_params ,
174190 )
175191 arm .set_start_state_to_current_state ()
176- goal_constraints = set_goal_constraints (0.0 , - 0.1 , 0.05 , 0.0 , 180.0 , - 90.0 )
192+ goal_constraints = set_goal_constraints (PRE_AND_POST_GRASP_POSE )
177193 arm .set_goal_state (motion_plan_constraints = [goal_constraints ])
178194 plan_and_execute (
179195 crane_plus ,
@@ -184,7 +200,7 @@ def main(args=None):
184200
185201 # 掴みに行く
186202 arm .set_start_state_to_current_state ()
187- goal_constraints = set_goal_constraints (0.0 , - 0.1 , 0.02 , 0.0 , 180.0 , - 90.0 )
203+ goal_constraints = set_goal_constraints (GRASP_POSE )
188204 arm .set_goal_state (motion_plan_constraints = [goal_constraints ])
189205 plan_and_execute (
190206 crane_plus ,
@@ -207,7 +223,7 @@ def main(args=None):
207223
208224 # 持ち上げる
209225 arm .set_start_state_to_current_state ()
210- goal_constraints = set_goal_constraints (0.0 , - 0.1 , 0.05 , 0.0 , 180.0 , - 90.0 )
226+ goal_constraints = set_goal_constraints (PRE_AND_POST_GRASP_POSE )
211227 arm .set_goal_state (motion_plan_constraints = [goal_constraints ])
212228 plan_and_execute (
213229 crane_plus ,
@@ -228,7 +244,7 @@ def main(args=None):
228244
229245 # 下ろす
230246 arm .set_start_state_to_current_state ()
231- goal_constraints = set_goal_constraints (0.25 , 0.0 , 0.06 , 0.0 , 90.0 , 0.0 )
247+ goal_constraints = set_goal_constraints (RELEASE_POSE )
232248 arm .set_goal_state (motion_plan_constraints = [goal_constraints ])
233249 plan_and_execute (
234250 crane_plus ,
0 commit comments