We have learned about ros nodes 2
so let's see how the ros nodes communicate among each other and we are going to learn about the ros topics 3
ros topics act as a bus among the node and that can exchange 4
or transfer the ros message so open up the terminal our terminal is already sourced 5
here you can see how the nodes are communicating with each other you can see two nodes that are 6
displayed in circle and they are communicating over a topic and one node is publishing the other 7
one the bottom one is subscribing and they are communicating a message via topic and here 8
you can see there are multiple node and they are communicating over one topic 9
two of them are Publishers and now two of them are subscribers so there can be multiple 10
node that can communicate over one topic any node can communicate with any other node over a common 11
topic so open up your terminal this terminal is already sourced and drag it here 12
for the visualization we are going to run again turtlesim node Ros2 run turtlesim package name and the node name turtlesim 13
and now open up another terminal ros2 topic list so here we have the first two topics will 14
always appear uh these topic contains information about the parameters if the parameter changes it 15
will store the information about it the rosout contains the logging information we do not need to 16
spend too much time with them these three topics are our main concern alright run another 17
node ros2 run turtlesim teleop key now we have two Nodes and 18
but the topics are same because the teleop node will be publishing over turtle one 19
slash cmd vel topic so let's see how we can monitor a topic we can monitor a data on a 20
specific topic by using a keyword that is echo so we'll just all right ros2 topic echo 21
turtle 22
cmd vel 23
and currently it is not showing us any data because the publisher hasn't 24
published any data over this topic so we will just press forward key once 25
yes we just press it once so it has displayed of this data 26
as you can see X is 2 and all other values are zero if we press a right button once 27
the Turtle has turned and it has given us the angular z value so this is how you can monitor 28
a topic and you can access all the data that is being published over it and let's see rqt graph 29
representation rqt_graph the enter and here it has displayed we will just refresh 30
and uh do not communicating with each other so you see echo we can find out all the data being 31
published over topic but we can also find out how many publisher and subscribers are related 32
to a topic and we can also find out the uh message type related to that topic so if we write 33
ros2 34
topic list minus t so it will display the type of the message that a particular 35
topic is using so it has displayed all the topics and their selected message type in 36
the list and the turtle1/cmd_vel has the geometry massages and twist so 37
you can also see the turtle one post has the message type Turtlesim message and post we 38
will see these messages and future videos but currently you just have to keep in mind there 39
are some message type that a particular topic uses to find out more information about a topic 40
To know the number of subscribers and publisher on related to a topic we can just use ros2 topic 41
info and let's say we have to learn about this topic 42
here so it has currently one subscriber and one publisher so why does it have just one publisher 43
and one subscriber ? the publisher that is publishing over this topic is the teleop and the subscriber is 44
turtlrsim window type of this topic is displayed here to geometric messages slash 45
message and twist to find out what is inside this message we can use a command ros2 interface 46
show and you can simply paste it here so it has a vector linear graphical 3 47
linear and vector 3 angular okay now we want to publish over a topic let's relaunch 48
every terminal from the beginning uh press Ctrl C to kill terminal 49
and here and you can press like Ctrl+L to clear it in every terminal 50
it enter a window appear and now we have to know the topic list ros2 topic list 51
so this is our concerning topic we will ros2 topic 52
info this topic and we know there is a zero publisher and one subscriber and here is the 53
message type what we will do we'll just copy ros we have to publish over this topic and we 54
will also use this message type how this message looks like so what we will do ros2 interface 55
show and this message and it has displayed us so this message has two vectors the 56
linear and angular so we want to publish uh over cmd vel so here is the command ros2 topic 57
pub and -- once so it means it will just publish it once and then it will terminate 58
and the topic name turtle one cmd vel and the message type then inverted comma track it linear 59
colon there are three further values in the sector so there will be the X colon space 60
let's say three and then comma and y colon space zero comma Z colon space zero close this with the 61
curly bracket and then comma and then there is the angular Vector as well and children 62
colon phase bracket X 63
X value 0 and Y value 0 64
and Z value should be uh this is the angular velocity we can give it to uh let's say we give it 65
uh three and close the curly bracket close the curly bracket again and close the inverted comma so this 66
will be the convention to publish over this topic and each topic will have a different message type 67
and there will be different parameters as well so at enter a loop is beginning and tells completed 68
a semi-circle what what if we want to publish it for a long time so instead of publishing it 69
here once we want to publish it at a continuous frequency so what we will change we'll just change 70
and this keyword I will mention it rate and let's say two so it will be publishing 71
twice a second let's change the value a little bit preview increase the value of linear X it will 72
be moving in a bigger Circle hopefully 73
yes it is moving and if you want to make this circle smaller then what you will do 74
we will press Ctrl C and give a high angular velocity and publish yes see rqt graph 75
so here you can see it is showing that a publisher is publishing 76
so what if we now get the info of this topic ros2 topic info turtle 1 and cmd 77
yes here you can see there is one publisher and one subscriber as well so we can also check the 78
frequency of a topic so we will check the frequency of this topic ros2 79
topic 80
HZ which is represents frequency topic so we will see 81
so here is the real-time value of the frequency so we have set the frequency to two now you 82
have learned all the information that you need to know about the ros topic you have learned 83
to publish you have learned to Echo and you have you can monitor a topic and you can also see 84
the publisher and subscribe will uh over related to a topic by just using 85
a keyword that is input and uh you can also check the frequency of a topic