1
- ---
1
+ from pycram.robot_description import RobotDescriptionfrom pycram.datastructures.enums import ObjectType ---
2
2
jupyter:
3
3
jupytext:
4
4
text_representation:
@@ -16,28 +16,26 @@ jupyter:
16
16
17
17
In this tutorial we will walk through the capabilities of task trees in pycram.
18
18
19
- First we have to import the necessary functionality from pycram .
19
+ Next we will create a bullet world with a PR2 in a kitchen containing milk and cereal .
20
20
21
21
``` python
22
- from pycram.bullet_world import BulletWorld
23
- from pycram.robot_descriptions import robot_description
24
- import pycram.task
25
- from pycram.resolver.plans import Arms
22
+ from pycram.worlds. bullet_world import BulletWorld
23
+ from pycram.robot_description import RobotDescription
24
+ import pycram.tasktree
25
+ from pycram.datastructures.enums import Arms, ObjectType
26
26
from pycram.designators.action_designator import *
27
27
from pycram.designators.location_designator import *
28
28
from pycram.process_module import simulated_robot
29
29
from pycram.designators.object_designator import *
30
+ from pycram.datastructures.pose import Pose
31
+ from pycram.world_concepts.world_object import Object
30
32
import anytree
31
33
import pycram.failures
32
- ```
33
34
34
- Next we will create a bullet world with a PR2 in a kitchen containing milk and cereal.
35
-
36
- ``` python
37
35
world = BulletWorld()
38
- robot = Object(robot_description.name, " robot " , robot_description.name + " .urdf" )
36
+ robot = Object(" pr2 " , ObjectType. ROBOT , " pr2 .urdf" )
39
37
robot_desig = ObjectDesignatorDescription(names = [' pr2' ]).resolve()
40
- apartment = Object(" apartment" , " environment" , " apartment.urdf" , position = [- 1.5 , - 2.5 , 0 ])
38
+ apartment = Object(" apartment" , " environment" , " apartment.urdf" , pose = Pose( [- 1.5 , - 2.5 , 0 ]) )
41
39
apartment_desig = ObjectDesignatorDescription(names = [' apartment' ]).resolve()
42
40
table_top = apartment.get_link_position(" cooktop" )
43
41
# milk = Object("milk", "milk", "milk.stl", position=[table_top[0]-0.15, table_top[1], table_top[2]])
@@ -53,7 +51,7 @@ import numpy as np
53
51
54
52
55
53
def get_n_random_positions (pose_list , n = 4 , dist = 0.5 , random = True ):
56
- positions = [pos[ 0 ] for pos in pose_list[:1000 ]]
54
+ positions = [pose.position_as_list() for pose in pose_list[:1000 ]]
57
55
all_indices = list (range (len (positions)))
58
56
print (len (all_indices))
59
57
pos_idx = np.random.choice(all_indices) if random else all_indices[0 ]
@@ -98,11 +96,11 @@ def get_n_random_positions(pose_list, n=4, dist=0.5, random=True):
98
96
99
97
``` python
100
98
from pycram.costmaps import SemanticCostmap
101
- from pycram.pose_generator_and_validator import pose_generator
99
+ from pycram.pose_generator_and_validator import PoseGenerator
102
100
103
101
scm = SemanticCostmap(apartment, " island_countertop" )
104
- poses_list = list (pose_generator (scm, number_of_samples = - 1 ))
105
- poses_list.sort(reverse = True , key = lambda x : np.linalg.norm(x[ 0 ] ))
102
+ poses_list = list (PoseGenerator (scm, number_of_samples = - 1 ))
103
+ poses_list.sort(reverse = True , key = lambda x : np.linalg.norm(x.position_as_list() ))
106
104
object_poses = get_n_random_positions(poses_list)
107
105
object_names = [" bowl" , " milk" , " breakfast_cereal" , " spoon" ]
108
106
objects = {}
@@ -111,9 +109,9 @@ for obj_name, obj_pose in zip(object_names, object_poses):
111
109
print (obj_name)
112
110
print (obj_pose)
113
111
objects[obj_name] = Object(obj_name, obj_name, obj_name + " .stl" ,
114
- position = [obj_pose[ 0 ][ 0 ] , obj_pose[ 0 ][ 1 ] , table_top[ 2 ]] )
115
- objects[obj_name].move_base_to_origin_pos ()
116
- objects[obj_name].original_pose = objects[obj_name].get_position_and_orientation()
112
+ pose = Pose( [obj_pose.position.x , obj_pose.position.y , table_top.z]) )
113
+ objects[obj_name].move_base_to_origin_pose ()
114
+ objects[obj_name].original_pose = objects[obj_name].pose
117
115
object_desig[obj_name] = ObjectDesignatorDescription(names = [obj_name], types = [obj_name]).resolve()
118
116
print (object_poses)
119
117
```
@@ -125,24 +123,25 @@ import pybullet as p
125
123
126
124
for link_name in apartment.links.keys():
127
125
world.add_vis_axis(apartment.get_link_pose(link_name))
128
- p.addUserDebugText(link_name, apartment.get_link_position(link_name))
126
+ # p.addUserDebugText(link_name, apartment.get_link_position(link_name), physicsClientId=world.id )
129
127
```
130
128
131
129
``` python
132
130
world.remove_vis_axis()
133
- p.removeAllUserDebugItems()
131
+ # p.removeAllUserDebugItems()
134
132
```
135
133
136
134
Finally, we create a plan where the robot parks his arms, walks to the kitchen counter and picks the thingy. Then we
137
135
execute the plan.
138
136
139
137
``` python
140
138
from pycram.external_interfaces.ik import IKError
139
+ from pycram.datastructures.enums import Grasp
141
140
142
141
143
- @pycram.task .with_tree
142
+ @pycram.tasktree .with_tree
144
143
def plan (obj , obj_desig , torso = 0.2 , place = " countertop" ):
145
- world.reset_bullet_world ()
144
+ world.reset_world ()
146
145
with simulated_robot:
147
146
ParkArmsActionPerformable(Arms.BOTH ).perform()
148
147
@@ -154,7 +153,7 @@ def plan(obj, obj_desig, torso=0.2, place="countertop"):
154
153
ParkArmsActionPerformable(Arms.BOTH ).perform()
155
154
good_torsos.append(torso)
156
155
picked_up_arm = pose.reachable_arms[0 ]
157
- PickUpActionPerformable(object_designator = obj_desig, arm = pose.reachable_arms[0 ], grasp = " front " ).perform()
156
+ PickUpActionPerformable(object_designator = obj_desig, arm = pose.reachable_arms[0 ], grasp = Grasp. FRONT ).perform()
158
157
159
158
ParkArmsActionPerformable(Arms.BOTH ).perform()
160
159
scm = SemanticCostmapLocation(place, apartment_desig, obj_desig)
@@ -180,7 +179,7 @@ for obj_name in object_names:
180
179
try :
181
180
plan(objects[obj_name], object_desig[obj_name], torso = torso, place = " island_countertop" )
182
181
done = True
183
- objects[obj_name].original_pose = objects[obj_name].get_position_and_orientation()
182
+ objects[obj_name].original_pose = objects[obj_name].pose
184
183
except (StopIteration , IKError) as e:
185
184
print (type (e))
186
185
print (e)
@@ -195,7 +194,7 @@ Now we get the task tree from its module and render it. Rendering can be done wi
195
194
anytree package. We will use ascii rendering here for ease of displaying.
196
195
197
196
``` python
198
- tt = pycram.task .task_tree
197
+ tt = pycram.tasktree .task_tree
199
198
print (anytree.RenderTree(tt, style = anytree.render.AsciiStyle()))
200
199
```
201
200
@@ -205,8 +204,8 @@ tree. Hence, a NoOperation node is the root of any tree. If we re-execute the pl
205
204
tree even though they are not connected.
206
205
207
206
``` python
208
- world.reset_bullet_world ()
209
- plan()
207
+ world.reset_world ()
208
+ plan(objects[ " milk " ], object_desig[ " milk " ] )
210
209
print (anytree.RenderTree(tt, style = anytree.render.AsciiStyle()))
211
210
```
212
211
@@ -216,9 +215,9 @@ reset objects are available. At the end of a with block the old state is restore
216
215
called `` simulation() `` .
217
216
218
217
``` python
219
- with pycram.task .SimulatedTaskTree() as stt:
220
- print (anytree.RenderTree(pycram.task .task_tree, style = anytree.render.AsciiStyle()))
221
- print (anytree.RenderTree(pycram.task .task_tree, style = anytree.render.AsciiStyle()))
218
+ with pycram.tasktree .SimulatedTaskTree() as stt:
219
+ print (anytree.RenderTree(pycram.tasktree .task_tree, style = anytree.render.AsciiStyle()))
220
+ print (anytree.RenderTree(pycram.tasktree .task_tree, style = anytree.render.AsciiStyle()))
222
221
```
223
222
224
223
Task tree can be manipulated with ordinary anytree manipulation. If we for example want to discard the second plan, we
@@ -233,30 +232,30 @@ We can now re-execute this (modified) plan by executing the leaf in pre-ordering
233
232
functionality. This will not append the re-execution to the task tree.
234
233
235
234
``` python
236
- world.reset_bullet_world ()
235
+ world.reset_world ()
237
236
with simulated_robot:
238
- [node.code.execute () for node in tt.root.leaves]
239
- print (anytree.RenderTree(pycram.task .task_tree, style = anytree.render.AsciiStyle()))
237
+ [node.action.perform () for node in tt.root.leaves]
238
+ print (anytree.RenderTree(pycram.tasktree .task_tree, style = anytree.render.AsciiStyle()))
240
239
```
241
240
242
241
Nodes in the task tree contain additional information about the status and time of a task.
243
242
244
243
``` python
245
- print (pycram.task .task_tree.children[0 ])
244
+ print (pycram.tasktree .task_tree.children[0 ])
246
245
```
247
246
248
247
The task tree can also be reset to an empty one by invoking:
249
248
250
249
``` python
251
- pycram.task .reset_tree()
252
- print (anytree.RenderTree(pycram.task .task_tree, style = anytree.render.AsciiStyle()))
250
+ pycram.tasktree.task_tree .reset_tree()
251
+ print (anytree.RenderTree(pycram.tasktree .task_tree, style = anytree.render.AsciiStyle()))
253
252
```
254
253
255
254
If a plan fails using the PlanFailure exception, the plan will not stop. Instead, the error will be logged and saved in
256
255
the task tree as a failed subtask. First let's create a simple failing plan and execute it.
257
256
258
257
``` python
259
- @pycram.task .with_tree
258
+ @pycram.tasktree .with_tree
260
259
def failing_plan ():
261
260
raise pycram.plan_failures.PlanFailure(" Oopsie!" )
262
261
@@ -267,8 +266,8 @@ failing_plan()
267
266
We can now investigate the nodes of the tree, and we will see that the tree indeed contains a failed task.
268
267
269
268
``` python
270
- print (anytree.RenderTree(pycram.task .task_tree, style = anytree.render.AsciiStyle()))
271
- print (pycram.task .task_tree.children[0 ])
269
+ print (anytree.RenderTree(pycram.tasktree .task_tree, style = anytree.render.AsciiStyle()))
270
+ print (pycram.tasktree .task_tree.children[0 ])
272
271
```
273
272
274
273
``` python
0 commit comments