In the last lecture, we created a simple robot model simulation and controlled it over Ros using the
ignition parameter bridge.
So let's configure our package so that we can create a launch file to easily launch our simulation and
any related nodes such as our parameter bridge.
First things first, let's configure our smokeless text file to utilize the ignition simulation by calling
the install command on the world and models directory so that when you make launch files you can easily
reference them.
So we should make sure to reference the ROS package that allows us to run ignition gazebo and our parameter
bridge, which is Ros Ignition gazebo.
Then you should also be sure to include it in your package, that XML file.
Then back to my C make list text file right below where I install my launch directory to the share folder.
I can make this a bit more compact, copy it and include it for my world and models directory.
Now, if I go ahead and save these files and rebuild my project with Culkin, build Simulink install.
All right.
Let's go ahead and build.
So now when I go into our install folder in our workspace directory.
Then into package, then share, and then into our package name again.
We eventually see the Models and Worlds folder, which has our linked files, which we're going to be
using for our simulation.
So let's go ahead and create a launch file to start up our simulation and the ignition bridge so we
can send commands over Ros to control our robot.
So I'll make a new launch file in my launch folder called Simulation Dot launch dot pie.
I'll include some of the standard imports, such as our launch description node and execute process
objects, which we've used before.
Then we will include a couple of imports which will help us resolve our paths to things such as our
world files.
So now I'll grab the path of the ignition Ross package so I can use it to launch our simulation.
So I want to grab the share directory so I can grab reference files such as the launch files.
Then I will do the same thing.
But grab the share directory of our package.
And then I will create one more variable to get the location of the world file.
Now, keep in mind that this path object in itself is not a string.
So if we want it to be just that full path, we have to call the dot as POSIX function.
And this will return the string representation of that particular path for us.
Now let's go ahead and define our Generate Launch description call, which we define our launch description
list in.
So the first thing I want to do is launch the simulation.
We could use the execute process object to run the same command we ran in terminal to start our ignition
gazebo.
But it's worth noting there is an existing launch file to allow us to do that from the ROS Gazebo SIM
package.
So I'll import a few more things which will allow us to reference another launch file.
Then I can reference the launch file like so.
And oops, I actually made a mistake here.
This is actually g z underscore sim dot launch by.
All right.
Basically what we did is reference a Python launch description which finds the ignition gazebo launch
file from the corresponding package and passes in extra arguments such as passing the simulation world
file path and the dash r flag, which tells the simulation to run on startup a.k.a not be paused.
Now I'll eventually go with the execute process command instead, but it is worth showing as this is
a recommended way to start your launch file by ignition and you can find more example launch files for
ignition at the following link.
Now that we've launched our simulation, let's create a node object, which will be our ignition parameter
bridge so we can convert the command velocity topic from ignition over to ROS two.
This is just like the terminal command we ran in the last lecture.
Now, there are two ways which you can remap the topic, either by passing in the Ross arguments like
we did in Terminal with the dash R flag and then passing in the the original topic name to the converted
topic name like this.
Or alternatively you can utilize the node objects remapping argument to do the same thing in a easier
to read tuple format.
So just go ahead and comment this out and try the remapping key.
So again, either format is acceptable, either US arguments with the dash r flag or re mappings, but
I find re mappings to be much more readable, especially if you end up remapping multiple topics.
Simply just keep adding tuples to the list.
Now there is one more thing we have to do.
If you remember from the last lecture, we needed to set an environment variable so that Ignition gazebo
knew where to look for our models we included in our world PSD file.
So I'll go ahead and import the functionality to allow us to set environment variables.
If you remember, we configured our models folder to get included into our shared directory so we can
go ahead and find it just like we did with our world file.
Then I need to add it to the beginning of my launch description so that it gets applied before we launch
our simulation.
This will take in the name of the environment variable, which is ignition gazebo, resource path,
and a value which will be our model's path variable.
Oh, and it seems I made a mistake here where I'm forgetting a comma, just causing some errors here.
So let's try this again.
There we go.
Now, my autocomplete is working properly.
Great.
This just about covers it.
Let's save the file and compile our workspace.
All right.
So that's gone ahead and compiled.
Now let's open up a terminal and I'll go ahead and source it and launch our new launch file.
And oops, we got one more.
Path is not horrible.
I must have missed one somewhere here.
So here we created our launch file path.
I forgot to convert this back to a string.
All right, let's try Save that since I use some link install, that should take change effect immediately.
Let's try this one more time.
Oh, and it seems I made one more typo here where I was supposed to include the actual world file,
not just stop at the world's directory.
So the file we are interested in running is our wheeled model world.
All right.
Hopefully no more typos.
Let's try this one more time.
Control C out of this.
Clear the screen.
And there we go.
Now we see our simulation opening with our corresponding world.
And now we can also go ahead and open up a second terminal tab and double check to see if the topic
is being remapped into ROS.
And it's not.
Well, and it seems I made one more typo down here where I was defining the topic message type.
So I misspelled geometry.
So geometry.
So there we go.
I just swapped a few letters.
So we're taking the modeled wheel model command velocity topic and we're taking the geometry.
Underscore messages, message twist from ignition messages twist.
All right, try this one more time.
So our simulation starts up like it did before.
And now we see this command veil topic.
So we could also go ahead and open up a visualization program like RCT to publish the values to our
robot like we've done in the previous lecture.
So here I already have it set up from last time.
So we'll just set this to, say 0.5 and start publishing.
And now if I head over to our simulation, we see that our robot is indeed moving.
All right.
So this seems to be in working order, but let's go back to our launch file so I can show you another
nifty feature you will commonly see when working with simulation launch files, which are event handlers.
You see, if we start this simulation and the user were to close the simulation window, the launch
file in the background would still be running.
So in order to stop this, we actually have to hit control C to stop things such as the parameter bridge.
To avoid this, we can instead set up an event handler to listen for a shutdown of the simulation and
stop the rest of the nodes and processes in the launch file.
So I'll go ahead and import some things which will help us with that.
And to use it, I can add it to our launch description like so.
So basically here I'm calling the unprocessed exit handler to detect when the simulation has been closed.
And then we will emit a shutdown event for our entire ROS launch instance.
Now, I need to define this simulation target action variable, which you can do by taking that action
out of your launch description and instead assigning it to a variable.
So essentially what we would normally do is take this include launch description object.
We'll just cut it out like this.
And then right above the definition, I can simply say simulation is equal to and paste it in like so.
I'll fix the tabbing a little bit.
And then now to add it back to our launch description, all we would have to do is type in the variable
simulation.
So this format does the same exact thing as what we had earlier in the sense that it's taking this value
and pulling it into our launch description.
But now we have this nice variable which we can reference for our target action in the Register event
handler.
Now the only problem is referencing a launch description.
File object does not give the functionality of referencing something like a node or executable process.
So if we were to save this launch file and rerun the simulation, I get an error saying caught exception
in launch since the target action is not an execute local or callable instance.
So this is why I prefer to use the execute process.
Call within the launch file to launch the simulation just like we did in terminal, which in my opinion
looks a lot cleaner and easier to understand.
But I wanted to go over this functionality of how you can include external launch descriptions from
other packages.
So for now, I'm just going to comment this form out.
And I'll just say here, you can't use with event handlers.
And so now we'll redefine our simulation variable and instead call execute process with the command
we used to run in terminal.
All right.
So again, we still have our simulation within our launch description, which it's referencing from
this variable.
And all we've done is changed it from this include launch description, format to execute process.
So now if I go ahead and save this file and rerun our launch file, I'm going to screen.
We see this launches as it did before and as we've been doing throughout this section.
But now if I go ahead and close the simulation, we see this will start closing out our parameter bridge
and other instances within the launch file.
So that's gone ahead and closed automatically since it detected we closed the simulation, which is
pretty handy if all that launch file is doing is working with that gazebo simulation instance.
So that just about covers utilizing these launch files for our simulation instances.
So two things I want to mention before we end off this lecture is that you can reference multiple ignition
to ROS topic conversions within our ignition bridge node.
So all you have to do is keep adding the topics which you want to transfer over from ignition to ROS
two.
And then the second thing I wanted to mention is if you want to learn more about event handlers such
as the one I've used here, you can check out the following raw materials page for more information.
All right.
That wraps up this lecture.
These last couple of lectures were mainly to help give you a baseline on how to incorporate simulation
usage with ignition gazebo into your RA package.
So in the next lecture, we will wrap this section up with a project to combine everything we've learned
about ignition gazebo, PSD files, creating models using plug ins, Ros Topic Bridging launch file
incorporation, all within a realistic robotics simulation project.
So I'll see you there.