Author: Piotr Szlachcic
We finally did it! Here's the long awaited Scratch integration tutorial for LeoOS. From now on you will be able to program your Rover via a block-based graphical user interface and it's as easy as it looks like ;-)
Scratch is a block-based visual programming language dedicated to education. It's taught and used in schools and other edicational institutions as one of the best ways to begin your programming adventure. It doesn't need you to know anything about software to start and it's easy to edit, yet provides all the basic functionality of the Rover.
For more information about Scratch in general check this link: https://scratch.mit.edu/about
Normally you would use Scratch with an online editor, but for Leo Rover we'll integrate the editor in a different way. We'll build the Scratch editor locally and install a dedicated ROS extension to establish communication between Scratch editor and the Rover ROS layer.
To make the installation process easier, we created a package of necessary dependencies, configuration files, and scripts. You just need to clone or download the repository from GitHub and run the script. With only a few commands everything will be done automatically.Please follow the instruction below.
Open ssh session. It will be necessary to access a remote terminal on Leo Rover.
Establish the Internet connection.
Clone leo_scratch repository from Leo Rover GitHub page.
cd ~/git clone https://github.com/LeoRover/leo_scratch.git
We recommend you clone it to the main directory, but doesn't matter where you decide to put it. If you put it somewhere else, pay attention as some of the next commands may require some changes.
Go into the cloned repository and run the script with root privileges (sudo). The default password to access root is
raspberry. Installation may take up to 10 minutes.
cd ~/leo_scratchsudo bash run.sh
After the installation, it's needed to restart the service that was created. Type the command below in the terminal. More information about the services will come later in this tutorial.
sudo systemctl restart scratch.service
To establish proper communication between Scratch editor and the ROS layer, rosapi node is needed. It provides GUI service calls and allows for getting meta-information related to ROS (like topic lists) and interacting with the parameter server.
Option A (recommended): Upgrade package list
sudo apt updatesudo apt upgrade
or Option B: Add rosapi node initialization to the main launch file
The rosapi node is a part of the rosbridge_server package installed on the Rover by default. You need to add a few commands to the main launch file to enable rosapi node.
/etc/ros/robot.launch and add commands between <launch> and </launch> tags. Try to add it as close to the bottom of the space as possible.
<node name="rosapi" pkg="rosapi" type="rosapi_node"><param name="topics_glob" value="[*]" /><param name="services_glob" value="[*]" /><param name="params_glob" value="[*]" /></node>
Finally, the installation and configuration of the editor are done. To load the interface you need to open you web browser when connected to the Rover AP and type the IP address of the Rover together with the interface port number.
You'll see something like that in your browser.
Click the extension icon in the right bottom corner and choose ROS extension.
Click on the icon to connect with rosbridge. Use the Rover address as the master IP (10.0.0.1 when you are connected directly to the Rover access point).
We created an example Scratch project to help you understand the language. You can simply load the project in your Scratch interface and control the Rover using keyboard arrows.
Download the project file from here (to your PC) and use the 'load' button in the editor.
We created a service called
scratch.service to launch Scratch editor hosting locally on the Rover. By default the service is enabled on every boot. Below you can find some helpful commands to check the servis status and control it.
systemct status scratch.service
sudo systemctl stop scratch.service
sudo systemctl start scratch.service
sudo systemctl enable scratch.service
sudo systemctl disable scratch.service
sudo systemctl restart scratch.service
If you have any issue with the tutorial or the software, please open a thread in the forum or write to me directly