1

00:00:04,437  -->  00:00:08,441
Now we'll be creating the cpp

2

00:00:08,441  -->  00:00:13,200
publisher you know already what is the
publisher its a topic on which the data

3

00:00:13,200  -->  00:00:19,200
will be publishing okay come on to the screen
and here is the method how to create a publisher

4

00:00:19,200  -->  00:00:25,440
using the C plus plus okay it is saying that
here using this link you can download the code

5

00:00:26,160  -->  00:00:33,300
okay we have already created the package inside the
already uh C plus plus file present and what we

6

00:00:33,300  -->  00:00:39,960
will do we have to keep our new code in this SRC
folder in order to maintain a package structure

7

00:00:39,960  -->  00:00:48,420
click right open in terminal and then you can
just paste the link and these file is downloaded

8

00:00:48,420  -->  00:00:56,580
so we also want this package to be opened
in the vs code click right here code space

9

00:00:58,380  -->  00:01:04,320
and here we have let's learn more about
this code so we will just remove that these

10

00:01:04,320  -->  00:01:09,840
two libraries that will allow us to handle
the memory and uh like using the number so

11

00:01:09,840  -->  00:01:18,480
these two libraries are related to the uh
ros2 RCL CPP is a ros client library with

12

00:01:18,480  -->  00:01:26,400
C plus plus and here it is the string that we
string message that we are going to use in our

13

00:01:26,400  -->  00:01:33,480
publisher you can also use the chatgpt to
get the full explanation of the code here we

14

00:01:33,480  -->  00:01:45,196
have the namespace and here is the class minimal  publisher that is here from the RCL CPP : : and the node

15

00:01:45,196  -->  00:01:55,863
here is the function  minimal publisher which is custructor here we are mentioning the node name you can
even change this name here we have the variable

16

00:01:55,863  -->  00:02:02,400
that is initialized with the zero and here we are
creating a publisher that is publishing messages

17

00:02:02,400  -->  00:02:11,760
of string type and the topic name is topic and here
we have a timer and it will be repeating itself

18

00:02:11,760  -->  00:02:17,640
after 500 millisecond node is pointing towards
a minimal publisher and here we have the timer

19

00:02:17,640  -->  00:02:24,000
callback that is declared in the private here is
the definition of the timer callback here we have

20

00:02:24,000  -->  00:02:31,200
the message of type string and the message
dot data so it has an instance data in it so

21

00:02:31,200  -->  00:02:39,360
we are assigning it the string value like a
hello word we're also converting the integer

22

00:02:39,360  -->  00:02:46,980
to the string in order to add the string here
we have the RCL CPP info it will be printing the

23

00:02:46,980  -->  00:02:53,100
information on the terminal then it publishes
the message onto the publisher here we have the three

24

00:02:53,100  -->  00:03:00,420
private member  Declaration the timer and the
publisher and the variable count and the main

25

00:03:00,420  -->  00:03:08,400
it initializes and then creates the instance
of minimal publisher Class feed into the spin

26

00:03:08,400  -->  00:03:15,780
function it will be like circling and processing
ros messages and data until it will be shut down

27

00:03:18,780  -->  00:03:25,620
in order to run this node we will need to
make some changes in package dot XML and

28

00:03:25,620  -->  00:03:33,180
the cmake list so here we have the method
to add the dependencies in the package.xml

29

00:03:33,180  -->  00:03:40,260
file so open up here the package.xml so
we have seen two dependencies in the code

30

00:03:40,860  -->  00:03:51,600
first one is the RCL CPP and the second one is
the STD message so we will be declaring inside

31

00:03:51,600  -->  00:03:59,160
the package dot XML we will just copy and we
will add these lines after the ament cmake

32

00:04:00,120  -->  00:04:06,900
we will come here and hit enter and Ctrl
V so we have added these two dependencies

33

00:04:07,860  -->  00:04:14,700
in our package.xml alright now
it will come to the C make list

34

00:04:17,760  -->  00:04:23,820
all right here we have already the executable
file that was created when we created the

35

00:04:23,820  -->  00:04:33,180
package and now we will just copy and go to
here and here we have the find package line

36

00:04:38,100  -->  00:04:45,780
find package RCL CPP and STD messages
so these are the dependents that we are

37

00:04:45,780  -->  00:04:53,160
mentioning here now we have to declare our
node so here is the method as executable

38

00:04:53,880  -->  00:05:02,340
and there there we are mentioning the name of the
node talker and then the related C plus plus file

39

00:05:02,340  -->  00:05:13,080
ament target dependencies talker depends upon the
RCL CPP and STD messages simply copy this and go

40

00:05:13,080  -->  00:05:20,280
to here paste it here alright so we are giving
it the name talker okay now we have to mention

41

00:05:20,280  -->  00:05:28,020
the name of the node inside the install Target so
that draws to run can find the executable okay so

42

00:05:28,020  -->  00:05:37,080
uh here is the node that we have to mention inside
the install so uh here is the line install we will

43

00:05:37,080  -->  00:05:44,280
just hit enter there is already an executable
file present so we will just enter and talker

44

00:05:46,800  -->  00:05:55,140
all right so we have mentioned our node so now we
have told our package that there is a C plus plus

45

00:05:55,140  -->  00:06:03,000
file and the node name is talker and we have
mentioned the dependencies in package XML file

46

00:06:03,000  -->  00:06:11,040
we will try to build it open the terminal
go to your ros2 workspace colcon

47

00:06:11,820  -->  00:06:18,780
build minus minus sym link minus installed

48

00:06:21,180  -->  00:06:29,520
so it successfully built now we will Source
our local setup install local setup.bash

49

00:06:31,140  -->  00:06:36,840
so if we have source to first base
now we will write ros2 run

50

00:06:37,860  -->  00:06:43,740
package name which is turtlesimbot and if we double tab

51

00:06:44,400  -->  00:06:52,080
it will show us all the executable files
that are available so we will issues topic

52

00:06:56,160  -->  00:07:01,620
alright so it is publishing now
hello world and the number next to it

53

00:07:02,940  -->  00:07:08,640
let's modify this publisher we want a
list in which there are several string

54

00:07:08,640  -->  00:07:14,460
members we will be calling each line one
by one now I will create a list my list

55

00:07:25,920  -->  00:07:30,780
so we will have to declare the
type we will use the static

56

00:07:31,800  -->  00:07:40,020
and then std
double colon vector and inside std

57

00:07:43,320  -->  00:07:46,920
double colon string

58

00:07:49,920  -->  00:07:51,300
and then space my list

59

00:07:56,580  -->  00:08:02,460
okay so here we have declared our list and
now we have to mention that how we are going

60

00:08:02,460  -->  00:08:10,140
to call the member of the list so if we come
here message dot data we are giving the value

61

00:08:10,740  -->  00:08:20,460
call my list my list and then the member so
so we can use the remainder method so count

62

00:08:23,820  -->  00:08:34,860
and percentage and then the
size of my list my list dot size

63

00:08:38,100  -->  00:08:40,320
let's try to build this

64

00:08:44,220  -->  00:08:46,560
now we'll run our node talker

65

00:08:49,440  -->  00:08:55,560
uh it is saying I'm learning growth I haven't
made a mistake that this count variable is not

66

00:08:55,560  -->  00:09:08,880
being increased so previously it was increasing
build it again to node yeah I am learning raw

67

00:09:08,880  -->  00:09:17,160
through and I will learn micros and I will
make my first row a hardware Robot Turtle

68

00:09:17,160  -->  00:09:23,160
Sim oh yes so this is how we can modify any
code let's make it even more good looking

69

00:09:32,760  -->  00:09:40,080
yes and here now we can see that a string
is ending and now it is like printing it

70

00:09:40,080  -->  00:09:48,720
here so what we will do open up an other
terminal see the ros2 topic list

71

00:09:51,720  -->  00:10:01,680
here is the topic name uh topic so we
will try to echo it Ros2 topic echo

72

00:10:04,260  -->  00:10:05,340
and topic name

73

00:10:07,920  -->  00:10:11,460
and here we can see it is printing all the

74

00:10:11,460  -->  00:10:16,980
information here as it was
printing it here
