2. Installation Instructions

2.1. Raspbian Image

This tutorial will teach your how to set up a Rover-specific Raspbian image from scratch and the basic workflow to run the Roverapp applications.

2.1.1. Requirements

The following are the build-time dependencies required for the Roverapp:

  • build-essential

  • cmake

  • git-core

  • python-pip Python package installer

  • Python 2.7

  • gcc

The following are the run-time dependencies used for the Roverapp:

  • Raspbian or similar distro that uses the Raspberry Pi metadata (meta-raspberrypi)

  • Access Point setup (with IP 192.168.168.1)

  • Python 2.7

  • psutil Python module

  • wiringPi library

  • raspicam-0.1.2 or raspicam-0.1.3 library

  • OpenCV 3.2.0 library

  • Json-Cpp library

  • bluetooth-dev, bluez, pi-bluetooth libraries

  • bcm2835 library

  • (modified) Adafruit_GFX and Adafruit_SSD1306 libraries

  • paho.mqtt.c libraries

2.1.2. Preparing the Raspbian Image

First, you need to download a fresh Raspbian Stretch image (desktop and recommended software) from here. Then you have to write the image to your SD card, for example via Etcher. Once you wrote successfully your Raspbian image on your SD card, insert it into the Raspberry Pi.

2.1.2.1. Configuring I2C, SSH and SPI

After your fresh installation you will need to configure the Raspberry Pi in order to run rover-app applications.

Note

Do NOT update your Raspbian image as this will take a lot of time.

2.1.2.1.1. Enable I2C
  • Open a terminal window

  • Run sudo raspi-config

  • Use the down arrow to select 5 Interfacing Options

  • Arrow down to P2 i2c

  • Select yes when it asks you to enable SSH

  • Use the right arrow to select the <Finish> button.

  • Select yes when it asks to reboot.

If everything went well, the Pi should respond with /dev/i2c-1 when you run ls /dev/*i2c*

2.1.2.1.2. Enable SSH
  • Open a terminal window

  • Run raspi-config

  • Use the down arrow to select 5 Interfacing Options

  • Arrow down to P2 ssh

  • Select yes when it asks you to enable SSH

  • Use the right arrow to select the <Finish> button.

  • Select yes when it asks to reboot.

If everything went well, you should be able to connect to the RPI3 through ssh from other computer.

2.1.2.1.3. Enable SPI
  • Open a terminal window

  • Run raspi-config

  • Use the down arrow to select 5 Interfacing Options

  • Arrow down to P4 spi

  • Select yes when it asks you to enable SPI

  • Use the right arrow to select the <Finish> button

  • Reboot your RPI3

2.1.3. Manual Installation Instructions

Note

We are working on providing a Docker image to automate the installation process

2.1.3.1. Installing Roverapp dependencies

2.1.3.1.1. Install CMake
1
$ sudo apt-get install cmake
2.1.3.1.2. Install wiring pi
1
2
3
4
5
  $ cd ~/  && \
     git clone git://git.drogon.net/wiringPi && \
     cd wiringPi/ &&  \
     git pull origin && \
     ./build

More installation information for wiringPi are available here.

2.1.3.1.3. Install jsoncpp
1
2
$ sudo apt-get -y install libjsoncpp-dev && \
   sudo ln -s /usr/include/jsoncpp/json/ /usr/include/json
2.1.3.1.4. Install Openssl
1
$ sudo apt-get -y install libssl-dev
2.1.3.1.5. Install paho.mqtt.c

To install paho.mqtt.c libraries for MQTT-based cloud communication, execute the following commands:

1
2
3
4
5
$ cd ~/ && \
   git clone https://github.com/eclipse/paho.mqtt.c.git && \
   cd paho.mqtt.c/ && \
   make && \
   sudo make install

If this makes problems, just try the following:

1
$ pip install paho-mqtt
2.1.3.1.6. Install i2c tools
2.1.3.1.7. Install psutil

psutil is a performance tool library that is written in Python and that is able to provide information about GNU/Linux-based systems.

1
$ sudo pip install psutil
2.1.3.1.8. Install bluetooth
1
2
$ sudo apt-get install -y bluez \
   libbluetooth-dev
2.1.3.1.9. Install raspicam
1
2
3
4
5
6
7
8
$ cd ~/ && \
   git clone https://github.com/6by9/raspicam-0.1.3.git && \
   cd raspicam-0.1.3 && \
   mkdir -p build && \
   cd build && \
   cmake .. &&\
   make &&\
   sudo make install

Note

As an alternative you can use the following git repository: raspicam 0.1.2.

Warning

If compilation using make command fails, one should make sure libmmal.so and libmmal_core.so is located in /opt/vc/lib. To install these libraries, one can do a Raspberry Pi firmware update: sudo rpi-update.

2.1.3.1.10. Install OpenCV

This installation follows the steps described here

Dependencies

1
2
3
4
5
$ sudo apt-get install -y libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev
 $ sudo apt-get install -y libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
 $ sudo apt-get install -y libxvidcore-dev libx264-dev
 $ sudo apt-get install -y libgtk2.0-dev
 $ sudo apt-get install libatlas-base-dev gfortran

Getting OpenCV

1
2
3
 $ cd ~
  $ wget -O opencv.zip https://github.com/Itseez/opencv/archive/3.4.1.zip
  $ unzip opencv.zip

Getting opencv contrib

1
2
  $ wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.4.1.zip
   $ unzip opencv_contrib.zip

Compiling OpenCV

1
2
3
4
5
6
7
8
9
 $ cd ~/opencv-3.4.1/
   $ mkdir build
   $ cd build
   $ cmake -D CMAKE_BUILD_TYPE=RELEASE \
         -D CMAKE_INSTALL_PREFIX=/usr/local \
         -D INSTALL_C_EXAMPLES=ON \
         -D INSTALL_PYTHON_EXAMPLES=ON \
         -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.4.1/modules \
         -D BUILD_EXAMPLES=ON ..

Check if you have any errors. Otherwise we can compile OpenCV. This step will take some hours from 2 up to 5-6, depending on the size of your SD card and the speed.

1
$ make -j4

Once you are done, let’s install OpenCV:

1
2
 $ sudo make install
  $ sudo ldconfig

2.1.3.2. Installing Roverapp

After the prerequisite are fulfilled, the Roverapp can be installed. Roverapp’s installation process is simplified by using CMake tool, a semi-automated Makefile generator for GCC compiler. Therefore, the Roverapp contains a CMakeLists.txt file.

Note

When adding and linking new libraries, objects, source files, or headers, the CMake file must be tailored accordingly.

2.1.3.2.1. Compiling
1
2
3
4
$ cd ~
 $ git clone https://github.com/phil-hei/rover-app.git
 $ cd rover-app/
 $ ./make_roverapp.sh
2.1.3.2.2. Configuring Cloud connection

In order to connect to the Hono or any other MQTT-supporting message gateway, the Rover needs to be configured with the according details such as Broker address and credentials. A template configuration file, called rover.conf.sample, is given in the directory samples.

1
$ cd samples/

Modify that file with the required values, namely the following attributes:

1
2
3
4
5
6
7
8
9
# Configuration file for roverapp.
 ROVER_IDENTITY_C=INSERT
 MQTT_BROKER_C=INSERT
 MQTT_BROKER_PORT_C=1883
 ROVER_MQTT_QOS_C=0
 MQTT_USERNAME_C=INSERT
 MQTT_PASSWORD_C=INSERT
 USE_GROOVE_SENSOR_C=0
 USE_REDIRECTED_TOPICS_C=1

Then you need to copy the file to right location:

1
$ sudo cp rover.conf.sample /etc/rover.conf

2.1.4. Running Roverapp

The Roverapp is located in the build/bin directory along with other scripts for testing Rover’s functionalities. When started, the Roverapp connects to the Cloud and continously sends telemetry data as well as listen for incoming command messages.

1
2
$ cd build/bin
 $ sudo ./roverapp

Note

If the installation process complains about not being able to find FindOpenCV.cmake or OpenCVConfig.cmake, or any .cmake file. For that matter, the file must be searched and exported to the environment with commands as following:

sudo find / -name *OpenCVConfig.cmake*
cd build
sudo OpenCV_DIR=<path/to/OpenCVConfig.cmake> cmake ..
make
sudo make install

Same goes with raspicam:

sudo find / -name *raspicamConfig.cmake*
cd build
sudo OpenCV_DIR=<path/to/raspicamConfig.cmake> cmake ..
make
sudo make install

2.2. Marker Detection

This shows how to calibrate the marker detection for the Rover based on OpenCV

2.2.1. Calibration of the picam in raspbian

  • Go to /home/pi/opencv_contrib-3.4.1/modules/aruco/samples and create a Charuco board

1
2
$ g++ $(pkg-config --libs --cflags opencv) -o create create_board_charuco.cpp
 $ ./create -d=10 -h=10 --ml=100 --sl=150 -w=7 --si=true image.jpg

More information about create via $ ./create -h

  • Print the generated image and put it on some hard surface

  • Measure with a ruler the dimensions of the black squares and markers. We will need it as an input when calibrating the camera.

  • To calibrate the camera, we need a file with detector parameters, called detector_params.yaml. This file is usually in the same folder as the other source files given by openCV contributions.

  • Compile and run the calibration program:

1
2
$ g++ $(pkg-config --libs --cflags opencv) -o calibrate calibrate_camera_charuco.cpp
$ ./calibrate -d=10 --dp=detector_params.yml -h=10 --ml=0.018 --sl=0.027 -w=7 --sc=true calibration.txt

Note

More information about create via $ ./calibrate -h

2.3. Roverweb Installation

2.3.1. Requirements

The following are the build-time dependencies required for the roverweb:

  • git-core

The following are the run-time used for the roverweb:

  • Raspbian or similar distro that uses the Raspberry Pi metadata (meta-raspberrypi)

  • Access Point setup (with IP 192.168.168.1)

  • node.js with version 8.x or higher

  • node.js modules: net, connect, server-static, http, socket.io, express, path, mqtt

  • mjpg-streamer-experimental

  • curl

2.3.2. Manual Installation Instructions

2.3.2.1. Installing Roverweb dependencies

2.3.2.1.1. Installing curl
1
sudo apt-get install curl
2.3.2.1.2. Installing node.js and its required modules

To serve web-pages and handle communications, node.js is an important dependency for Roverweb. The following commands can be used to download and install node.js:

1
2
3
$ sudo apt-get update
 $ curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
 $ sudo apt install nodejs

Check if node.js is successfully installed:

1
$ node -v

There are additional node.js modules which are required for roverweb. Those modules must be installed by running the following:

1
$ sudo npm install net connect serve-static http socket.io express path mqtt

Warning

In case of problems while running roverweb, do this step after navigation to project directory.

2.3.2.1.3. Installing mjpg-streamer-experimental

One particular mjpg-streamer version provides streaming with Raspberry Pi. In order to install the module, execute the following commands:

1
2
3
4
5
6
7
8
$ sudo apt-get install cmake libjpeg8-dev
 $ git clone https://github.com/jacksonliam/mjpg-streamer.git
 $ cd mjpg-streamer-experimental
 $ mkdir build
 $ cd build
 $ cmake ..
 $ make
 $ sudo make install

2.3.2.2. Installing Roverweb

2.3.2.2.1. Downloading (Fetching) Roverweb

After roverweb is installed, there is no need to install it to any static location. You can continue by running the server: roverweb Getting started