Difference between revisions of "ViRHaS"

From AIRWiki
Jump to: navigation, search
(ViRHaS App)
Line 21: Line 21:
 
Source code: https://github.com/michele-bertoni/ViRHaS
 
Source code: https://github.com/michele-bertoni/ViRHaS
  
==Requirements==
+
==Structure==
 
ViRHaS is structured into 3 parts:
 
ViRHaS is structured into 3 parts:
  
Line 30: Line 30:
 
- User device: it may be any modern electronical device, for example laptop, smartphone, desktop computer, etc... ; the device receives video streaming and sends controls.
 
- User device: it may be any modern electronical device, for example laptop, smartphone, desktop computer, etc... ; the device receives video streaming and sends controls.
  
==Components==
+
==Software components==
 
All software components may be divided into four parts:
 
All software components may be divided into four parts:
  
Line 84: Line 84:
  
 
Connect page is the one used for playing with the robot: the entire page is filled with 2 canvases, inside which streaming is displayed. To return the main menu and close connections, user must click or tap any part of the screen, then a small arrow button is displayed in the bottom left angle for a few seconds: by clicking that button the game returns to the main menu and all open sockets are closed.
 
Connect page is the one used for playing with the robot: the entire page is filled with 2 canvases, inside which streaming is displayed. To return the main menu and close connections, user must click or tap any part of the screen, then a small arrow button is displayed in the bottom left angle for a few seconds: by clicking that button the game returns to the main menu and all open sockets are closed.
 +
 +
 +
== ViRHaS controller ==
 +
This Qt command line application is not as multiplatform as the application, because it uses some libraries available only on Linux distribution: one of these libraries is v4l2 (Video4Linux2), which is not available, for example, on Windows .
 +
 +
When program starts with no parameters, it reads settings to understand if the Raspberry is the master or the slave. This setting is automatically setted permanently by running once the program with the parameter "-c" for the master and "-s" for the slave.
 +
 +
If Raspberry is slave, the program creates only one server for the video, while if it's master, the program creates one more server to handle controls reception. When a socket is opened between client and server, if it's a video socket, camera starts shooting and ByteArrays containing frames are sent over the socket.
 +
 +
On the control socket, ViRHaS controller receives default commands, then elaborates them and sends them to the Arduino, as described before.

Revision as of 23:32, 7 July 2017

ViRHaS
Image of the project ViRHaS
Short Description: Omnidirectional robot, drivable in virtual reality
Coordinator: AndreaBonarini (andrea.bonarini@polimi.it)
Tutor: AndreaBonarini (andrea.bonarini@polimi.it)
Collaborator:
Students: MicheleBertoni (michele2.bertoni@mail.polimi.it)
Research Area: Robotics
Research Topic: Robot development
Start: 2016/10/20
End: 2016/07/07
Status: Completedwarning.png"Completed" is not in the list of possible values (Active, Closed) for this property.
Level: Bs
Type: Course

ViRHaS is a ominidirectional robot, based on Triskar model, equipped with two Raspberry Pi Cameras. These cameras can be used either to watch video streaming from multiple devices, either to control robot in 3D mode: this mode is available both for smartphone (inside a VRBOX) and for PC plugged to a 3D-ready screen.

Source code: https://github.com/michele-bertoni/ViRHaS

Structure

ViRHaS is structured into 3 parts:

- Raspberry Pis are the hub of the entire robot: they handle both video and control streaming: one raspberry, the one with local address 192.168.1.3 is the master, while the other (192.168.1.4) is a slave device and only handles video transmission;

-Arduino Mega is used to control the motors: it's a slave device, controlled by master Raspberry Pi: Raspberry sends over USB serial to the Arduino a byte vector, which contains all speed components; then Arduino computes PID and control motors over PWM;

- User device: it may be any modern electronical device, for example laptop, smartphone, desktop computer, etc... ; the device receives video streaming and sends controls.

Software components

All software components may be divided into four parts:

- Video capture: performed only by Raspberry Pis, uses v4l2 libraries to get MJPG streaming from cameras; all data is stored in ByteArrays;

- Communication: performed by all the parts of the robot, in particular using WebSockets from Raspberries to user device (and viceversa) and via Usb Serial communication from Raspberry to Arduino Mega;

- Video visualization: obviously, only user device can display video streaming: once received a new ByteArray containing a frame, the device loads the JPG image and displays it in the right position of the screen (user might change settings) using OpenGL and hardware acceleration of the GPU, if present;

- Control handling: each device, except the slave Pi, handle control:

   - user device is directly connected to the controller, which can be any kind supported by user device; the gamepad is handled transparently from the user device, which combines a key to 
     a default command (for example throttle, direction, etc...); this association may be changed by the user; 
   - Master Raspberry receives default commands, and from these calculates strafe, forward and angular components of the speed vector, then simplifies each component to a single byte for  
     a simplier parsing by the Arduino;
   - Arduino receives a 4 bytes string, composed by the 3 values and the string terminator 'n'; after parsing, it computes inverse kinematics and estimates each wheel speed; finally, target 
     speed enters the PID loop and the real speed is sent to each wheel via PWM.


Development

The first part of the project I developed was User Application: written in C++, using Qt libraries, this application is multiplatform, reliable and user-friendly: Qt compiler can generate executable file from the source code for almost every device.

Meanwhile, I developed "controller", which is the software running on Raspberry Pi: this is a simple command line interface which handles both communication and video capture. This software works in any device with a camera and v4l2 libraries installed. This is also written in C++, using Qt libraries.

Then, I developed the physical robot, the hardware component of the project, which is composed by 3 motors, 3 omni-wheels, 2 drivers, 1 Arduino Mega, 2 Raspberry Pi 3.0, 2 Raspberry Pi Cameras (v2.1), 1 router, 1 LiPo 12V battery, 1 LiPo 5V powerbank and all necessary wires.

In the end, I wrote the code for Arduino: I developed library MR001004.h to interface drivers(C++), I adapted library Triskar.h, to maintain compability with drivers(C++) and then I wrote the arduino code for serial communication, data parsing and ViRHaS movement.

ViRHaS App

ViRHaS application is simple but complete; its strength is cross-compatibility, in fact it works fine on almost every operating system:

- Linux (any distribution): perfectly working

- MacOS: perfectly working

- Android: perfectly working

- iOS: theoretically, software should work, but, since this is a closed OS i could not test it

- Windows: unfortunately the application on this OS has two known issues, both caused by Windows itself: the first is the incompability of the library QtGamepad with this OS, the second is a bug concerning window update immediately after stopping OpenGL.

Regarding the app structure, in the main menu, user can choose between some features: the most important ones are Connect and Settings.

Virhas app home.png

Settings page may be used to edit almost every parameter, both of the view and the control; favourite settings may be stored and automatically loaded when application starts. Preview button shows a 5 seconds preview of canvases size and position.

Virhas application settings.png

Connect page is the one used for playing with the robot: the entire page is filled with 2 canvases, inside which streaming is displayed. To return the main menu and close connections, user must click or tap any part of the screen, then a small arrow button is displayed in the bottom left angle for a few seconds: by clicking that button the game returns to the main menu and all open sockets are closed.


ViRHaS controller

This Qt command line application is not as multiplatform as the application, because it uses some libraries available only on Linux distribution: one of these libraries is v4l2 (Video4Linux2), which is not available, for example, on Windows .

When program starts with no parameters, it reads settings to understand if the Raspberry is the master or the slave. This setting is automatically setted permanently by running once the program with the parameter "-c" for the master and "-s" for the slave.

If Raspberry is slave, the program creates only one server for the video, while if it's master, the program creates one more server to handle controls reception. When a socket is opened between client and server, if it's a video socket, camera starts shooting and ByteArrays containing frames are sent over the socket.

On the control socket, ViRHaS controller receives default commands, then elaborates them and sends them to the Arduino, as described before.