Wiki source code of Dependencies and Compilation

Version 5.1 by stu120505 on 2020/04/03 00:34

Hide last authors
stu120505 4.1 1 = Building and Running the Pinball Autopilot on the Raspberry Pi =
stu120505 3.1 2
stu120505 5.1 3 The source code lies and building happens inside the folder called {{code language="none"}}pinballProject{{/code}}. For a fresh build, you need a not too old version of {{code language="none"}}make{{/code}}, a C++ compiler (we only tested {{code language="none"}}g++{{/code}}), an internet connection (for downloading the Kieler Compiler), the libraries {{code language="none"}}wiringPi{{/code}} and {{code language="none"}}opencv{{/code}} as well as the command-line tools [[mega-cmd>>url:https://mega.nz/cmd||shape="rect"]] and {{code language="none"}}python2{{/code}}. The tool for mega.nz (and also {{code language="none"}}python2{{/code}}) can be omitted (see below on how to compile without them), everything else except for {{code language="none"}}opencv{{/code}} comes pre-installed with Raspbian. For {{code language="none"}}opencv{{/code}} you need a 4.x version, 4.2.0 ought to work for example. Make sure to enable the option that the entries for {{code language="none"}}pkg-config{{/code}} get configured. It can be built from source on the Raspberry Pi in a few hours, make sure not to use too many threads for compilation because of limited RAM, also perhaps increase the swap.
stu120505 3.1 4
5 With all the pre-requisits met, you can use the {{code language="none"}}Makefile{{/code}} to build everything.
6
stu120505 4.1 7 (% class="wrapped" %)
stu120505 3.1 8 |=(((
9 Command
10 )))|=(((
11 Functionality (All the builds are incremental, i.e. only happen once when the source code is unchanged.)
12 )))
13 |(((
14 {{code language="none"}}
15 make
16 {{/code}}
17 )))|(((
18 same as 
19
20 {{code language="none"}}
21 make build_all
22 {{/code}}
23 )))
24 |(((
25 {{code language="none"}}
26 make build_all
27 {{/code}}
28 )))|(((
29 Build the main executable as well as the tools 
30
31 {{code language="none"}}
32 video_capture
33 {{/code}}
34
35 and 
36
37 {{code language="none"}}
38 calibrate
39 {{/code}}
40
41 .
42 )))
43 |(((
44 {{code language="none"}}
45 make build
46 {{/code}}
47 )))|(((
48 Build the main executable “
49
50 {{code language="none"}}
51 main
52 {{/code}}
53
54 ”.
55 )))
56 |(((
57 {{code language="none"}}
58 make run
59 {{/code}}
60 )))|(((
61 Build and execute the main executable.
62 )))
63 |(((
64 {{code language="none"}}
65 make ...xyz
66 {{/code}}
67 )))|(((
68 Make file called “
69
70 {{code language="none"}}
71 ...xyz
72 {{/code}}
73
74 ”, if a recipe exists. Most notably for 
75
76 {{code language="none"}}
77 ...xyz
78 {{/code}}
79
80 ~= 
81
82 {{code language="none"}}
83 calibrate
84 {{/code}}
85 )))
86 |(((
87 {{code language="none"}}
88 make capture
89 {{/code}}
90 )))|(((
91 Build {{code language="none"}}video_capture{{/code}} and execute it. This tool can only be executed on the Pi and can record a video
92 during manual gameplay which is then uploaded to mega.nz with a new numerical file-name.
93 )))
94 |(((
95 {{code language="none"}}make get{{/code}}
96 )))|(((
97 Executes a python script that can (interactively) get a recorded video from the mega.nz folder.
98 Intended for getting video input files transferred to a different machine (not the Pi) for testing the image detection.
99 )))
100 |(% colspan="1" %)(% colspan="1" %)
101 (((
102 {{code language="none"}}
103 make clean
104 {{/code}}
105 )))|(% colspan="1" %)(% colspan="1" %)
106 (((
107 Removes all generated files except for
108
109 {{code language="none"}}
110 _pi_logged_in
111 {{/code}}
112
113 , downloaded videos and the downloaded Kieler Compiler.
114 )))
115 |(% colspan="1" %)(% colspan="1" %)
116 (((
117 {{code language="none"}}
118 make clean_all
119 {{/code}}
120 )))|(% colspan="1" %)(% colspan="1" %)
121 (((
122 Like
123
124 {{code language="none"}}
125 make clean
126 {{/code}}
127
128 , but without the exceptions. This will delete everything in the folder 
129
130 {{code language="none"}}
131 video
132 {{/code}}
133
134 !
135 )))
136
137 For instructions on how to use the {{code language="none"}}./calibrate{{/code}}, see [[doc:World Coordinate System]].
138
139 Working without mega.nz (and python): On the pi, you need to create a file called {{code language="none"}}_pi_logged_in{{/code}} (e.g. with {{code language="none"}}touch _pi_logged_in{{/code}}) before calling {{code language="none"}}make{{/code}} for the first time. On a different machine, you don’t need to do this. You cannot use {{code language="none"}}make capture{{/code}} or {{code language="none"}}make get{{/code}} without these command-line tools.
140
141 If future updates of {{code language="none"}}mega-cmd{{/code}} or the command-line Kieler Compiler {{code language="none"}}kico.jar{{/code}} include relevant breaking changes, you might need to resolve those problems (work without {{code language="none"}}mega-cmd{{/code}} or acquire a {{code language="none"}}kico.jar{{/code}} from around March 2020).
142
143 = Setting up the Pi for Better Real Time Performance =
144
145 The program will stick its latency-sensitive threads for controlling the IO pins and for image processing to the cores 3 and 4 of the 4-core Raspberry Pi. To ensure best real-time performance, please configure the kernel parameter (% style="color: rgb(0,0,0);font-family: SFMono-Medium , SF Mono , Segoe UI Mono , Roboto Mono , Ubuntu Mono , Menlo , Courier , monospace;" %)2,3{{code language="none"}}isolcpus={{/code}}(%%) (they count from 0) to the file {{code language="none"}}/boot/cmdline.txt{{/code}} and reboot. This will make sure that the operating system doesn’t schedule any tasks on those cores.
146
147 = Building and Running on Any Other Linux Machine =
148
149 The program can be built and partially run on other machines. There you potentially need to install all the requirements yourself. Just {{code language="none"}}wiringPi{{/code}} is not needed. Also don’t use a machine where the current user is called {{code language="none"}}pi{{/code}}. We’ve observed problems with a too old version for {{code language="none"}}make{{/code}}, for example 4.2 should be new enough. Possibly {{code language="none"}}python2{{/code}} needs to be installed on your machine. Compared to a Raspberry Pi, compilation of {{code language="none"}}opencv{{/code}} on your machine is going to be a lot more fun (way faster and no issues with too little RAM) Regarding versions, see the relevant section above, note that {{code language="none"}}pkg-config{{/code}} is needed, too, in case you don’t have that already.
150
151 Running works like on the Pi. The main program will prompt you for the name (without extension) of a video file in the {{code language="none"}}video{{/code}} folder. Make sure to get some file, at the time of this writing there is a file called {{code language="none"}}1{{/code}} that you can get via {{code language="none"}}make get{{/code}} as well as a few more named files that were created before we had the {{code language="none"}}make capture{{/code}} command.
152
153 After choosing a video file, the program starts using the video input in “real time”; since things are not really real-time, the controller does not work too well. (Simulating time properly is not fundamentally a problem but something we didn’t finish implementing.) This means you can mostly ignore the debug-printouts about ticks happening. What you can do is test the image processing / ball detection. This works better than on the Pi, because we are providing controls for pausing or changing the playback speed.
154
stu120505 4.1 155 (% class="wrapped" %)
stu120505 3.1 156 |=(((
157 Key
158 )))|=(((
159 Playback effect
160 )))
161 |(((
162 {{code language="none"}}
163 <space>
164 {{/code}}
165 )))|(((
166 play/pause
167 )))
168 |(((
169 {{code language="none"}}
170 +
171 {{/code}}
172 )))|(((
173 increase playback speed ×2
174 )))
175 |(((
176 {{code language="none"}}
177 -
178 {{/code}}
179 )))|(((
180 decrease playback speed ×0.5
181 )))
182 |(% colspan="1" %)(% colspan="1" %)
183 (((
184 {{code language="none"}}
185 .
186 {{/code}}
187 )))|(% colspan="1" %)(% colspan="1" %)
188 (((
189 while paused, advance by one frame
190 )))
191
192 If you recalibrate the coordinate system on the Pi, you might want to transfer the config file for the coordinate system (however there is nothing really depending on the coordinate transformation being correct inside the image detection anyways).