-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpresentation.html
2817 lines (2286 loc) · 150 KB
/
presentation.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<!--
Copyright 2010 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Original slides: Marcin Wichary ([email protected])
Modifications: Ernest Delgado ([email protected])
Alex Russell ([email protected])
landslide modifications: Adam Zapletal ([email protected])
Nicolas Perriault ([email protected])
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<title>Lesson 2: ROS API and Build Tools</title>
<!-- Styles -->
<link rel="stylesheet" media="print" href="file:///usr/local/lib/python2.7/dist-packages/landslide-1.1.6-py2.7.egg/landslide/themes/default/css/print.css">
<link rel="stylesheet" media="screen, projection" href="file:///usr/local/lib/python2.7/dist-packages/landslide-1.1.6-py2.7.egg/landslide/themes/default/css/screen.css">
<!-- /Styles -->
<!-- Javascripts -->
<script type="text/javascript" src="file:///usr/local/lib/python2.7/dist-packages/landslide-1.1.6-py2.7.egg/landslide/themes/default/js/slides.js"></script>
<!-- /Javascripts -->
</head>
<body>
<div id="blank"></div>
<div class="presentation">
<div id="current_presenter_notes">
<div id="presenter_note"></div>
</div>
<div class="slides">
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-1">
<div class="inner">
<header><h1>Lesson 2: ROS API and Build Tools</h1></header>
<section><ul class="simple">
<li>This lesson is intended to be an hour long crash course in the ROS 2 Dashing API and build tools.</li>
<li>After this lesson you should be able to code and build a rudimentary ROS 2 application.</li>
<li>It should be noted, that since this is a "crash course" we are giving you a pre-configured Docker environment call ADE.<ul>
<li>We will not cover setting up the ROS environment.</li>
<li>This will be left as an exercise to the reader.</li>
<li>As much as possible we have used the tooling available <em>ROS 2 Dashing desktop full</em> installation.</li>
</ul>
</li>
<li>This crash course was written for ROS 2 Dashing.<ul>
<li>ROS 2 Foxy is about to be released.</li>
<li>This release is the first major, stable, release of ROS 2.</li>
</ul>
</li>
<li>The next lesson, lesson 3, will show you how to use the ROS 2 command line interface.</li>
</ul></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
1/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-2">
<div class="inner">
<header><h1>Before We Begin...</h1></header>
<section><img alt="file:///home/kscottz/Code/ros2_documentation/source/Related-Projects/AutowareLectureSeries/./images/jfk.jpg" class="align-center" src="file:///home/kscottz/Code/ros2_documentation/source/Related-Projects/AutowareLectureSeries/./images/jfk.jpg" style="width: 500px;" />
<p><em>"We choose to go to the moon, not because it is easy, but because it is hard."</em></p>
<p><strong>ROS is hard. There are many topics you must learn to become a skilled robotocist. We try to make it easy, but be aware the path ahead is difficult. You will get stuck. You will get frustrated. You will need help</strong></p>
<p><em>The good news is, all of this is OK and completely normal; there are resources out there to help!</em></p></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
2/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-3">
<div class="inner">
<header><h1>Getting Help!</h1></header>
<section><p><strong>ROS has a ton of resources to help you be succeed. You should be aware of these before you begin.</strong></p>
<ul class="simple">
<li>We have our own QA website like Stack Overflow called ROS Answers.<ul>
<li><a class="reference external" href="https://answers.ros.org/questions/">http://answers.ros.org</a></li>
<li>ROS answers actually predates the rise of Stack Overflow!</li>
</ul>
</li>
<li>Check out ROS Discourse. It is the community hub for news and discussion.<ul>
<li><a class="reference external" href="https://discourse.ros.org/">https://discourse.ros.org/</a></li>
<li><em>DO NOT</em> ask questions on discourse.</li>
</ul>
</li>
<li>We have a very large ROS wiki. It is mostly ROS 1.<ul>
<li><a class="reference external" href="http://wiki.ros.org/">http://wiki.ros.org/</a></li>
<li>Most of the content is still highly useful.</li>
</ul>
</li>
<li>Most of this talk comes from the ROS 2 documentation.<ul>
<li><a class="reference external" href="https://index.ros.org/doc/ros2/">https://index.ros.org/doc/ros2/</a></li>
<li>This is probably where you should look.</li>
</ul>
</li>
</ul></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
3/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-4">
<div class="inner">
<header><h1>Other and/or Unofficial Resources</h1></header>
<section><ul class="simple">
<li>The ROS / Robotics Sub Reddits are Great!</li>
<li>There is an "unofficial" <a class="reference external" href="https://discord.com/invite/HnVcz5a">ROS Discord</a>.<ul>
<li>Please try using ROS Answers first.</li>
</ul>
</li>
<li>We have a yearly ROS developers conference <a class="reference external" href="https://roscon.ros.org/2020/">ROSCon.</a><ul>
<li>Most of old talks are free on the web.</li>
</ul>
</li>
<li>We're not big on social media but we're busy on the twitter.<ul>
<li><a class="reference external" href="https://twitter.com/openroboticsorg">@OpenRoboticsOrg</a> is a bit more active.</li>
<li><a class="reference external" href="https://twitter.com/rosorg">@ROSOrg</a> "Official" ROS announcements.</li>
</ul>
</li>
<li><a class="reference external" href="https://www.openrobotics.org/">Open Robotics</a> is the non-profit that administers ROS and Ignition Gazebo.<ul>
<li>We take donations and take contract work from time to time.</li>
</ul>
</li>
</ul></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
4/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-5">
<div class="inner">
<header><h1>History of ROS</h1></header>
<section><p><em>PR2 Image</em></p>
<ul class="simple">
<li>Let's go back to the early 2000's.</li>
<li>Open Source is growing, but Windows dominates.</li>
<li>What about Robots?:<ul>
<li>Robots are expensive and mainly for mass manufacturing and R&D.</li>
<li>Mostly is "real-time" control systems. Just make arms move the same way over and over.</li>
<li>Not a lot of Open Source.</li>
</ul>
</li>
<li>~2006, Former Google VPs decide to work on Robots.<ul>
<li>Create a company called <a class="reference external" href="https://en.wikipedia.org/wiki/Willow_Garage">Willow Garage.</a></li>
<li>From this org we get OpenCV, PCL, ROS, PR2 Robot, and many spin outs.</li>
</ul>
</li>
<li>~2012 Willow Garage folds, Open Robotics emerges.<ul>
<li>2017 ROS 2 Begins to move ROS out of the lab (it was already out of the lab).</li>
<li>Address security and robustness concerns.</li>
<li>Add RTOS support and support other OS's.</li>
</ul>
</li>
</ul></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
5/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-6">
<div class="inner">
<header><h1>Concepts that Motivate ROS</h1></header>
<section><p>ROS's design was informed by <em>design patterns</em> that were successfully used in prior robotic systems. We can't cover each of these in detail, but reading about them will help you better understand ROS.</p>
<ul class="simple">
<li><strong>Processes / Threads ==> ROS Nodes</strong> -- A ROS Node is a self contained execution process, like a program. ROS is really a lot of tooling for running a bunch of programs in parallel.</li>
<li><strong>Buses / PubSub ==> ROS Topics</strong> -- The backbone of ROS is a <a class="reference external" href="https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern">publish/subscribe bus</a>. If you have ever used ZeroMQ, RabbitMQ, or ModBus, ROS topics are very similar.</li>
<li><strong>Serialization ==> ROS Messages / ROS Bags</strong> -- ROS uses a predefined messages to move data over topics. This allows data to be <a class="reference external" href="https://en.wikipedia.org/wiki/Serialization">serialized</a> between nodes in different programming languages. An analog would be Google Protocol Buffers. ROS can be written to file, called a bag. A good analogy is a python pickle file.</li>
<li><strong>Black Board Pattern ==> ROS Params</strong> -- A <a class="reference external" href="https://en.wikipedia.org/wiki/Blackboard_(design_pattern)">blackboard</a> is a way to create global variables between nodes/programs. A good analogy would be Redis.</li>
<li><strong>Synchronous Remote Procedure Call (RPC) ==> ROS Services</strong> -- A ROS service is a program that can be called by another program. The caller is blocked until the callee returns. This is formerly called a <a class="reference external" href="https://en.wikipedia.org/wiki/Remote_procedure_call">remote procedure call</a>.</li>
<li><strong>Asynchronous Remote Procedure Call (RPC) ==> ROS Actions</strong> -- A ROS action is a program that can be called by another program. The caller is <strong>not</strong> blocked until the callee returns.</li>
<li><strong>State Machines ==> ROS Life cycles</strong> -- <a class="reference external" href="https://en.wikipedia.org/wiki/Finite-state_machine">State machines</a> are a tool to move between states, or modes. State machines are a useful way to model machine behavior.</li>
<li><strong>Matrix Math for 3D Operations ==> URDF and TF</strong> -- TF, short for transform, and URDF (universal robot description format) are tools for automatically <a class="reference external" href="https://en.wikipedia.org/wiki/Matrix_(mathematics)">calculating robot geometry using matrix math</a> .</li>
</ul></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
6/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-7">
<div class="inner">
<header><h1>Jumping in the Deep End</h1></header>
<section><p>Let's start ADE and install / update deps</p>
<ul class="simple">
<li>First things first, let's make sure everything is ready to go.</li>
<li>Now is a good time to hit pause on the video make sure you have installed the requirements.</li>
<li>Install ADE as per Autoware Instructions.</li>
<li>Now were going to update the system, install ROS dashing, and a couple tools.</li>
</ul>
<pre><span></span>ade start
ade enter
<span class="nb">source</span> /opt/ros/dashing/setup.bash
sudo apt update
sudo apt install ros-dashing-turtlesim
sudo apt install ros-dashing-rqt-*
sudo apt-install byobu
</pre>
<p>You should now be ready for the class!</p></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
7/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-8">
<div class="inner">
<header><h1>Some Nomenclature as we Begin</h1></header>
<section><ul class="simple">
<li><strong>Package</strong> -- A collection of code.</li>
<li><strong>Workspace</strong> -- A workspace is a collection of source code / ROS packages that will run on a robot. It has a uniform directory structure. A good analogy is python virtual env, or "project" in most IDEs.</li>
<li><strong>Overlay</strong> -- A second workspace with more/different/new packages. If there are multiple versions of a package/code then the one at the bottom is used.</li>
<li><strong>Underlay</strong> -- The workspace, underneath an overlay, we're aware this is confusing.</li>
<li><strong>Colcon</strong> -- The ROS 2 build tool. Think of it as a layer above CMake/Make/SetupTools that helps these tools work together smoothly.</li>
</ul>
<p>This is a bit confusing. You may ask yourself why we have our own build tool. The short of it is that the ROS ecosystem consists of tens of thousands of developers, working on thousands of packages, across a handful of platforms, using multiple languages. We needed a flexible system to build code and one didn't exist at the time, and still doesn't exist.</p></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
8/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-9">
<div class="inner">
<header><h1>Let's Get Started</h1></header>
<section><p>As we're diving headfirst into ROS our first job is to checkout a repository of examples and build it. Roughly the steps to do this are as follows.</p>
<ul class="simple">
<li>Fire up a terminal manager inside the container. I use byobu. You can use whatever you want. You can also fire up 3 real terminals and call <cite>ade enter</cite> on them.</li>
<li>Source the ROS setup.bash file so we have the right version of ROS in our path.</li>
<li>Make a workspace called <cite>ros2_example_ws</cite>. We usually use <cite>_ws</cite> to indicate a workspace.</li>
<li>Clone an example repository and change to the dashing branch.<ul>
<li>Generally ROS repos have a branch per release.</li>
</ul>
</li>
<li>Use Colcon to build the source.</li>
</ul>
<pre><span></span><span class="nb">source</span> /opt/ros/dashing/setup.bash
mkdir -p ~/ros2_example_ws/src
<span class="nb">cd</span> ~/ros2_example_ws
git clone https://github.com/ros2/examples src/examples
<span class="nb">cd</span> ~/ros2_example_ws/src/examples/
git checkout dashing
<span class="nb">cd</span> ~/ros2_example_ws
colcon build --symlink-install
</pre></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
9/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-10">
<div class="inner">
<header><h1>Nodes and Publishers</h1></header>
<section><ul class="simple">
<li>The core of ROS is the ROS pub/sub bus. In ROS parlance this is called <cite>topic</cite>.<ul>
<li>A topic has a <cite>message type</cite> that is published on the bus. These messages are defined in a yaml file and define the serialization/deserialization format for ROS messages.</li>
<li>ROS has a lot of built in message types. There are lots of pre-defined messages for controlling a robot, distributing sensor data, and understanding the geometry of your robot.</li>
<li>ROS publishers produce messages and slowly or as quickly as they need to.</li>
<li>A ROS subscriber, <cite>subscribes</cite> to a <cite>topic</cite> and then does things with the information.</li>
</ul>
</li>
<li>ROS has lots of built-in tools for managing topics. You can list them, echo (watch) them, rename them (called remap), and store them to file (called bagging).</li>
<li>ROS <cite>Nodes</cite> are basically programs, or processes that run concurrently on ROS.<ul>
<li>A ROS node can publish to one or more topics.</li>
<li>That same node can subscribe to other topics.</li>
<li>Many nodes subscribe to topics, process the data, and publish the results.</li>
<li>ROS has tooling to start and stop multiple nodes at the same time.</li>
</ul>
</li>
</ul></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
10/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-11">
<div class="inner">
<header><h1>Preparing to Run a ROS Node</h1></header>
<section><ul class="simple">
<li>Open a new terminal, in Byobu you can do this by pressing <cite>F2</cite>.</li>
<li>First we need to source the <cite>setup.bash</cite> file for our <cite>workspace.</cite> This will help ROS find the programs we built.<ul>
<li><cite>source ./ros2_example_ws/install/setup.bash</cite></li>
<li>Protip: you can find any file using <cite>find ./ -name <file name></cite></li>
</ul>
</li>
<li><strong>ROS Best Practice</strong> <em>ALWAYS</em> build and execute in different terminals.<ul>
<li>The build terminal should source the global ROS setup.bash file (i.e. /opt/ros/dashing/setup.bash).</li>
<li>The execution terminal should source the <cite>setup.bash</cite> of your workspace</li>
<li>This is a common failure mode for new users. If something seems weird or funky. Create a new terminal and source the correct bash file.</li>
</ul>
</li>
</ul></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
11/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-12">
<div class="inner">
<header><h1>Let's Run a Simple C++ Publisher Node.</h1></header>
<section><ul class="simple">
<li>ROS has an advanced, and fairly complex CLI interface. We'll cover it in depth in our next lesson.</li>
<li>We are going to ask ros to run the EXECUTABLE <cite>publisher_lambda</cite> in our WORKSPACE named <cite>examples_rclcpp_minimal_publisher</cite>.</li>
<li>The syntax for doing this is <cite>ros2 run <WORKSPACE> <EXECUTABLE></cite></li>
<li>To run our publishing node, let's run the following command in our execution terminal: <cite>ros2 run examples_rclcpp_minimal_publisher publisher_lambda</cite></li>
<li>If everything works you should see something like this:</li>
</ul>
<pre><span></span>kscottz@ade:~$ ros2 run examples_rclcpp_minimal_publisher publisher_lambda
<span class="o">[</span>INFO<span class="o">]</span> <span class="o">[</span>minimal_publisher<span class="o">]</span>: Publishing: <span class="s1">'Hello, world! 0'</span>
<span class="o">[</span>INFO<span class="o">]</span> <span class="o">[</span>minimal_publisher<span class="o">]</span>: Publishing: <span class="s1">'Hello, world! 1'</span>
<span class="o">[</span>INFO<span class="o">]</span> <span class="o">[</span>minimal_publisher<span class="o">]</span>: Publishing: <span class="s1">'Hello, world! 2'</span>
<span class="o">[</span>INFO<span class="o">]</span> <span class="o">[</span>minimal_publisher<span class="o">]</span>: Publishing: <span class="s1">'Hello, world! 3'</span>
...
</pre>
<ul class="simple">
<li>To exit the program press <cite>CTRL-C</cite></li>
</ul></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
12/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-13">
<div class="inner">
<header><h1>What just happened?</h1></header>
<section><ul class="simple">
<li>We just executed a ROS node that publishes a simple string message to a topic called <cite>/topic</cite> twice a second.</li>
<li>I'll show you how I know this with some tools. We'll cover these tools in detail next time.</li>
</ul>
<pre><span></span>kscottz@ade:~$ ros2 topic list
/parameter_events
/rosout
/topic
kscottz@ade:~$ ros2 topic <span class="nb">echo</span> /topic
data: Hello, lambda world! <span class="m">63</span>
---
data: Hello, lambda world! <span class="m">64</span>
---
data: Hello, lambda world! <span class="m">65</span>
---
kscottz@ade:~$ ros2 topic hz /topic
average rate: <span class="m">2</span>.000
min: <span class="m">0</span>.500s max: <span class="m">0</span>.500s std dev: <span class="m">0</span>.00011s window: <span class="m">4</span>
kscottz@ade:~$
</pre></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
13/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-14">
<div class="inner">
<header><h1>Digging into the Code</h1></header>
<section><ul class="simple">
<li>Let's take a look at the code. Like a lot of software there is more than one way to skin a cat. Let's look at the member function approach.</li>
<li>Using your favorite editor open the following source file, <cite>./ros2_example_ws/src/examples/rclcpp/minimal_publisher/member_function.cpp</cite></li>
<li><strong>rclcpp</strong> is an abbreviation of "ROS Client Library C++", its the ROS C++ API</li>
</ul>
<table class="highlighttable"><tr><td class="linenos"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15</pre></td><td class="code"><pre><span></span><span class="cp">#include</span> <span class="cpf"><chrono></span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf"><memory></span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">"rclcpp/rclcpp.hpp" // THIS the header file for ROS 2 C++ API</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">"std_msgs/msg/string.hpp" // This is header for the messages we</span><span class="cp"></span>
<span class="c1">// want to user</span>
<span class="c1">// These are usually auto generated.</span>
<span class="k">using</span> <span class="k">namespace</span> <span class="n">std</span><span class="o">::</span><span class="n">chrono_literals</span><span class="p">;</span>
<span class="cm">/* This example creates a subclass of Node and uses std::bind() to register a</span>
<span class="cm">* member function as a callback from the timer. */</span>
<span class="c1">// Make a class called Minimal Publisher</span>
<span class="k">class</span> <span class="nc">MinimalPublisher</span> <span class="o">:</span> <span class="k">public</span> <span class="n">rclcpp</span><span class="o">::</span><span class="n">Node</span>
<span class="c1">// Have it inherit from the ROS Node Class</span>
</pre>
</td></tr></table></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
14/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-15">
<div class="inner">
<header><h1>Let's Build our Node's Constructor</h1></header>
<section><ul class="simple">
<li>The <cite>MinimalPublisher</cite> constructor inherits from the RCLCPP Base Class, gives the name a node, and sets our counter.</li>
<li>The next line creates a publisher object that publishes <cite>std_msgs::msg</cite>.</li>
<li>The constructor then creates a callback to the function <cite>timer_callback</cite> that gets called every 500ms.</li>
</ul>
<pre><span></span><span class="k">class</span> <span class="nc">MinimalPublisher</span> <span class="o">:</span> <span class="k">public</span> <span class="n">rclcpp</span><span class="o">::</span><span class="n">Node</span> <span class="c1">// Inherit from ROS Node</span>
<span class="p">{</span>
<span class="k">public</span><span class="o">:</span>
<span class="n">MinimalPublisher</span><span class="p">()</span>
<span class="o">:</span> <span class="n">Node</span><span class="p">(</span><span class="s">"minimal_publisher"</span><span class="p">),</span> <span class="n">count_</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span> <span class="c1">// Set the node name</span>
<span class="p">{</span> <span class="c1">//Create a publisher that pushes std_msgs::msg to the topic "topic"</span>
<span class="n">publisher_</span> <span class="o">=</span> <span class="k">this</span><span class="o">-></span><span class="n">create_publisher</span><span class="o"><</span><span class="n">std_msgs</span><span class="o">::</span><span class="n">msg</span><span class="o">::</span><span class="n">String</span><span class="o">></span><span class="p">(</span><span class="s">"topic"</span><span class="p">,</span> <span class="mi">10</span><span class="p">);</span>
<span class="n">timer_</span> <span class="o">=</span> <span class="k">this</span><span class="o">-></span><span class="n">create_wall_timer</span><span class="p">(</span> <span class="c1">// Call timer_callback every 500ms</span>
<span class="mi">500</span><span class="n">ms</span><span class="p">,</span> <span class="n">std</span><span class="o">::</span><span class="n">bind</span><span class="p">(</span><span class="o">&</span><span class="n">MinimalPublisher</span><span class="o">::</span><span class="n">timer_callback</span><span class="p">,</span> <span class="k">this</span><span class="p">));</span>
<span class="p">}</span>
</pre></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
15/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-16">
<div class="inner">
<header><h1>Now to Handle the Callback</h1></header>
<section><ul class="simple">
<li>In the callback function we do the following:<ul>
<li>Create the ROS <cite>std_msgs::msg::String()</cite> to send to our topic.</li>
<li>Construct the message that will be pushed to the ROS Topic</li>
<li>Log the results.</li>
<li>Actually publish the newly constructed message.</li>
</ul>
</li>
</ul>
<pre><span></span><span class="k">private</span><span class="o">:</span>
<span class="kt">void</span> <span class="n">timer_callback</span><span class="p">()</span>
<span class="p">{</span>
<span class="k">auto</span> <span class="n">message</span> <span class="o">=</span> <span class="n">std_msgs</span><span class="o">::</span><span class="n">msg</span><span class="o">::</span><span class="n">String</span><span class="p">();</span> <span class="c1">// create message</span>
<span class="n">message</span><span class="p">.</span><span class="n">data</span> <span class="o">=</span> <span class="s">"Hello, world! "</span> <span class="o">+</span> <span class="n">std</span><span class="o">::</span><span class="n">to_string</span><span class="p">(</span><span class="n">count_</span><span class="o">++</span><span class="p">);</span> <span class="c1">// Fill it up</span>
<span class="n">RCLCPP_INFO</span><span class="p">(</span><span class="k">this</span><span class="o">-></span><span class="n">get_logger</span><span class="p">(),</span> <span class="s">"Publishing: '%s'"</span><span class="p">,</span> <span class="n">message</span><span class="p">.</span><span class="n">data</span><span class="p">.</span><span class="n">c_str</span><span class="p">());</span> <span class="c1">// Log it</span>
<span class="n">publisher_</span><span class="o">-></span><span class="n">publish</span><span class="p">(</span><span class="n">message</span><span class="p">);</span> <span class="c1">// Publish</span>
<span class="p">}</span>
<span class="c1">// Create our private member variables.</span>
<span class="n">rclcpp</span><span class="o">::</span><span class="n">TimerBase</span><span class="o">::</span><span class="n">SharedPtr</span> <span class="n">timer_</span><span class="p">;</span>
<span class="n">rclcpp</span><span class="o">::</span><span class="n">Publisher</span><span class="o"><</span><span class="n">std_msgs</span><span class="o">::</span><span class="n">msg</span><span class="o">::</span><span class="n">String</span><span class="o">>::</span><span class="n">SharedPtr</span> <span class="n">publisher_</span><span class="p">;</span>
<span class="kt">size_t</span> <span class="n">count_</span><span class="p">;</span>
</pre></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
16/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-17">
<div class="inner">
<header><h1>Finally, Let's Create the Main for our Node</h1></header>
<section><ul class="simple">
<li>This last little bit creates the main node entry point.</li>
<li>Initializes <cite>rcpcpp</cite> with the values from the command line.</li>
<li>Run's the MinimalPublisher, until a terminate is given</li>
<li>Finally the node cleans up everything and exits.</li>
</ul>
<pre><span></span><span class="kt">int</span> <span class="nf">main</span> <span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span> <span class="n">argv</span><span class="p">[])</span>
<span class="p">{</span>
<span class="n">rclcpp</span><span class="o">::</span><span class="n">init</span><span class="p">(</span><span class="n">argc</span><span class="p">,</span> <span class="n">argv</span><span class="p">);</span> <span class="c1">// Init RCL</span>
<span class="n">rclcpp</span><span class="o">::</span><span class="n">spin</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">make_shared</span><span class="o"><</span><span class="n">MinimalPublisher</span><span class="o">></span><span class="p">());</span><span class="c1">// Run the minimal publish</span>
<span class="n">rclcpp</span><span class="o">::</span><span class="n">shutdown</span><span class="p">();</span> <span class="c1">// Cleanup on shut down.</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</pre></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
17/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-18">
<div class="inner">
<header><h1>Exercise: Modify and Build this Node</h1></header>
<section><ul class="simple">
<li>Let's try to make a few modification to our node for practice.<ul>
<li>Make it run at 10Hz (100ms) instead of 500.</li>
<li>Change the topic name from "topic" to "greetings."</li>
<li>Change the message "Hello Open Road."</li>
<li>Change the node name from <cite>minimal_publisher</cite>, <cite>revenge_of_minimal_publisher</cite></li>
</ul>
</li>
<li>Once you make these changes<ul>
<li>Save the file.</li>
<li>Toggle over to your execution window run</li>
<li>Run <cite>colcon build</cite></li>
<li>In your execution window run <cite>ros2 run examples_rclcpp_minimal_publisher publisher_member_function</cite></li>
</ul>
</li>
</ul></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
18/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-19">
<div class="inner">
<header><h1>Let's Try Subscribing.</h1></header>
<section><ul class="simple">
<li>The pattern here is similar to publishing.</li>
<li>We basically inherit from the Node class, and define the topic and message we want.</li>
<li>Whenever that topic is published we hit a callback.</li>
<li>If everything is correctly configured the file is at<ul>
<li>/ros2_example_ws/src/examples/rclcpp/minimal_subscriber/member_function.cpp</li>
</ul>
</li>
</ul>
<pre><span></span><span class="cp">#include</span> <span class="cpf">"rclcpp/rclcpp.hpp"</span><span class="cp"></span>
<span class="cp">#include</span> <span class="cpf">"std_msgs/msg/string.hpp"</span><span class="cp"></span>
<span class="k">using</span> <span class="n">std</span><span class="o">::</span><span class="n">placeholders</span><span class="o">::</span><span class="n">_1</span><span class="p">;</span>
<span class="c1">// Again we inherit the public interface of a ROS node.</span>
<span class="k">class</span> <span class="nc">MinimalSubscriber</span> <span class="o">:</span> <span class="k">public</span> <span class="n">rclcpp</span><span class="o">::</span><span class="n">Node</span>
<span class="p">{</span>
<span class="k">public</span><span class="o">:</span>
<span class="n">MinimalSubscriber</span><span class="p">()</span> <span class="c1">// Construct our node, calling it minimal_subscriber</span>
<span class="o">:</span> <span class="n">Node</span><span class="p">(</span><span class="s">"minimal_subscriber"</span><span class="p">)</span>
<span class="p">{</span> <span class="c1">// Create a subscription, to messages of the format stdmsg:msg:String</span>
<span class="n">subscription_</span> <span class="o">=</span> <span class="k">this</span><span class="o">-></span><span class="n">create_subscription</span><span class="o"><</span><span class="n">std_msgs</span><span class="o">::</span><span class="n">msg</span><span class="o">::</span><span class="n">String</span><span class="o">></span><span class="p">(</span>
<span class="c1">// Subscribe to the topic, "topic" and set a callback for when things are pub'd</span>
<span class="s">"topic"</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="n">std</span><span class="o">::</span><span class="n">bind</span><span class="p">(</span><span class="o">&</span><span class="n">MinimalSubscriber</span><span class="o">::</span><span class="n">topic_callback</span><span class="p">,</span> <span class="k">this</span><span class="p">,</span> <span class="n">_1</span><span class="p">));</span>
<span class="p">}</span>
<span class="p">...</span>
</pre></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">
Source: <a href="Lesson2Basics.rst">Lesson2Basics.rst</a>
</aside>
<aside class="page_number">
19/49
</aside>
</footer>
</div>
</div>
<!-- slide source: Lesson2Basics.rst -->
<div class="slide-wrapper">
<div class="slide slide-20">
<div class="inner">
<header><h1>More Subscriber</h1></header>
<section><ul class="simple">
<li>The subscriber node looks fairly similar to our publisher but instead of publishing on a regular callback, we get a callback when a new message hits our topic.</li>
</ul>
<table class="highlighttable"><tr><td class="linenos"><pre> 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19</pre></td><td class="code"><pre><span></span><span class="k">private</span><span class="o">:</span>
<span class="c1">// Whenever we get a new messaged published on our topic</span>
<span class="c1">// this callback will be executed.</span>
<span class="kt">void</span> <span class="n">topic_callback</span><span class="p">(</span><span class="k">const</span> <span class="n">std_msgs</span><span class="o">::</span><span class="n">msg</span><span class="o">::</span><span class="n">String</span><span class="o">::</span><span class="n">SharedPtr</span> <span class="n">msg</span><span class="p">)</span> <span class="k">const</span>
<span class="p">{</span>
<span class="c1">// Log the message that we are subscribed to</span>
<span class="n">RCLCPP_INFO</span><span class="p">(</span><span class="k">this</span><span class="o">-></span><span class="n">get_logger</span><span class="p">(),</span> <span class="s">"I heard: '%s'"</span><span class="p">,</span> <span class="n">msg</span><span class="o">-></span><span class="n">data</span><span class="p">.</span><span class="n">c_str</span><span class="p">());</span>
<span class="p">}</span>
<span class="n">rclcpp</span><span class="o">::</span><span class="n">Subscription</span><span class="o"><</span><span class="n">std_msgs</span><span class="o">::</span><span class="n">msg</span><span class="o">::</span><span class="n">String</span><span class="o">>::</span><span class="n">SharedPtr</span> <span class="n">subscription_</span><span class="p">;</span>
<span class="p">};</span>
<span class="c1">// This is effectively the same boiler plate from last time.</span>
<span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="o">*</span> <span class="n">argv</span><span class="p">[])</span>
<span class="p">{</span>
<span class="n">rclcpp</span><span class="o">::</span><span class="n">init</span><span class="p">(</span><span class="n">argc</span><span class="p">,</span> <span class="n">argv</span><span class="p">);</span>
<span class="n">rclcpp</span><span class="o">::</span><span class="n">spin</span><span class="p">(</span><span class="n">std</span><span class="o">::</span><span class="n">make_shared</span><span class="o"><</span><span class="n">MinimalSubscriber</span><span class="o">></span><span class="p">());</span>
<span class="n">rclcpp</span><span class="o">::</span><span class="n">shutdown</span><span class="p">();</span>
<span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
</pre>
</td></tr></table></section>
</div>
<div class="presenter_notes">
<header><h1>Presenter Notes</h1></header>
<section>
</section>
</div>
<footer>
<aside class="source">