Are you here because you have seen the video of the Ev3 Tracked Explorer Mark II and would like to build and drive it? Then, you are definitely reading the right post! Here, I will do my best to describe how to setup your Ev3 Brick to get it ready.
This is a lengthy post, so arm yourself up with patience and let’s get started!
Things to know
As you may well already know, the Lego Mindstorms Ev3 brick has a very nice feature: it comes with a microSD port that you can use to boot the brick with a new firmware without permanently affecting your beloved device. This means that you can always revert to the factory settings by just removing the microSD and then power cycling the Ev3 brick.
There are several firmware projects around to choose from if you don’t want to rely only on the original Lego Mindstorms graphical programming tools.
In this tutorial I will focus on ev3dev which is a Debian Linux-based operating system that runs on several Lego Mindstorms compatible platforms including the Lego Mindstorms Ev3 and Raspberry Pi-powered BrickPi. Several language bindings are available to choose from including Python. In case you’re interested a tutorial about Monobrick, have a look here instead.
Things to have
To follow and complete this tutorial, you need:
- The Lego Mindstorms Ev3 brick.
- microSD or microSDHC card of 2Gb or greater.
- USB hub to connect the WiFI dongle and the webcam. I’ve tried several USB hubs, and sometimes the WiFi dongle or the camera were not properly powered for reasons I’ve not investigated. In the end, I would suggest the Digitus DA70220 Hub 4 Ports, which works pretty well.
- USB webcam. I would suggest Logitech C270 Webcam HD.
- WiFi dongle. As you know the Ev3 Brick does not come with WiFi connection capability, so you need a WiFi dongle to stream the data from the webcam. Actually the Bluetooth connection can also be used as it comes with the Ev3 brick, and it has also the advantage that there is no need for a WiFi router in then middle, but the Bluetooth connection works over a very short range and also the bandwidth is limited. In the end I’ve tried with success the USB WiFi DONGLE AMIKO which has a big antenna very useful for this application.
Things to do
So, the main steps are:
- install the ev3dev firmware on the Ev3 Brick
- download the Rover App on the Ev3 Brick
- install mjpg-streamer
- run the Rover App
Some of the above steps are based on carefully shaped instructions found on the respective sources, so when appropriate you will find the link at the external page where the subject is discussed.
Install the ev3dev firmware on the Ev3 Brick
You can find excellent instructions to install the ev3dev firmware on a microSD card here. Once you’re done, proceed with the next step. (I promise to update this page with self-contained instructions).
Download the Rover App on the Ev3 Brick
All the source code for the Ev3 Tracked Explorer Mark II is on the SmallRobots.it GitHub repository.
Once you’re on GitHub, click on the Clone or download button, then choose Download Zip; the download should start shortly after.
Unzip the package you have just downloaded. It contains three folders:
- Pictures; it just contains some pictures of the EV3TE MII;
- Rover App; it’s the Python App that we will download to the Ev3 Brick in this tutorial;
- Remote App; it’s the Universal Windows Application which can remotely control the rover; I will show you how to compile and use this code in a separate tutorial, but try to compile it with Visual Studio 2017 in the meanwhile.
To download the Rover App on the Ev3 Brick, you can use any SFTP client you prefer. I suggest and actually use FileZilla, but any client that supports SFTP will do. Use the connection parameters as in the picture below:
- Protocol: SFTP – SSH File Transfer Protocol
- Host: use the IP address you can read on the Ev3 Brick display (in my case is 192.168.1.138 but in your case it will be most probably a different ip address; just read it on the Ev3 brick display – see picture on the left)
- Port: leave blank
- Logon Type: Normal
- User: “robot”
- Password: “maker” (this is the default password unless you have changed it)
Once you get connected, you should see a window like the picture below, which shows you on the left the folders on your computer, and on the right the folders on your remote ev3dev Ev3 brick. Copy the Rover App directory in the “/home/robot/” to complete this step (just drag and drop).
Install and configure mjpg-streamer
mjpg-streamer is a command line application that copies JPEG frames from one or more input plugins to multiple output plugins. It can be used to stream JPEG files over an IP-based network from a webcam to various types of viewers such as Chrome, Firefox, Cambozola, VLC, mplayer, and other software capable of receiving MJPG streams.
It was originally written for embedded devices with very limited resources in terms of RAM and CPU. Its predecessor “uvc_streamer” was created because Linux-UVC compatible cameras directly produce JPEG-data, allowing fast and perfomant M-JPEG streams even from an embedded device running OpenWRT. The input module “input_uvc.so” captures such JPG frames from a connected webcam. mjpg-streamer now supports a variety of different input devices.
Ok, to start the installation, just download the mjpg-streamer from this link on GitHub, unzip the package, and copy it on the ev3dev Ev3 brick in your /home directory using FileZilla (or any other SFTP client of your choice) as already shown before.
To install this package, you have to run a bunch of line commands on a ssh remote terminal to the Ev3 brick. First open a terminal on your PC and run the command:
when prompted for the password you should use maker if you have not changed it. When connected you should get to a view similar to this:
Now proceed to update the package lists for any upgrades of packages that need upgrading, as well as of new packages that have just come to the repositories (just be sure to run the commands on the ssh shell and not on your local computer shell ok?); insert root password when prompted.
sudo apt-get update
Then install or update cmake with experimental libjpeg, gcc and g++ with
sudo apt-get install cmake libjpeg8-dev
sudo apt-get install gcc g++
At this point, we have to proceed to compile the mpg-streamer library directly on the ev3dev Ev3 brick. This operation will take some time, but the procedure is almost completely automatic. Run the following commands:
sudo make install
Now it’s time to check that everything is up and running; be sure that the webcam is connected to the brick via the usb hub, and run the following command to run the streamer:
/usr/local/bin/mjpg_streamer -i "input_uvc.so -n -f 10 -q 50" -o "output_http.so -w /usr/local/www"
Next, open a browser and open a page at the following link: https://192.168.1.134:8080 (substitute my ip address with yours) and, voit-là, you should see the following page:
Ok, at this point you have two options:
- Run the above command whenever you wish to launch the mpjg_streamer; in this case jump to the last step of this tutorial;
- Setup the brick to run mjpg_streamer automatically on start-up; in this case, see below.
To set up the ev3dev Ev3 brick to run mjpg_streamer automatically on start-up, create a file called mjpg_streamer.service and put it in the folder /etc/systemd/system , with the following content:
ExecStart=/usr/local/bin/mjpg_streamer -i "input_uvc.so -n -f 10 -q 50" -o "output_http.so -w /usr/local/www"
Just check the correct path on the last line, then reboot and you’re set!
Run the Rover App
To run the Rover App, you have to mark the entry point Python script as executable. You have two options:
- Use command line since you should have the ssh terminal already open.
- Use FileZilla to get the benefit of the graphic user interface.
If you wish to use the command line, run the following command while you are in the Rover App folder
chmod ugo+x launcher.py
This will grant executable permission for all users to the launcher.py file.
If you wish to use FileZilla GUI, once connected to the ev3dev Ev3 brick, right click on launcher.py, and choose File Permission…, then check Execute, for the owner, the group, and the public. See picture below.
Once done, to run the application use file browser directly on the brick to launch the app. See below:
Congratulations! The Rover App is running and the rover is ready to be remotely controlled! Now compile and run the Remote App and enjoy. I’m currently working on a tutorial like this to show how compile and run the Remote App. Stay tuned!