Fix up Image Processing and include figures
[matches/MCTX3420.git] / reports / final / chapters / Design.tex
index 120bec0..6bf4d60 100644 (file)
@@ -155,7 +155,7 @@ Code to set actuator values is located in the \gitref{server}{actuators} subdire
 
 \subsubsection{Relay Controls}
 
-The electrical team employed three relays (model: ) for control over digital devices. The relays are switched using the GPIO outputs of the BeagleBone Black.
+The electrical team employed three relays for control over digital devices. The relays are switched using the GPIO outputs of the BeagleBone Black.
 
 \begin{itemize}
        \item Can select - Chooses which can can be pressurised (0 for strain, 1 for explode)
@@ -168,7 +168,7 @@ The use of a ``can select'' and ``can enable'' means that it is not a software p
 
 \subsubsection{PWM Outputs}
 
-A single PWM output is used to control a pressure regulator (model: ). The electrical team constructed an RC filter circuit which effectively averages the PWM signal to produce an almost constant analogue output. The period of the PWM is $2\text{kHz}$. This actuator has been calibrated, which allows the user to input the pressure value in kPa rather than having to control the PWM duty cycle correctly.
+A single PWM output is used to control a pressure regulator. The electrical team constructed an RC filter circuit which effectively averages the PWM signal to produce an almost constant analogue output. The period of the PWM is $2\text{kHz}$. This actuator has been calibrated, which allows the user to input the pressure value in kPa rather than having to control the PWM duty cycle correctly.
 
 
 \begin{figure}[H]
@@ -188,18 +188,18 @@ Several authentication methods are supported by the server; the method to use ca
   \item {\bf Unix style authentication}
 
 
-  Unix like operating systems store a plain text file (/etc/shadow) of usernames and encrypted passwords. To check a password is valid, it is encrypted and then compared to the stored encrypted password. The actual password is never stored anywhere. The /etc/shadow file must be maintained by shell commands run directly from the BeagleBone. Alternatively a web based system to upload a similar file may be created.
+  Unix like operating systems store a plain text file (/etc/shadow) of usernames and encrypted passwords\cite{shadow}. To check a password is valid, it is encrypted and then compared to the stored encrypted password. The actual password is never stored anywhere. The /etc/shadow file must be maintained by shell commands run directly from the BeagleBone. Alternatively a web based system to upload a similar file may be created.
 
   \item {\bf Lightweight Directory Access Protocol (LDAP)}
 
-  LDAP is a widely used data base for storing user information. A central server is required to maintain the LDAP database; programs running on the same network can query the server for authentication purposes.
+  LDAP\cite{ldap, ldap_man} is a widely used data base for storing user information. A central server is required to maintain the LDAP database; programs running on the same network can query the server for authentication purposes.
 
   The UWA user management system (Pheme) employs an LDAP server for storing user information and passwords. The software has been designed so that it can interface with an LDAP server configured similarly to the server on UWA's network. Unfortunately we were unable to gain permission to query this server. However an alternative server could be setup to provide this authentication mechanism for our system.
 
 
   \item {\bf MySQL Database}
 
-        MySQL is a popular and free database system that is widely used in web applications. The ability to search for a user in a MySQL database and check their encrypted password was added late in the design as an alternative to LDAP. There are several existing online user management systems which interface with a MySQL database, and so it is feasible to employ one of these to maintain a list of users authorised to access the experiment. UserCake is recommended, as it is both minimalistic and open source, so can be modified to suit future requirements. We have already begun integration of the UserCake system into the project, however a great deal of work is still required.
+        MySQL\cite{mysql} is a popular and free database system that is widely used in web applications. The ability to search for a user in a MySQL database and check their encrypted password was added late in the design as an alternative to LDAP. There are several existing online user management systems which interface with a MySQL database, and so it is feasible to employ one of these to maintain a list of users authorised to access the experiment. UserCake\cite{UserCake} is recommended, as it is both minimalistic and open source, so can be modified to suit future requirements. We have already begun integration of the UserCake system into the project, however a great deal of work is still required.
 
 
   MySQL and other databases are vulnerable to many different security issues which we did not have sufficient time to fully explore. Care should be taken to ensure that all these issues are addressed before deploying the system.
@@ -218,7 +218,7 @@ This section describes the methods and processes used to communicate between the
 
 \begin{figure}[H]
        \centering
-       \includegraphics[width=1.1\textwidth]{figures/client_request_flowchart.png}
+       \includegraphics[width=0.8\textwidth]{figures/client_request_flowchart.png}
        \caption{High level flow chart of a client request to server response} 
        \label{client_request_flowchart.png}
 \end{figure}
@@ -256,7 +256,7 @@ From the client side, the server interface is accessed through an Application Pr
 
 \begin{figure}[H]
        \centering
-       \includegraphics[width=1.1\textwidth]{figures/fastcgi-flow-chart.png}
+       \includegraphics[width=0.9\textwidth]{figures/fastcgi-flow-chart.png}
        \caption{Flow chart of a client request being processed (within the server program). Relevant files are \gitref{server}{fastcgi.c} and \gitref{server}{fastcgi.h}.} 
        \label{fastcgi-flow-chart.png}
 \end{figure}
@@ -266,7 +266,7 @@ In the case of the server API designed, requests are formatted as such:
 \url{https://host/api/module?key1=value1&key2=value2...&keyN=valueN} (where \verb/host/ is replaced with the IP address or hostname of the server).
 
 
-The API consists of modules that can accept a certain number of arguments (specified as key-value pairs), depending on what that module (Figure \ref{modules}) does. For example, to query the API about basic information (running state, whether the user is logged in etc), the following query is used:
+The API consists of modules accepting arguments (specified as key-value pairs), depending on what that module (Figure \ref{modules}) does. For example, to query the API about basic information (running state, whether the user is logged in etc), the following query is used:
 
 \url{https://host/api/identify}
 
@@ -285,9 +285,9 @@ Keeping the API format simple also made it easier to write the code that parsed
 
 This request handling code went through a number of iterations before the final solution was reached. Changes were made primarily as the number of modules grew, and as the code was used more. 
 
-One of the greatest changes to request handling was with regards to how parameters were parsed. Given a request of: \url{http://host/api/actuators?name=pregulator\&start_time=0\&end_time=2}, The module handler would receive as the parameters \texttt{name=pregulator\&start_time=0\&end_time=2}. This string had to be split into the key/value pairs to be used, which resulted in the function \funct{FCGI_KeyPair} being made, which was initially sufficient for most cases.
+One of the greatest changes to request handling was with regards to how parameters were parsed. Given a request of: \url{http://host/api/actuators?name=pregulator\&start_time=0\&end_time=2}, The module handler would receive as the parameters \texttt{name=pregulator\&start_time=0\&end_time=2}. This string had to be split into the key/value pairs, so the function \funct{FCGI_KeyPair} being made.
 
-However, as more module handlers were created, and as the number of parameters required increased, \funct{FCGI_KeyPair} became increasingly cumbersome to use. \funct{FCGI_ParseRequest} was created in response, and internally uses \funct{FCGI_KeyPair}, but abstracts request parsing greatly. In essence, it validates the user input, rejecting anything that doesn't match a specified format. If it passes this test, it automatically populates variables with these values. The \funct{IndentifyHandler} module handler in \gitref{server}{fastcgi.c} is a very good example of how this works. 
+With increased usage, this was found to be insufficient. \funct{FCGI_ParseRequest} was created in response, and internally uses \funct{FCGI_KeyPair}, but abstracts request parsing greatly. In essence, it validates the user input, rejecting anything that doesn't match a specified format. If it passes this test, it automatically populates variables with these values. The \funct{IndentifyHandler} module handler in \gitref{server}{fastcgi.c} is a very good example of how this works. 
 
 \begin{figure}[H]
        \centering
@@ -323,7 +323,6 @@ A standard JSON response looks like such:
     "control_state" : "Running",
     "description" : "MCTX3420 Server API (2013)",
     "build_date" : "Oct 24 2013 19:41:04",
-    "clock_getres" : 0.000000001,
     "api_version" : 0,
     "logged_in" : true,
     "user_name" : "_anonymous_noauth"
@@ -392,13 +391,11 @@ Initially, a system known as ``Common Gateway Interface'', or CGI was explored.
 \begin{figure}[H]
        \centering
        \includegraphics[width=0.8\textwidth]{figures/custom_webserver.png}
-       \caption{Block Diagram of a request to a custom webserver} 
+       \caption{Block Diagram of a request to a custom web server} 
        \label{custom_webserver.png}
 \end{figure}
 
-Before FastCGI was found, the plan was to build a custom web server (Figure \ref{custom_webserver.png} that used threading. Both the sensor/actuator control and the web interface would reside in the same process. By having both in the same process, continuous control is possible whilst waiting for web requests to be received.
-
-This would have worked, and in fact operates similarly to the final solution, but it was not without drawbacks. By building a custom web server, more effort would have to be spent just to maintain low-level web functionalities, such as responding appropriately to a client request. Perhaps more importantly, features taken for granted from a standard web server would become increasingly difficult to support with a custom web server. For example, services like TLS encryption and PHP support would be near-impossible, or at least very difficult to add. In other words, it was deemed that this solution would be inflexible and not particularly maintainable into the future.
+Another system considered was to build a custom web server (Figure \ref{custom_webserver.png} that used threading, integrating both the control and web components. This option was primarily discarded because it was inflexible to supporting extended services like PHP and TLS encryption. See \href{https://github.com/szmoore/MCTX3420/issues/6}{Issue 6} on GitHub for more information.
 
 \begin{figure}[H]
        \centering
@@ -419,7 +416,7 @@ In comparison, FastCGI (Figure \ref{fastcgi.png}) can be seen as the ``best of b
        \item Consider using X-Accel-Redirect along with UserCake (Section \ref{Authentication}) to make a finer-grained access control system to information such as the system logs
 \end{enumerate}
 
-\section{Server Configuration}
+\section{BeagleBone Configuration}\label{Configuration}
 
 \subsection{Operating system}
 The Beaglebone has been configured to use the Ubuntu operating system. The original operating system was Angstrom, which was unsuitable because it lacked a number of software packages required. Detailed instructions on how to install this operating system exist on the project wiki\cite{mctx3420_wiki}.
@@ -428,7 +425,7 @@ In particular, Ubuntu 13.04 running Linux kernel 3.8.13-bone28 was used, which i
 
 Specifically, there was much grief over getting the pins to function correctly, especially for PWM output. Lacking any great documentation, much trial and error was spent determining the best configuration. The BeagleBone Black uses what is termed a ``device tree'' \cite{beaglebone3.8, devicetreetutorial} and ``device tree overlays'' to dynamically determine what each pin does. This is because each pin can have more than one function, so a ``device tree overlay'' determines what it does at any one point. However, this also complicates matters, since what pins do essentially have to be loaded at runtime. 
 
-PWM control in particular took many hours to achieve, which was not helped by a lot of conflicting information available online. As a result, the primary tool used to correctly determine proper PWM control was the use of a cathode ray oscilloscope. Quite briefly, it was found that certain actions had to be performed in a very specific order to make PWM control available. There were also specific limitations, such as pairs of pins being coupled to the same time base (period). The wiki goes into more detail on the issues found.
+PWM control in particular took many hours to achieve, which was not helped by a lot of conflicting information available online. As a result, the primary tool used to correctly determine proper PWM control was the use of a cathode ray oscilloscope. Quite briefly, it was found that certain actions had to be performed in a very specific order to make PWM control available. The wiki goes into more detail on the issues found.
 
 Getting the cameras to work on the BeagleBone was another major issue faced. After much testing, it was simply found that the cameras could only work on the latest version of the operating system. On anything else, only low resolution captures of around 352x288 pixels could be achieved.
 
@@ -442,9 +439,7 @@ A number of packages are required to compile the code:
 These packages should be installed with the command \texttt{apt-get install}.
 
 \subsection{Required configurations}
-Many components need to be configured correctly for the server to work. In particular, these configurations relate to the web server, nginx, as well as logging software used, rsyslog. These configurations are automatically installed by a specific script on the git repository.
-
-There is a folder, labelled server-configs. Executing \gitref{server-configs}{install.sh} as root should install all the required configuration files to run the server correctly.
+Many components need to be configured correctly for the server to work. In particular, these configurations relate to the web server, nginx, as well as logging software used, rsyslog. Executing \gitref{server-configs}{install.sh} as root should install all the required configuration files to run the server correctly.
 
 % END Jeremy's section
 
@@ -534,7 +529,7 @@ To increase the accuracy in finding the edge, I considered the Canny Edge theore
        \label{canny_edges_noise.png}
 \end{figure}
 
-After the Sensors Team relayed that they were now attaching something to the can in order to measure the change position, I decided to simply stick with the Canny Edge algorithm and implement something similar to what I had in my previous testing.  The figures in appendix A shows the progression of the image through the algorithm.  Figure 2A shows the original image, whereas 2B shows the blurred (with a BLUR value of 5) gray scale image.  Whereas figure 2C shows the image after going through the Canny Edge algorithm with a low threshold of 35.   Figures 3A and 3B both have the same input image, however different input values.  It can be seen how tweaking the values can remove outliers, as figure 3B is skewed to the right due to the outliers.  From figure 4 it can be seen that despite there being no points in the edge in the top half of the image, the edge has still been accurately determined.  
+After the Sensors Team relayed that they were now attaching something to the can in order to measure the change position, I decided to simply stick with the Canny Edge algorithm and implement something similar to what I had in my previous testing.  The images in Figure \ref{canny_demo} shows the progression of the image through the algorithm.  Figure \ref{canny_demo} A shows the original image, whereas \ref{canny_demo}B shows the blurred (with a BLUR value of 5) gray scale image.  Whereas figure \ref{canny_demo}C shows the image after going through the Canny Edge algorithm with a low threshold of 35.   Figures \ref{canny_demo}D and \ref{canny_demo}E both have the same input image, however different input values.  It can be seen how tweaking the values can remove outliers, as figure \ref{canny_demo}E is skewed to the right due to the outliers.  From figure \ref{canny_demo}F it can be seen that despite there being no points in the edge in the top half of the image, the edge has still been accurately determined.  
 
 The testing done shows that given a rough edge with few outliers an edge can be determined, however there is an obvious degree of inaccuracy the greater the variance of the edge. The best solution to this however does not lie in software.  If an edge was used that was straight even at that magnification with a good contrast then the results would be much more accurate (i.e. the accuracy of the dilatometer is currently more dependent on the object used than the software). 
 
@@ -552,8 +547,6 @@ Earlier in the semester we were informed by the Sensors Team that instead of a d
        \item The algorithm can be improved to try and neglect outliers in the edge image; however this is not as necessary if the original object used gives a sufficiently smooth and straight edge.
 \end{itemize}
 
-% END Callum's section
-
 \subsection{Results}
 
 Figure \ref{image_in_api.png} shows an image obtained from one of two dilatometers used in the system setup with collaboration between all teams. The image is of a white Lego tile attached to the can. This image was successfully streamed using the server software, and results of the dilatometer readings were monitored using the same software. Unfortunately we were unable to maintain a constant value for a stationary can, indicating that the algorithm needs further development. Due to a leak in the can seal we were unable to pressurize the can sufficiently to see a noticeable change in the edge position.
@@ -565,6 +558,25 @@ Figure \ref{image_in_api.png} shows an image obtained from one of two dilatomete
        \label{image_in_api.png}
 \end{figure}
 
+\begin{figure}[H]
+       \centering
+
+       \begin{tabular}{cc}
+               \includegraphics[width=0.4\textwidth]{figures/dilatometer_test.jpg} A &
+               \includegraphics[width=0.4\textwidth]{figures/dilatometer_test.jpg} B  \\
+               \includegraphics[width=0.4\textwidth]{figures/dila_blur7thresh36.png} C &
+               \includegraphics[width=0.4\textwidth]{figures/dila_blur5thresh30.png} D \\
+               \includegraphics[width=0.4\textwidth]{figures/dila_blur9thresh35.png} E &
+               \includegraphics[width=0.4\textwidth]{figures/dila_blur9thresh35_2.png} F
+       \end{tabular}
+       \caption{Canny Edge Algorithm in Action}
+       \label{canny_demo}
+\end{figure}
+
+% END Callum's section
+
+
+
 
 \section{Human Computer Interaction and the Graphical User Interface}
 

UCC git Repository :: git.ucc.asn.au