compute_ik.py
Go to the documentation of this file.
1 #! /usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 
4 from moveit.task_constructor import core, stages
5 from geometry_msgs.msg import PoseStamped, Pose, Point
6 from std_msgs.msg import Header
7 import time
8 
9 from py_binding_tools import roscpp_init
10 
11 roscpp_init("mtc_tutorial")
12 
13 # Specify the planning group
14 group = "panda_arm"
15 
16 # Create a task
17 task = core.Task()
18 task.name = "compute IK"
19 
20 # Add a stage to retrieve the current state
21 task.add(stages.CurrentState("current state"))
22 
23 # Add a planning stage connecting the generator stages
24 planner = core.PipelinePlanner() # create default planning pipeline
25 task.add(stages.Connect("connect", [(group, planner)])) # operate on group
26 del planner # Delete PipelinePlanner when not explicitly needed anymore
27 
28 # [propertyTut12]
29 # Add a Cartesian pose generator
30 generator = stages.GeneratePose("cartesian pose")
31 # [propertyTut12]
32 # Inherit PlanningScene state from "current state" stage
33 generator.setMonitoredStage(task["current state"])
34 # Configure target pose
35 # [propertyTut13]
36 pose = Pose(position=Point(z=0.2))
37 generator.pose = PoseStamped(header=Header(frame_id="panda_link8"), pose=pose)
38 # [propertyTut13]
39 
40 # [initAndConfigComputeIk]
41 # Wrap Cartesian generator into a ComputeIK stage to yield a joint pose
42 computeIK = stages.ComputeIK("compute IK", generator)
43 computeIK.group = group # Use the group-specific IK solver
44 # Which end-effector frame should reach the target?
45 computeIK.ik_frame = PoseStamped(header=Header(frame_id="panda_link8"))
46 computeIK.max_ik_solutions = 4 # Limit the number of IK solutions
47 # [propertyTut14]
48 props = computeIK.properties
49 # derive target_pose from child's solution
50 props.configureInitFrom(core.Stage.PropertyInitializerSource.INTERFACE, ["target_pose"])
51 # [propertyTut14]
52 
53 # Add the stage to the task hierarchy
54 task.add(computeIK)
55 # [initAndConfigComputeIk]
56 
57 if task.plan():
58  task.publish(task.solutions[0])
59 
60 time.sleep(1) # sleep some time to allow C++ threads to publish their messages
moveit::task_constructor


demo
Author(s): Robert Haschke , Simon Goldstein , Henning Kayser
autogenerated on Sat May 3 2025 02:40:30