blob: d5a4e632892efcd0245685e4554e02030c078ab0 [file] [log] [blame]
Austin Schuh7400da02018-01-28 19:54:58 -08001/*!
2
3\page developer Developer Guidelines
4@tableofcontents
5
6We very much welcome external developers. Small changes and contributions can be made via pull requests.
7If you have a larger enhancement, bug fix or other contribution in mind, feel free to first create an issue
8to align the development with ongoing activities.
9
10\section Code Formatting
11We support clang-format and provide a style template to automatically format the source code.
12Please refer to the clang-format style sheet in the package root directory for our conventions.
13Or simply rely on clang-format to do the formatting for you.
14
15Note for developers using the *Eclipse IDE*: you can conveniently integrate clang-format (and our .clang-format
16configuration file) in your project using the "CppStyle" plugin (see http://www.cppstyle.com/ for
17detailed information). To automatically format the code according to ct-style, just mark the source-code
18and press *Ctrl+Shift+f*.
19
20
21Example command for running clang-tidy:
22\code
23$ catkin build --no-deps <package_name> -v --make-args clang-tidy
24\endcode
25
26For 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
33CT relies on explicit template instantiation, that means precompilation of the library for
34user-specified state and control dimensions.
35While CT handles things slightly different, please see [this post](https://anteru.net/blog/2008/11/19/318/index.html)
36to learn more about the subject.
37The 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
42The template file has the following placeholders
43
44Placeholder | Description
45-------------- | -------------
46STATE_DIM_PRESPEC | The state dimension
47CONTROL_DIM_PRESPEC | The control dimension
48SCALAR_PRESPEC | The scalar type
49DOUBLE_OR_FLOAT | "true" if the scalar type is double or float
50POS_DIM_PRESPEC | Position dimension for symplectic integrator (default: 0)
51VEL_DIM_PRESPEC | Velocity dimension for symplectic integrator (default: 0)
52
53You 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
60The 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
70which is often the case if no special care is taken.
71
72
73\section other_guidelines Other guidelines
74
75 - Headerguards:
76please use
77\code
78#pragma once
79\endcode
80as 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,
89compare the following bugreport: http://eigen.tuxfamily.org/bz/show_bug.cgi?id=1049
90Currently, the best option is to declare and define shared pointers using CT types as in the following example
91\code{.cpp}
92std::shared_ptr<ct::core::ControlledSystem<state_dim, control_dim>> nonlinearSystem( new SomeClass(...));
93\endcode
94
95*/