1
00:00:00,870 --> 00:00:06,090
In the last lecture, we created a simple robot model simulation and controlled it over Ros using the

2
00:00:06,090 --> 00:00:07,640
ignition parameter bridge.

3
00:00:07,650 --> 00:00:13,710
So let's configure our package so that we can create a launch file to easily launch our simulation and

4
00:00:13,710 --> 00:00:16,620
any related nodes such as our parameter bridge.

5
00:00:18,230 --> 00:00:25,670
First things first, let's configure our smokeless text file to utilize the ignition simulation by calling

6
00:00:25,670 --> 00:00:31,760
the install command on the world and models directory so that when you make launch files you can easily

7
00:00:31,760 --> 00:00:32,660
reference them.

8
00:00:32,870 --> 00:00:38,660
So we should make sure to reference the ROS package that allows us to run ignition gazebo and our parameter

9
00:00:38,660 --> 00:00:41,960
bridge, which is Ros Ignition gazebo.

10
00:00:44,480 --> 00:00:48,200
Then you should also be sure to include it in your package, that XML file.

11
00:00:57,940 --> 00:01:03,280
Then back to my C make list text file right below where I install my launch directory to the share folder.

12
00:01:03,310 --> 00:01:09,700
I can make this a bit more compact, copy it and include it for my world and models directory.

13
00:01:19,110 --> 00:01:26,940
Now, if I go ahead and save these files and rebuild my project with Culkin, build Simulink install.

14
00:01:31,720 --> 00:01:32,020
All right.

15
00:01:32,020 --> 00:01:33,220
Let's go ahead and build.

16
00:01:34,490 --> 00:01:39,020
So now when I go into our install folder in our workspace directory.

17
00:01:40,640 --> 00:01:45,500
Then into package, then share, and then into our package name again.

18
00:01:45,500 --> 00:01:51,560
We eventually see the Models and Worlds folder, which has our linked files, which we're going to be

19
00:01:51,560 --> 00:01:53,420
using for our simulation.

20
00:01:54,230 --> 00:02:00,350
So let's go ahead and create a launch file to start up our simulation and the ignition bridge so we

21
00:02:00,350 --> 00:02:03,320
can send commands over Ros to control our robot.

22
00:02:03,770 --> 00:02:10,400
So I'll make a new launch file in my launch folder called Simulation Dot launch dot pie.

23
00:02:11,270 --> 00:02:16,250
I'll include some of the standard imports, such as our launch description node and execute process

24
00:02:16,250 --> 00:02:18,200
objects, which we've used before.

25
00:02:23,110 --> 00:02:28,900
Then we will include a couple of imports which will help us resolve our paths to things such as our

26
00:02:28,900 --> 00:02:29,890
world files.

27
00:02:39,090 --> 00:02:45,060
So now I'll grab the path of the ignition Ross package so I can use it to launch our simulation.

28
00:02:45,060 --> 00:02:49,860
So I want to grab the share directory so I can grab reference files such as the launch files.

29
00:02:54,730 --> 00:02:56,110
Then I will do the same thing.

30
00:02:56,110 --> 00:02:58,750
But grab the share directory of our package.

31
00:03:06,260 --> 00:03:10,190
And then I will create one more variable to get the location of the world file.

32
00:03:17,440 --> 00:03:20,800
Now, keep in mind that this path object in itself is not a string.

33
00:03:20,800 --> 00:03:26,890
So if we want it to be just that full path, we have to call the dot as POSIX function.

34
00:03:28,290 --> 00:03:32,310
And this will return the string representation of that particular path for us.

35
00:03:32,340 --> 00:03:37,710
Now let's go ahead and define our Generate Launch description call, which we define our launch description

36
00:03:37,710 --> 00:03:38,370
list in.

37
00:03:42,340 --> 00:03:45,060
So the first thing I want to do is launch the simulation.

38
00:03:45,070 --> 00:03:49,990
We could use the execute process object to run the same command we ran in terminal to start our ignition

39
00:03:49,990 --> 00:03:50,730
gazebo.

40
00:03:50,740 --> 00:03:55,510
But it's worth noting there is an existing launch file to allow us to do that from the ROS Gazebo SIM

41
00:03:55,510 --> 00:03:56,320
package.

42
00:03:56,320 --> 00:04:00,460
So I'll import a few more things which will allow us to reference another launch file.

43
00:04:06,450 --> 00:04:09,150
Then I can reference the launch file like so.

44
00:04:42,730 --> 00:04:44,620
And oops, I actually made a mistake here.

45
00:04:44,620 --> 00:04:48,460
This is actually g z underscore sim dot launch by.

46
00:04:49,000 --> 00:04:49,490
All right.

47
00:04:49,510 --> 00:04:54,910
Basically what we did is reference a Python launch description which finds the ignition gazebo launch

48
00:04:54,910 --> 00:05:00,880
file from the corresponding package and passes in extra arguments such as passing the simulation world

49
00:05:00,880 --> 00:05:06,880
file path and the dash r flag, which tells the simulation to run on startup a.k.a not be paused.

50
00:05:07,030 --> 00:05:12,100
Now I'll eventually go with the execute process command instead, but it is worth showing as this is

51
00:05:12,100 --> 00:05:17,200
a recommended way to start your launch file by ignition and you can find more example launch files for

52
00:05:17,200 --> 00:05:19,150
ignition at the following link.

53
00:05:20,100 --> 00:05:24,540
Now that we've launched our simulation, let's create a node object, which will be our ignition parameter

54
00:05:24,540 --> 00:05:29,680
bridge so we can convert the command velocity topic from ignition over to ROS two.

55
00:05:29,700 --> 00:05:32,670
This is just like the terminal command we ran in the last lecture.

56
00:06:02,960 --> 00:06:07,700
Now, there are two ways which you can remap the topic, either by passing in the Ross arguments like

57
00:06:07,700 --> 00:06:14,060
we did in Terminal with the dash R flag and then passing in the the original topic name to the converted

58
00:06:14,060 --> 00:06:15,410
topic name like this.

59
00:06:15,890 --> 00:06:21,260
Or alternatively you can utilize the node objects remapping argument to do the same thing in a easier

60
00:06:21,260 --> 00:06:22,850
to read tuple format.

61
00:06:22,870 --> 00:06:26,360
So just go ahead and comment this out and try the remapping key.

62
00:06:38,300 --> 00:06:43,580
So again, either format is acceptable, either US arguments with the dash r flag or re mappings, but

63
00:06:43,580 --> 00:06:48,860
I find re mappings to be much more readable, especially if you end up remapping multiple topics.

64
00:06:48,860 --> 00:06:52,070
Simply just keep adding tuples to the list.

65
00:06:52,100 --> 00:06:54,460
Now there is one more thing we have to do.

66
00:06:54,470 --> 00:06:59,060
If you remember from the last lecture, we needed to set an environment variable so that Ignition gazebo

67
00:06:59,090 --> 00:07:02,990
knew where to look for our models we included in our world PSD file.

68
00:07:02,990 --> 00:07:07,640
So I'll go ahead and import the functionality to allow us to set environment variables.

69
00:07:15,440 --> 00:07:20,660
If you remember, we configured our models folder to get included into our shared directory so we can

70
00:07:20,660 --> 00:07:23,690
go ahead and find it just like we did with our world file.

71
00:07:30,540 --> 00:07:35,010
Then I need to add it to the beginning of my launch description so that it gets applied before we launch

72
00:07:35,010 --> 00:07:35,970
our simulation.

73
00:07:36,000 --> 00:07:41,100
This will take in the name of the environment variable, which is ignition gazebo, resource path,

74
00:07:41,100 --> 00:07:44,190
and a value which will be our model's path variable.

75
00:07:47,580 --> 00:07:52,140
Oh, and it seems I made a mistake here where I'm forgetting a comma, just causing some errors here.

76
00:07:52,140 --> 00:07:53,280
So let's try this again.

77
00:07:53,610 --> 00:07:54,170
There we go.

78
00:07:54,180 --> 00:07:55,860
Now, my autocomplete is working properly.

79
00:08:06,000 --> 00:08:06,480
Great.

80
00:08:06,480 --> 00:08:07,940
This just about covers it.

81
00:08:07,950 --> 00:08:11,940
Let's save the file and compile our workspace.

82
00:08:14,390 --> 00:08:14,660
All right.

83
00:08:14,660 --> 00:08:16,130
So that's gone ahead and compiled.

84
00:08:17,310 --> 00:08:21,630
Now let's open up a terminal and I'll go ahead and source it and launch our new launch file.

85
00:08:26,220 --> 00:08:27,300
And oops, we got one more.

86
00:08:27,660 --> 00:08:28,850
Path is not horrible.

87
00:08:28,860 --> 00:08:30,570
I must have missed one somewhere here.

88
00:08:30,570 --> 00:08:32,580
So here we created our launch file path.

89
00:08:32,580 --> 00:08:35,340
I forgot to convert this back to a string.

90
00:08:36,090 --> 00:08:41,220
All right, let's try Save that since I use some link install, that should take change effect immediately.

91
00:08:41,280 --> 00:08:42,570
Let's try this one more time.

92
00:08:43,710 --> 00:08:48,570
Oh, and it seems I made one more typo here where I was supposed to include the actual world file,

93
00:08:48,570 --> 00:08:50,760
not just stop at the world's directory.

94
00:08:50,760 --> 00:08:55,380
So the file we are interested in running is our wheeled model world.

95
00:08:55,770 --> 00:08:56,100
All right.

96
00:08:56,100 --> 00:08:57,050
Hopefully no more typos.

97
00:08:57,060 --> 00:08:58,560
Let's try this one more time.

98
00:08:59,430 --> 00:09:00,420
Control C out of this.

99
00:09:00,600 --> 00:09:01,500
Clear the screen.

100
00:09:03,210 --> 00:09:04,050
And there we go.

101
00:09:04,050 --> 00:09:08,280
Now we see our simulation opening with our corresponding world.

102
00:09:09,320 --> 00:09:14,300
And now we can also go ahead and open up a second terminal tab and double check to see if the topic

103
00:09:14,300 --> 00:09:16,340
is being remapped into ROS.

104
00:09:16,490 --> 00:09:17,540
And it's not.

105
00:09:18,680 --> 00:09:23,660
Well, and it seems I made one more typo down here where I was defining the topic message type.

106
00:09:23,660 --> 00:09:25,640
So I misspelled geometry.

107
00:09:25,730 --> 00:09:27,140
So geometry.

108
00:09:27,140 --> 00:09:27,670
So there we go.

109
00:09:27,680 --> 00:09:29,510
I just swapped a few letters.

110
00:09:29,630 --> 00:09:34,430
So we're taking the modeled wheel model command velocity topic and we're taking the geometry.

111
00:09:34,430 --> 00:09:38,930
Underscore messages, message twist from ignition messages twist.

112
00:09:39,290 --> 00:09:41,060
All right, try this one more time.

113
00:09:47,130 --> 00:09:49,770
So our simulation starts up like it did before.

114
00:09:52,110 --> 00:09:54,900
And now we see this command veil topic.

115
00:09:55,290 --> 00:10:00,240
So we could also go ahead and open up a visualization program like RCT to publish the values to our

116
00:10:00,240 --> 00:10:02,220
robot like we've done in the previous lecture.

117
00:10:04,600 --> 00:10:06,910
So here I already have it set up from last time.

118
00:10:08,490 --> 00:10:13,100
So we'll just set this to, say 0.5 and start publishing.

119
00:10:13,110 --> 00:10:18,840
And now if I head over to our simulation, we see that our robot is indeed moving.

120
00:10:20,900 --> 00:10:21,230
All right.

121
00:10:21,230 --> 00:10:24,890
So this seems to be in working order, but let's go back to our launch file so I can show you another

122
00:10:24,890 --> 00:10:30,480
nifty feature you will commonly see when working with simulation launch files, which are event handlers.

123
00:10:30,500 --> 00:10:36,260
You see, if we start this simulation and the user were to close the simulation window, the launch

124
00:10:36,260 --> 00:10:38,480
file in the background would still be running.

125
00:10:39,260 --> 00:10:44,650
So in order to stop this, we actually have to hit control C to stop things such as the parameter bridge.

126
00:10:44,660 --> 00:10:50,780
To avoid this, we can instead set up an event handler to listen for a shutdown of the simulation and

127
00:10:50,780 --> 00:10:53,780
stop the rest of the nodes and processes in the launch file.

128
00:10:53,780 --> 00:10:57,320
So I'll go ahead and import some things which will help us with that.

129
00:11:09,850 --> 00:11:13,150
And to use it, I can add it to our launch description like so.

130
00:11:22,200 --> 00:11:27,930
So basically here I'm calling the unprocessed exit handler to detect when the simulation has been closed.

131
00:11:27,930 --> 00:11:32,340
And then we will emit a shutdown event for our entire ROS launch instance.

132
00:11:32,460 --> 00:11:38,160
Now, I need to define this simulation target action variable, which you can do by taking that action

133
00:11:38,160 --> 00:11:42,600
out of your launch description and instead assigning it to a variable.

134
00:11:43,600 --> 00:11:48,000
So essentially what we would normally do is take this include launch description object.

135
00:11:48,010 --> 00:11:49,720
We'll just cut it out like this.

136
00:11:51,320 --> 00:11:59,210
And then right above the definition, I can simply say simulation is equal to and paste it in like so.

137
00:11:59,580 --> 00:12:01,160
I'll fix the tabbing a little bit.

138
00:12:03,000 --> 00:12:08,400
And then now to add it back to our launch description, all we would have to do is type in the variable

139
00:12:08,400 --> 00:12:09,420
simulation.

140
00:12:11,560 --> 00:12:18,820
So this format does the same exact thing as what we had earlier in the sense that it's taking this value

141
00:12:18,820 --> 00:12:21,700
and pulling it into our launch description.

142
00:12:21,820 --> 00:12:27,340
But now we have this nice variable which we can reference for our target action in the Register event

143
00:12:27,340 --> 00:12:28,030
handler.

144
00:12:28,480 --> 00:12:30,850
Now the only problem is referencing a launch description.

145
00:12:30,850 --> 00:12:36,830
File object does not give the functionality of referencing something like a node or executable process.

146
00:12:36,850 --> 00:12:43,990
So if we were to save this launch file and rerun the simulation, I get an error saying caught exception

147
00:12:43,990 --> 00:12:48,100
in launch since the target action is not an execute local or callable instance.

148
00:12:48,100 --> 00:12:50,920
So this is why I prefer to use the execute process.

149
00:12:50,920 --> 00:12:55,930
Call within the launch file to launch the simulation just like we did in terminal, which in my opinion

150
00:12:55,930 --> 00:12:57,520
looks a lot cleaner and easier to understand.

151
00:12:57,520 --> 00:13:03,580
But I wanted to go over this functionality of how you can include external launch descriptions from

152
00:13:03,580 --> 00:13:04,810
other packages.

153
00:13:05,600 --> 00:13:08,030
So for now, I'm just going to comment this form out.

154
00:13:09,620 --> 00:13:14,960
And I'll just say here, you can't use with event handlers.

155
00:13:17,860 --> 00:13:22,810
And so now we'll redefine our simulation variable and instead call execute process with the command

156
00:13:22,810 --> 00:13:24,100
we used to run in terminal.

157
00:13:34,360 --> 00:13:34,720
All right.

158
00:13:34,720 --> 00:13:38,950
So again, we still have our simulation within our launch description, which it's referencing from

159
00:13:38,950 --> 00:13:39,730
this variable.

160
00:13:39,730 --> 00:13:44,890
And all we've done is changed it from this include launch description, format to execute process.

161
00:13:44,890 --> 00:13:51,130
So now if I go ahead and save this file and rerun our launch file, I'm going to screen.

162
00:13:54,750 --> 00:13:58,830
We see this launches as it did before and as we've been doing throughout this section.

163
00:13:58,830 --> 00:14:06,210
But now if I go ahead and close the simulation, we see this will start closing out our parameter bridge

164
00:14:06,210 --> 00:14:08,540
and other instances within the launch file.

165
00:14:08,550 --> 00:14:12,960
So that's gone ahead and closed automatically since it detected we closed the simulation, which is

166
00:14:12,960 --> 00:14:18,810
pretty handy if all that launch file is doing is working with that gazebo simulation instance.

167
00:14:20,140 --> 00:14:25,340
So that just about covers utilizing these launch files for our simulation instances.

168
00:14:25,360 --> 00:14:30,430
So two things I want to mention before we end off this lecture is that you can reference multiple ignition

169
00:14:30,430 --> 00:14:34,630
to ROS topic conversions within our ignition bridge node.

170
00:14:34,630 --> 00:14:40,510
So all you have to do is keep adding the topics which you want to transfer over from ignition to ROS

171
00:14:40,510 --> 00:14:41,020
two.

172
00:14:41,020 --> 00:14:45,070
And then the second thing I wanted to mention is if you want to learn more about event handlers such

173
00:14:45,070 --> 00:14:50,230
as the one I've used here, you can check out the following raw materials page for more information.

174
00:14:52,320 --> 00:14:52,850
All right.

175
00:14:52,860 --> 00:14:54,420
That wraps up this lecture.

176
00:14:54,420 --> 00:14:59,460
These last couple of lectures were mainly to help give you a baseline on how to incorporate simulation

177
00:14:59,460 --> 00:15:03,210
usage with ignition gazebo into your RA package.

178
00:15:03,330 --> 00:15:08,520
So in the next lecture, we will wrap this section up with a project to combine everything we've learned

179
00:15:08,520 --> 00:15:15,960
about ignition gazebo, PSD files, creating models using plug ins, Ros Topic Bridging launch file

180
00:15:15,960 --> 00:15:20,700
incorporation, all within a realistic robotics simulation project.

181
00:15:20,700 --> 00:15:22,080
So I'll see you there.
