Wiki source code of ROS Crash Course
Hide last authors
| author | version | line-number | content |
|---|---|---|---|
| |
3.1 | 1 | (% class="wikigeneratedid" id="HC2B2BCrashCrashCourse" %) |
| 2 | Using C++. | ||
| |
1.1 | 3 | |
| 4 | == Day 1 == | ||
| 5 | |||
| 6 | main function | ||
| 7 | |||
| 8 | g++ source1.cpp -o program1 | ||
| 9 | |||
| |
3.1 | 10 | Paths, "/" and "." and ".." in navigating directories - absolute vs relative |
| |
1.1 | 11 | |
| |
5.1 | 12 | data type - binary itself is meaningless unless you say what information that the binary bits represent |
| |
1.1 | 13 | |
| 14 | declare variables (int, char, string as series of chars) | ||
| 15 | |||
| 16 | statements end with semicolon | ||
| 17 | |||
| |
3.1 | 18 | cstdio library #include |
| |
1.1 | 19 | |
| 20 | calling a function - printf | ||
| 21 | |||
| 22 | if condition block else block (example: do something different based on argc) | ||
| 23 | |||
| 24 | for loop - 3 statements (initialiser, condition, post-loop advancement) and a code block | ||
| 25 | |||
| 26 | Homework: study "while" loop and "switch" statement | ||
| 27 | |||
| 28 | == Day 2 == | ||
| 29 | |||
| 30 | While loop - condition and 1 code block. | ||
| 31 | |||
| 32 | Do while loop - code block then condition. | ||
| 33 | |||
| 34 | While loop = for loop with empty initialiser/advancement statements | ||
| 35 | |||
| |
3.1 | 36 | Switch - match expression's result to case label, execute statements until break. |
| |
1.1 | 37 | |
| |
3.1 | 38 | Switch vs if-else differences - number of times expressions are evaluated |
| |
1.1 | 39 | |
| |
5.1 | 40 | write your own function |
| |
1.1 | 41 | |
| 42 | calling with parameters copied as separate set of var values in function | ||
| 43 | |||
| 44 | classes as blueprints. | ||
| 45 | |||
| 46 | complex var data type - instances of a class all have the same set of fields | ||
| 47 | |||
| 48 | the "." field accessor (var1.func1() etc) | ||
| 49 | |||
| 50 | each instance have it's own separate memory for storing data. | ||
| 51 | |||
| 52 | Example code - fibonacci sequence. | ||
| 53 | |||
| 54 | Value overflow because not enough number of bits to represent large numbers. | ||
| 55 | |||
| |
5.1 | 56 | Various integer data types - specifier in printf |
| 57 | |||
| |
1.1 | 58 | Homework: implement factorial (1 to 20) calculator |
| 59 | |||
| |
3.1 | 60 | in Linux, most things are case-sensitive. (A not equals a) |
| 61 | |||
| |
1.1 | 62 | == Day 3 == |
| 63 | |||
| 64 | factorial printer - 2 approaches: | ||
| 65 | |||
| |
2.1 | 66 | 1. for-loop that goes 1 to 20 and each loop calls fact(n ) function and prints return. |
| |
1.1 | 67 | 1. for-loop that goes 1 to 20 and multiplies once each time and print. |
| 68 | |||
| 69 | set initial values of vars when declaring otherwise initial values are unpredictable | ||
| 70 | |||
| |
3.1 | 71 | factorial function - implemented in recursive way, closer to mathematical definition |
| |
1.1 | 72 | |
| |
3.1 | 73 | stack memory |
| |
1.1 | 74 | |
| |
3.1 | 75 | stack frame to store var values in each function call |
| |
1.1 | 76 | |
| |
3.1 | 77 | stack overflow/crash (segfault) |
| 78 | |||
| 79 | base condition to stop the recursion | ||
| 80 | |||
| 81 | recursive algorithms are common - e.g. when dealing with trees | ||
| 82 | |||
| 83 | spaces in file/directory names and how to navigate - space is special in terminal | ||
| 84 | |||
| 85 | understand names chosen by yourself vs names chosen by other people for your use | ||
| 86 | |||
| 87 | creating ros package - arguments: package name, dependencies | ||
| 88 | |||
| 89 | CMakeLists.txt (.txt file can also be used with other programs) | ||
| 90 | |||
| 91 | cmake = build tool - compile many files in some defined ways | ||
| 92 | |||
| 93 | package.xml - information for ROS | ||
| 94 | |||
| 95 | compiling - carefully read and understand and seek answers to error messages | ||
| 96 | |||
| 97 | msg files - fields declaration with data type | ||
| 98 | |||
| |
4.1 | 99 | create cpp file for a node |
| |
3.1 | 100 | |
| |
4.1 | 101 | quick reading of code for publisher node |
| 102 | |||
| |
3.1 | 103 | homework: implement message subscriber node according to ROS book |