1
00:00:01,140 --> 00:00:07,350
Up to this point, we have been running all of our rosters nodes independently, with each node needing

2
00:00:07,350 --> 00:00:09,660
its own dedicated terminal to run.

3
00:00:10,050 --> 00:00:14,160
We have also had to open extra terminals to do actions such as setting parameters.

4
00:00:14,460 --> 00:00:19,860
Launch files are a feature in ROS which allow you to launch multiple nodes and configure them all with

5
00:00:19,860 --> 00:00:20,850
a single command.

6
00:00:21,210 --> 00:00:25,960
In this lecture we will create a launch file to launch our RPM publisher node.

7
00:00:25,980 --> 00:00:32,580
So the first thing we will do is open up V's code and create a new folder in our package by right clicking

8
00:00:32,580 --> 00:00:39,760
and clicking a new folder and we will call this folder launch within our newly created launch folder.

9
00:00:39,780 --> 00:00:48,030
We'll create a new file which we will call RPM underscore node dot launch dot py.

10
00:00:48,510 --> 00:00:53,310
Now I know this may be a bit confusing to have two file extensions in a file name, but in ROS two launch

11
00:00:53,310 --> 00:00:55,750
files are essentially made from Python code.

12
00:00:55,770 --> 00:00:59,130
That's why we edit it with the dot py extension.

13
00:00:59,130 --> 00:01:05,880
But essentially the launch portion of it is a tribute to ROS one launch files which used to use XML

14
00:01:05,880 --> 00:01:08,480
syntax rather than python code.

15
00:01:08,490 --> 00:01:12,480
Just know that it's generally accepted to have the word launch near the end of the launch file.

16
00:01:12,480 --> 00:01:17,130
So if you wanted to, you could have used an underscore instead of a period before the word launch for

17
00:01:17,130 --> 00:01:20,900
this python file, we are going to be importing functionality from the launch module.

18
00:01:20,910 --> 00:01:28,060
Specifically, we will be including launch description from launch and node from launch roster actions.

19
00:01:28,080 --> 00:01:33,120
Note that this is not the same node object from the ROS client library we have been using in our code

20
00:01:33,120 --> 00:01:33,810
so far.

21
00:01:34,440 --> 00:01:39,210
In order for the ROS to launch command to interpret this python file, we will need to have a function

22
00:01:39,210 --> 00:01:44,430
called Generate Launch description in it, which returns a launch description object.

23
00:01:50,520 --> 00:01:55,800
This launch description object will contain a list of things we want to configure or run in this launch

24
00:01:55,830 --> 00:01:56,420
file.

25
00:01:56,430 --> 00:02:02,160
In this case, we just want to launch our RPM node, so I will create a node object.

26
00:02:03,890 --> 00:02:09,140
So on the screen, I'm showing you the source code for this node class, which contains all the optional

27
00:02:09,140 --> 00:02:12,720
parameters you can include with launching a node.

28
00:02:12,740 --> 00:02:18,890
For this case, I will specify the package, which is our Udemy ras to package our executable, which

29
00:02:18,890 --> 00:02:24,800
is RPM, pub node pie and the name of the node which I will just call RPM pub node.

30
00:02:27,910 --> 00:02:28,120
No.

31
00:02:28,120 --> 00:02:29,530
And I forgot a comma here.

32
00:02:30,540 --> 00:02:31,200
Here we go.

33
00:02:31,230 --> 00:02:36,390
If I wanted to add more nodes, I could simply add them to the list and then I could configure this

34
00:02:36,390 --> 00:02:37,810
one just as I did the one above.

35
00:02:37,830 --> 00:02:40,980
But for now, I'm just to keep the simple and just launch our RPM node.

36
00:02:41,010 --> 00:02:46,080
Now we can save this file and head over to our make list text file.

37
00:02:46,940 --> 00:02:50,860
So here we're going to have to configure our make list X file to be able to run launch files.

38
00:02:50,870 --> 00:02:55,370
The only thing we need to do is to create another install function, which I will put after the one

39
00:02:55,370 --> 00:02:57,610
we currently have to set up our Python scripts.

40
00:02:57,620 --> 00:03:02,150
So the only thing we need to do is create another install function, which I will just put after the

41
00:03:02,150 --> 00:03:05,300
one we currently have to set up our Python scripts.

42
00:03:05,360 --> 00:03:10,610
Within this install function we will use the directory keyword and the directory we will be including

43
00:03:10,610 --> 00:03:12,470
is our launch folder.

44
00:03:12,620 --> 00:03:18,230
Then we will point the destination location to the share folder followed by the project name.

45
00:03:21,270 --> 00:03:22,950
Ock with that saved the file.

46
00:03:24,660 --> 00:03:30,060
And now we can run our newly created launch file by going ahead and rebuilding our workspace directory,

47
00:03:30,060 --> 00:03:35,190
which you can do by either going to terminal run, build task or control shift B which will run our

48
00:03:35,400 --> 00:03:37,290
can build Simulink install command.

49
00:03:39,470 --> 00:03:41,270
Oh, and it seems I made a mistake here.

50
00:03:41,270 --> 00:03:44,930
I accidentally placed our launch folder within the workspace.

51
00:03:44,930 --> 00:03:47,900
I meant to place it within the package.

52
00:03:48,050 --> 00:03:50,240
So I'll go ahead and move this.

53
00:03:51,090 --> 00:03:52,290
Into our package.

54
00:03:55,250 --> 00:04:01,190
All right, so now we're in our sauce raw stew package, and then we have our launch folder, RPM,

55
00:04:01,190 --> 00:04:01,880
long shot pie.

56
00:04:01,880 --> 00:04:04,910
And just to show you what this looks like inside the workspace directory.

57
00:04:07,670 --> 00:04:12,320
So here we have our package, so we have our scripts folder with all our Python files and our launch

58
00:04:12,320 --> 00:04:14,960
folder with our launch file.

59
00:04:17,430 --> 00:04:17,700
All right.

60
00:04:17,700 --> 00:04:19,230
Let's go ahead and try to rebuild that.

61
00:04:21,040 --> 00:04:21,370
All right.

62
00:04:21,370 --> 00:04:23,470
And that time we build successfully.

63
00:04:23,620 --> 00:04:27,670
So let's go ahead and open up a terminal and we'll go ahead and source it.

64
00:04:32,630 --> 00:04:38,060
And now we can run our launch file using the Ross to launch command, which takes in the name of the

65
00:04:38,060 --> 00:04:40,430
package and the name of the launch file.

66
00:04:40,460 --> 00:04:45,740
In this case, we will launch our raw package's RPM node launch file.

67
00:04:46,150 --> 00:04:49,130
Oh, and it seems I made a typo within my launch file.

68
00:04:51,080 --> 00:04:56,690
So our package name is Ros two package, so I only forgot the two there so we can go ahead and save

69
00:04:56,690 --> 00:04:57,170
this.

70
00:04:57,170 --> 00:05:00,170
And all the changes should take effect because we're using Simulink install.

71
00:05:00,170 --> 00:05:02,060
So if I try to rerun this one more time,

72
00:05:05,540 --> 00:05:12,230
we see process started with PID and the corresponding number and I can double check that this is running

73
00:05:12,230 --> 00:05:18,230
by running across to node list and we see our RPM publisher node is running just as it would have been

74
00:05:18,230 --> 00:05:20,000
with Ros to run.

75
00:05:20,390 --> 00:05:21,470
So congratulations.

76
00:05:21,470 --> 00:05:25,300
You have successfully launched your own node using a launch file.

77
00:05:25,310 --> 00:05:29,780
Now it's worth noting the launch files can be used to run external system commands as well.

78
00:05:29,960 --> 00:05:36,050
We can do this with the execute process object, which we will have to import from the launch actions

79
00:05:36,050 --> 00:05:36,710
module.

80
00:05:40,820 --> 00:05:45,420
Then within our launch subscription list, we will add an execute process to run a command.

81
00:05:45,440 --> 00:05:49,640
In this case, I will run the ROS to topic list command.

82
00:05:49,670 --> 00:05:53,250
This command will be the value of the CMD argument.

83
00:05:53,270 --> 00:05:57,170
We split this command up word for word in a list like so.

84
00:05:59,140 --> 00:06:04,570
Then I will set the output argument to screen, which means the output of this command will show up

85
00:06:04,570 --> 00:06:05,470
in our terminal.

86
00:06:06,020 --> 00:06:06,590
With that.

87
00:06:06,590 --> 00:06:07,790
Let's save the file.

88
00:06:08,900 --> 00:06:12,440
And again, it should automatically take effect because we're using Simulink install.

89
00:06:12,470 --> 00:06:16,370
So now if I go ahead and rerun this launch file.

90
00:06:17,610 --> 00:06:18,330
We see here.

91
00:06:18,330 --> 00:06:23,820
We got a subset of information printing to the screen where it says Ross 2-2 because this is the second

92
00:06:23,820 --> 00:06:29,760
command that's running within our launch file and it starts with Ross two and we see it prints out the

93
00:06:29,760 --> 00:06:34,080
corresponding topics if we had run Ross to topic list.

94
00:06:34,320 --> 00:06:37,320
So we see the same information here within our launch file.

95
00:06:37,320 --> 00:06:43,290
So that's just one of the ways which you can configure your launch file to utilize terminal actions.

96
00:06:44,060 --> 00:06:48,800
One thing I briefly want to mention before we head over to the next lecture is if you wanted to configure

97
00:06:48,800 --> 00:06:52,910
parameters within your node object, you can also do that using the parameters argument.

98
00:06:54,350 --> 00:07:01,580
And this takes in a list of dictionaries, which in this case each dictionary will have the value of

99
00:07:01,580 --> 00:07:03,350
your particular parameter.

100
00:07:03,350 --> 00:07:09,740
So you'd put in your parameter name with the colon and you'd specify the parameter value.

101
00:07:11,370 --> 00:07:15,390
So I'm going to put this back to the way it was, but just know that this is the syntax in order to

102
00:07:15,390 --> 00:07:16,530
set parameters of your node.

103
00:07:16,530 --> 00:07:22,020
If they have been declared already, which we will be taking a look at in the next lecture.

104
00:07:23,190 --> 00:07:23,870
Great.

105
00:07:23,880 --> 00:07:29,610
You have learned how to use launch files to automatically start up ROS nodes and run terminal commands.

106
00:07:29,760 --> 00:07:31,410
Let's review what we learned.

107
00:07:32,850 --> 00:07:37,830
In this lecture, we learned how we could create launch files so that we could run multiple nodes as

108
00:07:37,830 --> 00:07:42,420
well as other functionality with a single ROS to launch terminal Command.

109
00:07:42,450 --> 00:07:48,360
We created our launch files in Python by importing the launch description node and execute process objects

110
00:07:48,360 --> 00:07:53,520
from the different launch modules and then utilize them within our launch files.

111
00:07:53,520 --> 00:07:55,620
Generate Launch Description function.

112
00:07:56,980 --> 00:08:03,790
In our lunch description, we were able to run our Ross nodes we created using the node object and specifying

113
00:08:03,790 --> 00:08:05,650
the package and executable name.

114
00:08:05,770 --> 00:08:11,770
We can then also pass in a node name which will override the default node name specified in the code.

115
00:08:12,130 --> 00:08:15,820
You can even specify values of particular parameters of that node.

116
00:08:16,150 --> 00:08:21,310
We also took a look at the execute process instance in which we can run terminal commands utilizing

117
00:08:21,310 --> 00:08:26,890
our launch file and we specify output to screen so that the output of these commands can be seen on

118
00:08:26,890 --> 00:08:27,430
the terminal.

119
00:08:27,430 --> 00:08:28,720
We run the launch file in.
