Przejdź do treści

Planowanie i wykonywanie akcji robota z wykorzystaniem Behavior Tree (0-10 points)

Description

The goal of this task is to implement a Behavior Tree (BT) to simulate a robot performing a "pick-and-place" task. Use the py_trees library to structure the behavior tree and simulate the individual actions required for the task.

Implement a BT that allows a mobile robot to:

  • Move to the location of the first object.
  • Pick up the first object.
  • Move to another location.
  • Place the first object.
  • Repeat the same steps for the second object.
  • Move to the starting pose.
Requirements
  • Implement three custom behaviors: MoveTo, PickObject, and PlaceObject. Each behavior should simulate its corresponding task and return py_trees.common.Status.SUCCESS upon completion.
  • Create a behavior tree and add the defined behaviors to it in the proper order.
  • Set up and run the tree by ticking it repeatedly.
  • Print the status of the robot (position, carried object) after each tick.
  • Add tree visualization.
  • Visualize the scene with the robot’s position (which can be represented as a point) and the positions of the objects. The visualization should be updated as the robot executes its actions. You can use any visualization library, e.g. matplotlib.

Remarks

  • Install the py_trees library using:
pip install py_trees

Examples

  • Define Custom Behaviors
import py_trees

class MoveTo(py_trees.behaviour.Behaviour):
    def __init__(self, name, location):
        super(MoveTo, self).__init__(name)
        self.location = location

    def update(self):
        print(f"Moving to {self.location}")

        return py_trees.common.Status.SUCCESS
  • Create a tree and add behavior
def create_behavior_tree():
    root = py_trees.composites.Sequence("Root", memory=False)
    move_to_pick = MoveTo(name="MoveToPick", location="Pick Location")
    root.add_children([move_to_pick])

    return root
  • Execute the behavior tree
if __name__ == "__main__":
    tree = create_behavior_tree()
    print("Starting behavior tree execution:")
    tree.setup(timeout=15)

    for _ in range(4):
        status = tree.tick_once()
        print(f"Tree status: {status}")

Resources