|
|
|
import numpy as np |
|
from env_utils import put_first_on_second, get_obj_pos, get_obj_names, say, get_corner_name, get_side_name, is_obj_visible, stack_objects_in_order |
|
from plan_utils import parse_obj_name, parse_position, parse_question, transform_shape_pts |
|
|
|
objects = ['yellow block', 'green block', 'yellow bowl', 'blue block', 'blue bowl', 'green bowl'] |
|
|
|
say('Ok - putting the yellow block on the yellow bowl') |
|
put_first_on_second('yellow block', 'yellow bowl') |
|
objects = ['yellow block', 'green block', 'yellow bowl', 'blue block', 'blue bowl', 'green bowl'] |
|
|
|
say('I moved the yellow block') |
|
objects = ['yellow block', 'green block', 'yellow bowl', 'blue block', 'blue bowl', 'green bowl'] |
|
|
|
say('Got it - putting the green block on the top right corner') |
|
corner_pos = parse_position('top right corner') |
|
put_first_on_second('green block', corner_pos) |
|
objects = ['yellow block', 'green block', 'yellow bowl', 'blue block', 'blue bowl', 'green bowl'] |
|
|
|
order_bottom_to_top = ['green block', 'yellow block', 'blue bowl'] |
|
say(f'Sure - stacking from top to bottom: {", ".join(order_bottom_to_top)}') |
|
stack_objects_in_order(object_names=order_bottom_to_top) |
|
objects = ['cyan block', 'white block', 'cyan bowl', 'blue block', 'blue bowl', 'white bowl'] |
|
|
|
matches = {'cyan block': 'cyan bowl'} |
|
say('Got it - placing the cyan block on the cyan bowl') |
|
for first, second in matches.items(): |
|
put_first_on_second(first, get_obj_pos(second)) |
|
objects = ['cyan block', 'white block', 'cyan bowl', 'blue block', 'blue bowl', 'white bowl'] |
|
|
|
say('No problem! Making a line of blocks on the right side') |
|
block_names = parse_obj_name('the blocks', f'objects = {get_obj_names()}') |
|
line_pts = parse_position(f'a 30cm vertical line on the right with {len(block_names)} points') |
|
for block_name, pt in zip(block_names, line_pts): |
|
put_first_on_second(block_name, pt) |
|
objects = ['yellow block', 'red block', 'yellow bowl', 'gray block', 'gray bowl', 'red bowl'] |
|
|
|
say('Sure thing - putting the yellow block between the blue bowl and the green block') |
|
target_pos = parse_position('a point in the middle betweeen the blue bowl and the green block') |
|
put_first_on_second('yellow block', target_pos) |
|
objects = ['yellow block', 'red block', 'yellow bowl', 'gray block', 'gray bowl', 'red bowl'] |
|
|
|
say('no, I can only move objects around') |
|
objects = ['yellow block', 'green block', 'yellow bowl', 'gray block', 'gray bowl', 'green bowl'] |
|
|
|
say('Ok. stacking the blocks on the right side with the gray block on the bottom') |
|
right_side = parse_position('the right side') |
|
put_first_on_second('gray block', right_side) |
|
order_bottom_to_top = ['gray block', 'green block', 'yellow block'] |
|
stack_objects_in_order(object_names=order_bottom_to_top) |
|
objects = ['yellow block', 'green block', 'yellow bowl', 'blue block', 'blue bowl', 'green bowl'] |
|
|
|
bowl_name = np.random.choice(['yellow bowl', 'green bowl']) |
|
say(f'Sounds good! Hiding the blue bowl under the {bowl_name}') |
|
put_first_on_second(bowl_name, 'blue bowl') |
|
objects = ['pink block', 'green block', 'pink bowl', 'blue block', 'blue bowl', 'green bowl'] |
|
|
|
say('Sure - moving the green bowl left by 10 centimeters') |
|
left_pos = parse_position('a point 10cm left of the green bowl') |
|
put_first_on_second('green bowl', left_pos) |
|
objects = ['pink block', 'green block', 'pink bowl', 'blue block', 'blue bowl', 'green bowl'] |
|
|
|
say(f'I did not move the red bowl') |
|
objects = ['pink block', 'green block', 'pink bowl', 'blue block', 'blue bowl', 'green bowl'] |
|
|
|
say('Sure - moving the green bowl right by 10 centimeters') |
|
left_pos = parse_position('a point 10cm right of the green bowl') |
|
put_first_on_second('green bowl', left_pos) |
|
objects = ['brown bowl', 'green block', 'brown block', 'green bowl', 'blue bowl', 'blue block'] |
|
|
|
top_block_name = parse_obj_name('top most block', f'objects = {get_obj_names()}') |
|
bottom_block_name = parse_obj_name('bottom most block', f'objects = {get_obj_names()}') |
|
closest_corner_pos = parse_position(f'the corner closest to the {bottom_block_name}', f'objects = {get_obj_names()}') |
|
say(f'Putting the {top_block_name} on the {get_corner_name(closest_corner_pos)}') |
|
put_first_on_second(top_block_name, closest_corner_pos) |
|
objects = ['brown bowl', 'green block', 'brown block', 'green bowl', 'blue bowl', 'blue block'] |
|
|
|
closest_side_position = parse_position('the side closest to the green block') |
|
say(f'Got it - putting the brown bowl on the {get_side_name(closest_side_position)}') |
|
put_first_on_second('brown bowl', closest_side_position) |
|
objects = ['brown bowl', 'green block', 'brown block', 'green bowl', 'blue bowl', 'blue block'] |
|
|
|
bowl_name = parse_obj_name('the bowl that has the blue block', f'objects = {get_obj_names()}') |
|
if bowl_name: |
|
target_pos = parse_position(f'a point 10cm to the right of the {bowl_name}') |
|
say(f'No problem - placing the green block to the right of the {bowl_name}') |
|
put_first_on_second('green block', target_pos) |
|
else: |
|
say('There are no bowls that has the blue block') |
|
objects = ['brown bowl', 'green block', 'brown block', 'green bowl', 'blue bowl', 'blue block'] |
|
|
|
block_names = parse_obj_name('blocks other than the blue block', f'objects = {get_obj_names()}') |
|
corners = parse_position('the bottom corners') |
|
for block_name, pos in zip(block_names, corners): |
|
put_first_on_second(block_name, pos) |
|
objects = ['pink block', 'gray block', 'orange block'] |
|
|
|
say('Ok - putting the pink block on the bottom side') |
|
bottom_side_pos = parse_position('the bottom side') |
|
put_first_on_second('pink block', bottom_side_pos) |
|
objects = ['yellow bowl', 'blue block', 'yellow block', 'blue bowl'] |
|
|
|
if parse_question('is the blue block to the right of the yellow bowl?', f'objects = {get_obj_names()}'): |
|
say('yes, there is a blue block to the right of the yellow bow') |
|
else: |
|
say('no, there is\'t a blue block to the right of the yellow bow') |
|
objects = ['yellow bowl', 'blue block', 'yellow block', 'blue bowl'] |
|
|
|
n_yellow_objs = parse_question('how many yellow objects are there', f'objects = {get_obj_names()}') |
|
say(f'there are {n_yellow_objs} yellow object') |
|
objects = ['pink block', 'green block', 'pink bowl', 'blue block', 'blue bowl', 'green bowl'] |
|
|
|
left_block_name = parse_obj_name('left most block', f'objects = {get_obj_names()}') |
|
say(f'Moving the {left_block_name} on the green bowl') |
|
put_first_on_second(left_block_name, 'green bowl') |
|
objects = ['pink block', 'green block', 'pink bowl', 'blue block', 'blue bowl', 'green bowl'] |
|
|
|
block_names = parse_obj_name(f'blocks other than the {left_block_name}', f'objects = {get_obj_names()}') |
|
corners = parse_position('the corners') |
|
say(f'Ok - moving the other {len(block_names)} blocks to different corners') |
|
for block_name, pos in zip(block_names, corners): |
|
put_first_on_second(block_name, pos) |
|
objects = ['pink block', 'green block', 'pink bowl', 'blue block', 'blue bowl', 'green bowl'] |
|
|
|
if parse_question('is the pink block on the green bowl', f'objects = {get_obj_names()}'): |
|
say('Yes - the pink block is on the green bowl.') |
|
else: |
|
say('No - the pink block is not on the green bowl.') |
|
objects = ['pink block', 'green block', 'pink bowl', 'blue block', 'blue bowl', 'green bowl'] |
|
|
|
left_block_names = parse_question('what are the blocks left of the green bowl', f'objects = {get_obj_names()}') |
|
if len(left_block_names) > 0: |
|
say(f'These blocks are left of the green bowl: {", ".join(left_block_names)}') |
|
else: |
|
say('There are no blocks left of the green bowl') |
|
objects = ['yellow block', 'green block', 'yellow bowl', 'blue block', 'blue bowl', 'green bowl'] |
|
|
|
say('ok') |
|
objects = ['yellow block', 'green block', 'yellow bowl', 'blue block', 'blue bowl', 'green bowl'] |
|
|
|
order_bottom_to_top = ['green bowl', 'blue block', 'green block', 'yellow block'] |
|
say('stacking the blocks on the green bowl') |
|
stack_objects_in_order(object_names=order_bottom_to_top) |
|
objects = ['yellow block', 'green block', 'yellow bowl', 'gray block', 'gray bowl', 'green bowl'] |
|
|
|
say('putting the yellow bowl on the blue bowl') |
|
put_first_on_second('yellow bowl', 'blue bowl') |
|
objects = ['pink block', 'gray block', 'orange block'] |
|
|
|
say('Ok - moving all blocks 5cm toward the top') |
|
block_names = parse_obj_name('the blocks', f'objects = {get_obj_names()}') |
|
for block_name in block_names: |
|
target_pos = parse_position(f'a point 5cm above the {block_name}') |
|
put_first_on_second(block_name, target_pos) |
|
objects = ['cyan block', 'white block', 'purple bowl', 'blue block', 'blue bowl', 'white bowl'] |
|
|
|
block_names = parse_obj_name('the blocks', f'objects = {get_obj_names()}') |
|
triangle_pts = parse_position(f'a triangle with size 10cm around the middle with {len(block_names)} points') |
|
say('Making a triangle of blocks around the middle of the workspace') |
|
for block_name, pt in zip(block_names, triangle_pts): |
|
put_first_on_second(block_name, pt) |
|
objects = ['cyan block', 'white block', 'purple bowl', 'blue block', 'blue bowl', 'white bowl'] |
|
|
|
triangle_pts = transform_shape_pts('scale it by 0.5x', shape_pts=triangle_pts) |
|
say('Making the triangle smaller') |
|
block_names = parse_obj_name('the blocks', f'objects = {get_obj_names()}') |
|
for block_name, pt in zip(block_names, triangle_pts): |
|
put_first_on_second(block_name, pt) |
|
objects = ['brown bowl', 'red block', 'brown block', 'red bowl', 'pink bowl', 'pink block'] |
|
|
|
farthest_bowl_name = parse_obj_name('the bowl farthest from the red block', f'objects = {get_obj_names()}') |
|
say(f'Putting the red block on the {farthest_bowl_name}') |
|
put_first_on_second('red block', farthest_bowl_name) |