Difference between revisions of "Run WCPS In Docker Container Guide"

From Cyber-Physical Systems Laboratory
Jump to navigationJump to search
Line 33: Line 33:
 
:please refer to: http://www.mathworks.com/help/matlab/matlab_external/changing-default-compiler.html for more details on changing and setting Matlab default compiler.
 
:please refer to: http://www.mathworks.com/help/matlab/matlab_external/changing-default-compiler.html for more details on changing and setting Matlab default compiler.
  
=='''3.    Download the image of WCPS components'''==
+
==Download the image of WCPS components==
 
:The already built WCPS Docker image contains the following components:
 
:The already built WCPS Docker image contains the following components:
 
:'''Operating system:''' Ubuntu 14.04 (distributed from Docker hub)
 
:'''Operating system:''' Ubuntu 14.04 (distributed from Docker hub)
Line 55: Line 55:
 
:*To pull the image from Docker hub use the command:
 
:*To pull the image from Docker hub use the command:
 
:'''docker pull sywxh2012/wcps'''
 
:'''docker pull sywxh2012/wcps'''
 
  
 
=='''4.    Run the Simulink model with Docker container'''==
 
=='''4.    Run the Simulink model with Docker container'''==

Revision as of 20:37, 30 August 2016

The Advantage of Using Docker for WCPS

Docker container efficiently wraps and organizes the code, runtime, system tools, system libraries that enable WCPS to run smoothly. Regardless of operating systems of the host computer, the Docker container will always run the same. This feature enables users of WCPS from all backgrounds to utilize the tool without modifying the configurations and system files in their computers.
For more detailed explanation of Docker, please visit:
https://www.docker.com/what-docker

Materials needed:

1. Docker:

For Linux/Mac OSX 10.9 and below/Windows 8 and below:
Please install Docker toolbox at: https://www.docker.com/products/overview
For Mac OSX 10.10 and above/Windows 10:
Please install a newer version of Docker: https://www.docker.com/products/overview
Refer to the “Getting Started Guide” for a more detailed introduction to Docker and make sure that Docker machine and container are working properly.

2. Matlab r2013a:

For Mac Users:
please refer to entry 9 and 11 of “//link to WCPS installation manual” for installation and trouble shooting guides.
Windows Users:
1. Download the installer and the packages from: http://www.mathworks.com/downloads/web_downloads/select_platform?dl_action=choose_products&tab=f
2. Please refer to http://www.mathworks.com/support/sysreq/files/SystemRequirements-Release2013a_SupportedCompilers.pdf for details on required compiler from running R2013a on Windows. :Typically, Microsoft Windows SDK or Visual Studio would work.
3. After successfully start Matlab user interface, please type “mex -setup” in the command window and choose the compiler you want Matlab to use.
Linux Users:
1. Download and install Matlab from:
http://www.mathworks.com/downloads/web_downloads/select_products?dl_action=choose_products&platform_id=57&release_name=R2013a&tab=f
2. Please refer to http://www.mathworks.com/support/sysreq/files/SystemRequirements-Release2013a_SupportedCompilers.pdf for details on required compiler from running R2013a on 64-bit Linux machine. Recommended compiler would be the GNU gcc/g++ 4.4.x series.
3. From the terminal, edit the file ~/.matlab/R2013b/mexopts.sh, so that CC=’gcc’ is changed to –> CC=’gcc-4.7_ and CCX=’g++’ is changed to –> CCX=’g++-4.7_. Then in Matlab terminal type “mex –setup” and choose compiler to be gcc/g++.
For all users:
please refer to: http://www.mathworks.com/help/matlab/matlab_external/changing-default-compiler.html for more details on changing and setting Matlab default compiler.

Download the image of WCPS components

The already built WCPS Docker image contains the following components:
Operating system: Ubuntu 14.04 (distributed from Docker hub)
GCC compiler: gcc 4.4.7 (used as default), gcc 4.8.4
JDK: java version “1.8.0_91”, Java(TM) SE Runtime Environment (build 1.8.0_91-b14), java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)
Msp430: msp430mcu, msp430-libc, mspdebug, gcc-msp430, gdb-msp430
Nesc: nesc-1.3.4, ncc 1.2.4
TinyOS: TinyOS 2.x
TOSSIM library: micaz TOSSIM library
Python: Python 2.7.6
The /TinyOS-Harry directory contains source code for: TinyOS, nesc, msp430.
The /wcps directory contains source code for: python server.
  • The image has been pushed to Docker hub and is made public. The link to the image is:
https://hub.docker.com/r/sywxh2012/wcps/
  • Search the image in Docker Quickstart Terminal using:
docker search sywxh2012/wcps
  • To pull the image from Docker hub use the command:
docker pull sywxh2012/wcps

4. Run the Simulink model with Docker container

We want to run the Matlab model: Copy_of_CoupledTanks_WCPS_v2_DoubleSD
Download the project folder from: https://github.com/sywxh2012/wcps
1. Run the image sywxh2012/wcps in a Docker container:
In Docker Quickstart terminal use the command:
docker run -it -p 55000:10032 sywxh2012/wcps bash
This binds the 10032 port of the newly created container to 55000 port of the docker-machine that hosts the containers, and all incoming connections to 55000 port of the docker-machine (IP address:192.168.99.100) will be routed to 10032 port of the container. (Note that these two port numbers are fairly random and are used as examples in this case)
2. Type ifconfig in Docker container to know its IP address (in eth0: inet addr), in our case it’s 172.17.0.2
In the docker container, cd to /wcps directory and type command:
vim tossim-event-server-iccps15.py
This opens the python server file, type :177 to go to line 177, type i to enter write mode, and change the ‘localhost’ to ‘container IP’ (in our case it’s ‘172.17.0.2’). The press escape and type :wq to save the file.
Use command: python tossim-event-server-iccps15.py -69
To start the python server in the container. The “-69” indicates the noise level WCPS is simulating.
3. Open tossim-event-client-ss.py in project folder in Matlab, change line 44 to:
server_address = ('192.168.99.100', 55000)
Then save the file, this line creates a socket between Matlab and Docker container.
After this step, run Matlab model and everything should be working.
Successful run in terminal should look like:
Image011.png

Notes for Windows/Linux Users:

Linux:
In the file “ps_aggregation.m” line 10, “str2num” should be abandoned. Instead “str2double” should be used to prevent dimension mismatch error.
Windows:
1. In the file “ps_aggregation.m” line 10, “str2num” should be abandoned. Instead “str2double” should be used to prevent dimension mismatch error.
2. In the file “python.m”, where python function call used in Matlab is defined, change line 63 and 64 to the correct Path and name of the Python “.exe” file one chooses to uses. That file is typically in the “C:\cygwin\bin” folder.