User Tools

Site Tools


Upload failed. Maybe wrong permissions?
adrl:education:completed_projects:lombrisf2014f

<latex>{\fontsize{16pt}\selectfont \textbf{Cost-Function Toolbox
for Optimal Control}} </latex>

<latex>{\fontsize{12pt}\selectfont \textbf{Fabian Lombris}} </latex>
<latex>{\fontsize{10pt}\selectfont \textit{Bachelor Thesis}} </latex>

<latex> {\fontsize{12pt}\selectfont \textbf{Abstract} </latex>
In nowadays field of robotics, scientists often have to deal with cost functions for their optimal control algorithms. Since there usually isn't just one correct solution in order to get the best possible result, the cost functions have to be tested against each other, using various compositions and parameter values. This can result in an exceedingly time consuming task. In this assignment, we created toolbox to simplify the creation and evaluation of cost functions using automatic differentiation including a research about automatic differentiation itself and available tools to use it with C++. The toolbox allows users to combine various terms to a cost function and evaluate it for its first and second order derivative, without having to do any differentiation by hand, in a quick and easy manner. Furthermore, no knowledge about automatic differentiation is required. Even though the toolbox needs further improvements especially in execution times of second order derivatives, it can already provide big support for people who only work with manually calculated and hard-coded derivatives.

<latex> {\fontsize{12pt}\selectfont \textbf{Automatic Differentiation} </latex>
Automatic Differentiation is a computation trick to compute the derivative of a function without making any numerical approximations. A autodiff tool therefore registers any use of an operator like addition, multiplication, etc. but also for example the use of trigonometric functions in so called work variables. This is possible through the use of a specifically defined type for the function variables, e.g. AD<double> instead of the standard type double. The programmer of such a tool then defines the derivative of those work variables, e.g. for a multiplication a*x the derivative is x. Afterwards, by applying the chain rule, the derivative of the whole function can be built and evaluated. Even though the computation of a derivative using automatic differentiation obviously needs more time then using hard coded derivatives, it still can be an improvement in terms of time consumption, if the function to be derived is very complex.

<latex> {\fontsize{12pt}\selectfont \textbf{Cost Function Toolbox} </latex>
The cost function toolbox provides an easy way to create a cost function by adding up various terms and evaluate it for its function value and first and second order derivatives. To compute the derivatives, it makes use of the autodiff tool CppAD. However, it is also possible to provide terms with a hard-coded derivative and combine them with terms using CppAD within the same cost function. The user interface looks as follows:

The user would first create a cost function object using CostFunctionAD if he plans on using CppAD or CostFunctionAnalytic if he already knows the analytic derivative of every term he uses. The next step is creating the needed by either using the already provided terms or writing their own terms by alternating an existing one and then adding them to the cost function. This is the only part where the user needs to know something about automatic differentiation, i.e. where to use the type CppAD::AD<double>. The last step before evaluating the cost function is to set values for state and control variables. It is also possible to change the values of the weights of any term afterwards to compare the different results with each other without having to recompile.

<latex> {\fontsize{12pt}\selectfont \textbf{Result} </latex>
The timing results show a big di erence between the execution time for rst order derivatives and second order derivatives when using CppAD. The reason for this divergence is, that for second order derivatives CppAD makes 2n computations, n being the number of state or control variables, and for first order derivatives it only makes one computation.
Considering that the toolbox can make 10'000 second order derivative computations in around 3 to 4 seconds, it is still very fast and we even didn't have to spend time on deriving the function by hand.

adrl/education/completed_projects/lombrisf2014f.txt ยท Last modified: 2015/03/03 13:55 (external edit)