1
00:00:06,040 --> 00:00:10,690
Now we will try to create a publisher using Python.

2
00:00:15,160 --> 00:00:20,050
Well, when we created the package, we used the build type and went CMake.

3
00:00:20,080 --> 00:00:23,380
Then how we will add the python node into it.

4
00:00:23,560 --> 00:00:26,590
It allows us to just use C plus plus.

5
00:00:27,580 --> 00:00:31,780
Well, there will be a little bit modification needed.

6
00:00:31,930 --> 00:00:32,410
Yeah.

7
00:00:32,440 --> 00:00:38,620
Here have the instruction and we can simply edit our own packets.

8
00:00:38,620 --> 00:00:46,180
So it has stated that you can create a package using CMake and we have done already.

9
00:00:46,210 --> 00:00:50,950
Here it is explaining that how you can add a python node into it.

10
00:00:51,100 --> 00:00:56,020
Make a folder which has the same name as the package here.

11
00:00:56,320 --> 00:00:58,750
Let's ruler new folder.

12
00:00:59,170 --> 00:01:00,700
Now you're inside the package.

13
00:01:00,910 --> 00:01:06,280
Turtle Same port done.

14
00:01:06,760 --> 00:01:15,500
And the second thing is that we have to create a file whose inside that folder and its name should be

15
00:01:15,530 --> 00:01:16,670
double underscore init.

16
00:01:16,670 --> 00:01:17,930
Double underscore dot py.

17
00:01:18,050 --> 00:01:19,400
Where do we need that?

18
00:01:19,400 --> 00:01:27,140
Inside the folder we create an empty PY file and this is something that already present when you create

19
00:01:27,140 --> 00:01:28,120
a python package.

20
00:01:28,130 --> 00:01:34,220
And then we have to make a script folder in which we can keep our python nodes.

21
00:01:34,250 --> 00:01:40,730
Open your terminal City rose to workspace.

22
00:01:42,760 --> 00:01:43,530
For you.

23
00:01:43,580 --> 00:01:53,580
We are into our workspace and now source it Source Install local setup dot Dartfish workspaces Source

24
00:01:53,630 --> 00:01:56,950
code to inside your package src.

25
00:01:57,620 --> 00:02:02,780
And there we have the turtle sync package and then again the turtle sim.

26
00:02:02,990 --> 00:02:06,740
And now we have to create our init file.

27
00:02:07,190 --> 00:02:09,500
It will be like touch.

28
00:02:11,890 --> 00:02:12,940
Underscore.

29
00:02:13,300 --> 00:02:14,860
Underscore and.

30
00:02:15,670 --> 00:02:16,750
Underscore.

31
00:02:16,930 --> 00:02:18,820
Underscore dot pi.

32
00:02:19,420 --> 00:02:26,780
Make it executable C or D plus x and compile.

33
00:02:26,780 --> 00:02:28,800
And now this is executable file.

34
00:02:28,810 --> 00:02:35,950
Now we will have to go back and then make our directory.

35
00:02:38,480 --> 00:02:39,800
There's in this directory.

36
00:02:39,800 --> 00:02:42,020
We can keep our python nodes.

37
00:02:42,050 --> 00:02:44,580
We will go inside that directory.

38
00:02:44,600 --> 00:02:46,290
So career torch.

39
00:02:47,570 --> 00:02:50,690
Using the torch command, we can create a file.

40
00:02:50,870 --> 00:02:51,580
Touch.

41
00:02:51,590 --> 00:02:56,210
You can say my python.

42
00:02:58,880 --> 00:03:02,450
publisher.py.

43
00:03:04,730 --> 00:03:05,180
Okay.

44
00:03:05,180 --> 00:03:13,910
And then we should have to make it executable or d plus x and the file.

45
00:03:14,900 --> 00:03:18,390
Now we have set up the files in our brackets.

46
00:03:18,490 --> 00:03:18,640
Okay.

47
00:03:18,650 --> 00:03:26,550
It says you have to add shebang line first and a python file third.

48
00:03:26,880 --> 00:03:33,980
I'm going back and then we can open up the package in the VS code.

49
00:03:35,090 --> 00:03:36,110
There we go.

50
00:03:37,070 --> 00:03:45,330
And we will have this python file here and we will add the first line.

51
00:03:45,350 --> 00:03:50,420
Every python file should have this first shebang line and this is must.

52
00:03:51,110 --> 00:03:52,850
But you will be wondering that.

53
00:03:52,850 --> 00:03:55,670
Why didn't we add this in the init.py.

54
00:03:55,850 --> 00:04:04,880
Well the init.py case is different because this file and mainly used to let the ros know that in this

55
00:04:04,880 --> 00:04:08,060
package something is related to the python is present.

56
00:04:08,690 --> 00:04:12,020
There are the instructions were added to package our XML file.

57
00:04:14,950 --> 00:04:16,630
Just copy this line.

58
00:04:19,480 --> 00:04:20,260
Okay.

59
00:04:20,260 --> 00:04:23,070
And open our package or animal.

60
00:04:23,080 --> 00:04:26,840
And there you can see the line under it.

61
00:04:26,860 --> 00:04:32,800
We will add our new line and now we can open our CMake list.

62
00:04:32,800 --> 00:04:38,470
And there we have to mention that Findpackage and CMake Python is required.

63
00:04:38,830 --> 00:04:47,080
So we will just copy this line and come here to the list and there we go.

64
00:04:47,080 --> 00:04:47,890
Find package.

65
00:04:47,890 --> 00:04:50,410
We will just add the line under this.

66
00:04:50,680 --> 00:05:00,070
And here here are some part that is related to the python and we will just copy it and come right here.

67
00:05:02,620 --> 00:05:05,740
After the Cplusplus dagger.

68
00:05:07,430 --> 00:05:11,810
Add this line of code here and in these scripts.

69
00:05:13,510 --> 00:05:13,980
I'm sorry.

70
00:05:13,990 --> 00:05:16,720
Our folder name was script.

71
00:05:17,200 --> 00:05:24,220
Just training and anchor and script.

72
00:05:24,220 --> 00:05:26,530
And then what was inside?

73
00:05:30,100 --> 00:05:33,400
They sit here and that's it.

74
00:05:34,210 --> 00:05:47,260
Our package can now run Python and C plus plus notes Q1's back and call convert one final samling minus

75
00:05:47,260 --> 00:05:47,920
install.

76
00:05:51,640 --> 00:06:04,000
We build successful source, install the local setup dot bash, find the executor ros to and run turtle

77
00:06:04,970 --> 00:06:06,880
port and double tab.

78
00:06:07,210 --> 00:06:12,640
We have one more executable file that is my python publisher dot pi.

79
00:06:12,700 --> 00:06:14,740
And this is absolutely empty.

80
00:06:14,770 --> 00:06:15,940
It will do nothing.

81
00:06:17,440 --> 00:06:19,120
My python.

82
00:06:20,440 --> 00:06:21,260
That's it.

83
00:06:21,330 --> 00:06:24,910
It will do nothing because it has nothing inside it.

84
00:06:25,330 --> 00:06:31,000
We will come to the documentation and here we will copy this code.

85
00:06:31,600 --> 00:06:33,820
That is the publisher.

86
00:06:35,260 --> 00:06:40,540
We can paste it here as we have changed the python file.

87
00:06:41,300 --> 00:06:49,300
We do not need to use a call Qualcomm and Source Command again because the python node does not need

88
00:06:49,300 --> 00:06:53,550
to be built every time you can add it and run simply this.

89
00:06:54,110 --> 00:06:55,540
Minimal publisher.

90
00:06:55,640 --> 00:07:02,110
I'm going to change the name to like Python publisher.

91
00:07:02,270 --> 00:07:03,410
That's that's fine.

92
00:07:04,730 --> 00:07:05,060
Okay.

93
00:07:05,060 --> 00:07:10,550
And the topic name were choosing a different topic name.

94
00:07:10,560 --> 00:07:17,810
We will choosing the string message Docker communication and I will just paste it here.

95
00:07:17,840 --> 00:07:21,350
The code is doing the same as T plus nor was doing.

96
00:07:21,350 --> 00:07:26,420
And there you can also find the explanation that what part is doing what?

97
00:07:26,450 --> 00:07:29,990
Well, if we have to note and we will run this.

98
00:07:33,370 --> 00:07:39,010
And now, as you can see, it is publishing the data to the topic.

99
00:07:39,030 --> 00:07:44,020
Now we have a Python code that is publishing on to the topic.

100
00:07:44,140 --> 00:07:49,720
And but we have also another publisher that we created using the C plus plus.

101
00:07:49,720 --> 00:07:51,070
We will also run this.

102
00:07:57,030 --> 00:08:02,040
Ross to run turtle same port.

103
00:08:02,040 --> 00:08:06,990
And there was a toggle mode that will be publishing on the same topic.

104
00:08:07,140 --> 00:08:09,420
And now we have two publisher.

105
00:08:09,450 --> 00:08:11,660
They both are publishing on one topic.

106
00:08:11,670 --> 00:08:14,910
So now we will run a subscriber.

107
00:08:25,640 --> 00:08:28,310
It is receiving the data from the both topics.

108
00:08:28,520 --> 00:08:43,130
Now we will open another terminal rose to topic equal and we have the string message communication topic.

109
00:08:43,130 --> 00:08:45,120
And there you can also see.

110
00:08:45,140 --> 00:08:52,310
Now we will see the connection between the nodes and topics using the archetype graph aka underscore

111
00:08:52,310 --> 00:08:52,760
graph.

112
00:08:58,780 --> 00:08:59,470
There we go.

113
00:09:00,190 --> 00:09:08,370
Minimal publisher and Python publisher are publishing on this topic and the string subscribers CV.

114
00:09:08,680 --> 00:09:11,020
I hope this was a fun activity for you.

115
00:09:11,200 --> 00:09:17,950
And now we can run C plus plus and Python node on inches one package.

116
00:09:17,980 --> 00:09:18,580
All right.
