Now we are going to write the code for the subscriber and we are not going to write.
Someone else is going to write.
Yeah, this chibitty.
You can use Chat Liberty to write your code.
You can get rid of this struggle of writing the code.
You can just tell chettipatti and get what you want.
Okay, we will do that.
We will say to church to write the rows to ship string subscriber or cord hit enter.
The one thing that you need to understand about our subscriber subscriber will be called whenever it
receives data and there will be a callback function that will be called whenever the subscriber receives
the data.
And then you can do your further processing.
So it has provided us the code.
We will use this to open up our VS code in which we have already publisher and my node dot cpp file.
We will just create another one new file subscriber dot js We have this and we will just copy and paste
it here.
All right.
It has created the subscriber with a similar fashion, except you can see it here.
Instead of using Create publisher, it has issues create subscriber and there is a callback function
to string callback that is declared here.
If this is just printing the information, explain the code line by line.
It is going to solve all the problems that you can possibly have with the code.
And there you go.
It will explain everything.
So we have our subscriber code here, but we cannot use it.
Why?
Because we have to tell that we have created a node to the package.
How we do that, we mention it in package XML file and cmakelists.
Okay.
And the package XML will declare the dependencies.
So it is dependent on the messages that we have already declared.
So that's it.
We will not edit anything in the package XML file, but we will go to the cmake list and there we will
add a node.
So we will just copy it here.
First it.
Fuel cell listener.
And then the pot is a shark and the file name is subscriber.
Listener Nordeney.
And it depends on our messages.
In the installed, we will just write the name of the node, which is listener.
Yes.
And now we will try to build it.
The court is filled.
Source.
Install local setup source workspace.
And now we will run the subscriber ros to run turtle.
Same for and press double tab.
Now it is offering three nodes so we will just write listener and hit enter.
So now the node is running and we will see Ros topic.
And now we see there is our topic.
Today's topic name.
And this is our the name of the subscriber.
But in the publisher the topic name was just topic.
We will just try to modify both of the topics and we will give them a common name in order to set their
communication.
Remember, if we want a publisher and subscriber communicate, there should be a common topic with the
same name.
Okay, come here to the publisher.
And there is the topic, which is topic trained.
Message.
Commission me question.
Okay, so this is our topic name.
Now save it.
And also come here.
And this is the subscriber topic.
Okay, so now we will build it again.
And now we will run our subscriber.
And now we will check the name of the topic.
And there we go.
String message communication.
Okay, So currently it is not showing any data because there is no publisher.
But we are going to we will just open another terminal source, install local setup dot bash.
And now the terminal is sourced and it knows we have a workspace called Ros Workspace.
And now we will run the Ros to run turtle same port.
And then the publisher, which was Docker and it is publishing the data, hopefully.
And there you go.
It is.
And we can also check it from here.
Rose to topic equal.
Topping name, and it is also receiving the data here.
Okay.
And press control C to kill it.
And now we will see the connection using our equity graph.
Arc underscore graph.
Okay.
The notes are minimal.
Publisher and the string subscriber and the topic name is String message communication.