leofeltrin commited on
Commit
ec3a27a
·
1 Parent(s): ff08450

Corrigir uso de cores: usar utils.COLORS[color] em vez de string; adicionar instrucoes nos prompts

Browse files
cliport/generated_tasks/create_containers_insert_colored_blocks_fixed.py ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import os
3
+ import pybullet as p
4
+ import random
5
+ from cliport.tasks import primitives
6
+ from cliport.tasks.grippers import Spatula
7
+ from cliport.tasks.task import Task
8
+ from cliport.utils import utils
9
+
10
+
11
+ class CreateContainersInsertColoredBlocks(Task):
12
+ """Create containers and insert colored blocks into them."""
13
+
14
+ def __init__(self):
15
+ super().__init__()
16
+ self.max_steps = 10
17
+ self.lang_template = "put the {color} block in the {color} container"
18
+ self.task_completed_desc = "done inserting colored blocks into containers."
19
+ self.additional_reset()
20
+
21
+ def reset(self, env):
22
+ super().reset(env)
23
+
24
+ # Define colors for blocks and containers.
25
+ colors = ['red', 'green', 'blue', 'yellow', 'purple']
26
+
27
+ # Add containers.
28
+ container_size = (0.1, 0.1, 0.1)
29
+ container_template = 'container/container-template.urdf'
30
+ containers = []
31
+ for color in colors:
32
+ # IMPORTANT: Use fill_template() for container-template.urdf
33
+ replace = {'DIM': container_size, 'HALF': (container_size[0] / 2, container_size[1] / 2, container_size[2] / 2)}
34
+ container_urdf = self.fill_template(container_template, replace)
35
+ container_pose = self.get_random_pose(env, container_size)
36
+ # IMPORTANT: Use utils.COLORS[color] for RGB values, not the string
37
+ container_id = env.add_object(container_urdf, container_pose, 'fixed', color=utils.COLORS[color])
38
+ containers.append(container_id)
39
+
40
+ # Add blocks.
41
+ block_size = (0.04, 0.04, 0.04)
42
+ block_urdf = 'stacking/block.urdf'
43
+ blocks = []
44
+ for color in colors:
45
+ block_pose = self.get_random_pose(env, block_size)
46
+ # IMPORTANT: Use utils.COLORS[color] for RGB values
47
+ block_id = env.add_object(block_urdf, block_pose, color=utils.COLORS[color])
48
+ blocks.append(block_id)
49
+
50
+ # Goal: each block is in the container of the same color.
51
+ for i in range(len(blocks)):
52
+ language_goal = self.lang_template.format(color=colors[i])
53
+ # Use p.getBasePositionAndOrientation() to get container pose dynamically
54
+ container_pose_tuple = p.getBasePositionAndOrientation(containers[i])
55
+ self.add_goal(
56
+ objs=[blocks[i]],
57
+ matches=np.ones((1, 1)),
58
+ targ_poses=[container_pose_tuple],
59
+ replace=False,
60
+ rotations=True,
61
+ metric='pose',
62
+ params=None,
63
+ step_max_reward=1.0 / len(blocks),
64
+ language_goal=language_goal
65
+ )
66
+
prompts/topdown_task_generation_prompt/cliport_prompt_code_split_template.txt CHANGED
@@ -292,6 +292,8 @@ CRITICAL FOR CONTAINER INSERTION TASKS:
292
  - Each object should have its own `add_goal()` with `targ_poses=[container_pose]` and `step_max_reward=1.0 / num_objects`
293
  - Example: For 2 objects in container, create 2 separate `add_goal()` calls, each with `step_max_reward=1.0 / 2`
294
  - Use `metric='pose'` for precise insertion, or `metric='zone'` with `params=[(container_pose, zone_size)]` for flexible placement
 
 
295
 
296
  CRITICAL FOR SPIRAL PATTERNS:
297
  - For spiral patterns, you MUST use POLAR COORDINATES with increasing radius and varying angle
 
292
  - Each object should have its own `add_goal()` with `targ_poses=[container_pose]` and `step_max_reward=1.0 / num_objects`
293
  - Example: For 2 objects in container, create 2 separate `add_goal()` calls, each with `step_max_reward=1.0 / 2`
294
  - Use `metric='pose'` for precise insertion, or `metric='zone'` with `params=[(container_pose, zone_size)]` for flexible placement
295
+ - To get container pose dynamically, use `p.getBasePositionAndOrientation(container_id)` which returns `(position, orientation)` tuple
296
+ - **CRITICAL FOR COLORS**: When using colors, ALWAYS use `color=utils.COLORS['red']` (RGB values), NEVER use `color='red'` (string). For color names in strings, use `'red'`, but for color parameter, use `utils.COLORS['red']`
297
 
298
  CRITICAL FOR SPIRAL PATTERNS:
299
  - For spiral patterns, you MUST use POLAR COORDINATES with increasing radius and varying angle
prompts/topdown_task_generation_prompt_simple/cliport_prompt_code_split_template.txt CHANGED
@@ -290,6 +290,8 @@ CRITICAL FOR CONTAINER INSERTION TASKS:
290
  - Each object should have its own `add_goal()` with `targ_poses=[container_pose]` and `step_max_reward=1.0 / num_objects`
291
  - Example: For 2 objects in container, create 2 separate `add_goal()` calls, each with `step_max_reward=1.0 / 2`
292
  - Use `metric='pose'` for precise insertion, or `metric='zone'` with `params=[(container_pose, zone_size)]` for flexible placement
 
 
293
 
294
  CRITICAL FOR SPIRAL PATTERNS:
295
  - For spiral patterns, you MUST use POLAR COORDINATES with increasing radius and varying angle
 
290
  - Each object should have its own `add_goal()` with `targ_poses=[container_pose]` and `step_max_reward=1.0 / num_objects`
291
  - Example: For 2 objects in container, create 2 separate `add_goal()` calls, each with `step_max_reward=1.0 / 2`
292
  - Use `metric='pose'` for precise insertion, or `metric='zone'` with `params=[(container_pose, zone_size)]` for flexible placement
293
+ - To get container pose dynamically, use `p.getBasePositionAndOrientation(container_id)` which returns `(position, orientation)` tuple
294
+ - **CRITICAL FOR COLORS**: When using colors, ALWAYS use `color=utils.COLORS['red']` (RGB values), NEVER use `color='red'` (string). For color names in strings, use `'red'`, but for color parameter, use `utils.COLORS['red']`
295
 
296
  CRITICAL FOR SPIRAL PATTERNS:
297
  - For spiral patterns, you MUST use POLAR COORDINATES with increasing radius and varying angle
prompts/vanilla_task_generation_prompt/cliport_prompt_code_split_template.txt CHANGED
@@ -284,6 +284,8 @@ CRITICAL FOR CONTAINER INSERTION TASKS:
284
  - Each object should have its own `add_goal()` with `targ_poses=[container_pose]` and `step_max_reward=1.0 / num_objects`
285
  - Example: For 2 objects in container, create 2 separate `add_goal()` calls, each with `step_max_reward=1.0 / 2`
286
  - Use `metric='pose'` for precise insertion, or `metric='zone'` with `params=[(container_pose, zone_size)]` for flexible placement
 
 
287
 
288
  CRITICAL FOR SPIRAL PATTERNS:
289
  - For spiral patterns, you MUST use POLAR COORDINATES with increasing radius and varying angle
 
284
  - Each object should have its own `add_goal()` with `targ_poses=[container_pose]` and `step_max_reward=1.0 / num_objects`
285
  - Example: For 2 objects in container, create 2 separate `add_goal()` calls, each with `step_max_reward=1.0 / 2`
286
  - Use `metric='pose'` for precise insertion, or `metric='zone'` with `params=[(container_pose, zone_size)]` for flexible placement
287
+ - To get container pose dynamically, use `p.getBasePositionAndOrientation(container_id)` which returns `(position, orientation)` tuple
288
+ - **CRITICAL FOR COLORS**: When using colors, ALWAYS use `color=utils.COLORS['red']` (RGB values), NEVER use `color='red'` (string). For color names in strings, use `'red'`, but for color parameter, use `utils.COLORS['red']`
289
 
290
  CRITICAL FOR SPIRAL PATTERNS:
291
  - For spiral patterns, you MUST use POLAR COORDINATES with increasing radius and varying angle