In this lecture, we will be learning about how to utilize 2 2
the ROS2 bridge so that we can communicate with systems 3 3
running ROS1. 4 4
So the first thing I'm going to do is head over to my bashrc 5 5
file, which I'll edit in atom at the bottom, we should 6 6
have our sources for our ROS2 installation. 7 7
I'm going to go ahead and comment mines out so that no ROS 8 8
is sourced. 9 9
I'll go ahead and save this and close. 10 10
Now, if I open a new terminal, I should be unable to use 11 11
RO2 or any ROS1 commands. 12 12
Now we can move on to installing ROS1 onto our system 13 13
so that we can utilize the bridge here locally. 14 14
So here I'm on the ROS Noetic installation page since I'm 15 15
currently running Ubuntu 20. 16 16
So go ahead and open up a terminal. 17 17
We'll go ahead and set up our sources list, put in your password, 18 18
then we'll go ahead and set up our keys. 19 19
Then we'll run pseudo app update. 20 20
All right, go ahead and clear the screen. 21 21
And for the purposes of this video, I'm not going to install 22 22
the full desktop version of ROS Noetic partly because it 23 23
will also coincide with my current installations of RViz and 24 24
gazebo. So instead of what I'm going to do is just simply 25 25
install the base version of ROS Noetic. 26 26
So this will just give me the basic packages and communication 27 27
libraries, no user interface tools or anything like that. 28 28
So I'll just go ahead and install this. 29 29
I'll go ahead and hit 30 30
yes. 31 31
And so this will take a while to install. 32 32
So I'll go ahead and pause the video now and we'll come back 33 33
once it's finished. 34 34
Alright. 35 35
So the installation finished. 36 36
We can just see that all it did was set up all the packages. 37 37
That took about maybe four minutes for me. 38 38
So that should have been too bad for you. 39 39
Now we'll go ahead and move on with the environment set up 40 40
of this. 41 41
So in order for us to utilize our ROS1, right, we can't 42 42
use anything 43 43
yet. 44 44
If I use roscore, which is a ROS1 command to start 45 45
the ROS Master. 46 46
Even though we have ROS installed, we can't use anything 47 47
because we haven't set up our environment file. 48 48
So if I go ahead and source my terminal environment, we should 49 49
now see that I can run things like roscore. 50 50
Great. 51 51
So now this device has ROS1 and ROS2 installed on 52 52
it. But by default, neither will be sourced on terminal startup. 53 53
So the next thing we're going to do is we're going to make 54 54
sure that we have all these other dependencies for building 55 55
packages. So I'll go ahead and copy and paste this in. 56 56
Go ahead and hit. 57 57
"Y" and enter. 58 58
In most cases, you already have ROS dep installed, but you 59 59
can double check by pasting in this so we can see I've already 60 60
have it installed. 61 61
We can double check that it's initialized by running these 62 62
commands. So here we can see error sources file already exists. 63 63
So I'm not going to bother removing that one creating a new 64 64
one. I'll just leave it as is. 65 65
Okay, so now we have ROS1 and ROS2 installed and we 66 66
have our extra dependencies if we have to build any packages. 67 67
So for now, I'm actually going to start off clean with a 68 68
new terminal environment that's not sourced on any ROS system. 69 69
So now if I run ROS2 help see ROS2 command not found 70 70
or roscore, and we see roscore not found. 71 71
Okay, so this terminal instance can't see either one of our 72 72
ROS installations. 73 73
So now we'll go ahead to the ROS1 bridge documentation. 74 74
Alright, so here are the prerequisites. 75 75
We should have majority of these prerequisites from the basic 76 76
installation. But first off, I'll go ahead and source the 77 77
ROS1 installation, as these are catered towards the ROS1 78 78
installation. 79 79
So I'll do source/opt/ros/noetic. 80 80
--- 81 81
And so now I should have access to my tools like roscore 82 82
and we can see I do. 83 83
Now I'll just make sure that I have all these other packages 84 84
installed, which I can do using pseudo apt install. 85 85
And then we do ROS the name of the distribution which in 86 86
this case for me is Noetic. 87 87
And then the name of the package. 88 88
So things like catkin, roscpp, roslaunch, rosmsg 89 89
should all be already installed because that comes with the 90 90
basic installation. 91 91
The main things we're going to be missing though, are going 92 92
to be those that are utilized for the examples including 93 93
the tutorials and the RQT image view. 94 94
So I can go ahead and install those specifically. 95 95
And note instead of using underscores when using the pseudo 96 96
apt command, you should use just a simple dash when you see 97 97
the package name separated by underscores. 98 98
So as you can see here, instead of doing roscpy_tutorials 99 99
I am doing roscpy-tutorials, but that correlates 100 100
to the correct package. 101 101
And then last but not least, I'll install the RQT image view. 102 102
Alright. 103 103
And we should be good to go on that front. 104 104
You can double check with all the other packages that you 105 105
have them properly installed. 106 106
Moving on. 107 107
We can go on to building the bridge from source. 108 108
So earlier we installed ROS2 from source. 109 109
And so in order to utilize it, we actually have to make sure 110 110
that we skip the ROS1 bridge command on build initially. 111 111
So I'll go ahead and do that now in a new terminal. 112 112
So here you are seeing we're rebuilding the ROS2 installation, 113 113
but this should go by a lot faster since we've already built 114 114
it already. 115 115
This time we're just simply skipping the ROS1 bridge. 116 116
That took 20 minutes or so. 117 117
We did have some standard error outputs from RQT, GUI and 118 118
RM Connect. 119 119
I'm not going to be using Connect and I don't plan on using 120 120
the RQT Gui, so I don't think this will affect us for right 121 121
now. So I'm just going to continue on with the read me documentation 122 122
for utilizing the ROS bridge. 123 123
So now we need to source our ROS1 environment. 124 124
We will do source/opt/ros/noetic/setup.bash 125 125
ROS2 installation which is located here in my 126 126
workspace directory. 127 127
So I'll do source install setup bash. 128 128
So I'll mention that the distribution was Noetic before. 129 129
That's fine, because that's what indeed we were doing. 130 130
We had our ROS1 source, and then now we just source our 131 131
ROS Fox installation. 132 132
Now we can build the ROS1 bridge using this command. 133 133
So this will only rebuild the ROS1 bridge package so 134 134
it won't rebuild the whole ROS2 installation. 135 135
So we'll go ahead and run this. 136 136
Alright. 137 137
So our ROS1 bridge finished building. 138 138
That took about eight minutes for me. 139 139
So I we'll go through and try to run some examples. 140 140
So I'll go ahead and open up new terminals that are independent 141 141
of this one, since this one has both of them. 142 142
sourced, I'll put this one away. 143 143
So the first one I'll do is source this terminal to have 144 144
only ROS1 to imitate my previous robot or system which 145 145
only ran ROS1 code, such as sources opt ROS noetic 146 146
setup.bash 147 147
And then we'll just run a roscore instance. 148 148
Then for this example, we'll need another shell which has 149 149
ROS1 and then ROS2 source, which pretty much makes 150 150
up the previous terminal we had and did our installation. 151 151
So I'm going to bring that one back. 152 152
And what we're going to do is export the ROS Master URI 153 153
to match that of the local host or in this case, what this 154 154
URI should be. 155 155
So we can go ahead and export that. 156 156
And now we can try run the ROS2 bridge. 157 157
Alright. 158 158
So here we can see that it created a bridge for the ROS 159 159
out and RCL interface tags. 160 160
Here I go and open a new terminal tab. 161 161
Source opt ROS Noetic, setup.bash ROS topic list. 162 162
All right. 163 163
So we see that it converted our ROS out from ROS1, to ROS2 164 164
Alright, so now we can go ahead and actually start some 165 165
notes. For this example, we'll need another terminal which 166 166
has our ROS1 source, which I just did here. 167 167
I should go ahead and clear the screen and we'll go ahead 168 168
and run talker node from the tutorials. 169 169
So here we see these "Hello Worlds" publishing out. 170 170
And now I can go ahead and open up another ROS2 instance. 171 171
So this one has our ROS bridge running. 172 172
So I'm going to open up another terminal tab and I'm going 173 173
to source our install setup bash file. 174 174
And then we can do our listener node. 175 175
Okay. 176 176
And here we can see we are receiving the "Hello World" messages 177 177
from ROS version one. 178 178
In this case, Noetic ROS2 Foxy. 179 179
So there you go. 180 180
That's how you can utilize the ROS bridge to bridge over 181 181
perhaps old nodes that you had made in ROS1, and then 182 182
you can implement them into ROS2 nodes. 183 183
I'll go ahead and stop these. 184 184
That's it. 185 185
For this part of the video, I will do a second part of the 186 186
video where I will do cross device communication using the 187 187
ROS bridge. 188 188
Alright, so here we are. 189 189
I have two different computers going right now that are connected 190 190
to each other via an Ethernet switch. 191 191
So the first one is our original computer, which is running 192 192
our ubuntu 20, where we have our ROS2 Foxy installed 193 193
as well as ROS1. 194 194
Noetic, on the second computer, we have a laptop of mine 195 195
that's running Ubuntu 18. 196 196
And this one is running ROS Melodic. 197 197
So starting off with my laptop, I can go ahead and open up 198 198
a terminal here just to show this to you. 199 199
If I go over and do ROS version -d, as you can see, I'm running 200 200
Melodic. And if I were to do ROS2 help, you can see that 201 201
I do not have ROS2 install. 202 202
All right, so that's the first thing to note. 203 203
The second thing to note when working with two different 204 204
systems is that each one will have its own independent IP 205 205
address, either by you setting it or by a router setting 206 206
it. So I can check that by running the IF Config command. 207 207
And so here we can see my IP address for this computer is 208 208
192.168.50.177, so all my other local computers that are 209 209
on this network can't communicate with this computer by locating 210 210
this IP address. 211 211
So we can do the same thing over here on my Ubuntu 20 machine. 212 212
So if I go over here and I type in If Config, you can see 213 213
this machine has an IP address of 192.168.50.3 214 214
So be wary of what your machines IP addresses are, because 215 215
they will vary from mine if you are trying to reproduce what 216 216
I'm about to do here. 217 217
All right. 218 218
So heading back to my machine running Ubuntu 18, I can go 219 219
ahead and clear the screen. 220 220
So this will be running our ROS1 instance. 221 221
And we'll be simulating essentially that this is one of our 222 222
robots running a ROS1 node. 223 223
And then we want our Ubuntu 20 machine which has ROS2 224 224
and ROS1 installed to be able to communicate with this 225 225
one. And so we don't want to have to install ROS2 in this 226 226
machine. So we're going to go through how we can go about 227 227
doing that. 228 228
If we have an older robot that we developed code for, we 229 229
can still utilize it with newer machines that run ROS2. 230 230
So the first thing to note, whenever we're dealing with ROS 231 231
networking, we have to set ROS master URI and the ROS IP 232 232
of the device. 233 233
So I've gone ahead and listed these down. 234 234
Right. 235 235
So we just took note of the IP address, and I'll put it back 236 236
up on here. 237 237
IF config. 238 238
All right, so this one is 192.168.50.177 239 239
So in ROS1, there was a central ROS Master server, which 240 240
all the ROS nodes would have to communicate with. 241 241
I will have that set running on this computer. 242 242
So what I will do is set my ROS Master URI by using the 243 243
export command, and I will set it to all set up to https 244 244
this IP address, and then Port 11 3 11, which is a default 245 245
Port ROS1 runs off of. 246 246
So I'll go ahead and run that. 247 247
Then I'm going to set the ROS IP of this particular device, 248 248
which is just the IP address part. 249 249
So you don't need the Http, and you don't need the Port number 250 250
at the end of it. 251 251
And so with that, now, this knows that the ROS Master should 252 252
be running on this machine on Port 11 3 11, because this 253 253
is the machine with this particular IP address. 254 254
So now we can go ahead and start our ROS Master for ROS 255 255
one using ROS Core. 256 256
Okay, so now we have a roscore instance running. 257 257
So our ROS Melodic is running. 258 258
So now if we go over to our one to 20 machine, we can run 259 259
through the first example from the ROS1 bridge documentation 260 260
in a very similar way. 261 261
So right now, our shell A, which is ROS1 only, is that 262 262
Ubuntu 18 computer that I just ran roscore on. 263 263
So that only has ROS Melodic on it, and it's now running 264 264
roscore. 265 265
So now this will be our shell B. 266 266
So we first source ROS1. 267 267
In this case, I don't have melodic, but I have Noetic, but 268 268
this will still work, even though it's a different distribution. 269 269
So if I go ahead and run this source command right here, 270 270
I am sourcing my Noetic setup bash where I installed it. 271 271
Okay, so now my ROS Noetic is sourced for this terminal. 272 272
Then we'll go ahead and source our ROS2 instance, which 273 273
I also have here because I built ROS2 from source. 274 274
So I have it here in my workspace folder, ROS2 Foxy, and 275 275
then install setup bash. 276 276
And so we got a little warning here saying set to Noetic 277 277
before, please make sure. 278 278
But that's totally fine. 279 279
So for now, I'm just going to clear the screen. 280 280
And now we need to export the ROS Master URI and our ROS 281 281
IP address to match what it's supposed to be. 282 282
So first off, we'll set the ROS Master URI. 283 283
So the same thing we just set it to on the other computer. 284 284
Right. 285 285
So the ROS Master is running on the open to 18 computer, 286 286
which has this IP address. 287 287
So this will be our Master URI we want to communicate with. 288 288
And then, as we mentioned, if I type in is config. 289 289
Right. 290 290
This is the IP address for this specific computer. 291 291
So I'm going to export the ROS IP variable here in my terminal 292 292
so that it knows that this is the ROS IP of this machine. 293 293
Cool that I can go ahead and clear the screen. 294 294
And now we can run ROS bridge. 295 295
So if I go ahead and run this ROS2 run ROS1 bridge 296 296
dynamic bridge, you can go ahead and run it, and you can 297 297
see it created the bridge, and it's already beginning to 298 298
convert those messages. 299 299
Now we can actually open up another terminal to follow through 300 300
with this example. 301 301
And we will open this up on our Ubuntu 18 machine. 302 302
And this will be our talker note that comes with just the 303 303
normal ROS Py tutorials for ROS1. 304 304
So I'll go ahead and do that now. 305 305
So I'll control alt T. 306 306
So now I have a new terminal here. 307 307
And just to make sure again, just to prove to you that this 308 308
is only source with this ROS melodic. 309 309
If I do, ROS version -d it says melodic. ROS2 help. 310 310
And you can see I don't have ROS2 installed on this machine, 311 311
so I'm not trying to pull anything here. 312 312
This machine only has ROS1 on it. 313 313
We will need to make sure, though, that we have our Master 314 314
URI and IP properly set in every terminal. 315 315
So normally you would set this in your bash RC file so that 316 316
it runs every time you open a new terminal. 317 317
But for right now, I'm just going to set this manually. 318 318
Each time we open a new terminal, we will only be opening 319 319
these terminals. 320 320
This should be fine. 321 321
And now we can go ahead and run our talker node. 322 322
So here we can see the default Hello World messages are pointing 323 323
to the screen. 324 324
Now, if I go back to my ubuntu 20 machine, I can open up another 325 325
shell that only needs to have ROS2 sourced on it. 326 326
So I'll go ahead and do control alt T. 327 327
And here's my second instance. 328 328
And so I will source my ROS Foxy install, and we don't have 329 329
to worry about the warning. 330 330
And then if now I go ahead and run a listener. 331 331
Right. 332 332
So there are no talker nodes running on this machine the 333 333
only talker node is running on the Ubuntu 18 machine. 334 334
But because we have our bridge running here, we should be 335 335
able to listen in on those messages over the network, because 336 336
we set our ROS Master URI and our ROS IP address accordingly. 337 337
Actually, that's actually what I need to do here. 338 338
So before I go ahead and run that, I will need to set our 339 339
ROS Master URI and our ROS IP in this terminal, since this 340 340
is a new terminal, alright 341 341
With that, now I can go ahead and run the listener. 342 342
And here you can see the ROS bridge detects that message 343 343
coming from the ROS2, and the ROS1 it bridges it. 344 344
And here we can see I heard Hello World, which is matching 345 345
with what is being sent from the Ubuntu 18 computer. 346 346
Cool! 347 347
And it's worth noting that this works both ways. 348 348
So I'll go ahead and stop this listener node, and I'll stop 349 349
the talker node on the other machine. 350 350
I'll go ahead and clear the screen on both of these. 351 351
But this also works from ROS2 to ROS1. 352 352
So if you create any new nodes on your ROS2 instance 353 353
that you want your ROS1 computer to Subscribe to, it 354 354
works the same way. 355 355
Instead of running the listener node this time, I can run 356 356
the talker node. 357 357
So if we say talker, we can see we're publishing Hello World. 358 358
And then counter variable. 359 359
That's what this version of talker looks like for ROS2. 360 360
And now if I run the listener node on our own to 18 machine 361 361
that is running only ROS1 the ROS bridge will show up, 362 362
that it's bridging the communications. 363 363
And we can see here that my ROS2 publishing Hello World 364 364
is being received on my ROS1 machine, and it's receiving 365 365
the Hello World messages just fine on the listener node. 366 366
I can go ahead and stop this node. 367 367
With that, you have successfully implemented use of the ROS2 368 368
bridge so that you could bridge communications between 369 369
ROS1 and ROS2 systems.