-
Notifications
You must be signed in to change notification settings - Fork 1
10. Tutorial 10
In this tutorial, we will learn how to create a playful library, i.e. create playful code which may be reused across projects. The playful program is the same as tutorial 9, plus a node for displaying position information of all existing schemes (position_logger)
program:
virtual_balls_detection
display_robot
targeting ball: ball_display
targeting ball: ball_interaction, priority of inv_distance | base_score=1.0 ; speed=0.1
stay_put, priority of 1
# position_logger is defined in playful_tutorial_library
position_logger, priority of 1
Code for position logger is located in the playful_tutorial_library repository:
https://github.com/vincentberenz/playful_tutorial_library.git
This library must be cloned in the same directory as playful_tutorial (i.e. <HOME>). Other locations will not work. You may clone it now.
A playful library is a folder with 3 sub-directories: config, play and py. Files and folders in a library work in the exact same ways as the files we studied in this tutorial. Importing a library will makes its code (python and playful) available in the current project.
To import a library in a project, you need:
-
to put it in the same folder as the current project. In this case, playful_tutorial_library should be put in the same folder playful_tutorial was cloned (<HOME>)
-
to import the libary in a imports.txt file in a config folder. In this case, this was done in the config folder of this tutorial (<HOME>/playful_tutorial/tutorials/tutorial10/config/imports.txt) (note: it would have been imported in the config folder at the root (<HOME>/playful_tutorial/config/imports.txt), playful_tutorial_library would have been imported for all tutorials)
Content of imports.txt:
playful_tutorial_library
Good software practices suggest you create as many libraries as possible, as they correspond to code that can be reused across projects.
If you run this tutorial without cloning playful_tutorial_library in the right folder, import will fail (warning message displayed) and an error will be thrown at runtime (about a missing node, position_logger, defined in the library)
If the library is cloned at the correct location, 'playful trail' will display which files from the library are imported
So, to get this tutorial to work:
- clone https://github.com/vincentberenz/playful_tutorial_library.git in <HOME>
- run 'playful trail', and check files from the libraries are included
- run 'playful execute' as for the other tutorials.
Playful has been developed at the Max Planck Institute for Intelligent Systems, Tuebingen, Germany