Spaces:
Sleeping
Sleeping
Commit
·
1f48d6e
1
Parent(s):
6111b73
Adicionar suporte para multiplas estruturas (duas piramides): codigo exemplo e instrucoes nos prompts
Browse files- cliport/generated_tasks/build_two_pyramids_blue_red_fixed.py +158 -0
- prompts/topdown_task_generation_prompt/cliport_prompt_code_split_template.txt +8 -0
- prompts/topdown_task_generation_prompt_simple/cliport_prompt_code_split_template.txt +8 -0
- prompts/vanilla_task_generation_prompt/cliport_prompt_code_split_template.txt +8 -0
cliport/generated_tasks/build_two_pyramids_blue_red_fixed.py
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 BuildTwoPyramidsBlueRed(Task):
|
| 12 |
+
"""Build two pyramids: one with blue blocks and one with red blocks."""
|
| 13 |
+
|
| 14 |
+
def __init__(self):
|
| 15 |
+
super().__init__()
|
| 16 |
+
self.max_steps = 20
|
| 17 |
+
self.lang_template = "build two pyramids: one with blue blocks and one with red blocks"
|
| 18 |
+
self.task_completed_desc = "done building two pyramids."
|
| 19 |
+
self.additional_reset()
|
| 20 |
+
|
| 21 |
+
def reset(self, env):
|
| 22 |
+
super().reset(env)
|
| 23 |
+
|
| 24 |
+
# Add two bases/stands for the pyramids
|
| 25 |
+
base_size = (0.05, 0.15, 0.005)
|
| 26 |
+
base_urdf = 'stacking/stand.urdf'
|
| 27 |
+
|
| 28 |
+
# First base (for blue pyramid) - positioned on the left side of workspace
|
| 29 |
+
# Workspace bounds: X: [0.25, 0.75], Y: [-0.5, 0.5], Z: [0, 0.3]
|
| 30 |
+
base1_center = (0.4, -0.2, 0.001) # Left side, within bounds
|
| 31 |
+
base1_rotation = (0, 0, 0, 1)
|
| 32 |
+
base1_pose = (base1_center, base1_rotation)
|
| 33 |
+
env.add_object(base_urdf, base1_pose, category='fixed')
|
| 34 |
+
|
| 35 |
+
# Second base (for red pyramid) - positioned on the right side of workspace
|
| 36 |
+
base2_center = (0.6, 0.2, 0.001) # Right side, within bounds
|
| 37 |
+
base2_rotation = (0, 0, 0, 1)
|
| 38 |
+
base2_pose = (base2_center, base2_rotation)
|
| 39 |
+
env.add_object(base_urdf, base2_pose, category='fixed')
|
| 40 |
+
|
| 41 |
+
# Add blocks: 6 blue blocks for first pyramid, 6 red blocks for second pyramid
|
| 42 |
+
block_size = (0.04, 0.04, 0.04)
|
| 43 |
+
block_urdf = 'stacking/block.urdf'
|
| 44 |
+
|
| 45 |
+
blue_blocks = []
|
| 46 |
+
red_blocks = []
|
| 47 |
+
|
| 48 |
+
# Add 6 blue blocks
|
| 49 |
+
for _ in range(6):
|
| 50 |
+
block_pose = self.get_random_pose(env, block_size)
|
| 51 |
+
block_id = env.add_object(block_urdf, block_pose, color=utils.COLORS['blue'])
|
| 52 |
+
blue_blocks.append(block_id)
|
| 53 |
+
|
| 54 |
+
# Add 6 red blocks
|
| 55 |
+
for _ in range(6):
|
| 56 |
+
block_pose = self.get_random_pose(env, block_size)
|
| 57 |
+
block_id = env.add_object(block_urdf, block_pose, color=utils.COLORS['red'])
|
| 58 |
+
red_blocks.append(block_id)
|
| 59 |
+
|
| 60 |
+
# Define target poses for pyramids using RELATIVE positions
|
| 61 |
+
# Pyramid structure: 3 blocks base, 2 blocks middle, 1 block top
|
| 62 |
+
place_pos = [
|
| 63 |
+
(0, -0.05, 0.03), # Left base
|
| 64 |
+
(0, 0.0, 0.03), # Center base
|
| 65 |
+
(0, 0.05, 0.03), # Right base
|
| 66 |
+
(0, -0.025, 0.08), # Left middle
|
| 67 |
+
(0, 0.025, 0.08), # Right middle
|
| 68 |
+
(0, 0.0, 0.13) # Top
|
| 69 |
+
]
|
| 70 |
+
|
| 71 |
+
# Apply relative positions to each base pose
|
| 72 |
+
blue_targs = [(utils.apply(base1_pose, pos), base1_pose[1]) for pos in place_pos]
|
| 73 |
+
red_targs = [(utils.apply(base2_pose, pos), base2_pose[1]) for pos in place_pos]
|
| 74 |
+
|
| 75 |
+
# Goal: Build blue pyramid (bottom row: 3 blocks)
|
| 76 |
+
self.add_goal(
|
| 77 |
+
objs=blue_blocks[:3],
|
| 78 |
+
matches=np.ones((3, 3)),
|
| 79 |
+
targ_poses=blue_targs[:3],
|
| 80 |
+
replace=False,
|
| 81 |
+
rotations=True,
|
| 82 |
+
metric='pose',
|
| 83 |
+
params=None,
|
| 84 |
+
step_max_reward=1.0 / 6,
|
| 85 |
+
symmetries=[np.pi/2]*3,
|
| 86 |
+
language_goal="build the bottom row of the blue pyramid with three blue blocks"
|
| 87 |
+
)
|
| 88 |
+
|
| 89 |
+
# Goal: Build blue pyramid (middle row: 2 blocks)
|
| 90 |
+
self.add_goal(
|
| 91 |
+
objs=blue_blocks[3:5],
|
| 92 |
+
matches=np.ones((2, 2)),
|
| 93 |
+
targ_poses=blue_targs[3:5],
|
| 94 |
+
replace=False,
|
| 95 |
+
rotations=True,
|
| 96 |
+
metric='pose',
|
| 97 |
+
params=None,
|
| 98 |
+
step_max_reward=1.0 / 6,
|
| 99 |
+
symmetries=[np.pi/2]*2,
|
| 100 |
+
language_goal="build the middle row of the blue pyramid with two blue blocks"
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
+
# Goal: Build blue pyramid (top: 1 block)
|
| 104 |
+
self.add_goal(
|
| 105 |
+
objs=blue_blocks[5:],
|
| 106 |
+
matches=np.ones((1, 1)),
|
| 107 |
+
targ_poses=blue_targs[5:],
|
| 108 |
+
replace=False,
|
| 109 |
+
rotations=True,
|
| 110 |
+
metric='pose',
|
| 111 |
+
params=None,
|
| 112 |
+
step_max_reward=1.0 / 6,
|
| 113 |
+
symmetries=[np.pi/2],
|
| 114 |
+
language_goal="place the top block to complete the blue pyramid"
|
| 115 |
+
)
|
| 116 |
+
|
| 117 |
+
# Goal: Build red pyramid (bottom row: 3 blocks)
|
| 118 |
+
self.add_goal(
|
| 119 |
+
objs=red_blocks[:3],
|
| 120 |
+
matches=np.ones((3, 3)),
|
| 121 |
+
targ_poses=red_targs[:3],
|
| 122 |
+
replace=False,
|
| 123 |
+
rotations=True,
|
| 124 |
+
metric='pose',
|
| 125 |
+
params=None,
|
| 126 |
+
step_max_reward=1.0 / 6,
|
| 127 |
+
symmetries=[np.pi/2]*3,
|
| 128 |
+
language_goal="build the bottom row of the red pyramid with three red blocks"
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
# Goal: Build red pyramid (middle row: 2 blocks)
|
| 132 |
+
self.add_goal(
|
| 133 |
+
objs=red_blocks[3:5],
|
| 134 |
+
matches=np.ones((2, 2)),
|
| 135 |
+
targ_poses=red_targs[3:5],
|
| 136 |
+
replace=False,
|
| 137 |
+
rotations=True,
|
| 138 |
+
metric='pose',
|
| 139 |
+
params=None,
|
| 140 |
+
step_max_reward=1.0 / 6,
|
| 141 |
+
symmetries=[np.pi/2]*2,
|
| 142 |
+
language_goal="build the middle row of the red pyramid with two red blocks"
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
# Goal: Build red pyramid (top: 1 block)
|
| 146 |
+
self.add_goal(
|
| 147 |
+
objs=red_blocks[5:],
|
| 148 |
+
matches=np.ones((1, 1)),
|
| 149 |
+
targ_poses=red_targs[5:],
|
| 150 |
+
replace=False,
|
| 151 |
+
rotations=True,
|
| 152 |
+
metric='pose',
|
| 153 |
+
params=None,
|
| 154 |
+
step_max_reward=1.0 / 6,
|
| 155 |
+
symmetries=[np.pi/2],
|
| 156 |
+
language_goal="place the top block to complete the red pyramid"
|
| 157 |
+
)
|
| 158 |
+
|
prompts/topdown_task_generation_prompt/cliport_prompt_code_split_template.txt
CHANGED
|
@@ -279,4 +279,12 @@ CRITICAL FOR PYRAMIDS, BRIDGES, AND MULTI-LAYER STRUCTURES:
|
|
| 279 |
- Split the reward across layers: `step_max_reward=1.0 / num_layers` for each layer
|
| 280 |
- Each layer should have its own `language_goal` describing that specific step (e.g., "build the bottom row", "build the middle row", "place the top block")
|
| 281 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
Now write the code for the task "TASK_NAME_TEMPLATE" in python code block starting with ```python. Reminder: TASK_STRING_TEMPLATE
|
|
|
|
| 279 |
- Split the reward across layers: `step_max_reward=1.0 / num_layers` for each layer
|
| 280 |
- Each layer should have its own `language_goal` describing that specific step (e.g., "build the bottom row", "build the middle row", "place the top block")
|
| 281 |
|
| 282 |
+
CRITICAL FOR MULTIPLE STRUCTURES (e.g., "two pyramids", "three towers", "multiple zones"):
|
| 283 |
+
- If the task requires MULTIPLE separate structures (e.g., "two pyramids", "one blue pyramid and one red pyramid"), you MUST create separate base poses for each structure
|
| 284 |
+
- Use different base poses (e.g., `base1_pose`, `base2_pose`) positioned at different locations in the workspace
|
| 285 |
+
- Create separate target pose lists for each structure using `utils.apply()` with each respective base pose
|
| 286 |
+
- Use MULTIPLE sets of `add_goal()` calls - one set for each structure (e.g., 3 goals for first pyramid, 3 goals for second pyramid)
|
| 287 |
+
- Each structure should have its own objects and its own goals, clearly separated in the code
|
| 288 |
+
- Example: For "two pyramids", create `blue_blocks` and `red_blocks`, `blue_targs` and `red_targs`, and separate `add_goal()` calls for each pyramid
|
| 289 |
+
|
| 290 |
Now write the code for the task "TASK_NAME_TEMPLATE" in python code block starting with ```python. Reminder: TASK_STRING_TEMPLATE
|
prompts/topdown_task_generation_prompt_simple/cliport_prompt_code_split_template.txt
CHANGED
|
@@ -277,4 +277,12 @@ CRITICAL FOR PYRAMIDS, BRIDGES, AND MULTI-LAYER STRUCTURES:
|
|
| 277 |
- Split the reward across layers: `step_max_reward=1.0 / num_layers` for each layer
|
| 278 |
- Each layer should have its own `language_goal` describing that specific step (e.g., "build the bottom row", "build the middle row", "place the top block")
|
| 279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
Now write the code for the task "TASK_NAME_TEMPLATE" in python code block starting with ```python. Reminder: TASK_STRING_TEMPLATE
|
|
|
|
| 277 |
- Split the reward across layers: `step_max_reward=1.0 / num_layers` for each layer
|
| 278 |
- Each layer should have its own `language_goal` describing that specific step (e.g., "build the bottom row", "build the middle row", "place the top block")
|
| 279 |
|
| 280 |
+
CRITICAL FOR MULTIPLE STRUCTURES (e.g., "two pyramids", "three towers", "multiple zones"):
|
| 281 |
+
- If the task requires MULTIPLE separate structures (e.g., "two pyramids", "one blue pyramid and one red pyramid"), you MUST create separate base poses for each structure
|
| 282 |
+
- Use different base poses (e.g., `base1_pose`, `base2_pose`) positioned at different locations in the workspace
|
| 283 |
+
- Create separate target pose lists for each structure using `utils.apply()` with each respective base pose
|
| 284 |
+
- Use MULTIPLE sets of `add_goal()` calls - one set for each structure (e.g., 3 goals for first pyramid, 3 goals for second pyramid)
|
| 285 |
+
- Each structure should have its own objects and its own goals, clearly separated in the code
|
| 286 |
+
- Example: For "two pyramids", create `blue_blocks` and `red_blocks`, `blue_targs` and `red_targs`, and separate `add_goal()` calls for each pyramid
|
| 287 |
+
|
| 288 |
Now write the code for the task "TASK_NAME_TEMPLATE" in python code block starting with ```python. Reminder: TASK_STRING_TEMPLATE
|
prompts/vanilla_task_generation_prompt/cliport_prompt_code_split_template.txt
CHANGED
|
@@ -266,6 +266,14 @@ CRITICAL FOR PYRAMIDS, BRIDGES, AND MULTI-LAYER STRUCTURES:
|
|
| 266 |
- Include `symmetries=[np.pi/2]*n` parameter in `add_goal()` to allow 90-degree rotations
|
| 267 |
- Split the reward across layers: `step_max_reward=1.0 / num_layers` for each layer
|
| 268 |
- Each layer should have its own `language_goal` describing that specific step (e.g., "build the bottom row", "build the middle row", "place the top block")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 269 |
- ALL target poses MUST be within workspace bounds: X: [0.25, 0.75], Y: [-0.5, 0.5], Z: [0, 0.3]
|
| 270 |
|
| 271 |
Now write the code for the task "TASK_NAME_TEMPLATE" in python code block starting with ```python. Reminder: TASK_STRING_TEMPLATE
|
|
|
|
| 266 |
- Include `symmetries=[np.pi/2]*n` parameter in `add_goal()` to allow 90-degree rotations
|
| 267 |
- Split the reward across layers: `step_max_reward=1.0 / num_layers` for each layer
|
| 268 |
- Each layer should have its own `language_goal` describing that specific step (e.g., "build the bottom row", "build the middle row", "place the top block")
|
| 269 |
+
|
| 270 |
+
CRITICAL FOR MULTIPLE STRUCTURES (e.g., "two pyramids", "three towers", "multiple zones"):
|
| 271 |
+
- If the task requires MULTIPLE separate structures (e.g., "two pyramids", "one blue pyramid and one red pyramid"), you MUST create separate base poses for each structure
|
| 272 |
+
- Use different base poses (e.g., `base1_pose`, `base2_pose`) positioned at different locations in the workspace
|
| 273 |
+
- Create separate target pose lists for each structure using `utils.apply()` with each respective base pose
|
| 274 |
+
- Use MULTIPLE sets of `add_goal()` calls - one set for each structure (e.g., 3 goals for first pyramid, 3 goals for second pyramid)
|
| 275 |
+
- Each structure should have its own objects and its own goals, clearly separated in the code
|
| 276 |
+
- Example: For "two pyramids", create `blue_blocks` and `red_blocks`, `blue_targs` and `red_targs`, and separate `add_goal()` calls for each pyramid
|
| 277 |
- ALL target poses MUST be within workspace bounds: X: [0.25, 0.75], Y: [-0.5, 0.5], Z: [0, 0.3]
|
| 278 |
|
| 279 |
Now write the code for the task "TASK_NAME_TEMPLATE" in python code block starting with ```python. Reminder: TASK_STRING_TEMPLATE
|