Software Engineering - ImmersiveSystems/net-robo GitHub Wiki

Introduction

This page will document the engineering behind the software component of the project. This document is primarily concerned with the server platform and the components and communication involved with the server and the Raspberry Pi.

Workflow

Web Platform

The web platform acts as the hub where all information in the system will flow to. It also allow users on the internet to interface the various robots linked to the system. A database is also required to store information. User experience and design are also important factors to consider.

Server Programming Language

The programming language on the server-side of the web platform. Popular programming languages include PHP, Ruby, Python and Node.js. Each programming language offers different advantages and disadvanages.

Server Programming Language Considered

Python

Python is easy to learn and most of the team is already familiar with the language. Python has a popular framework called Django which has excellent documentation and a large community. For a web framework, Django is fairly fast.

Ruby

Ruby is easy to learn as well, but none of the team is familiar with the language. Ruby on Rails is by the far the most popular framework for Ruby and has excellent documentation and a huge community. Lots of gems available which do most of the work with you. Not as fast as Django.

Node.js

Relatively new as a server language. It's basically Javascript. The community is still very young and thus still very splintered. However, the community is rapidly growing. One of the biggest advantages of Node.js is it's speed (it's based on an asynchronous model) and great optimization for a large amount of concurrent connections.

Server Programming Language Chosen - Node.js

We ultimately decided to choose Node.js due to it's speed, simplicity and ability to handle a larger amount of concurrent connections. Sockets are also easier to set up in Node.js which is important as sockets are the primary means of the server communication with the various Raspberry Pis. While Ruby and Python are better for a traditional web application, for a real-time project such as this, Node.js is the best fit.

Node.js Server Frameworks

Node.js by itself isn't really ideal for creating a web application, so we enlist the usage of web frameworks to do much of the work for us when creating a web application such as routing and database connection. As the Node.js community is still young, it's still very splintered, and as a result, there isn't a definite web framework to use such as Django for Python or Rails for Ruby.

Web Frameworks Considered

Express.js

A popular web framework for Node.js but still very simple. Handles some of the more tedious code of creating a web application, but still expects you to create some of the more basic parts.

Sails.js

A comprehensive web framework based on Express and socket.io. Resembles a traditional web application but there only exists a very small community supporting this web framework.

Meteor

A very exciting web framework for Node.js. Has received tons of press and funding and has a growing community. The most interesting part of Meteor is that the HTML is sent on a wire to users so changes are are rendered instantly on the user's end. However, there are concerns with Meteor not being production ready.

MEAN Stack

Is a full stack as opposed to a web framework which it includes more libraries to help with web development. MEAN stands for MongoDB, Express.js, Angular.js and Node.js. The MEAN stack is quite popular but there isn't a real primary developer, as it's up to the user to integrate these four components together separately. One of the models of the MEAN stack is to be lean, which means it is easy to set-up and deploy.

Web Frameworks Chosen - MEAN Stack

We initially decided to try Sails.js as it's a similar to more traditional web frameworks such as Django or Rails. However, we quickly found that the lack of a dedicated community was alarming and disadvantageous. Moreover, there are certain parts in the web framework we found to be quite unflexible such as trying to open a socket connection between the server and a Python socket client. We ultimately decided against Sails.js as it feels like we would eventually end up fighting the framework instead of working alongside it.

We also tried Meteor but ultimately decided against it as we were concerned with it not being production-ready.

The MEAN stack was chosen as it is based on Express.js which is the most mature of the web frameworks. However, compared to Express.js, the MEAN stack provided much more as it has inherent support for Angular.js and MongoDB which will be useful during web development. Furthermore, the MEAN stack is very to setup and deploy. The primary concern of using the MEAN stack will be that we would have to ensure that these four separate modules continue to play well with each other in the future.

Other Technologies for First Prototype

AngularJS

AngularJS is a Javascript front-end framework maintained by Google. It helps in developing the client-side of the server and offers some powerful capabilities.

MongoDB

MongoDB is a NoSQL database which means it stores entries in JSON unlike traditional SQL databases. Storing entries in JSON is not only easier to maintain and migrate but also means that throughout the stack, we are using Javascript instead of being required to learn an assortment of different languages.

Bootstrap

Bootstrap is popular front-end framework for CSS maintained by Twitter and makes the UI design much easier and attractive. However, most Bootstrap sites end up looking similar to each other, so it might be better to roll out our own CSS later.

Streaming

Streaming live video is of central importance in this project. Lag should be minimized so the users have seamless control of the robot. While not necessary, it may also be important to allow multiple users to view the same stream simultaneously.

Streaming Technologies Considered

WebRTC

A low-latency real-time communication technology developed by Google. Still very new and being only supported by Google at the moment, is only usable in Firefox and Chrome. As it's primarily developed for communication, is not ideal for broadcasting.

RTMP

One of the most popular broadcasting formats available at the moment. Is low-latency but requires a separate server to be set up as a dedicated media server. One disadvantage of RTMP is that it's flash based.

RTSP

Another broadcasting format but has been falling out of favour due to RTMP.

HTTP Live Streaming

Streams over HTTP which means we don't need a separate server to stream. As it streams over HTTP, it is HTML5 based. However, it does not support low-latency streaming.

Streaming Technologies Chosen - RTMP

RTMP was chosen as it seems to be the most mature and best fit of all the choices. HTTP live streaming does not support low latency streaming so it cannot be used to reliably controlled the robot. WebRTC is just not mature enough at the moment as only Chrome and Firefox browsers support the technology. RTMP seems to be the most flexible and powerful of the solutions as it can easily support multiple streams and have them broadcasted to hundreds of viewers.

RTMP Media Servers

A separate server is needed for RTMP streaming. There are a number of servers which are available

RTMP Media Servers Considered

Wowza

The most popular RTMP media server with active support and tons of features. Is the server offered by AWS as well. However, this is a commercial product.

Red5

Free RTMP server that supports Windows but is overly complicated.

Nginx RTMP Server

Free RTMP server that does not have support for Windows system. Is easy to use and setup.

RTMP Media Servers Chosen - Nginx RTMP Server

Nginx RTMP server is a free solution which is ideal for prototyping. It was also relatively to set up and get running. Only disadvantage is that it requires a linux system to run the server. Thus, we used a netbook to act as the server as it doesn't require too much resources to run.

Server and Robot Communication

The communication between the server and the Robots is done via the server and the microprocessor (Raspberry Pi/Beaglebone Black) of the robot. We run the server as a socket server and have the Raspberry Pi open a socket connection to the server with Python. Once this socket connection is opened, we may have the server and Raspberry Pi communicate in real-time.

Media Encoding on the Raspberry Pi

To stream to the RTMP server, the format of the stream should be in FLV.

Encoders Considered

FFmpeg

Popular encoder but the binaries are not included in the repo for the Pi which means we will have to compile it ourselves. Takes about 6 hours to compile on the Pi without including add-ons.

Libav

A fork of the FFmpeg library. Binaries are included in the repo for the Pi so we don't need to compile ourselves.

Gstreamer

Popular encoding and streaming tool for the Pi, but is rather complicated to set up.

Encoders Chosen - Libav

Gstreamer was too complicated to set up and there's not much support for it compared to FFmpeg or libav. Libav and FFmpeg are basically the same so libav was chosen to save compilation troubles.