take_rack_to_location:
  params:
    - BId
    - RId
    - RackDestination
  bb_keys:
    - rack_location
  definition:
    sequence:
      # if rack already at location, don't do anything.
      decorators:
        - module: values_set_decorator
          args:
            keys: [BId, RId, RackDestination]
        - module: succeed_if_true_decorator
          args:
            name: "Is Rack Already at Destination?"
            module: butler_functions
            function: rack_already_at_location
            args:
              - RId
              - RackDestination
      children:
        # get rack location
        task:
          name: "Get Rack Location"
          module: get_rack_location_task
          args:
            rack_id: RId
            rack_location: rack_location
        # lift down before going to rack, otherwise might hit it!
        task:
          name: "Lift down (so we dont hit rack)"
          module: lift_task
          args:
            bid: BId
            direction: down
          decorators:
            # preempt if already at rack. don't need to reach with lift down then.
            - module: succeed_if_true_decorator
              name: "Already at rack?"
              args:
                module: butler_functions
                function: butler_already_at_location
                args:
                  - BId
                  - rack_location
            # preempt if already down
            - module: succeed_if_true_decorator
              name: "Already lifted down?"
              args:
                module: butler_functions
                function: lift_already_down
                args:
                  - BId
        # goto rack
        task:
          module: goto_barcode_task
          name: "Goto Rack"
          args:
            bid: BId
            location: rack_location
          decorators:
            - module: values_set_decorator
              args:
                keys: [rack_location]
        # we're under rack. lift up rack unless already lifted
        task:
          module: lift_task
          name: "Lift up rack"
          args:
            bid: BId
            direction: up
          decorators:
            - module: succeed_if_true_decorator
              name: "Already lifted up?"
              args:
                module: butler_functions
                function: lift_already_up
                args:
                  - BId
        # we're below rack and have lifted it. goto destination with rack
        task:
          name: "Goto Rack Destination"
          module: goto_barcode_task
          args:
            bid: BId
            location: RackDestination
          