In the last lecture, we learned how to create our own model 2 2
in Gazebo, which we made this simple wheeled model. 3 3
If you remember, we saved our model in a folder in our home 4 4
directory. So Let's take a look at the files that were created. 5 5
So if you go into model editor models, here in wheeled models, 6 6
we see that we have a model config and a model SDF file. 7 7
Let's take a look at these in Atom. We can see this model 8 8
config is an XML file with basic info such as the name of 9 9
the model, the version, and author info. 10 10
The SDF file is also an XML file which is structured as a 11 11
model tag which have various link property Tags in it. 12 12
We can see the visual info, as well as the collision info, 13 13
which we set when we created our model within Gazebo. 14 14
This continues on for all of our links. 15 15
Once we get low enough within the file, we begin seeing our 16 16
joints. So as you remember, we joined these individual links 17 17
or shapes together with joints. 18 18
Here we can see the first joint I made, which was a revolute 19 19
joint which combined the base of my robot to the first wheel. 20 20
One of the things ROS2 tried to implement was the usage of 21 21
ROS straight into an SDF file, 22 22
since they could be easily created using the model editor 23 23
we use in the last lecture. Rather than just talking about 24 24
it, Let's jump into an example. 25 25
We will first need to install the Gazebo ROS packages. 26 26
Let's go ahead and open our terminal. 27 27
I'll go ahead and stop this current instance of Gazebo by 28 28
hitting 'control C' and I'll clear the screen. 29 29
First thing I'll go ahead and do is update our apt repositories. 30 30
All right, then I can go ahead and install the Gazebo ROS 31 31
packages using 'sudo apt 32 32
install ROS Foxy Gazebo ROS P-K-G-S'. Alright, I'll go 33 33
ahead and hit Y and enter to install. 34 34
Alright, so that's installed, so I'll go ahead and clear the screen. 35 35
This package comes with prebuilt example. 36 36
Let's go ahead and take a look at one that is similar to 37 37
what we've made in the last lecture. 38 38
Here I am using the verbose flag which prints out more logging 39 39
of what is happening behind the scenes of Gazebo. 40 40
When we run the command, we see a robot with spheres for 41 41
wheels and a smaller wheel that's behind it to act as a caster. 42 42
Now Let's look back at the terminal where we launched this. 43 43
Here we see info about a wheel pair, as well as subscribers, 44 44
publishers, and transforms. 45 45
So I'll go ahead and open a new terminal tab using 'Control 46 46
Shift T' and check out the available topics using ROS2 Topic 47 47
list. There are three topics of interest here. 48 48
The 'Demo command demo' topic is actually a topic I can publish 49 49
to in order to move the robot. 50 50
Then we have the 'Demo odom Demo' Topic, which is providing 51 51
information about the robots position relative to our simulation 52 52
world. Lastly, the TF topic contains information on the transforms 53 53
of the links and joints in our model. 54 54
I can go ahead and open up is using RViz 2. 55 55
We can see we have some errors here. 56 56
This is because the default fixed frame is map, which does 57 57
not exist in the simulation. 58 58
So if I select it, I can Select the dropdown list, and Select 59 59
the link from this particular model. 60 60
In this case I can Select chassis and the errors will go 61 61
away. Now if I select add I could Select by topic. 62 62
In this case I can Select Odometry. 63 63
Here we can see an arrow appear with this yellow field. 64 64
This yellow field is basically the covariance, which I can disable 65 65
by Unchecking it in the drop down menu. 66 66
And so here is the direction which our robot is pointing 67 67
essentially, and this will update as the robot moves. We can 68 68
then go to add again, 69 69
And this time I can Select 'by type' and I can Scroll down 70 70
to TF. 71 71
And here we can see the individual transforms of our robot. 72 72
If I go ahead and hit the drop down arrow, I can click on 73 73
'show names' and here we can see each corresponding transform 74 74
name. Here we have the right wheel. 75 75
Here we have the left wheel. 76 76
Here we have the chassis and here we actually have the odometry 77 77
of our world. 78 78
Alright, I'll Uncheck 'show names' just so that we can see 79 79
the actual transforms a little bit better. 80 80
And here we can also see the relationship between the wheels 81 81
and our chassis via this yellow line which represents the 82 82
joint. Alright, our screen is going to get a bit clustered 83 83
here, so I'll shrink down the window and close the side tabs. 84 84
Now I will go back to terminal. 85 85
I'll open a new terminal tab using 'Control shift T' and run 86 86
RQT. Once it opens I will move it under my RViz window. 87 87
Then I'll open the message publishers plugin and I can go 88 88
ahead and Select the 'command demo' topic... and I can't see the 89 89
topic name... 90 90
We'll actually need to extend this out a little bit. 91 91
We see the 'command demo'. I can hit 'add'. 92 92
We can see this topic is of type 'twist' which contains both 93 93
linear and angular velocities of our object. 94 94
I'll go ahead and re shrink this back down. 95 95
I'll minimize this terminal. 96 96
And now if I go ahead and set this X velocity, to say 1, 97 97
and I begin publishing to the topic, 98 98
We can see the wheeled model in our simulation 99 99
begin to move. 100 100
I'll go ahead and set this down to zero and we should see 101 101
the robot stop. 102 102
Okay, we saw a lot of things happen there. 103 103
First of all, the robot drove forward in gazebo. 104 104
Then in the RViz window, we were able to see the transforms 105 105
of the wheels rotate, as well as the transform of the world 106 106
origin move farther away. 107 107
I can move back towards the origin so we can see the origin 108 108
transform a little bit closer within the RViz window. 109 109
I'll go ahead and stop. 110 110
And so here we can see this is the origin of our world relative 111 111
to the transforms within our RViz window. 112 112
So here we can see there's a lot of information flowing between 113 113
ROS and our Gazebo simulation. 114 114
We could apply the same features in real life on our own 115 115
robots without using Gazebo using various sensors and localization 116 116
Nodes, which would calculate the transforms of our robot. 117 117
Okay, now Let's take a look at the world file which allowed 118 118
all of this to happen. 119 119
I will open up our terminal, which we launched Gazebo in, and 120 120
I will go ahead and copy the path which this world file was 121 121
located. And then in a new terminal tab, I can just simply 122 122
type 'Atom', and put in the file path. And so here we can see it 123 123
opens up an Atom. So it doesn't immediately recognize 124 124
the XML syntax so I can go ahead down here and set it as 125 125
such. All right, now it's a bit more readable with the syntax 126 126
color. So here we can see this world file is just an SDF 127 127
file. After our SDF tag, there is a world tag where the ground 128 128
plane and our sun are included, followed by the actual model 129 129
we see in the simulation. 130 130
Here we can see this the same SDF format that the robot we 131 131
created has. 132 132
The main difference comes towards the end. 133 133
Here at the end we see a plugin tag here. 134 134
The plugin is named 'Diff Drive', and it references the Gazebo 135 135
ROS 'diff drive SO' file, which is from the Gazebo ROS packages 136 136
library we installed. 137 137
Then below we can configure the ROS topics, including the namespace, 138 138
which was set to demo, and topic names, followed by specifying 139 139
the joint names in the SDF model, which we want to assign 140 140
to the left and right joint wheels. 141 141
Then some wheel limits are set and specify what publishers 142 142
we want to use and what frames we want. 143 143
All this information is specific to this particular plugin. 144 144
We could easily apply this to the model we created earlier. 145 145
I will just copy it and paste it into our model's SDF file. 146 146
So I will put it at the bottom, right before the end of our 147 147
model tag. 148 148
Next, I will modify the namespace and topic names so that 149 149
you can see that there's a difference. 150 150
Next, I will change the joint names so it matches what the 151 151
joint names are in my SDF file above. 152 152
Here we can see it's called 'link zero joint 1' and this one 153 153
actually represents my left wheel. 154 154
So if I Scroll down under the left joint tag, I'll simply 155 155
paste in this 'Link zero underscore joint underscore one' and 156 156
I'll just paste it here for the right joint change 1 to 157 157
0 to represent the first revolute joint I created, which 158 158
is right here. 159 159
'Link zero joint 0' which is our right wheel. 160 160
If I recall, my wheel diameter is 1, and my wheel separation 161 161
is 0.75, then I will leave everything else as is, except for 162 162
the robot base frame I will have set to 'Link zero', which 163 163
is our initial box link. 164 164
So if I Scroll up to the top here, we can see our very first 165 165
link we created is named 'Link Zero', and you could go ahead 166 166
and change all these names so that they were more descriptive. 167 167
These were just the auto generated names that the Gazebo 168 168
Model editor created for us. I will change the Odometry 169 169
frame name to just 'Odom'. 170 170
So then I can go ahead and save this file. 171 171
And now I will go to my terminal, which has gazebo open and 172 172
I can stop it with 'control C'. 173 173
And then I'll run Gazebo and I'll call the 'verbose' tag again. 174 174
And then I'll type in '-s libgazebo_ros_factory.so' 175 175
So this second half of the command is the plugin, 176 176
which allows us to communicate with the Gazebo simulation 177 177
over ROS2. 178 178
This was automatically started in the last example because 179 179
it came straight from the Gazebo plugin package, which is 180 180
a ROS2 package. 181 181
So I'll go ahead and hit enter. 182 182
So if I go back to the terminal, we can indeed see ROS was 183 183
initialized. Now nothing else happened here because our model 184 184
is not yet imported. 185 185
So Let's go ahead and do that. 186 186
So if I go to insert, and down here I can see my wheeled model 187 187
from our model editor path. 188 188
So if I go ahead and click on it, I'll put it around the 189 189
origin. And now if I go back to my terminal, we can see all 190 190
the information related to the plugin, including the wheel 191 191
pair, information publishers, subscribers, and link transforms. 192 192
So now Let's go back to my RQT and my RViz, and so I can stop 193 193
publishing to this topic because it actually no longer exists 194 194
and I will remove it. 195 195
And in our RViz, our chassis fixed frame no longer exists. 196 196
So I actually will change this to Link zero and now we will 197 197
see all the corresponding topics properly. 198 198
I'll go ahead and uncheck this odometry tag for now because 199 199
this is from our old robot. 200 200
And here we're getting some warnings about our TF frames, 201 201
and that's because it's actually cached in some of the old 202 202
frames from the previous model. 203 203
So I can actually go ahead and I'll just restart RViz to 204 204
get rid of that. 205 205
Go back to my RViz2 window and restart it. 206 206
All right. 207 207
So we will change this to Link zero. 208 208
We'll fix our errors at our TF frames. 209 209
Alright. 210 210
And we see that all appears without any warnings or errors. 211 211
So here we see our 'Link zero', which is our base. 212 212
We see our 'Link one', which is our first wheel and our 'Link 213 213
one clone', which is our second wheel and the world frame. 214 214
I'll go ahead and minimize this terminal. And down in RQT, I can 215 215
refresh the topics using this refresh button. 216 216
And now if I go ahead and check out some of the topics to 217 217
choose from, I can choose the 'my bot' command topic. 218 218
I'll go ahead and add it, and now I should be able to control 219 219
the model that we created in the last lecture by simply putting 220 220
in a velocity of, say 1, and then I can go ahead and check 221 221
the check Mark so that it starts publishing. 222 222
And now we see the robot begins to move and set this back 223 223
to zero 224 224
So it stops. 225 225
And if I wanted to, I could set the angular velocity if I 226 226
wanted to turn the robot. 227 227
So if I turn this to say 0 5, you'll see, the robot slowly 228 228
starts to turn. 229 229
I could drive back to the origin like this. 230 230
Okay, great. 231 231
We successfully made a robot simulation model which can interact 232 232
with ROS, but it's also worth noting that Gazebo can also 233 233
help simulate sensor values. 234 234
Let's try an example that uses a camera. 235 235
I go to my terminal, I'll close the current simulation, I'll 236 236
clear the screen, then I'll type in 'gazebo', 237 237
I'll call the verbose flag again, and this one will be -- 238 238
--. Alright, so it seems there was an error opening the 239 239
plug in. 240 240
Alright, so if you're running into this issue where you see 241 241
it says fail to load plug in. 242 242
Sometimes the terminal gets a little bugged out and doesn't 243 243
get source properly. 244 244
Go ahead and open up a new one. 245 245
I'll slide it to the beginning. 246 246
Here we'll copy the previous command we ran. 247 247
Let's see if we have more luck in this terminal. 248 248
Alright, there we go. 249 249
I didn't see any errors that time, so I think we're okay. 250 250
I'll go ahead and close this terminal for now, since I'm 251 251
not using it. 252 252
If we go over to gazebo, we can see a ball bouncing up and 253 253
down as well as a screen which seems to be displaying like 254 254
an image of sorts. 255 255
So essentially what's happening is there's link here that 256 256
has no geometry with our camera in it and it's looking in 257 257
this direction and the screen is being portrayed right here 258 258
so that you can visualize what the camera is seeing. 259 259
So Let's go ahead and view this camera data. 260 260
I'll go over to our RQT window. 261 261
So here we have our message publisher. 262 262
I'll go ahead and stop publishing since we're don't have 263 263
a robot to interact with. 264 264
If I go down to the visualization tab, open up image view. 265 265
I'll Select the 'image raw' message and we can see a ball bouncing 266 266
up and down. 267 267
Note, if you're using this within a virtual machine, you 268 268
may not be able to see the image. 269 269
And that's mainly because of the quality of service policies 270 270
in ROS2 actually get hung up in virtual machines sometimes. 271 271
So if you're running into this issue where you're not able 272 272
to see the camera feed on RQT, 273 273
I have created a script which is available in the resources 274 274
section which you can use, which will create a subscriber 275 275
with the proper quality of service configuration that should 276 276
be able to run within your virtual machine and show your 277 277
camera feed. 278 278
All right, with that out of the way... 279 279
So we see the ball, and I can actually add things to the simulation 280 280
so that we can make sure that we are seeing what's happening 281 281
in the simulation. 282 282
So I'll go ahead and insert my ambulance. 283 283
And now if I go back to my RQT window, I can see the ball 284 284
bouncing up and down in front of my ambulance. 285 285
It is worth noting that RViz also has an image viewing 286 286
attribute to it. 287 287
So if I go ahead and open this Sidebar, I can add by topic 288 288
our image raw and I'll just choose our raw camera image. 289 289
Okay, but Unfortunately, we are unable to see anything. 290 290
And that's actually because of a bug right now, which is 291 291
in RViz, which you can't view a camera feed unless you have 292 292
selected a fixed frame which is related or connected to that 293 293
camera. And so since this simulation actually doesn't have 294 294
any joints like an actual physical camera joint to publish 295 295
to that we could Select in this fixed frame section, we actually 296 296
are unable to use this camera plugin within RViz, so hopefully 297 297
they fix that in the future. 298 298
Another thing you should know about since we talked about 299 299
quality of service settings, is you can go ahead and under 300 300
topic within this camera, 301 301
You can go over to the history, reliability, and durability 302 302
policies in case you need to change it. 303 303
And in most cases, you may need to change the reliability 304 304
policy to best effort in order to view the image. 305 305
But of course, that will be once you've selected a frame 306 306
related to your camera image, which we can't do for this 307 307
example. So for now, I'll just go ahead and remove this camera 308 308
since we can't really do it in RViz for now. 309 309
Okay, so with that, we see that there's a camera in our simulation 310 310
and it's publishing over 311 311
ROS. So Let's go ahead and take a look at the source code 312 312
of this example to see how this camera works. 313 313
So go ahead and stop the simulation. 314 314
And we can see the last image frame that was available from 315 315
the simulation. 316 316
And now instead of calling Gazebo, I will just simply type 317 317
in 'Atom' using the same file path. 318 318
So now we have this camera demo world. 319 319
I'll go ahead and change the file format to XML. 320 320
Here we see the ground plane model. 321 321
If we Scroll down, we eventually get to the ball model. 322 322
And if we continue to Scroll down, we see there is a camera 323 323
model which essentially shows a link named Camera link which 324 324
has a sensor attached to it, followed by a plugin called 325 325
camera controller, which comes from the file name 'Lib Gazebo 326 326
underscore ROS underscore camera'. Here, the main things 327 327
we can change are the Node namespace, and that someone named 328 328
Louis needs to fix the remapping functionality. 329 329
So best of luck to Louis that he can address this. 330 330
If you want to learn more about available sensors, feel free 331 331
to check out the Gazebo ROS packages GitHub page and Select 332 332
the 'Foxy' branch. 333 333
Or you can simply check out all the different example worlds 334 334
they have available, so I can open up this directory in our 335 335
File Explorer by simply, instead of typing in, 'Atom', I can type 336 336
in, 'nautilus', which is the name of our File Explorer. 337 337
And so here are all the available worlds which come with the 338 338
Gazebo ROS packages plug in. 339 339
So if I put in this in list view, we can see a series of 340 340
different plugins to try, including several camera worlds. 341 341
We can try differential drive, GPS sensors, and much more. 342 342
So feel free to check these out if you want to add more functionality 343 343
to your ROS simulations in Gazebo. 344 344
Great. 345 345
Hopefully, now you have a better feel on setting up simulations 346 346
utilizing various plugins and utilizing the visualization 347 347
tools to help you visualize the data coming from those simulations.