PageRenderTime 80ms CodeModel.GetById 34ms RepoModel.GetById 0ms app.codeStats 0ms

/PDF/slam-optim-documentation.tex

http://slam-optim-matlab.googlecode.com/
LaTeX | 323 lines | 230 code | 26 blank | 67 comment | 0 complexity | 1dfd44a7a9e5668ebcd244fa75e4f9cb MD5 | raw file
  1. %
  2. % A simple LaTeX template for Books
  3. % (c) Aleksander Morgado <aleksander@es.gnu.org>
  4. % Released into public domain
  5. %
  6. \documentclass{article}
  7. \usepackage[a4paper, top=3cm, bottom=3cm]{geometry}
  8. \usepackage[latin1]{inputenc}
  9. \usepackage{setspace}
  10. \usepackage{fancyhdr}
  11. \usepackage{tocloft}
  12. %
  13. \usepackage{fancyvrb}
  14. \usepackage{graphics} % for pdf, bitmapped graphics files
  15. \usepackage{epsfig} % for postscript graphics files
  16. \usepackage{subfigure,amsmath,array,amsbsy,amsfonts,amssymb}
  17. \newcommand{\inv}{^{-1}}
  18. \newcommand{\tr}{^{\!\top}}
  19. \newcommand{\invtr}{^{-\!\top}}
  20. \newcommand{\diag}{\operatornamewithlimits{diag}}
  21. \newcommand{\argmax}{\operatornamewithlimits{argmax}}
  22. \newcommand{\argmin}{\operatornamewithlimits{argmin}}
  23. \def\R{{\rm I\mkern-3mu R}}
  24. \begin{document}
  25. \pagestyle{empty}
  26. %\pagenumbering{}
  27. % Set book title
  28. \title{\textbf{MATLAB TOOLBOX FOR SMOOTHING AND MAPPING}}
  29. % Include Author name and Copyright holder name
  30. \author{Viorela Ila}
  31. % 1st page for the Title
  32. %-------------------------------------------------------------------------------
  33. \maketitle
  34. % General definitions for all Chapters
  35. %-------------------------------------------------------------------------------
  36. % Define Page style for all chapters
  37. \pagestyle{fancy}
  38. % Delete the current section for header and footer
  39. \fancyhf{}
  40. % Set custom header
  41. \lhead[]{\thepage}
  42. \rhead[\thepage]{}
  43. % Set arabic (1,2,3...) page numbering
  44. \pagenumbering{arabic}
  45. % Set double spacing for the text
  46. \doublespacing
  47. % Include dots between chapter name and page number
  48. \renewcommand{\cftchapdotsep}{\cftdotsep}
  49. %Finally, include the ToC
  50. \tableofcontents
  51. \newpage
  52. % Not enumerated chapter
  53. %-------------------------------------------------------------------------------
  54. \section{Introduction}
  55. This toolbox implements deferent optimization strategies to solve the simultaneous localization and mapping (SLAM) problem. This is needed to enable autonomous robots to localize, map and navigate previously unknown environments. This work considers smoothing rather than filtering. The advantage is that the estimation errors are reduced by using
  56. better linearization points. Both, \emph{pose SLAM} (smoothing the robot's trajectory only) and \emph{full SLAM} (estimating the trajectory together with landmarks in the environment) are considered. The user can also chose between \emph{batch} and \emph{incremental} optimization.
  57. \\
  58. The purpose of the toolbox is to test the mathematics behind the smoothing and mapping algorithms. It is not optimized for speed but still timing of the algorithms is available so that the user can compare different solvers and/or state representations.
  59. \\
  60. The toolbox is available here\\ {\small {\url{https://wiki.laas.fr/robots/ViorelaIla?action=AttachFile&do=view&target=SAMToolbox.tar.gz}}\\ \normalsize It includes three implementations for incremental online smoothing and mapping; a new method of incremental Cholesky updates (called \emph{ L-SLAM}) together with QR factorization of the matrix $A$ (which in the SLAM literature is known as SAM, smoothing and mapping \cite{Dellaert06ijrr}) and the Cholesky decomposition of the matrix $\Lambda$ (based on incremental updates of $\Lambda$ from \cite{Ila10tro}).
  61. % If the chapter ends in an odd page, you may want to skip having the page
  62. % number in the empty page
  63. \newpage
  64. \thispagestyle{empty}
  65. % First enumerated chapter
  66. %-------------------------------------------------------------------------------
  67. \section{Mathematical background}
  68. %
  69. The SLAM problem estimates the robot trajectory ${\bf x} =\left\{ x_{i}|i\in0..n\right\} $ and the position of landmarks in the environment ${\bf l} =\left\{ l_{j}|j\in1..nl\right\} $ given a set of observations ${\bf z} =\left\{ z_{k}|k\in1..m\right\}$ and control inputs ${\bf u} =\left\{ u_{i}|i\in1..n\right\}$ . Figure~\ref{fig:BN-FG} a) shows the graphical model representation of such a distribution as a Bayes net. In general, for the Bayes net representation we can write the joint density as:
  70. %
  71. \begin{equation}
  72. P({\bf x},{\bf l},{\bf z},{\bf u})\propto P(x_{0})\prod_{j}^{nl} P({\bf l}_{j})\prod_{i}^{n} P(x_{i+1}\mid x_{i},u_{i})\prod_{k}^{m} P(z_{k}\mid x_{i_k},l_{j_k})
  73. \end{equation}
  74. %
  75. where $\prod_{j}^{nl} P({\bf l}_{j})$ can be omitted as it is uninformative and the equation above becomes:
  76. %
  77. \begin{equation}
  78. P({\bf x},{\bf l},{\bf z},{\bf u})\propto P(x_{0})\prod_{i}^{n} P(x_{i+1}\mid x_{i},u_{i})\prod_{k}^{m} P(z_{k}\mid x_{i_k},l_{j_k})
  79. \end{equation}
  80. \subsection{Factor graph formulation}
  81. %
  82. When the factorization is made explicit we obtain the equivalent factor graph representation of the problem:
  83. %
  84. \begin{equation}
  85. P({\bf x},{\bf l},{\bf z},{\bf u})=\phi(x_{0})\prod_{i}^{n}\psi(x_{i+1},x_{i})\prod_{k}^{m}\varphi(x_{i_k},l_{j_k})
  86. \label{eq:fg}
  87. \end{equation}
  88. %
  89. In a typical SLAM application, there are three types of factors: the unary factors $\phi(x_{0})\propto P(x_{0})$, odometric factors $\psi(x_{i+1},x_{i})\propto P(x_{i+1}\mid x_{i},u_{i})$ and measurement factors $ \varphi(x_{i_k},l_{j_k})\propto P(z_{k}\mid x_{i_k},l_{j_k})$ and the corresponding graphical representation is shown in Figure \ref{fig:BN-FG} b).
  90. %
  91. \begin{figure}[t]
  92. \begin{center}
  93. \begin{array}{cc}
  94. \includegraphics[width=7cm]{figs/BN.pdf} & \includegraphics[width=7cm]{figs/FG.pdf}\\
  95. a) & b)
  96. \end{array}
  97. \end{center}
  98. \caption{a) Bayes net representation of SLAM. b) Factor graph representation of SLAM.}
  99. \label{fig:BN-FG}
  100. \end{figure}
  101. %%%%
  102. \subsection{Maximum likelihood estimation}
  103. The optimization problem associated with the full SLAM problem can be concisely stated in terms of a sparse least-squares problem. We want to obtain the maximum likelihood estimate (MLE) for all robot poses ${\bf x}$ and all landmarks ${\bf l}$ collected in vector $\theta=({\bf x},{\bf l})$ :
  104. \begin{equation}
  105. \boldsymbol{\theta}^{*}=\argmax_{\boldsymbol{\theta}}\: P(\boldsymbol{\theta}\mid{\bf z},{\bf u})=\argmin_{\boldsymbol{\theta}}\:\left\{ -\log(P(\theta\mid{\bf z},{\bf u}))\right\} .
  106. \label{eq:ML}
  107. \end{equation}
  108. In general, for the SLAM problem, we assume Gaussian distributions and we write:
  109. %
  110. \begin{equation}
  111. \begin{array}{ccc}
  112. x_i= f_{i}({\bf x}_{i-1},{\bf u}_{i})-{\bf w}_{i} & \Leftrightarrow & P({\bf x}_{i+1}\mid{\bf x}_{i},{\bf u}_{i})\propto\exp\left(-\frac{1}{2}\parallel f_{i}({\bf x}_{i-1},{\bf u}_{i})-{\bf x}_{i}\parallel_{\Gamma_{i}}^{2}\right)\\
  113. z_k=h_{k}({\bf x}_{i_{k}},{\bf l}_{j_{k}})-{\bf v}_{k}& \Leftrightarrow & P({\bf z}_{k}\mid{\bf x}_{i_{k}},{\bf l}_{j_{k}})\propto\exp\left(-\frac{1}{2}\parallel h_{k}({\bf x}_{i_{k}},{\bf l}_{j_{k}})-{\bf z}_{k}\parallel_{\Sigma_{k}}^{2}\right)
  114. \end{array}
  115. \end{equation}
  116. %
  117. where $f$ and $h$ are motion and measurement models, $v$ and $w$ are the normally distributed zero-mean motion and measurement noise with covariance matrices $\Gamma_{i}$ and $\Sigma_{k}$, respectively.
  118. %
  119. \subsection{Least-squares problem}\label{subsec:solveSLAM}
  120. Finding the MLE from equation \ref{eq:ML} is done by solving the following non-linear least-squares problem
  121. %
  122. \begin{equation}
  123. \boldsymbol{\theta}^{*}=\argmin \left\{\sum_{i=1}^{n}\parallel f_{i}({\bf x}_{i-1},{\bf u}_{i}) -{\bf x}_{i}\parallel_{\Gamma_{i}}^{2} + \sum_{k=1}^{m}\left\Vert h_{k}({\bf x}_{i_{k}},{\bf l}_{j_{k}})-{\bf z}_{k}\right\Vert _{\Sigma_{k}}^{2} \right \}.
  124. \label{eq:nlls}
  125. \end{equation}
  126. In practice solving this typically nonconvex optimization problem is difficult and prone to local minima. Therefore, non-linear optimization methods such as Gauss-Newton or Levenberg-Marquardt are used to approximate the minimum incrementally, by solving a series of linearized problems. At each iteration, we collect the Jacobian matrices into the matrix $A$ and the current residuals into the right-hand side vector ${\bf b}$ as in \cite{Dellaert06ijrr} ,we obtain the following standard least-squares problem in $\delta$:
  127. %
  128. \begin{equation}
  129. f(\boldsymbol{\delta})=\frac{1}{2}\left\Vert A\boldsymbol{\delta}-{\bf b}\right\Vert ^{2}
  130. \label{eq:linearEq}
  131. \end{equation}
  132. %
  133. In general, matrix $A$ can be very large, but is quite sparse. In~\cite{Dellaert06ijrr,Kaess08tro} it has been shown that matrix $A$ naturally corresponds to the factor graph representation in equation \ref{eq:fg}. The normalized equation is given by:
  134. %
  135. \begin{equation}
  136. f(\boldsymbol{\delta})=\frac{1}{2}\left\Vert \Lambda\boldsymbol{\delta}-{\boldsymbol \eta}\right\Vert ^{2}
  137. \label{eq:normalEq}
  138. \end{equation}
  139. %
  140. where $\Lambda=A^{T}A$ is the information matrix and ${\boldsymbol \eta}=A^{T} {\bf b}$ is the information vector. The information matrix $\Lambda$ corresponds to the Markov random field associated with the SLAM problem. We call ``information form'' of the SLAM problem when the state is represented by the information matrix $\Lambda$ and the information vector ${\boldsymbol \eta}$. The information matrix has the advantage of being sparse and remaining of the size of the state $(n+nl)\times (n+nl)$ even if the number of measurements increases.
  141. \subsection{Solving the SLAM problem}\label{subsec:solveSLAM}
  142. To solve the linearized version of equation~\ref{eq:normalEq} we can employ either iterative or direct methods. Each of these families of optimization techniques presents its own advantages and limitations.
  143. %%%%
  144. \subsubsection*{Iterative methods}
  145. Iterative methods, on one hand, only require access to the gradient and have a small memory footprint, but can suffer from poor convergence.
  146. The current state of the art in iterative methods applied to SLAM problem stems from the work
  147. by~\cite{Olson06icra} whose main contribution is a parameterization of the global poses in terms of increments along the trajectory.
  148. Grisetti~\cite{Grisetti07rss,Grisetti10iros} adopted this incremental parameterization as well, but instead defines it on a spanning tree. Both lines of
  149. work use stochastic gradient descent (SGD) to minimize the resulting objective functions in terms of incremental poses.
  150. %%%%
  151. \subsubsection*{Direct methods}
  152. On the other hand, direct methods exhibit quadratic convergence and can be quite efficient for sparse problems like SLAM.
  153. The linear system can be solved directly either by Cholesky or QR matrix factorizations of the matrix $\Lambda$, respectively
  154. $A$ and then performing backsubstitution.
  155. \\
  156. \emph{Cholesky factorization} yields $A\tr A =R\tr R$, where $R\tr$ is the Cholesky factor, and a forward and back substitutions on $R\tr {\bf y} = A\tr {\bf b}$ and
  157. $R\:\theta = {\bf y}$ first recovers ${\bf y}$, then the actual solution, the update $\theta$.
  158. \\
  159. Alternatively we can skip the normal equation in \ref{eq:normalEq} and apply\emph{ QR factorization} directly to the matrix $A$ in \ref{eq:linearEq}, yielding $A = Q\:R$. The solution $\theta$ can be directly obtained by backsubstitution in $R\theta = {\bf d}$ where ${\bf d}=R\invtr\:A\tr\:{\bf b}$. Note that $Q$ is not explicitly formed; instead ${\bf b}$ is modified during factorization to obtain $\bf d$.\\
  160. \\
  161. Recently has been shown in \cite{Konolige10iros} that sparse Cholesky decomposition on $A\tr A$ performs faster than QR decomposition on $A$ .
  162. %Even if updating $A$ it's more efficient (one block line is added to the matrix every new constraint) than updating $A\tr A$,
  163. Performing both operations; $A\tr A$ and Cholesky decomposition, on sparse matrices remains more efficient than performing QR decomposition on $A$.
  164. \\
  165. In both strategies, finding the solution involves backsubstitution; if the factor $R$ is sparse, the backsubstitution performs rapidly, but it becomes more inefficient when the fill-in increases. The structure of the factor, in particular the number of non-zero elements in each row and column can be predicted by forming the ``elimination tree''. Forming the elimination tree depends on the chosen elimination ordering. To avoid the fill-in, efficient elimination orderings need to be found. While finding the variable ordering that leads to the minimal fill-in is NP-hard \cite{Arnborg87siam} for general problems, one typically uses heuristics such as the column approximate minimum degree (COLAMD) algorithm by~\cite{Davis04acm}, which provide close to optimal orderings for many problems.
  166. %%%%
  167. \subsection{New method to incrementally update the Cholesky factor}\label{subsec:LSLAM}
  168. The insights gained from the Bayes tree data structure allowed us to develop new simplified incremental algorithms, more suitable to very large scale applications such those in the project ROSACE.
  169. For that we investigated how to incrementally update directly the Cholesky factor $L=R\tr$ in order to combine the advantages of incremental updates and sparse Cholesky decomposition.
  170. \\
  171. Integrating a new measurement to the information form is additive. Updating $\Lambda$ and $ {\boldsymbol \eta}$ we obtain:
  172. \begin{eqnarray}
  173. \begin{array}{cc}
  174. \tilde \Lambda= \left (\begin{array}{cc}
  175. \Lambda_{11} & \Lambda_{21}\tr \\
  176. \Lambda_{21} & \Lambda_{22}+\Omega
  177. \end{array} \right )\:; & \tilde {\boldsymbol \eta}=\left[\begin{array}{c} {\boldsymbol \eta}_{1}\\ {\boldsymbol \eta}_{2}+{\boldsymbol \omega}\end{array}\right]
  178. \end{array}
  179. \label{eq:updateLambda}
  180. \end{eqnarray}
  181. where $\Omega$ is the increment in information given by $H\tr\:\Sigma_{z_k}\:H$ and ${\boldsymbol \omega}= H\:\Sigma_{z_k}\inv {\bf e_k}$, ${\bf e_k}$ being the prediction-measurement error. Only a part of the information matrix is changed in the update step and the same happens with the lower diagonal factor $L$. The update factor becomes:
  182. \begin{eqnarray}
  183. %
  184. \tilde L= \left (\begin{array}{cc}
  185. L_{11} & \\
  186. L_{21} & \tilde L_{22}
  187. \end{array} \right )
  188. \label{eq:updateL}
  189. \end{eqnarray}
  190. %
  191. From $\tilde \Lambda = \tilde L\:\tilde L\tr$ and equations \ref{eq:updateLambda} and \ref{eq:updateL} we can write:
  192. %
  193. \begin{eqnarray}
  194. \Lambda_{22}+\Omega= L_{21}\: L_{21}\tr + \tilde L_{22}\: \tilde L_{22}\tr
  195. \label{eq:L22a}
  196. \end{eqnarray}
  197. %
  198. and the changed part of the $\tilde L$ factor can be computed by applying Cholesky decomposition only to the reduced size matrix:
  199. %
  200. \begin{eqnarray}
  201. \tilde L_{22}= chol(\Lambda_{22}+\Omega-L_{21}\: L_{21}\tr)
  202. \label{eq:L22b}
  203. \end{eqnarray}
  204. %
  205. %L22_new\(L22*d2+H'*dz);
  206. The part of the RHS: $\tilde {\bf d}=\left[\begin{array}{c} {\bf d_1}\\ \tilde{\bf d_2}\end{array}\right]$ affected by the new measurement can also be easily updated
  207. \begin{eqnarray}
  208. \tilde {\bf d_2}= \tilde L_{22}\backslash ({\boldsymbol \eta}_{2}+{\boldsymbol \omega} -L_{21}\: {\bf d_1})
  209. \label{eq:L22b}
  210. \end{eqnarray}
  211. %
  212. In an online applications, where the robots are mostly performing exploration task either to map the environment or to navigate towards a specific goal, the new measurements affect variables that are close in the state representation, resulting in small sizes on the information increments $\Omega$ and ${\boldsymbol \omega}$ which translates in efficiency of the update step. Furthermore, in the case of ground robots odometric measurements have higher rate but they only link consecutive robot poses. Therefore adding an odometric measurement can be considered constant time. The constant is $1$ for the particular case of Pose SLAM and $k$ for the case of landmark SLAM, where $k$ is the number of landmarks visible at a time instant.
  213. \\
  214. After updating $\tilda L$ and $\tilda {\bf d}$ backsubstitution is performed to find the solution.
  215. %By representing the SLAM problem using Bayes trees we learned that during the update process not all the variable are affected and that recovering a nearly exact solution in every step does not require solving for all variables~\cite{Kaess10wafr}. Computational cost can be reduced significantly in this way.
  216. % Translating this to our new method it results in performing the backsubstitution partially. Full backsubstitution starts with the last line of the factor $L$ and goes up to the top, obtaining the $\boldsymbol \delta$. A partial solving starts from the last variable and continue processing until the change of the variable is lower than a threshold $\alfa$.
  217. \\
  218. %%%%%%%%%%%%
  219. %%%%
  220. \subsection{Optimization on Manifold}\label{subsec:manifold}
  221. The toolbox supports 2D and 3D SLAM. For the 2D the state is represented using $(x,y,\theta)$ and for the 3D the state is representing using $(x,y,z,\phi,\theta,\psi)$. Those are parameterizations of rotation-translation transformation between robot poses in the case of pose SLAM and/or robot position and landmarks in the case of landmark SLAM. Unfortunately those are global parameterizations which exhibits singularities or other anomalies at various points in the parameter space. These anomalies can cause serious problems for gradient based minimization procedures, like Gauss-Newton or Levenberg-Marquard.
  222. Optimization problems on a manifold such as SO(3) involves calculating incremental steps in the tangent space to the manifold.
  223. %%%%%%%%%%%%%%%%%%%%%%%%%%
  224. \section{Implementation Details}\label{subsec:Impl}
  225. The toolbox implements and test the SLAM nonlinear optimization problem. To test the
  226. \subsection{Nonlinear optimization}
  227. Gauss-Newon method:
  228. %--------------------------------------------------------------------
  229. \begin{Verbatim}[frame=single]
  230. Algorithm: Gauss-Newton
  231. i=1;
  232. done=(i>=Solver.maxIT);
  233. while ~done
  234. [dm,time_solve]=solveSystem(System);
  235. done=((norm(dm)<Solver.tol)||(i>=Solver.maxIT));
  236. if ~done
  237. Config=newConfig(Config,dm);
  238. ck=cputime;
  239. System=linearSystem(Config,Graph,System);
  240. i=i+1;
  241. end
  242. \end{Verbatim}
  243. %--------------------------------------------------------------------
  244. Levenberg-Marquard method:
  245. %--------------------------------------------------------------------
  246. \begin{Verbatim}[frame=single]
  247. Algorithm: Levenberg-Marquard
  248. factor=10;
  249. lambda=Solver.lambda;
  250. lambda_max=1e7;
  251. System_new=System;
  252. current_error=10000000;
  253. i=0;
  254. done=0;
  255. while ~done
  256. i=i+1;
  257. [S,v]=prepareSystem(System_new.A,System_new.b,lambda);
  258. dm=S\v;
  259. if ((norm(dm)<Solver.tol)||(i>=Solver.maxIT))
  260. done=1;
  261. else
  262. Config_new=newConfig2D(Config,dm);
  263. System_new=linearSystem(Config_new,Graph,System_new);
  264. next_error=norm(System_new.b); %norm(System_new.A*dm-System_new.b);
  265. if(next_error<=current_error)&& (lambda <= lambda_max)
  266. done =((current_error-next_error)<.005);
  267. fprintf('.');
  268. if mod(i,50)==0
  269. fprintf('\n');
  270. end
  271. Config=Config_new;
  272. current_error=next_error;
  273. System=System_new;
  274. lambda=lambda/factor;
  275. else
  276. lambda=lambda*factor;
  277. end
  278. end
  279. end
  280. \end{Verbatim}
  281. \begin{Verbatim}[frame=single]
  282. function [S,v]=prepareSystem(A,b,lambda)
  283. Atr=A';
  284. H = Atr*A;
  285. v = Atr*b;
  286. D = diag(diag(H));
  287. S =(H+lambda*D);
  288. end
  289. \end{Verbatim}
  290. %--------------------------------------------------------------------
  291. % Last pages for ToC
  292. %-------------------------------------------------------------------------------
  293. \newpage
  294. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  295. \bibliographystyle{IEEEtran}
  296. \bibliography{references/refs_gatech,references/gps,references/refs_add}
  297. \end{document}