1
00:00:00,910 --> 00:00:04,900
In this lecture, we're going to take a look at different ways we can compile our package, which is

2
00:00:04,900 --> 00:00:07,510
going to be a bit helpful for us later on in the future.

3
00:00:07,510 --> 00:00:14,080
So if I open up Visual Studio Code and I head over to my make list text file when we were installing

4
00:00:14,080 --> 00:00:20,980
our Python scripts, we call this install command, followed by the name of each of our scripts and

5
00:00:20,980 --> 00:00:24,800
we specified a destination lib slash project name.

6
00:00:24,820 --> 00:00:31,810
What this did was made a copy of our Python scripts in the install directory of our workspace.

7
00:00:32,600 --> 00:00:36,290
So for example if I had to me Ross to package lib.

8
00:00:38,050 --> 00:00:43,720
And then our package name, this is the lib package name that we're specifying here in the destination.

9
00:00:43,720 --> 00:00:48,130
So here we see a publisher, py and a subscriber py file.

10
00:00:48,220 --> 00:00:54,060
These are copies of the scripts we created when we ran cocaine build.

11
00:00:54,070 --> 00:00:59,310
And these are the files that get referenced when we use the ROS to run command.

12
00:00:59,320 --> 00:01:00,750
So why does this matter?

13
00:01:00,760 --> 00:01:07,030
Well, because if we make any changes to our scripts, for example, let's go over to our publisher

14
00:01:07,030 --> 00:01:07,630
file.

15
00:01:08,950 --> 00:01:15,070
And we'll change the print statement to say new publisher and node running If I make changes and I hit

16
00:01:15,070 --> 00:01:16,150
control SE.

17
00:01:16,180 --> 00:01:17,830
We can go over to a terminal.

18
00:01:19,230 --> 00:01:20,730
Source our workspace.

19
00:01:25,580 --> 00:01:28,490
And use the RAR to run command like we did in the last lecture.

20
00:01:30,010 --> 00:01:36,010
So notice here it says publisher node running, but we obviously changed it to new publisher node running.

21
00:01:36,010 --> 00:01:41,470
Well, that's because, as I said, it's referencing this file which was copied when we ran Coal can

22
00:01:41,470 --> 00:01:41,860
Build.

23
00:01:41,860 --> 00:01:44,620
So this file only says publisher Node running.

24
00:01:44,620 --> 00:01:46,450
The changes didn't take effect here.

25
00:01:47,520 --> 00:01:52,350
So this can be kind of annoying because that means we need to recompile our whole package just to address

26
00:01:52,350 --> 00:01:55,340
that one little change we made to our script.

27
00:01:55,350 --> 00:02:00,630
So let's go ahead and compile our package in a different way so we don't have to worry about this.

28
00:02:00,630 --> 00:02:03,060
So I'm going to go ahead and start with a clean slate workspace.

29
00:02:03,060 --> 00:02:07,350
So I'm going to delete my build, install and log folders.

30
00:02:07,350 --> 00:02:10,970
So now I only have the source folder which contains my packages.

31
00:02:10,980 --> 00:02:12,960
Now I'm going to go back to my terminal.

32
00:02:14,350 --> 00:02:15,730
I'll stop this Publisher note.

33
00:02:16,060 --> 00:02:17,110
Clear the screen.

34
00:02:17,320 --> 00:02:24,010
And if you actually notice, if I were to try and run that command, it says Rescue package not found.

35
00:02:24,010 --> 00:02:28,450
That's because I actually deleted the files where everything was held, even though our source folder

36
00:02:28,450 --> 00:02:29,830
is still intact.

37
00:02:30,820 --> 00:02:36,630
But if I go over to my workspace directory, we can run the call, can build command.

38
00:02:36,640 --> 00:02:42,670
But this time we're going to specify a special option by doing dash dash Simulink install and you can

39
00:02:42,670 --> 00:02:43,760
use tab completion here.

40
00:02:43,780 --> 00:02:48,940
So what Simulink install is going to do is whenever there are files that are copied over, instead of

41
00:02:48,940 --> 00:02:53,630
creating a brand new version of that file, it's going to make a link to that existing file instead.

42
00:02:53,650 --> 00:02:55,870
So let's just go ahead and see what this does.

43
00:02:58,890 --> 00:03:03,390
So again, we get our depreciation warnings from our setup tools, depreciation warning from our IP

44
00:03:03,420 --> 00:03:03,980
package.

45
00:03:03,990 --> 00:03:06,300
For now, we're just going to go ahead and ignore that.

46
00:03:06,540 --> 00:03:11,820
And now if I go into my install directory, as you can see, our build, install and log directory,

47
00:03:11,820 --> 00:03:14,160
we're regenerated since we reran colon build.

48
00:03:14,490 --> 00:03:16,890
But now if I go into our package.

49
00:03:18,260 --> 00:03:20,080
We see these arrows.

50
00:03:20,090 --> 00:03:23,120
And so this means that this is a linked file.

51
00:03:23,120 --> 00:03:28,640
So if I go ahead and open this with the text editor, it says new publisher node running.

52
00:03:28,640 --> 00:03:34,580
And if I go ahead and make more changes, so I'm going to say new new publisher, node running, I know

53
00:03:34,580 --> 00:03:37,100
that's not original, but just to show the difference.

54
00:03:38,880 --> 00:03:43,230
Now, if I reopen this file again, we see the changes immediately took effect.

55
00:03:43,230 --> 00:03:45,750
So here we see that new new publisher note is running.

56
00:03:45,750 --> 00:03:52,170
So this is super helpful in the sense that we can make changes to our source code and it'll immediately

57
00:03:52,170 --> 00:03:56,370
take effect into our workspace without having to recompile.

58
00:03:59,700 --> 00:04:06,100
I can also prove this by opening a terminal at this location and we can use the read link command.

59
00:04:06,120 --> 00:04:08,550
So in this case, I'll do read Link publisher PI.

60
00:04:08,550 --> 00:04:12,540
And here we see it is pointing to our source folder.

61
00:04:13,930 --> 00:04:18,820
Now, we will still need to run and build regardless if we create new files.

62
00:04:19,000 --> 00:04:24,100
And it can be easy to forget that dash dash Simulink install like when running call can build.

63
00:04:24,130 --> 00:04:28,420
So let's go ahead and set up our VS code editor to remember.

64
00:04:28,420 --> 00:04:34,450
For us to do this, we're going to head over to our Visual Studio code editor and add some contents

65
00:04:34,450 --> 00:04:37,420
into this dot vs code folder you see here.

66
00:04:38,000 --> 00:04:44,750
So I'm going to go ahead and right click on it hit new file and I'm going to create a tasks dot JSON

67
00:04:44,750 --> 00:04:50,690
file and oops, I accidentally put a comma there instead of a period.

68
00:04:52,190 --> 00:04:57,020
There we go, tasks, JSON, and now we're going to set up our tasks.

69
00:04:57,020 --> 00:04:57,230
Here.

70
00:04:57,230 --> 00:05:01,730
You can find more information on Vsco codes, documentation page on task, but for now, let's go ahead

71
00:05:01,730 --> 00:05:03,110
and jump right into it.

72
00:05:26,660 --> 00:05:33,740
So here all I'm doing is mapping the coal can build Simulink install command to the build labeled task

73
00:05:33,740 --> 00:05:38,120
in VTS code, and we specified that these commands run in the shell.

74
00:05:38,300 --> 00:05:41,540
Notice that I source my ROS installation before building.

75
00:05:41,540 --> 00:05:47,270
That is because by default the VZ code shell does not source our bash, our c file in our home directory

76
00:05:47,270 --> 00:05:48,950
like our normal terminal does.

77
00:05:48,950 --> 00:05:52,310
So we have to manually specify the source of the Ross installation.

78
00:05:52,310 --> 00:05:57,020
Or alternatively, you can change this to source your bash or C file if you want it to.

79
00:05:57,020 --> 00:06:02,240
Then I use two ampersand symbols which specify to run the next command if the first one is successful.

80
00:06:02,240 --> 00:06:04,670
So with that, I'll go ahead and save this file.

81
00:06:04,790 --> 00:06:10,580
And now instead of having to run colon build from terminal, every time we want to make changes, we

82
00:06:10,580 --> 00:06:14,750
can instead head over to terminal and run build task.

83
00:06:14,750 --> 00:06:16,850
So this opens a terminal here at the bottom.

84
00:06:16,850 --> 00:06:21,560
And as you can see, it compiled using the code that we just specified.

85
00:06:21,560 --> 00:06:27,830
So it went ahead and source our Ross Humble set up bash file and then ran colon build Simulink install

86
00:06:27,830 --> 00:06:31,070
where we see our code got compiled.

87
00:06:31,280 --> 00:06:35,270
Then from here I can simply hit spacebar to close the terminal.

88
00:06:35,270 --> 00:06:40,010
But all the changes have taken into effect and I can actually prove this really quickly by going ahead.

89
00:06:43,040 --> 00:06:46,340
And deleting the build, install and log folders one more time.

90
00:06:47,090 --> 00:06:50,570
And I will run that terminal run build task.

91
00:06:51,990 --> 00:06:54,890
And we see they all get created again.

92
00:06:54,900 --> 00:06:57,810
Now, for the time being, since we're not using that my PIP package.

93
00:06:57,810 --> 00:07:02,100
And that was only for the example back in the Configuring Packages lecture.

94
00:07:02,100 --> 00:07:07,440
I'm going to go ahead and delete this package for now just so that we stop getting that depreciation

95
00:07:07,440 --> 00:07:09,300
warning from the.

96
00:07:10,300 --> 00:07:12,700
The package resources, depreciation warnings.

97
00:07:13,710 --> 00:07:16,920
Due to the setup copy files being depreciated.

98
00:07:16,920 --> 00:07:21,140
And because we're not really using that package anyway throughout this course.

99
00:07:21,150 --> 00:07:24,330
So since I made those changes, I should actually recompile one more time.

100
00:07:28,030 --> 00:07:29,670
But now we see it's super easy.

101
00:07:29,680 --> 00:07:31,150
We don't have to remember any commands.

102
00:07:31,150 --> 00:07:36,790
Simply head over to this run, build task or use the control shift to be shortcut and any changes we've

103
00:07:36,790 --> 00:07:39,520
made to our packages we'll get compiled in.

104
00:07:42,320 --> 00:07:42,590
All right.

105
00:07:42,590 --> 00:07:46,870
And there's one more thing I need to show you to make sure that all of this works as intended.

106
00:07:46,880 --> 00:07:54,700
So if I head over to my terminal and I go over and change into my scripts directory, if I hit ls.

107
00:07:54,860 --> 00:08:00,150
Notice that my Python scripts are in this white text.

108
00:08:00,170 --> 00:08:04,860
Now this means that it's just a normal file with read write privileges.

109
00:08:04,880 --> 00:08:08,630
Now we're actually using these files as executables, right?

110
00:08:08,630 --> 00:08:12,340
We are executing these Python scripts to run our ROS code.

111
00:08:12,350 --> 00:08:18,260
So the one bad thing about sym linking our files is we need to make sure that they are executable as

112
00:08:18,260 --> 00:08:21,970
is because code can build actually used to take care of that for us.

113
00:08:21,980 --> 00:08:27,170
And I can show this by trying to source our workspace and trying to list our executables.

114
00:08:28,010 --> 00:08:32,360
So now if we run our ROS to package executables.

115
00:08:33,610 --> 00:08:34,840
The name of our package.

116
00:08:35,230 --> 00:08:41,860
Notice no executables get listed, and if I try to run one of our nodes, say our publisher node, it

117
00:08:41,860 --> 00:08:43,890
says no executable found.

118
00:08:43,900 --> 00:08:49,480
So the reason why this is happening is because our linked file is not configured as an executable.

119
00:08:49,480 --> 00:08:55,540
So the way we go about changing this in UNIX is by using the Mod command, which changes the permissions

120
00:08:55,540 --> 00:08:57,100
of a particular file.

121
00:08:57,100 --> 00:09:01,870
So for example, if I wanted to change the permissions of my publisher node to be an executable, I

122
00:09:01,870 --> 00:09:07,180
could do c h mod plus X in the name of the file, which in this case is publisher py.

123
00:09:07,210 --> 00:09:08,940
Now if I hit LS.

124
00:09:08,980 --> 00:09:14,680
Notice it's in this green text now which is symbolizing that this is an executable file.

125
00:09:14,680 --> 00:09:21,970
And if I rerun that ROS to package executables lists, we see our publisher PY is now considered an

126
00:09:21,970 --> 00:09:28,390
executable while our subscribers py is still not so you need to be sure that all of your source files

127
00:09:28,390 --> 00:09:34,630
are considered as executables so we can actually go ahead and automate this in our test JSON file to

128
00:09:34,630 --> 00:09:41,500
make sure it does that for us so that any python files that are within our packages get set to be executable.

129
00:09:41,500 --> 00:09:45,250
You can feel free to change this if that's not a desired behavior, but for the most part, most people

130
00:09:45,250 --> 00:09:48,340
won't have an issue with setting their Python scripts to be executable.

131
00:09:48,340 --> 00:09:52,540
So I can do this by adding another set of double and percent symbols.

132
00:09:52,540 --> 00:09:58,270
So after we finish building, let's make sure we look for all of our Python files and set them to be

133
00:09:58,270 --> 00:09:58,780
executable.

134
00:09:58,780 --> 00:10:00,520
And we can do that with the following command.

135
00:10:03,040 --> 00:10:07,450
So I know this is a bit of a complex command, but essentially we're running the find command in our

136
00:10:07,450 --> 00:10:14,050
directory and we're looking for the whole name within our source directory, any Python files.

137
00:10:14,050 --> 00:10:19,840
So any python files within the packages within our source directory, we'll then execute the command

138
00:10:19,840 --> 00:10:26,440
plus x command, which we ran earlier in our terminal so we can go ahead and save this and we can go

139
00:10:26,440 --> 00:10:27,910
ahead and rebuild our workspace.

140
00:10:27,910 --> 00:10:30,490
I'll go ahead and hit Control shift B to run the build task.

141
00:10:30,940 --> 00:10:34,180
And we see that's running this whole command for us.

142
00:10:34,300 --> 00:10:37,900
And now if I go over to terminal, I can go ahead and run.

143
00:10:37,900 --> 00:10:44,590
LZ And now we see that all of my Python scripts are now green, meaning they are all executable.

144
00:10:44,590 --> 00:10:51,850
And if I run Ros to package executables and Ros do package again, we see both the publisher and subscriber

145
00:10:51,850 --> 00:10:52,570
node.

146
00:10:52,570 --> 00:10:52,990
All right.

147
00:10:52,990 --> 00:10:58,000
With that, we've successfully configured our Visual Studio workspace to automatically source our Ros

148
00:10:58,000 --> 00:11:03,430
Humble installation run code can build with Simulink install so that any changes we make to our scripts

149
00:11:03,430 --> 00:11:08,590
will automatically take effect in the ROS Terminal command line interface and make sure that any python

150
00:11:08,590 --> 00:11:12,190
files we have within our workspace are marked as executable.

151
00:11:12,340 --> 00:11:17,800
So all this is done at the click of a button and we no longer have to worry about it.
