Austin Schuh | 7400da0 | 2018-01-28 19:54:58 -0800 | [diff] [blame^] | 1 | /*! |
| 2 | |
| 3 | \page developer Developer Guidelines |
| 4 | @tableofcontents |
| 5 | |
| 6 | We very much welcome external developers. Small changes and contributions can be made via pull requests. |
| 7 | If you have a larger enhancement, bug fix or other contribution in mind, feel free to first create an issue |
| 8 | to align the development with ongoing activities. |
| 9 | |
| 10 | \section Code Formatting |
| 11 | We support clang-format and provide a style template to automatically format the source code. |
| 12 | Please refer to the clang-format style sheet in the package root directory for our conventions. |
| 13 | Or simply rely on clang-format to do the formatting for you. |
| 14 | |
| 15 | Note for developers using the *Eclipse IDE*: you can conveniently integrate clang-format (and our .clang-format |
| 16 | configuration file) in your project using the "CppStyle" plugin (see http://www.cppstyle.com/ for |
| 17 | detailed information). To automatically format the code according to ct-style, just mark the source-code |
| 18 | and press *Ctrl+Shift+f*. |
| 19 | |
| 20 | |
| 21 | Example command for running clang-tidy: |
| 22 | \code |
| 23 | $ catkin build --no-deps <package_name> -v --make-args clang-tidy |
| 24 | \endcode |
| 25 | |
| 26 | For clang-format it's just the same: |
| 27 | \code |
| 28 | $ catkin build --no-deps <package_name> -v --make-args clang-format |
| 29 | \endcode |
| 30 | |
| 31 | \section Explicit Template Instantiation |
| 32 | |
| 33 | CT relies on explicit template instantiation, that means precompilation of the library for |
| 34 | user-specified state and control dimensions. |
| 35 | While CT handles things slightly different, please see [this post](https://anteru.net/blog/2008/11/19/318/index.html) |
| 36 | to learn more about the subject. |
| 37 | The basic idea is that for all templated class there is |
| 38 | - a header (.h) that defines the class and its methods |
| 39 | - an (header) implementation (-impl.h) that implements all methods |
| 40 | - a cpp template file (.cpp.in) that instantiates the template |
| 41 | |
| 42 | The template file has the following placeholders |
| 43 | |
| 44 | Placeholder | Description |
| 45 | -------------- | ------------- |
| 46 | STATE_DIM_PRESPEC | The state dimension |
| 47 | CONTROL_DIM_PRESPEC | The control dimension |
| 48 | SCALAR_PRESPEC | The scalar type |
| 49 | DOUBLE_OR_FLOAT | "true" if the scalar type is double or float |
| 50 | POS_DIM_PRESPEC | Position dimension for symplectic integrator (default: 0) |
| 51 | VEL_DIM_PRESPEC | Velocity dimension for symplectic integrator (default: 0) |
| 52 | |
| 53 | You can use these placeholders in the code |
| 54 | \code{.cpp} |
| 55 | #if \@DOUBLE_OR_FLOAT\@ |
| 56 | template class ct::coreMyClass<\@STATE_DIM_PRESPEC\@, \@CONTROL_DIM_PRESPEC\@>; |
| 57 | #endif |
| 58 | \endcode |
| 59 | |
| 60 | The parser in the CMakeLists.txt would then create the following code out of this |
| 61 | (for STATE_DIM=3, CONTROL_DIM=2, SCALAR=double) |
| 62 | |
| 63 | \code{.cpp} |
| 64 | #if 1 |
| 65 | template class ct::coreMyClass<3, 2>; |
| 66 | #endif |
| 67 | \endcode |
| 68 | |
| 69 | \note The parameter DOUBLE_OR_FLOAT is optional but can be used if your class does not compile for Auto-Diff types |
| 70 | which is often the case if no special care is taken. |
| 71 | |
| 72 | |
| 73 | \section other_guidelines Other guidelines |
| 74 | |
| 75 | - Headerguards: |
| 76 | please use |
| 77 | \code |
| 78 | #pragma once |
| 79 | \endcode |
| 80 | as header guards, rather than |
| 81 | \code |
| 82 | #ifndef |
| 83 | #define |
| 84 | /*...*/ |
| 85 | #endif |
| 86 | \endcode |
| 87 | |
| 88 | - never use **std::make_shared** and **std::allocate_shared** within the CT. They cause aligment issues, |
| 89 | compare the following bugreport: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1049 |
| 90 | Currently, the best option is to declare and define shared pointers using CT types as in the following example |
| 91 | \code{.cpp} |
| 92 | std::shared_ptr<ct::core::ControlledSystem<state_dim, control_dim>> nonlinearSystem( new SomeClass(...)); |
| 93 | \endcode |
| 94 | |
| 95 | */ |