def pickup_next(): '''Release the box in gripper (if any) and pick up the one below. Assumption: robot is in front of a box/stack; lift is at level 1.''' robot.gripper_to_open() robot.lift_down() robot.gripper_to_closed() robot.lift_up()
def make_tower(): count = 0 while robot.sense_color() != "": count = count + 1 robot.drive_right() robot.drive_right() boxes = count while boxes > 0: robot.drive_left() robot.drive_left() boxes = boxes - 1 robot.lift_up() robot.gripper_to_open() robot.drive_right() robot.lift_down() robot.gripper_to_closed() while boxes < (count - 1): boxes = boxes + 1 robot.lift_up() robot.drive_right() robot.drive_right() robot.gripper_to_open() robot.lift_down() if boxes != count - 1: robot.gripper_to_closed()
def swap_left_mid(): robot.drive_right() robot.lift_up() robot.gripper_to_open() robot.lift_down() robot.gripper_to_closed() move()
def count_boxes(): if robot.sense_color() == "": return 0 else: robot.lift_up() num_above = count_boxes() robot.lift_down() return 1 + num_above
def find(colour): robot.init(height=5, boxes=[["black", "blue", "white", "red"]]) j = 1 while robot.sense_color() != "": if robot.sense_color == colour: return True # Why this doesn't work? robot.lift_up() j = j + 1 return False
def unstack_tower_of_two(): # Move to the middle right_two_spaces() # and do the unstacking manoeuvre unstack_to_the_left() # -------------Here to do the up-fold-down to initialize the gripper! robot.lift_up() robot.gripper_to_folded() robot.lift_down()
def put_down_blocks(): # Move the lift down, and release the blocks. robot.lift_down() robot.gripper_to_open() # Because there is now a block to the right (the one that we # unstacked from), we must do the up-fold-down manoeuvre. robot.lift_up() robot.gripper_to_folded() robot.lift_down()
def make_tower(n): robot.init(width=2 * n - 1, boxes="flat") robot.drive_right() robot.lift_up() while n > 1: pickup_next() move_to_next_stack() n = n - 1 robot.gripper_to_folded() robot.lift_down()
def unstack_tower_of_three(): # Move to the right-most stack right_two_spaces() right_two_spaces() # and do the unstacking manoeuvre unstack_to_the_left() robot.lift_up() robot.gripper_to_closed() left_two_spaces() put_down_blocks()
def unstack_tower_of_three(): # Move to the right-most stack right_two_spaces() right_two_spaces() # and do the unstacking manoeuvre twice unstack_to_the_left() unstack_to_the_left() robot.lift_up() robot.gripper_to_folded() robot.lift_down()
def find(color): index = 0 while (robot.sense_color() != color) and (robot.sense_color() != ""): index = index + 1 print(index) if (robot.sense_color != ""): robot.lift_up() if robot.sense_color() == color: return index + 1 else: return -1
def swap_middle_and_right(): robot.lift_up() move_2steps_right() open_down_and_close_up() move_2steps_left() robot.lift_down() robot.gripper_to_open() robot.lift_up() robot.gripper_to_closed() move_2steps_right() robot.lift_down()
def pickup_and_replace(): robot.lift_up() open_down_and_close_up() move_2steps_right() open_down_and_close_up() move_2steps_left() robot.lift_down() robot.gripper_to_open() robot.lift_up() robot.gripper_to_closed() move_2steps_right() robot.lift_down()
def make_tower(n): robot.init(width=2 * n - 1, boxes="flat") robot.drive_right() robot.lift_up() i = 0 while i < n - 1: pickup_next() move_to_next_stack() i = i + 1 robot.gripper_to_folded() robot.lift_down() return "Tower complete!"
def find(colour): current_hight = 0 current_color = robot.sense_color() while current_color != '': while current_color != colour: robot.lift_up() current_hight = current_hight + 1 current_color = robot.sense_color() if current_color == '': return -1 else: current_color == colour return current_hight, current_color
def swap_middle_and_left(): robot.lift_up() robot.drive_left() robot.drive_left() robot.drive_left() robot.drive_left() robot.lift_down() robot.gripper_to_closed() #green box is in the gripper! robot.lift_up() robot.drive_right() robot.drive_right() robot.gripper_to_open() robot.lift_down() robot.gripper_to_closed() #blue box is in the gripper! robot.drive_left() robot.drive_left() robot.gripper_to_open() robot.lift_up() robot.gripper_to_closed() robot.drive_right() robot.drive_right() robot.lift_down() robot.gripper_to_open() robot.lift_up() robot.gripper_to_folded()
def swap_left_and_middle(): robot.drive_right() robot.lift_up() robot.gripper_to_open() robot.lift_down() robot.gripper_to_closed() robot.lift_up() robot.drive_right() robot.drive_right() robot.gripper_to_open() robot.lift_down() robot.gripper_to_closed() robot.drive_left() robot.drive_left() robot.gripper_to_open() robot.lift_up() robot.gripper_to_closed() robot.drive_right() robot.drive_right() robot.lift_down() robot.gripper_to_open() robot.lift_up() robot.gripper_to_folded() robot.drive_left() robot.drive_left() robot.drive_left() robot.lift_down()
def swap_left_and_middle(): robot.drive_right() robot.lift_up() robot.gripper_to_open() robot.lift_down() robot.gripper_to_closed() # red box is in gripper! robot.lift_up() robot.drive_right() robot.drive_right() robot.gripper_to_open() # red box is on the top of green box! robot.lift_down() robot.gripper_to_closed() #green box is in gripper! robot.drive_left() robot.drive_left() #greem box is on the right! robot.gripper_to_open() robot.lift_up() robot.gripper_to_closed() robot.drive_right() robot.drive_right()
def open_down_and_close_up(): robot.gripper_to_open() robot.lift_down() robot.gripper_to_closed() robot.lift_up()
def grasp_blocks_above(): #the order was wrong #it should lift up first and then open the gripper robot.lift_up() robot.gripper_to_open() robot.gripper_to_closed()
def pickup_next(): '''Release the box in gripper (if any) and pick up the one below. Assumption: robot is in front of a box/stack; lift is at level 1.''' robot.gripper_to_open() robot.lift_down() robot.gripper_to_closed() robot.lift_up() # main program robot.init(width = 9, boxes = "flat") # position above first box robot.drive_right() robot.lift_up() # pick up, move right pickup_next() move_to_next_stack() # ...again pickup_next() move_to_next_stack() # ...again pickup_next() move_to_next_stack() # ...again pickup_next()
def grasp_blocks_above(): robot.gripper_to_open() robot.lift_up() robot.gripper_to_closed()
def grasp_blocks_above(): # i deleted the following line since i read through the error message. #gripper_to_open is the reason why the collision happened robot.gripper_to_open() robot.lift_up() robot.gripper_to_closed()