1
00:00:00,630 --> 00:00:06,060
So in the last two lectures, we are able to create our very own RAS nodes, which are able to communicate

2
00:00:06,060 --> 00:00:09,630
with each other using publisher and subscriber Python scripts.

3
00:00:09,900 --> 00:00:14,850
After writing the Python code, we would open a terminal, go into the scripts folder in our package

4
00:00:14,850 --> 00:00:18,750
and run the Python terminal command followed by our script name.

5
00:00:19,080 --> 00:00:21,690
Well, there's a better way to go about doing this.

6
00:00:21,840 --> 00:00:27,300
In this lecture, we will be configuring our package so that we can run our node from any location in

7
00:00:27,300 --> 00:00:28,110
the terminal.

8
00:00:28,470 --> 00:00:34,020
When we created our package earlier in the course, we had to specify the build type which we specified

9
00:00:34,020 --> 00:00:35,370
as amend make.

10
00:00:35,700 --> 00:00:40,890
This tells Ros to compile our package based on instructions specified in our packages.

11
00:00:40,920 --> 00:00:47,360
See make list, text file, see, make list files which are generally used for compiling C and C++ code.

12
00:00:47,370 --> 00:00:50,520
So this may seem unfamiliar to some of you, and that's okay.

13
00:00:50,520 --> 00:00:54,810
Since we will cover what you need to know to help with your ROS development.

14
00:00:54,840 --> 00:00:55,920
Let's get to it.

15
00:00:57,650 --> 00:01:02,450
When we created our package, we had to specify the build type, which we specified as a meant to make.

16
00:01:02,450 --> 00:01:06,740
What we are telling the compiler is that we will compile our package based on instructions specified

17
00:01:06,740 --> 00:01:08,810
in our make list text file.

18
00:01:08,840 --> 00:01:13,880
So let's go ahead and configure our package to include our Python nodes.

19
00:01:13,970 --> 00:01:19,870
In Visual Studio code, I will open up our package XML file and make list text file.

20
00:01:19,880 --> 00:01:23,360
So let's go ahead and configure our package XML file.

21
00:01:23,360 --> 00:01:25,990
I will add build tool dependencies for MNC.

22
00:01:26,000 --> 00:01:27,020
Make and amend.

23
00:01:27,050 --> 00:01:28,520
See make python.

24
00:01:30,400 --> 00:01:33,760
And I will add our RC LP library as a dependency.

25
00:01:39,120 --> 00:01:39,450
All right.

26
00:01:39,480 --> 00:01:44,470
I'll go ahead and save this package on XML file and move on to our make list text file.

27
00:01:44,490 --> 00:01:52,980
Here, I will add our packages for amend c, make python and rcl py using the find packages function.

28
00:01:58,050 --> 00:02:02,700
Now I know this make list text file can seem a little confusing and daunting at first, but trust me,

29
00:02:02,700 --> 00:02:05,850
we'll get used to this as we utilize it throughout the course.

30
00:02:06,000 --> 00:02:09,090
I meant Python needs to be pointed to a python package.

31
00:02:09,090 --> 00:02:14,210
A python package is simply a folder that has a init python file.

32
00:02:14,220 --> 00:02:20,100
In this case, we want our python package to be our scripts folder so I will create a new file in our

33
00:02:20,100 --> 00:02:22,230
scripts folder called underscore.

34
00:02:22,230 --> 00:02:23,790
Underscore in it.

35
00:02:23,790 --> 00:02:26,430
Underscore underscore dot pi.

36
00:02:26,700 --> 00:02:30,900
Now I don't need to put anything in this file so I can just close it.

37
00:02:31,170 --> 00:02:36,480
Now that our scripts folder looks like a Python package, we can configure it by using the meant python

38
00:02:36,480 --> 00:02:40,950
install command followed by the folder name, which is scripts.

39
00:02:42,820 --> 00:02:47,080
Then lastly, we need to specify our individual Python nodes.

40
00:02:47,110 --> 00:02:49,620
We do this with the install function.

41
00:02:49,630 --> 00:02:51,580
Use the programs keyword.

42
00:02:52,660 --> 00:02:55,240
Followed by the location of the script.

43
00:03:00,890 --> 00:03:06,020
And then we set the destination for our workspace to place it.

44
00:03:06,410 --> 00:03:11,140
In this case, we'll need to put it in the lib folder, followed by our package name.

45
00:03:11,150 --> 00:03:17,690
And the last thing in our make list text file should always be this amount package function, so don't

46
00:03:17,690 --> 00:03:22,970
put code below this line as it will not get properly called when we build our project.

47
00:03:23,000 --> 00:03:25,520
Be sure to save this file when you're done editing.

48
00:03:25,640 --> 00:03:28,220
And now there's actually one more thing we need to do.

49
00:03:28,220 --> 00:03:34,490
Since Cement C make is primarily meant to run a C++ code, we have to tell Ros how we want this script

50
00:03:34,490 --> 00:03:35,570
to be executed.

51
00:03:35,720 --> 00:03:41,540
We do this by opening up our Python scripts that we want to run with Ros and then at the top add a Unix

52
00:03:41,540 --> 00:03:46,760
shebang character sequence, which is the pound sign followed by an exclamation mark, and then point

53
00:03:46,760 --> 00:03:49,880
it to our python three environment for Ubuntu.

54
00:03:49,910 --> 00:03:56,690
This will be located at forward slash us r forward slash bin forward slash in v space.

55
00:03:56,690 --> 00:03:57,850
Python three.

56
00:03:57,860 --> 00:04:01,010
We will have to do this for all of our python scripts.

57
00:04:05,490 --> 00:04:09,450
So would that be sure to save the changes you've made to all these files?

58
00:04:09,870 --> 00:04:12,450
And now if we go ahead and open up a terminal.

59
00:04:12,570 --> 00:04:14,040
I'll go ahead and clear the screen.

60
00:04:14,430 --> 00:04:18,780
And now we'll go ahead and change into our workspace directory here.

61
00:04:18,780 --> 00:04:21,240
So I'll go back a few directories.

62
00:04:25,680 --> 00:04:28,290
And now we can run our calc and build command.

63
00:04:32,440 --> 00:04:36,670
Well, and it seems I ran into an error with using the immense python install package.

64
00:04:36,670 --> 00:04:44,320
Command says target may not contain a slash, so I must have accidentally included a slash when I was

65
00:04:44,560 --> 00:04:46,480
implementing the script folder name.

66
00:04:46,480 --> 00:04:49,210
So go ahead and get rid of the slash in this function call.

67
00:04:49,210 --> 00:04:49,870
Save it.

68
00:04:51,040 --> 00:04:55,690
And now if I go ahead and clear the screen and rerun that Culkin build command.

69
00:04:56,640 --> 00:04:58,750
We see it builds successfully.

70
00:04:58,770 --> 00:05:03,240
Once it's built, we can source the setup file in the install directory.

71
00:05:03,390 --> 00:05:09,000
Now we can check that we configured our package properly by using the ROS to package executables command

72
00:05:09,000 --> 00:05:13,470
and we will specify our package, which in this case is Udemy ROS package.

73
00:05:13,740 --> 00:05:18,510
Here we see a list of executables available in these packages, which in this case is our publisher

74
00:05:18,630 --> 00:05:20,730
API and subscriber pie notes.

75
00:05:20,820 --> 00:05:25,590
Now we can run our nodes using the RAS to run command to launch our publisher node.

76
00:05:25,590 --> 00:05:34,380
Just run RAS to run Udemy RAS two package publisher PI and we see our publisher node running as we did

77
00:05:34,380 --> 00:05:36,940
when we ran it using the Python three command.

78
00:05:36,960 --> 00:05:39,580
Just to show you that this works for our subscriber node as well.

79
00:05:39,600 --> 00:05:45,330
I will open a new terminal tab and again I'll have to source that install setup file.

80
00:05:46,560 --> 00:05:51,480
Since this is a new environment and run our subscriber script.

81
00:05:53,570 --> 00:05:58,340
And here we are receiving the messages in our subscriber node that are being published over here by

82
00:05:58,340 --> 00:05:59,520
our publisher Node.

83
00:05:59,540 --> 00:06:01,820
So I can go ahead and stop these with control C.

84
00:06:02,420 --> 00:06:08,330
So here we are able to run our Python scripts using the ROS to run command because we configured our

85
00:06:08,330 --> 00:06:09,140
package.

86
00:06:09,140 --> 00:06:13,220
This way we can distribute the package to other developers and they can easily run the scripts like

87
00:06:13,220 --> 00:06:13,700
so.

88
00:06:14,770 --> 00:06:15,080
OC.

89
00:06:15,100 --> 00:06:21,670
We got our nodes to properly compile by modifying our make lists, text file and packaged XML files.

90
00:06:21,850 --> 00:06:27,970
Most popular ROS packages use C++ so it's good to get you better situated to this way of building ROS

91
00:06:27,970 --> 00:06:32,110
packages so you can understand the format when you use other packages.

92
00:06:32,290 --> 00:06:35,690
But it's worth noting there is another way to compile our package.

93
00:06:35,710 --> 00:06:41,860
There's a second build type called Amend Python, which is generally used if your package is solely

94
00:06:41,860 --> 00:06:43,990
composed of Python scripts.

95
00:06:44,470 --> 00:06:48,940
This will make our package show more resemblance to that of a standard Python package.

96
00:06:49,030 --> 00:06:56,020
But note the downside of this method is it does not allow you to use any C++ nodes in your ROS package.

97
00:06:56,020 --> 00:06:59,560
Should you want to include C++ code later on down the line.

98
00:06:59,890 --> 00:07:03,700
This is one of the reasons why I recommend using the C make build type.

99
00:07:04,120 --> 00:07:09,100
I will go ahead and show you this layout anyway on a new package so that you are aware of it in case

100
00:07:09,100 --> 00:07:11,800
you see other developers using this build type.

101
00:07:13,450 --> 00:07:15,250
So I'll go ahead and clear the screens.

102
00:07:16,270 --> 00:07:21,490
I'll actually close the second terminal and then I'll head over to the source folder of this workspace.

103
00:07:22,810 --> 00:07:23,080
All right.

104
00:07:23,080 --> 00:07:28,090
So here we see our original Udemy Ross two package, which is now configured with our make list text

105
00:07:28,090 --> 00:07:28,670
file.

106
00:07:28,690 --> 00:07:34,600
And now instead, I'm going to create a new package which I will just call my py package and pass the

107
00:07:34,600 --> 00:07:36,310
build type amount python.

108
00:07:40,680 --> 00:07:40,980
All right.

109
00:07:40,980 --> 00:07:44,370
So we see some text, but the terminal and if I open up a file explorer.

110
00:07:47,300 --> 00:07:54,320
We now have our IP package and instead of having RC make list text file configuration, it now has a

111
00:07:54,320 --> 00:07:57,550
Python package, a resource folder, test folder.

112
00:07:57,560 --> 00:08:03,350
We still have a package of XML, but instead of make lists we have a setup config and set up pie files

113
00:08:03,350 --> 00:08:09,530
before we modify our setup py file, let's include our publisher and subscriber code into this new package.

114
00:08:09,530 --> 00:08:14,870
So instead of the scripts directory we will put it into this my py package which already has an init

115
00:08:15,260 --> 00:08:16,280
py file in it.

116
00:08:16,520 --> 00:08:18,230
So open a new window.

117
00:08:25,160 --> 00:08:28,490
And we'll copy these two nodes we just created.

118
00:08:30,190 --> 00:08:34,900
Now I will go ahead and rename these files just so that we can distinguish them.

119
00:08:34,930 --> 00:08:40,150
So go ahead and click on this and you can right click and go to rename or use the F two shortcut.

120
00:08:40,150 --> 00:08:47,830
And I'll just call this publisher to py just so that we can see that there is a difference between where

121
00:08:47,830 --> 00:08:49,270
these files are located.

122
00:08:50,380 --> 00:08:50,680
All right.

123
00:08:50,680 --> 00:08:56,470
So let's get to configuring our new package XML file for this new ROS package.

124
00:08:56,590 --> 00:09:03,250
So now if I head over to source, go over to my PIP package, I can go ahead and configure our new package

125
00:09:03,370 --> 00:09:07,270
XML file to contain exec dependencies for our cl py.

126
00:09:12,790 --> 00:09:14,950
And the standard message is library.

127
00:09:19,170 --> 00:09:20,750
I'll go ahead and save this.

128
00:09:20,760 --> 00:09:24,140
And next we can edit our setup file.

129
00:09:24,150 --> 00:09:26,740
So here we're going to create our node executables.

130
00:09:26,760 --> 00:09:30,630
This is done in the entry points section towards the end of the file.

131
00:09:30,660 --> 00:09:34,560
So within console scripts we will add an entry to the list.

132
00:09:34,680 --> 00:09:36,960
First, I will add our publisher node.

133
00:09:37,150 --> 00:09:38,550
I'll give it an executable name.

134
00:09:38,550 --> 00:09:43,290
In this case, my publisher and I will set it equal to the name of my package.

135
00:09:43,320 --> 00:09:51,630
Dot the same name of our Python script, which is publisher two and then a semi colon and the name of

136
00:09:51,630 --> 00:09:55,530
the function we want to run, which in this case will be our main function.

137
00:09:56,530 --> 00:09:59,380
And we can do the same for our subscriber node.

138
00:10:11,350 --> 00:10:13,810
All right with this, I'll go ahead and save the file.

139
00:10:13,870 --> 00:10:17,010
We'll go back to our terminal and we will rerun our call.

140
00:10:17,020 --> 00:10:19,000
Can build command within the workspace.

141
00:10:19,480 --> 00:10:24,940
Since we only made changes to the new package, we can use the packages select parameter of colon built

142
00:10:24,970 --> 00:10:28,600
to specify to only build that particular package.

143
00:10:28,600 --> 00:10:31,390
Since that's the only package in this case we made changes to.

144
00:10:32,860 --> 00:10:35,500
So here we see set up tools, depreciation warning.

145
00:10:35,500 --> 00:10:40,510
This will be addressed by the Ross community in later Ross distributions, but for now you can just

146
00:10:40,510 --> 00:10:40,840
ignore it.

147
00:10:40,840 --> 00:10:46,210
It's just a warning our workspace has compiled successfully and I can test that by sourcing our install

148
00:10:46,210 --> 00:10:47,500
setup file.

149
00:10:49,150 --> 00:10:53,890
And then trying to run our publisher node from that new my PY package.

150
00:10:54,890 --> 00:10:59,450
So here we see again our publisher node is running and we can do it once more with our subscriber node

151
00:10:59,450 --> 00:10:59,930
below.

152
00:11:04,710 --> 00:11:09,570
And here we see we're receiving our messages just as we were in our other package.

153
00:11:09,570 --> 00:11:13,080
So this is just two ways to go about creating a Ross package.

154
00:11:13,080 --> 00:11:20,550
One is specific to only being able to run Python files, and one allows you to do C++ files along with

155
00:11:20,550 --> 00:11:23,610
the Python scripts like we were doing earlier.

156
00:11:23,610 --> 00:11:29,760
So feel free to use either version either by configuring a make list text file with your particular

157
00:11:29,760 --> 00:11:37,170
scripts or by using the immense Python method and configuring your console scripts in a setup file.

158
00:11:37,170 --> 00:11:43,020
But again, I will refer to the make list text file version using a C build type because that is the

159
00:11:43,020 --> 00:11:46,470
most common build type you will see amongst ROS packages.

160
00:11:48,050 --> 00:11:49,610
Well, congratulations.

161
00:11:49,610 --> 00:11:54,410
You just learned how to configure your workspace in two different ways to run your Python nodes within

162
00:11:54,410 --> 00:11:55,700
your ROS package.

163
00:11:55,730 --> 00:11:57,620
Let's review what we learned.

164
00:11:59,220 --> 00:12:04,650
In this lecture, we learned how to configure our packages so we can run our Python scripts using the

165
00:12:04,650 --> 00:12:08,970
ROS to run command for packages that use the C make build type.

166
00:12:08,970 --> 00:12:15,720
We configured the package xml file by including build tool dependencies for a meant c, make c make

167
00:12:15,720 --> 00:12:18,360
python and rcl py.

168
00:12:18,720 --> 00:12:24,150
Then we configured our to make list text files where we used find package to include the same dependencies.

169
00:12:24,150 --> 00:12:30,390
Then we set our scripts folder as our python package directory by using a mint python install package.

170
00:12:30,720 --> 00:12:34,290
Remember that the folder must have an init script in it.

171
00:12:34,930 --> 00:12:41,800
Then we use the install programs to include each of our scripts and set the destination to lib slash

172
00:12:41,800 --> 00:12:45,730
and the package name which we are able to call with the project name variable.

173
00:12:47,050 --> 00:12:51,910
We configured our Python files by telling the compiler how to run our scripts.

174
00:12:51,910 --> 00:12:58,690
And once we did all of that, we were able to build source and run our python nodes using the ROS to

175
00:12:58,690 --> 00:12:59,680
run command.

176
00:13:00,070 --> 00:13:04,660
We also took a look at how to configure our package XML and setup files.

177
00:13:04,660 --> 00:13:08,810
If you use the omit python as your build type for your package.

178
00:13:08,830 --> 00:13:14,560
So configuring our package XML, we have to include these exec dependencies for RC, LP and any message

179
00:13:14,560 --> 00:13:20,310
types we are using as well as configuring our setup py file which will be created in place of a make

180
00:13:20,380 --> 00:13:26,470
list text file where you will edit your console scripts to include the executable name you want and

181
00:13:26,470 --> 00:13:32,020
point it to the package name specific script file name with a particular function to run when we run

182
00:13:32,020 --> 00:13:33,610
the RAR to run command.
