This notebook will describe how:
Snap! is a "very powerful visual, drag-and-drop programming language. It is an extended reimplementation of Scratch (a project of the Lifelong Kindergarten Group at the MIT Media Lab) that allows you to Build Your Own Blocks". It is an extremely efficient tool to learn how to program for kids or even college students and also a powerful prototyping method for artists.
Note: We assume in this tutorial that you are familiar with the basic of Snap! or Scratch. If it's not the case you can find a lot of documentation online. We especially recommand the very good Snap! reference manual.
Comments, issues, improvements and updates can be sent directly on the dedicated section of the github issue tracker.
Note: for this notebook we will use a simulated poppy humanoid in V-REP (see this v-rep notebook for details on how they can be installed and connected) but you can use any other creature (e.g. a real poppy ergo for instance). Only the configuration of the robot host will change (see details below).
Please refer to the install section if you don't know how to install these libraries or how to connect to your Poppy Creature.
Before being able to control a simulated Poppy Creature with Snap! blocks a few steps are required:
Note: If you want to control a real Poppy Creature this is even simpler. As Poppy Creatures come with an embedded board with everything configured, you only need to connect to their webserver. Assuming that you are working with a Poppy-ErgoJr and that you are on the same network that your creature, you only have to connect to http://poppy-ergojr:8080/snap (see here for details).
from poppy.creatures import PoppyHumanoid poppy = PoppyHumanoid(simulator='vrep', use_snap=True)
Note for advanced users: setting the use_snap arg to True basically creates a webserver which allows Snap! to get/post values from/to a Poppy Creature through pypot REST API. Then we use the http block to connect Snap! with the robot (you can refer to the section The Outside World from Snap! reference manual for more details). You can manually specify the host and port to which the server will be attached using snap_host and snap_port args. Here, we use the default values which bind the server to the localhost. Yet, this will not allow for external connections. You can use snap_host='0.0.0.0' to automatically attach the webserver to the IP of your machine. Hostnames can also be used, for instance Poppy Creatures usually provide an hostname such as host='poppy-humanoid.local'.
Note for advanced user: the run method will run the server forever and thus block the main thread. This is here not a problem as you do not need to execute extra code for this tutorial. If you need to run other python code after, you can run this method inside a thread.
You can create a poppy creature from python with the above code, but you can also use a simple command on your terminal:
poppy-snap --vrep poppy-humanoid
If you want to try other configurations, look at the help of poppy-snap:
Now that we have anything we need to control our Poppy Creature, we just need to run Snap! on a web browser.
We will now detail on you can control your Poppy Creature via the two approaches:
Note that the online one is more straightforward and should thus be privileged except if you do not have an internet connection.
The last step required before actually making your robot moves in Snap! is to import our predefined blocks. Snap! provides a really simple way to do that: you just have to go to this url: http://snap.berkeley.edu/snapsource/snap.html#open:http://127.0.0.1:6969/snap-blocks.xml
Note: if you changed the web server host, you need to change it in here as well. For instance if you use the Poppy Ergo default hostname you need to go to http://snap.berkeley.edu/snapsource/snap.html#open:http://poppy-ergojr.local:6969/snap-blocks.xml instead.
You should now see something like this in your browser (note importing the blocks may take a few seconds):
The Poppy's specific blocks can be found on pypot/server/pypot-snap-blocks.xml directory in the pypot installation folder (its location will depend on your operating system and how you installed it). You can use the explorer/finder to find it.
Alternatively you can directly download it from the github repository. For instance:
Once imported you should see something like:
You can see that our base project comes with a few specific blocks such as:
Those blocks can be used to respectively:
Other blocks are also available. Their behavior should be easily deduced from their name.
You can easily see all blocks relative to poppy in Snap! with the "find blocks" feature. You have to right-click in the left part of Snap! page and select "find blocks":
If you type robot on the search input, you will select all poppy blocks:
To control a motor via a slider you need to:
Then, connect it to a motor:
On the pypot install directory pypot/server/pypot-snap-record-orchestration-demo.xml (its location will depend on your operating system and how you installed it), you can find a project tutorial of how to make orchestration of move record. Alternatively you can directly download it from the github repository:
or getting it from Snap! cloud.
This project will guide you step by step on how to use Snap! to record and play many nested move.