In this chapter, an explanation of the experiments conducted during this dissertation in order to evaluate the estimation of verticality and the stabilization of the \gls{rtu} (humanoid head) will be presented, along with their respective results.

\section{Using \texttt{rosbag} and \texttt{roslaunch}}

In each experiment, data was recorded with a frequency of 100 Hz into a \texttt{.bag} file using the \texttt{rosbag} package \cite{noauthor_rosbag_nodate} and then converted into a .csv file using a python executable named \texttt{bag2csv.py} \cite{speal_rostools:_2014}.

\begin{sloppypar}
	In order to run these experiments in a more controlled fashion, two \texttt{.launch} files were created. These use the \texttt{roslaunch} tool \cite{noauthor_roslaunch_nodate} to launch the \gls{ros} nodes used in each experiment, as well as a \texttt{rosbag} node, which subscribes to all topics and records the data into \texttt{.bag} files. These files are named \texttt{chessboard\_rosbag.launch} and \texttt{chessboard\_v2\_rosbag.launch} and can be found on the \texttt{launch} folder of the \texttt{head\_stabilization} package.
\end{sloppypar}

\section{Experiments with chessboard mounted on the manipulator arm}
In this section, the experiments performed with the chessboard mounted on the manipulator arm will be described. After this description, the experiment results will be analyzed through the use of descriptive statistics (e.g. averages, standard deviations), plots and summary tables. Any unreasonable spikes in the servomotor position line of these plots is due to a malfunction of the servomotors when trying to read their current position and was not an actual position that the servo passed through.


This process of experiment description and subsequent result analysis will be repeated for each different experiment.
\newpage
\subsection{Line tracking evaluation}
\subsubsection{Experiment description}                         

The first experiment was one that could evaluate the robustness of the line tracking method and that could also verify its viability when tracking objects travelling/rotating at high speeds. In these experiments, the chessboard had to be mounted on the manipulator and, to do so, more mechanical parts had to be designed and built. The drawings of these parts are in Appendix A (Chessboard connection to manipulator).

A \gls{tp} program named \texttt{JS\_ROLL} containing movement instructions for the FANUC robotic manipulator was created (Fig. \ref{fig:JSROLL}) in order to perform experiments where the roll angle would vary. These movements had to be able to demonstrate the aforementioned capabilities of the tracking method and are described next.

\begin{figure}[H]
	\centering
	\includegraphics[width=\textwidth]{./Imagens/JS_ROLL.jpg}
	\caption{The \texttt{JS\_ROLL} TP program.}
	\label{fig:JSROLL}
\end{figure}

The first line of the program commands the manipulator with the chessboard mounted on it to align its end-effector axis with the camera's optical axis, making the chessboard look like it is facing the camera and in an horizontal position (Fig. \ref{fig:chess_in_manip}). The next line then applies a rotation to the sixth joint of the manipulator (See Fig. \ref{fig:robotjoints}), so that a 45\textdegree\space clockwise rotation is observed. The third line then applies a 90\textdegree\space rotation on the same joint but in the opposite direction, so that the chessboard passes its initial position and rotates 45\textdegree\space counterclockwise. Finally, the manipulator is sent to its initial position and stops its movement.

\begin{figure}[H]
	\centering
	\includegraphics[width=0.7\textwidth]{./Imagens/chess_in_manip.png}
	\caption{The initial position of the chessboard.}
	\label{fig:chess_in_manip}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=.4\textwidth]{./Imagens/tripod.jpg}
	\caption{The RTU mounted in a tripod during experiments.}
	\label{fig:tripod}
\end{figure}

Whilst the manipulator is moving the chessboard, the \gls{rtu} will be mounted on a tripod two meters in front of it (Fig. \ref{fig:tripod}). The drawings of the mechanical parts designed to mount the \gls{rtu} on the tripod are in Appendix A (\gls{rtu} connection to tripod). No stabilization will occur yet, since the purpose of this experiment is to first verify if this is a viable method to track the chessboard. The range of motion applied to the chessboard also attempts to simulate the variation in the roll angle that the camera would observe when a humanoid robot is falling to its side. Several maximum speeds were applied to the manipulator's movements to test the limits of the line tracking method.

In total, 30 trials were made, divided equally between three different angular speed values. These values are expressed relative to the maximum joint velocity achievable by the manipulator and are the following: 5\% (0.63 rad/s), 15\% (1.88 rad/s) and 30\% (3.77 rad/s).

\subsubsection{Result analysis}

To better demonstrate the results of this experiment, the plots of example trials run at each of the different manipulator speeds are shown in figures \ref{fig:ltev_5}\hspace{0.2mm},\space\ref{fig:ltev_15} and \ref{fig:ltev_30} and a summary of these results is present in table \ref{tab:lte}. The error in these trials was considered to be the difference between the measured angle and the robot's joint position. The descriptive statistics that were gathered in these trials are the mean of the absolute value of the error ($\overline{E}$), the maximum error ($E_{max}$) and the standard deviation ($\sigma$) calculated using the population formula. 

\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{./Imagens/tracking evaluation/roll_5.PNG}
	\caption{A plot of a trial run to evaluate line tracking by varying the roll angle. 5\% manipulator speed used. $\overline{E}=2.14$\textdegree, $E_{max}=5.52$\textdegree\space and $\sigma=1.32$\textdegree.}
	\label{fig:ltev_5}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{./Imagens/tracking evaluation/roll_15.PNG}
	\caption{A plot of a trial run to evaluate line tracking by varying the roll angle. 15\% manipulator speed used. $\overline{E}=7.39$\textdegree, $E_{max}=14.11$\textdegree\space and $\sigma=4.34$\textdegree.}
	\label{fig:ltev_15}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{./Imagens/tracking evaluation/roll_30.PNG}
	\caption{A plot of a trial run to evaluate line tracking by varying the roll angle. 30\% manipulator speed used. $\overline{E}=11.78$\textdegree, $E_{max}=36.35$\textdegree\space and $\sigma=10.34$\textdegree.}
	\label{fig:ltev_30}
\end{figure}

\begin{table}[H]
	\centering
\caption{Line tracking evaluation results.}
	\label{tab:lte}
	\begin{tabular}{lccc}
		\toprule \textbf{Descriptive statistics} & &\textbf{Manipulator speed}& \\
		& 5\% & 15\% & 30\% \\ \midrule
		$\overline{E}$  & 2.14\textdegree & 7.39\textdegree & 11.78\textdegree \\
		$E_{max}$ & 5.52\textdegree & 14.11\textdegree & 36.35\textdegree\\
		$\sigma$ & 1.32\textdegree & 4.34\textdegree & 10.34\textdegree\\ \bottomrule
	\end{tabular}
\end{table}


By analyzing the data from the trials run at 5\% manipulator speed, it is possible to conclude that the line tracking method works great at low angular speeds.
When using greater manipulator speeds, however,  the error starts to become larger, as can be seen in the trials run at 15\% manipulator speed.

The fastest speed used in these trials was 30\% of the manipulator's max speed. The results got even worse, indicating that the line tracking is indeed affected greatly by the speed of objects being tracked.

Overall, the line tracking method performed well since an angular speed of 3.77 rad/s (30\% manipulator speed) is faster than what is thought to be needed for this work. A humanoid robot would never fall to its side that quickly unless if being pushed very hard. As such, it was assumed that a manipulator speed of 15\% should be used for the rest of the experiments.

With a quick glance at each of the different plots we can also see that there is a ``shift to the right'' in the joint position line which increases because the delay between the chessboard moving and the tracking algorithm performing its calculations becomes more apparent. This delay is caused by the low frame rate of the camera mounted in the \gls{rtu}, and is the main reason for the line tracking becoming worse at high angular speeds.


\subsection{Proportional control of RTU}\label{sec:prop_eval}
\subsubsection{Experiment description}
After being able to estimate verticality by using the line tracking method, an experiment whose purpose was to evaluate the quality of the control algorithm with just a proportional component (Sec. \ref{sec:motor_control}) was designed. It is very similar to the line tracking evaluation experiment, with the only difference being that the servomotor responsible for the roll angle in the \gls{rtu} is now being actuated to ``follow'' the chessboard's movements.

To verify if the distance from the \gls{rtu} to the chessboard had any influence in the results of the control algorithm, the tests were also repeated with a one meter distance between them.

In total, 30 trials were made, 15 of them with a two meter distance and the other 15 with a one meter distance. These 15 trials were divided as follows: five trials for a manipulator speed of 5\% (0.63 rad/s) and a servomotor speed of 10/255 (actual physical value depends on servomotor load and was not calculated/measured); five trials for a manipulator speed of 15\% (1.88 rad/s) and a servomotor speed of 10/255; and five trials for a manipulator speed of 15\% (3.77 rad/s) and a servomotor speed of 32/255.

\subsubsection{Result analysis}

To better demonstrate the results of this experiment, the plots of example trials run at a 2 meter distance between \gls{rtu} and chessboard are shown in figures \ref{fig:lt_5_10}\hspace{0.2mm},\space\ref{fig:lt_15_10} and \ref{fig:lt_15_32}. Since the plots from trials run at a 1 meter distance are very similar, these will not be shown. A summary of these results is present in table \ref{tab:pce}. This time, the error in these trials was considered to be the difference between the servomotor position and the robot's joint position.

\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{./Imagens/motor control/chess_on_manip/line tracking/2 meters/roll_5_10.PNG}
	\caption{A plot of a trial run to evaluate proportional control using line tracking by varying the roll angle. 5\% manipulator speed and 10/255 servo speed. 2 meters distance. $\overline{E}=3.21$\textdegree, $E_{max}=9.90$\textdegree\space and $\sigma=2.49$\textdegree.}
	\label{fig:lt_5_10}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{./Imagens/motor control/chess_on_manip/line tracking/2 meters/roll_15_10.PNG}
	\caption{A plot of a trial run to evaluate proportional control using line tracking by varying the roll angle. 15\% manipulator speed and 10/255 servo speed. 2 meters distance. $\overline{E}=22.83$\textdegree, $E_{max}=54.47$\textdegree\space and $\sigma=17.42$\textdegree.}
	\label{fig:lt_15_10}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{./Imagens/motor control/chess_on_manip/line tracking/2 meters/roll_15_32.PNG}
	\caption{A plot of a trial run to evaluate proportional control using line tracking by varying the roll angle. 15\% manipulator speed and 32/255 servo speed. 2 meters distance. $\overline{E}=10.73$\textdegree, $E_{max}=28.96$\textdegree\space and $\sigma=8.09$\textdegree.}
	\label{fig:lt_15_32}
\end{figure}

\begin{table}[H]
	\centering
	\caption{Proportional control of RTU results.}
	\label{tab:pce}
	\begin{tabularx}{\textwidth}{llYYY}
		\toprule &\textbf{Descriptive statistics} & \multicolumn{3}{c}{\textbf{Manipulator speed--Servo speed}} \\
		&					& 5\%--10 & 15\%--10 & 15\%--32 \\ \midrule
		&$\overline{E}$  & 3.45\textdegree & 24.58\textdegree & 13.83\textdegree \\
		\textbf{1 meter}	&$E_{max}$ & 9.80\textdegree & 59.42\textdegree & 36.68\textdegree\\
		&$\sigma$ & 2.29\textdegree & 19.50\textdegree & 9.56\textdegree\\ \midrule
		
		&$\overline{E}$  & 3.21\textdegree & 22.83\textdegree & 10.73\textdegree \\
		\textbf{2 meters}	&$E_{max}$ & 9.90\textdegree & 54.47\textdegree & 28.96\textdegree\\
		&$\sigma$ & 2.49\textdegree & 17.42\textdegree & 8.09\textdegree\\ \bottomrule
	\end{tabularx}
\end{table}

From the trials run at 5\% manipulator speed and 10/255 servomotor speed, it is possible to conclude that results were as expected when running at low angular speeds. When using a manipulator speed of 15\%, whilst maintaining the servo speed at 10/255, the error increased dramatically, as was predicted, because the \gls{rtu} could not keep up with the chessboard's movement because of its low motor speed. A servo speed of 32/255 was then used with the same manipulator speed to try and diminish this error. This specific value was used because as can be seen in Fig. \ref{fig:lt_15_32}, a servo speed this high begins to introduce instability to the system.

By analyzing table \ref{tab:pce}, it is also possible to conclude that there is not much difference between the results of experiments made at 1 meter distance and 2 meter distance. However, since 2 meter results were slightly better, this was the distance used for the remaining experiments.

After these trials, it was possible to conclude that a better alternative had to be found when it comes to the control algorithm used, and so work was done in order to implement a \gls{pd} control algorithm. 

%\begin{figure}[H]
%	\centering
%	\includegraphics[width=0.9\textwidth]{./Imagens/motor control/chess_on_manip/line tracking/1 meter/roll_5_10.PNG}
%	\caption{A plot of a trial run to evaluate proportional control using line tracking by varying the roll angle. 5\% manipulator speed and 10/255 servo speed. 1 meter distance. $\overline{E}=3.45$\textdegree, $E_{max}=9.80$\textdegree\space and $\sigma=2.29$\textdegree.}
%	\label{fig:lt1m_5_10}
%\end{figure}
%
%\begin{figure}[H]
%	\centering
%	\includegraphics[width=0.9\textwidth]{./Imagens/motor control/chess_on_manip/line tracking/1 meter/roll_15_10.PNG}
%	\caption{A plot of a trial run to evaluate proportional control using line tracking by varying the roll angle. 15\% manipulator speed and 10/255 servo speed. 1 meter distance. $\overline{E}=24.58$\textdegree, $E_{max}=59.42$\textdegree\space and $\sigma=19.50$\textdegree.}
%	\label{fig:lt1m_15_10}
%\end{figure}
%
%\begin{figure}[H]
%	\centering
%	\includegraphics[width=0.9\textwidth]{./Imagens/motor control/chess_on_manip/line tracking/1 meter/roll_15_32.PNG}
%	\caption{A plot of a trial run to evaluate proportional control using line tracking by varying the roll angle. 15\% manipulator speed and 32/255 servo speed. 1 meter distance. $\overline{E}=13.83$\textdegree, $E_{max}=36.68$\textdegree\space and $\sigma=9.56$\textdegree.}
%	\label{fig:lt1m_15_32}
%\end{figure}

\subsection{PD control of RTU}\label{sec:pd_eval}
\subsubsection{Experiment description}

After testing the limits of the proportional control algorithm, the \gls{pd} control algorithm (Sec. \ref{sec:motor_control}) was also evaluated. For all experiments evaluating \gls{pd} control, a servomotor speed of 255 (maximum speed) was used on roll angle experiments and the distance between \gls{rtu} and chessboard was always two meters. For experiments where the roll angle was being tested, the manipulator maximum angular velocity used was 15\% (108\textdegree/s) and for experiments where the tilt angle was being tested, a velocity of 5\% (20\textdegree/s) was used.

Trials were made using both of the tracking methods described. To show the progressive tuning of the \gls{pd} control's parameters when used in conjunction with the line tracking method, 15 trials were made with a manipulator speed of 15\% (108\textdegree/s). Five trials were run with these parameters: $K_p=0.3, K_d=0$; five with $K_p=0.7, K_d=0.15$; and five with $K_p=0.8,K_d=0.15$. The same \gls{tp} program (\texttt{JS\_ROLL}) was used.

To better visualize the software architecture used during the trials with the line tracking method to stabilize the \gls{rtu}, a diagram (Fig. \ref{fig:rqt_graph1}) containing the relevant \gls{ros} nodes and topics was created using the \texttt{rqt\_graph} tool \cite{noauthor_rqt_graph_nodate}.

\begin{figure}[H]
	\centering
	\includegraphics[width=\textwidth]{./Imagens/rqtgraph1.png}
	\caption{An overview of the ROS nodes and topics running during experiments on RTU stabilization using the line tracking method.}
	\label{fig:rqt_graph1}
\end{figure}

To show the progressive tuning of the \gls{pd} control's parameters when used in conjunction with the pose estimation method, 15 trials were run when altering the chessboard's roll angle and 15 more when altering the chessboard's tilt angle. From the roll angle experiments, five trials were run with $K_p=0.2, K_d=0$; five with $K_p=0.5, K_d=0.4$; and five with $K_p=0.7, K_d=0.4$.

To perform experiments which test the control on the tilt angle, a second \gls{tp} program was created named \texttt{JS\_TILT} (Fig. \ref{fig:JSTILT}).

\begin{figure}[H]
	\centering
	\includegraphics[width=\textwidth]{./Imagens/JS_TILT.jpg}
	\caption{The \texttt{JS\_TILT} TP program.}
	\label{fig:JSTILT}
\end{figure}

The first line of the program sends the manipulator to the same initial position as in the other experiments. The second line applies a rotation to the manipulator's fifth joint, with a value of 20\textdegree, making the chessboard tilt upwards. On the third line of the program, a rotation of 40\textdegree\space is applied to the same joint, but in the opposite direction, making the chessboard go to its initial position and then tilt 20\textdegree\space downwards. Finally the manipulator returns to its initial position and stops its movement.

The servomotor speed used on the tilt experiments was variable (Sec. \ref{sec:motor_control}). Five trials were run with $K_p=0.01, K_d=0$; five with $K_p=0.1, K_d=0.1$; and five with $K_p=0.12, K_d=0.1$.

The software architecture used during the trials which used the pose estimation method to stabilize the \gls{rtu} can be seen in Fig. \ref{fig:rqt_graph2}.

\begin{figure}[H]
	\centering
	\includegraphics[width=\textwidth]{./Imagens/rqtgraph2.png}
	\caption{An overview of the ROS nodes and topics running during experiments on RTU stabilization using the pose estimation method.}
	\label{fig:rqt_graph2}
\end{figure}

\subsubsection{Result analysis}

To better demonstrate the results of this experiment, the plots of example trials run with the line tracking method are shown in figures \ref{fig:ltPID_kp_0.3}\hspace{0.2mm},\space\ref{fig:ltPID_kp_0.7_kd_0.15} and \ref{fig:ltPID_kp_0.8_kd_0.15} and a summary of these results is present in table \ref{tab:PDe_line}.

\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{./Imagens/motor control/chess_on_manip/line tracking/2 meters/rollPID_15_kp=0.3.PNG}
	\caption{A plot of a trial run to evaluate PD control using line tracking by varying the roll angle. 15\% manipulator speed. $K_p=0.3, K_d=0$. $\overline{E}=13.83$\textdegree, $E_{max}=36.68$\textdegree\space and $\sigma=9.56$\textdegree.}
	\label{fig:ltPID_kp_0.3}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{./Imagens/motor control/chess_on_manip/line tracking/2 meters/rollPID_15_kp=0.7_kd=0.15.PNG}
	\caption{A plot of a trial run to evaluate PD control using line tracking by varying the roll angle. 15\% manipulator speed. $K_p=0.7, K_d=0.15$. $\overline{E}=7.79$\textdegree, $E_{max}=24.12$\textdegree\space and $\sigma=6.90$\textdegree.}
	\label{fig:ltPID_kp_0.7_kd_0.15}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{./Imagens/motor control/chess_on_manip/line tracking/2 meters/rollPID_15_kp=0.8_kd=0.15.PNG}
	\caption{A plot of a trial run to evaluate PD control using line tracking by varying the roll angle. 15\% manipulator speed. $K_p=0.8, K_d=0.15$. $\overline{E}=7.68$\textdegree, $E_{max}=21.93$\textdegree\space and $\sigma=6.93$\textdegree.}
	\label{fig:ltPID_kp_0.8_kd_0.15}
\end{figure}

\begin{table}[H]
	\centering
	\caption{PD control of RTU results. Trials run with the line tracking method.}
	\label{tab:PDe_line}
	\begin{tabularx}{\textwidth}{lccc}
		\toprule \textbf{Descriptive statistics} & &\textbf{Controller parameters}& \\
		& $K_p=0.3$ & $K_p=0.7$, $K_d=0.15$ & $K_p=0.8$, $K_d=0.15$ \\ \midrule
		$\overline{E}$  & 14.19\textdegree & 7.79\textdegree & 7.68\textdegree \\
		$E_{max}$ & 38.06\textdegree & 24.12\textdegree & 21.93\textdegree\\
		$\sigma$ & 12.02\textdegree & 6.90\textdegree & 6.93\textdegree\\ \bottomrule
	\end{tabularx}
\end{table}

The first trials started with only a small proportional coefficient and had a large error because the control algorithm was not responsive enough. After boosting the proportional component, instability and loss of the tracked chessboard was reached around the 0.8 to 0.9 values. The proportional component was assigned a final value of $K_p=0.7$ and a derivative component was introduced with a value of $K_d=0.15$.

Although the error still diminishes slightly when using $K_p=0.8$ and $K_d=0.15$, as can be seen on the plot of the example trial using these values (Fig. \ref{fig:ltPID_kp_0.8_kd_0.15}), the instability that this increase in the proportional component causes is too much to be considered. If these values were used, the chessboard being tracked would be lost more than half of the times that the experiment was run.

By analyzing table \ref{tab:PDe_line}, it is possible to conclude that when applying a \gls{pd} control with the final controller parameters, and still using the line tracking method, results were better than when using the proportional control algorithm (table \ref{tab:pce}).

After arriving at the final \gls{pd} control parameters when using the line tracking method and varying the roll angle, the tilt angle also needed to be somehow tracked. It was at this point in the work that research was done to find the pose estimation method. Following the implementation of this method, three more types of trials were conducted for each angle to be altered. The \gls{pd} control's parameters had to be re-tuned to this kind of tracking method, as it has totally different characteristics.

The plots of example trials run with the pose estimation method while varying the roll angle are shown in figures \ref{fig:pose_kp_0.2}\hspace{0.2mm},\space\ref{fig:pose_kp_0.5_kd_0.4} and \ref{fig:pose_kp_0.7_kd_0.4} and a summary of these results is present in table \ref{tab:PDe_poseroll}.


\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{./Imagens/motor control/chess_on_manip/pose estimation/rollPID_15_kp=0.2.PNG}
	\caption{A plot of a trial run to evaluate PD control using pose estimation by varying the roll angle. 15\% manipulator speed. $K_p=0.2, K_d=0$. $\overline{E}=19.99$\textdegree, $E_{max}=54.63$\textdegree\space and $\sigma=16.93$\textdegree.}
	\label{fig:pose_kp_0.2}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{./Imagens/motor control/chess_on_manip/pose estimation/rollPID_15_kp=0.5_kd=0.4.PNG}
	\caption{A plot of a trial run to evaluate PD control using pose estimation by varying the roll angle. 15\% manipulator speed. $K_p=0.5, K_d=0.4$. $\overline{E}=9.93$\textdegree, $E_{max}=31.90$\textdegree\space and $\sigma=9.42$\textdegree.}
	\label{fig:pose_kp_0.5_kd_0.4}
\end{figure}


\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{./Imagens/motor control/chess_on_manip/pose estimation/rollPID_15_kp=0.7_kd=0.4.PNG}
	\caption{A plot of a trial run to evaluate PD control using pose estimation by varying the roll angle. 15\% manipulator speed. $K_p=0.7, K_d=0.4$. $\overline{E}=16.33$\textdegree, $E_{max}=37.18$\textdegree\space and $\sigma=10.51$\textdegree.}
	\label{fig:pose_kp_0.7_kd_0.4}
\end{figure}

\begin{table}[H]
	\centering
	\caption{PD control of RTU results. Trials run with the pose estimation method while varying the roll angle.}
	\label{tab:PDe_poseroll}
	\begin{tabularx}{\textwidth}{lccc}
		\toprule \textbf{Descriptive statistics} & &\textbf{Controller parameters}& \\
		& $K_p=0.2$ & $K_p=0.5$, $K_d=0.4$ & $K_p=0.7$, $K_d=0.4$ \\ \midrule
		$\overline{E}$  & 19.99\textdegree & 9.93\textdegree & 16.33\textdegree \\
		$E_{max}$ & 54.63\textdegree & 31.90\textdegree & 37.18\textdegree\\
		$\sigma$ & 16.93\textdegree & 9.42\textdegree & 10.51\textdegree\\ \bottomrule
	\end{tabularx}
\end{table}

The first trial run whilst using the pose estimation method to measure a change in the roll angle was made with $K_p=0.2$ and no derivative component, following the same train of thought as the previous experiments. Once again, the control algorithm is not responsive enough and as such, the error values are rather large. After extensive testing, the final values reached for the \gls{pd} control's parameters when using the pose estimation method were $K_p=0.5$ and $K_d=0.4$. A plot of an example trial with these values can be seen in Fig. \ref{fig:pose_kp_0.5_kd_0.4}.

The last trials varying the roll angle are meant to show that when using values greater than the ones that were established, besides not yielding far better results, when the \gls{rtu} was reaching its final position it could become unstable, balancing back and forth without ever stabilizing. An example of a trial of this type is shown in Fig. \ref{fig:pose_kp_0.7_kd_0.4}.

By analyzing table \ref{tab:PDe_poseroll} we can see that the best results are obtained with the final values of $K_p=0.5$ and $K_d=0.4$. However, these are worse than the results shown in table \ref{tab:PDe_line}, which were acquired using the line tracking method. This is thought to be because of the update rate of the pose estimation method being visibly lower than the one of the line tracking method.

The plots of example trials run with the pose estimation method while varying the tilt angle are shown in figures \ref{fig:posetilt_kp_0.01}\hspace{0.2mm},\space\ref{fig:posetilt_kp_0.1_kd_0.1} and \ref{fig:posetilt_kp_0.12_kd_0.1} and a summary of these results is present in table \ref{tab:PDe_posetilt}.

\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{./Imagens/motor control/chess_on_manip/pose estimation/tiltPID_5_kp=0.01.PNG}
	\caption{A plot of a trial run to evaluate PD control using pose estimation by varying the tilt angle. 5\% manipulator speed. $K_p=0.01, K_d=0$. $\overline{E}=8.62$\textdegree, $E_{max}=25.72$\textdegree\space and $\sigma=7.84$\textdegree.}
	\label{fig:posetilt_kp_0.01}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{./Imagens/motor control/chess_on_manip/pose estimation/tiltPID_5_kp=0.1_kd=0.1.PNG}
	\caption{A plot of a trial run to evaluate PD control using pose estimation by varying the tilt angle. 5\% manipulator speed. $K_p=0.1, K_d=0.1$. $\overline{E}=3.51$\textdegree, $E_{max}=13.13$\textdegree\space and $\sigma=3.87$\textdegree.}
	\label{fig:posetilt_kp_0.1_kd_0.1}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{./Imagens/motor control/chess_on_manip/pose estimation/tiltPID_5_kp=0.12_kd=0.1.PNG}
	\caption{A plot of a trial run to evaluate PD control using pose estimation by varying the tilt angle. 5\% manipulator speed. $K_p=0.12, K_d=0.1$. $\overline{E}=9.33$\textdegree, $E_{max}=41.60$\textdegree\space and $\sigma=12.59$\textdegree.}
	\label{fig:posetilt_kp_0.12_kd_0.1}
\end{figure}

\begin{table}[H]
	\centering
	\caption{PD control of RTU results. Trials run with the pose estimation method while varying the tilt angle.}
	\label{tab:PDe_posetilt}
	\begin{tabularx}{\textwidth}{lccc}
		\toprule \textbf{Descriptive statistics} & &\textbf{Controller parameters}& \\
		& $K_p=0.01$ & $K_p=0.1$, $K_d=0.1$ & $K_p=0.12$, $K_d=0.1$ \\ \midrule
		$\overline{E}$  & 8.62\textdegree & 3.51\textdegree & 9.33\textdegree \\
		$E_{max}$ & 25.72\textdegree & 13.13\textdegree & 41.60\textdegree\\
		$\sigma$ & 7.84\textdegree & 3.87\textdegree & 12.59\textdegree\\ \bottomrule
	\end{tabularx}
\end{table}

Although the tilt servo uses a different kind of \gls{pd} control (velocity control)(sec. \ref{sec:motor_control}), the procedure for its tuning is the same. The first component to introduce was the proportional component with a $K_p=0.01$ and to demonstrate that the control algorithm is not responsive enough the results of an example trial can be seen in Fig. \ref{fig:posetilt_kp_0.01}.

The final values reached for the \gls{pd} control when varying the tilt angle were $K_p=0.1$ and $K_d=0.1$.
A plot of an example trial with these values can be seen in Fig. \ref{fig:posetilt_kp_0.1_kd_0.1}. This plot also shows the problem that was the origin of having to use a different kind of control for the servo responsible for the tilt angle. As is seen in the servomotor position line, it is impossible to do a \gls{pd} control where the control variable is the servo's position if the current position of the servo is retrieved so badly. This mostly happens with the tilt servomotor for reasons explained in section \ref{sec:motor_control}.

From $K_p=0.12$  and onwards, high instability occurred when the \gls{rtu} was reaching its final position and once again, the servo would go back and forth, without ever stabilizing.

By analyzing table \ref{tab:PDe_posetilt}, it is possible to see the progressive tuning of the tilt angle servo's speed \gls{pd} controller's parameters. The best results are obtained with $K_p=0.1$ and $K_d=0.1$ and values higher than this resulted in an instability position of the \gls{rtu} at the end of experiments.
\newpage
\section{Experiments with RTU mounted on the manipulator arm}
\subsection{Experiments description}
After all of the experiments where the chessboard was mounted on the manipulator arm were done, the \gls{rtu} was mounted on the manipulator (Fig. \ref{fig:camera_in_manip}) to see if the response to the manipulator's movements was similar. To mount the \gls{rtu} on the manipulator, some of the previous mechanical parts designed were used, with the only extra alteration being two threaded holes on the \gls{rtu} support.

\begin{figure}[H]
	\centering
	\includegraphics[width=\textwidth]{./Imagens/camera_in_manip.jpg}
	\caption{The RTU mounted on the manipulator arm.}
	\label{fig:camera_in_manip}
\end{figure}

In these experiments, the control method used was solely the \gls{pd} control method but both tracking methods were tested. To do so, five trials were run with the line tracking method where $K_p=0.6, K_d=0.15$; five trials with the pose estimation method for the roll angle where $K_p=0.6, K_d=0.4$; and five trials with the pose estimation method for the tilt angle where $K_p=0.08, K_d=0.02$.

The distance to the chessboard was still two meters for all trials and servomotor speed was 255 for experiments where the roll angle was being tested. Additionally, two \gls{tp} programs were created, called \texttt{JS\_ROLL2} and \texttt{JS\_TILT2}. These are the same as the \gls{tp} programs explained above, only with an offset on the fifth axis of the manipulator in order to start the experiments with the \gls{rtu} leveled with the ground.

\subsection{Result analysis}

The plots of example trials run with the \gls{rtu} mounted in the manipulator are shown in figures \ref{fig:final_line_kp_0.6_kd_0.15}\hspace{0.2mm},\space\ref{fig:final_pose_kp_0.6_kd_0.4} and \ref{fig:final_posetilt_kp_0.08_kd_0.02} and a summary of these results is present in table \ref{tab:RTU_in_manip}.

\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{./Imagens/motor control/camera_on_manip/line_kp=0.6_kd=0.15.PNG}
	\caption{A plot of a trial run to evaluate PD control using line tracking by varying the roll angle. 15\% manipulator speed. $K_p=0.6, K_d=0.15$.$\overline{E}=7.54$\textdegree, $E_{max}=22.35$\textdegree\space and $\sigma=7.81$\textdegree.}
	\label{fig:final_line_kp_0.6_kd_0.15}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{./Imagens/motor control/camera_on_manip/rollpose_kp=0.6_kd=0.4.PNG}
	\caption{A plot of a trial run to evaluate PD control using pose estimation by varying the roll angle. 15\% manipulator speed. $K_p=0.6, K_d=0.4$. $\overline{E}=13.64$\textdegree, $E_{max}=31.05$\textdegree\space and $\sigma=9.96$\textdegree.}
	\label{fig:final_pose_kp_0.6_kd_0.4}
\end{figure}

\begin{figure}[H]
	\centering
	\includegraphics[width=0.9\textwidth]{./Imagens/motor control/camera_on_manip/tiltpose_kp=0.08_kd=0.02.PNG}
	\caption{A plot of a trial run to evaluate PD control using pose estimation by varying the tilt angle. 5\% manipulator speed. $K_p=0.08, K_d=0.02$. $\overline{E}=2.01$\textdegree, $E_{max}=5.88$\textdegree\space and $\sigma=1.52$\textdegree.}
	\label{fig:final_posetilt_kp_0.08_kd_0.02}
\end{figure}

\begin{table}[H]
	\centering
	\caption{Results of experiments performed with the RTU mounted on the manipulator.}
	\label{tab:RTU_in_manip}
	\begin{tabularx}{\textwidth}{llc}
		\toprule &\textbf{Descriptive statistics} & \textbf{Controller parameters} \\
		&& $K_p=0.6$, $K_d=0.15$ \\ \midrule
		&$\overline{E}$  & 7.54\textdegree \\
		\textbf{Line tracking - Roll}	&$E_{max}$ & 22.35\textdegree \\
		&$\sigma$ & 7.81\textdegree \\  \midrule
		&&\textbf{Controller parameters}\\
		&& $K_p=0.6$, $K_d=0.4$ \\ \midrule
		&$\overline{E}$  & 13.64\textdegree \\
		\textbf{Pose estimation - Roll}	&$E_{max}$ & 31.05\textdegree \\
		&$\sigma$ & 9.96\textdegree \\  \midrule
		&&\textbf{Controller parameters}\\
		&& $K_p=0.08$, $K_d=0.02$ \\ \midrule
		&$\overline{E}$  & 2.01\textdegree \\
		\textbf{Pose estimation - Tilt}	&$E_{max}$ & 5.88\textdegree \\
		&$\sigma$ & 1.52\textdegree \\  \midrule
	\end{tabularx}
\end{table}

A plot of an example trial where the line tracking method was used can be seen in Fig. \ref{fig:final_line_kp_0.6_kd_0.15}. The \gls{pd} control's parameters had to be slightly adjusted to avoid instability and the final values were $K_p=0.6$ and $K_d=0.15$.

Regarding the pose estimation trials, the \gls{pd} control's parameters were also changed when compared to the previous values where the chessboard was mounted on the manipulator. When varying the roll angle, the values used were $K_p=0.6$ and $K_d=0.4$ and a plot of an example trial run with those values can be seen in Fig. \ref{fig:final_pose_kp_0.6_kd_0.4}.

When running the tilt trials, the values $K_p=0.08$ and $K_d=0.02$ were used. A plot of an example trial run with those values can be seen in Fig. \ref{fig:final_posetilt_kp_0.08_kd_0.02}.

Overall, these results proved to be similar to what happened when the chessboard was mounted on the manipulator and the \gls{rtu} was mounted on the tripod, and confirm that no vibrations or disturbances coming from the manipulator interfere with the tracking or stabilization processes.

By analyzing table \ref{tab:RTU_in_manip}, it is possible to see that although needing a small alteration in the \gls{pd} values, the results are very similar to what happened in the experiments where the chessboard was mounted on the manipulator, with a slight increase in the mean error in the pose estimation - roll experiment.