In the last two lectures, we started using the ignition gazebo simulation and customizing our own simulation
by creating PDF files to customize our simulation world and models.
At the time of this recording, Ignition Gazebo does not have a built in model editor, so we'll be
using the older Gazebo Classic to make our robot model.
There are other three D design and CAD software you could use to export into the PDF format, but I'll
try to keep this section constrained to Gazebo and ROS as much as possible.
So for the time being, we can head over to the Gazebo Classic installation page.
The easiest way to go about installing the Zeebo is by running the installation script directly from
the website like so.
Down below.
There are alternative installation methods which you can try out if the insulation script fails for
some reason.
But I'm just going to go ahead and install it like so.
Don't have to put in your password.
And after a bit, that should have installed.
So go ahead and clear the screen.
So now we can go ahead and start Gazebo Classic by simply typing in Gazebo.
All right.
So it appeared behind my terminal.
So this is a gazebo by default.
There is nothing in our scene to navigate.
Gazebo.
Use your left mouse button to pan around the scene.
The right mouse button or scroll wheel to zoom in or out, and then shift left click or press the scroll
wheel button to rotate around a point in the scene.
Gazebo has a series of pre-made models which you can use in your simulations.
If I select insert mode, we can go ahead and head over to the model's gazebo sim dot org dropdown.
This might take a while to load if you've just installed gazebo to connect to the database, but essentially
this dropdown allows me to download these models from Gazebos website.
I can go ahead and select the ambulance and once that's gone ahead and download it, I'll go ahead and
zoom out with my scroll wheel.
We can see I can place it within my scene so I can just go ahead and left click and now it's within
my simulation.
So feel free to check out the other models that are available.
So great.
With that, we have imported a new model in our simulation.
Now this model is actually very basic, so the wheels don't even spin.
It's just it's essentially a cube wrapped with this ambulance skin, so you're not able to drive it
around.
But we could create our own model which would allow us to do that.
So go ahead and click on this ambulance.
You can either hit the delete key on your keyboard or just right click and delete.
Then if we head over to the edit toolbar tab, I can select model editor and here we can create a model
using basic three D shapes.
Let's make a super basic model that is just a box with two wheels and a sphere to act as a caster.
So first is to add a cube.
So if I go over to this left panel here, select box, I can go ahead and place it down in my simulation.
Now, if I double click on this box, I can edit this properties within the link Inspector tab.
So within the link tab I can scroll down to edit its posts.
Now keep in mind there are two post sections which might be a little bit confusing, so there is a post
subsection within inertial tab.
So usually I just like to close that so I don't get confused.
And here we just see the standard post tab which controls where our square is within the simulation
world coordinates.
So for example, I can try and center it so I can go ahead and put it at zero zero.
Then besides the link tab, we have the visual and collision tabs, so go ahead and expand those.
And basically this is what's going to dictate our properties for how these things look and act within
the simulation.
So here within the visual tab, I can scroll down to geometry and I can change the X, y, Z attributes
of this cube.
So in this case, I can go ahead and set the Y and Z parameters 2.5 meters to make this look more like
a rectangle.
So in the main window we can see our changes, but you notice there's a transparent outline of the original
cube.
Well, that's actually the collision model we are looking at.
So if I switch to the collision tab.
There is again a geometry subtab in which we'd have to change the attributes again.
So sometimes you'll have a visual model which has a rap or looks slightly different compared to the
collision model, which you may simplify or have be slightly modified.
But for now I'm just going to set it to be the same thing.
So 0.5 Y and 0.54 Z, and now we see that matches up.
So this collision model is what's used for the physics engine rendering.
This way you could create a complicated visual appearance, but keep the collision model which will
have physics applied to it in a simple manner.
So moving on, I'll go ahead and hit OC.
So now I'll go ahead and make my two wheels using cylinders.
I will double click on it, edit its pose so we can turn it on its side again.
Remember that there's two poses.
One is for the inertial physics calculation, so be sure to leave that as is.
So go ahead and collapse that and we can head down to the pose that's in its own section and I can change
the roll to 1.570796 radians, which roughly equates to 90 degrees of rotation.
Now we see the cylinder has rotated.
Now I will edit the size of the cylinder by changing the length to 0.25 meters in both the visual and
collisions tab.
So now I have my wheel and you could go ahead and move it however you want in the simulation to configure
where you want to place it relative to your other components.
So I'm actually going to go ahead and double click on this and place it where I want to.
So if I go back into link and into pose.
Set this to -0.375.
-0.4 and 0.5.
And so this now acts as a type of back wheel for our robot.
On the right side, if that's the front.
So I can go ahead and hit OC and now I can duplicate this wheel by clicking on it and right, clicking,
doing copy and we can right click and paste.
And now I have a cylinder with the same attributes and I'll go ahead and click on it and edit its position.
Again.
Don't edit the inertial posts.
Close this tab.
This is the pose we want to edit.
All righty.
Now, to complete this model, I'm going to go ahead and add in the sphere caster.
So I'll go ahead and add a sphere.
And set the size to 0.25 metres.
All right.
So I've gone ahead and done that and I'm actually going to replace the sphere.
So it's at the front of our robot chassis.
All right, So now I've gone ahead and place it in my simulation.
Now, the other thing I'm actually going to do is I'm going to double click on this one more time and
go into collision.
And if we scroll down, we'll see there's surface friction for these attributes on how we want this
to interact within our simulation.
So we want this to nicely slide against the ground plane.
So I'm going to have to set these friction variables MU and mu two to be something smaller because the
value of one is similar to having a very rough surface, which is hard to slide across.
So I want this to be more of a smooth interaction.
So I'll go ahead and cut this down to say 0.1 for both of them.
So go ahead and hit Ock.
And to make this look a little bit less awkward, I'm actually going to extend my cube out a little
bit.
So I'll set the X direction to instead be 1.5 and make sure to change it in the collision tab as well.
Okay, that looks a little bit better.
So we have this little rectangular chassis with two wheels and a spherical caster meant for sliding.
Now we have to create joints in order for these different shapes to be combined together.
So we can do this by selecting the joint icon in the top.
Then we'll have to choose our parent link, which in this case is our box.
And then the child will be the wheel, which in this case is closer to me.
So the back right wheel.
So above we can see it selected as a resolute type.
We could change this to one of the other available joints, but note that fixed, resolute and prismatic
are the most supported joints.
If you wanted to control these joints and Ross, I will leave it as resolute and I will select negative
Z axis for the rotation.
So you can actually see how this changes in our.
X, Y, and Z.
So now we have this yellow axis pointing here in our axis of rotation.
I'll go ahead and hit, create and do the same thing for our other wheel.
Then last thing.
I need to fix this sphere to the box.
So for joint type we will use type fixed.
So we don't need to worry about any axes of rotation because it's just going to stay right there.
And I'll go ahead and hit create.
All right.
That about covers it for this simple model so I can go to file and exit model editor, and it's going
to ask if you want to save changes before exiting.
So we're going to go ahead and hit, save and exit.
And here we see we're going to be naming our model where it gets saved by default in our home folder
in a folder called Model Editor Models.
So I'm just going to go ahead and call this wheeled model and hit save.
Once I hit Save, we are now back in our simulation world.
If I go over to the left panel, we now see that the wheel model is part of our list of models, and
it shows all of our individual links as well as joint relationships.
If I wanted to interact with these joints, I can drag out the right panel here that's hidden.
And if I select my robot, we can actually see we can interact with each joint by either applying a
force, setting a position or a velocity.
So before I set everything, I will make sure my simulation is paused, which you can check by looking
at the bottom left where we see this is still the play button.
Our timer is not playing.
So I'll go ahead and set the velocity for the first two joints to one meter per second.
Then on the right, I can set the values of the PID controller, which will try to apply the force of
the wheel to get it to maintain that speed.
In this case, I'll increase the gain to three for both of them.
Now, if I go ahead and play the simulation, we should see the model begin to drive because we are
turning the wheels with this particular velocity.
Great.
With that we are able to set our wheels to move at a certain rate.
I'll go ahead and pause this for now.
If I wanted to spin our robot around, I could change the speed to be negative on one wheel in order
to make our little wheeled bot turn.
So now if I hit play.
We see it is now rotating because one wheel is going forward and the other wheel is going backwards.
If I wanted to place the robot back to the way it was, I can go to edit and select reset model poses
and that will place it back at the center of my simulation.
Anyway, this is a good introduction to Gazebo Classic for those of you who have not used it before,
and hopefully more of these features that you're seeing here get included into the newer ignition gazebo
interface.
For now, we have an SDF of our simple wheeled robot model, so I'll go ahead and close out of Gazebo
Classic.
You know, we'll go ahead and close our browser.
Now I'll open up the file Explorer.
And here in our home folder, we have a model editor models folder which contains our wheeled modeled
robot folder that has the SDF and config file.
Now, go ahead and take this model, copy it over and place it into our ROS package within the models
folder.
So here we have our ground plane from earlier and now we have this wheeled model within our package.
Now let's open up V's code and create a new PDF World file to include this model in our underworld.
I'll hit new file and I'm just going to call this new file wheeled model world that SDF.
Then I'll copy over the contents from our test world from earlier.
And I'll paste it in and I'm going to delete the camera model that we were playing with earlier so that
our environment only contains this ground plane and a sun model and our normal plug ins.
And now we'll include our wheeled robot model.
So now I'll go ahead and save this and open up our terminal and set up our gazebo environment variable.
And let's go ahead and run our wheeled model world file.
So here we see our model partly wedged into the ground here.
So I can just go into translate mode and pull it out of the ground.
But we indeed see that the model we created in Gazebo Classic is able to transfer over to Ignition Gazebo.
So in this lecture off, let's take a quick look at how we can use plug ins to allow us to use the joints
that we made.
To show an example of this, we can check out the diff drive example PSD file.
So again, here is the world directory with the example PDF files from earlier.
So again, go into other locations.
Computer user share, Ignition, Ignition, gazebo, six and Worlds.
And the file that we're interested in this time around will be diff drive dot SDF.
So I'm going to go ahead and open this in a standard text editor.
Now let's also go ahead and launch this in ignition just so that you can see what this file entails
within the simulation.
All right.
So here we see two wheeled models somewhat similar to what we just made.
So if I go ahead and hit play, nothing really happens.
But we can actually go ahead and control these two robots by publishing messages to them.
And if we can control it through ignition, you already know we can just bridge the topic to work in
ROS using the parameter bridge.
But for now we will just try this out by copying the command that it actually shows within the top of
the file.
So here it says Differential drive plug in demo.
Try sending the commands ignition topic dashed and you specify the topic, which in this case we're
commanding the blue vehicle from the command velocity topic.
The message type is a twist message, and we're publishing a linear and angular part to twist.
And in this case we're saying go forward in the x direction 0.5 meters a second about and give it an
angular velocity in the Z axis direction of 0.05.
So I'll go ahead and copy this.
Open a second terminal.
And I'll go ahead and run this message.
And now we see this purple robot moving forward and slightly to the left since we had that Z angular
aspect to it.
And now if I go ahead and go up and set these back to zero, I.
We should see that the model stops moving.
And again, this particular simulation is set up with a blue vehicle and a green vehicle with these
topics already nicely set up for us so we could go ahead and move the second vehicle if we wanted to
by simply changing that name.
And I'll just go forward in this case a little bit and change it from blue to green.
And now we see the green robot moving directly forward.
And again, we can stop this by changing all the values to zero and publishing it again.
All right.
For now, go ahead and pause the simulation and we're going to head back to the C file so we can see
how this plugin is implemented.
So this plugin is called twice in this file one for each robot, but for now I'm just going to scroll
all the way down to the bottom where the second declaration is, since it's easiest to navigate to.
So here within this secondary model tags, right, we have a plugin called Ignition Gazebo Diff Drive
System and it points to the particular driver.
And here we see a couple of attributes such as the left, joint right, joint wheel separation wheel
radius and as well as some max and minimums for acceleration and velocity.
If you want more info on the available parameters for the diff drive plugin, you can check out the
gazebo Simu GitHub repository and check out the comments in the diff drive header file.
But for now, let's implement this plugin into our wheeled robot model we created to make it more interactive.
So I'll copy this code snippet.
And put it towards the end of the model file of our wheeled model.
Now, if you ever get errors like this, some of the namespaces for HTML does not match up.
So all we have to do is set this back to XML and we lose some of that functionality to automatically
autocomplete some scripting for us, but at least it will get rid of that those red error message lines.
But I'll go ahead and scroll all the way down.
And right before the model tag ends, we'll go ahead and paste in our plugin.
So now I'll go ahead and change the parameters to match our setup.
So if you follow along with my setup, each wheel was 0.4 meters away from the origin, so my wheel
separation is 0.8 meters and I'll set the wheel radius to 0.5.
Then our joint names were automatically created in the gazebo model editor.
So if we scroll up to the top.
We can see after our model tag we have a link tag.
This link is the box we started off with.
As we can see specified in the geometry tag.
So let's do some renaming in this file so that it makes a bit more sense.
So if I hit control H in V's code, this will pull up the find and replace window.
You could also go into the edit tab and go to replace and let's rename link zero so it makes more sense.
In this case I will name it to chassis since this box acts like a robot chassis that everything is mounted
to.
And the reason we are utilizing this replace all functionality is we want to make sure we keep together
all of our linked connections.
So all of our joints which are utilizing these link names, we want to make sure that these all get
changed correctly.
So I'll just go ahead and hit replace all.
And if you're unsure, you could actually go ahead and check this.
So here we see the joint name link zero to Joint zero.
So now it'll change it to chassis to join zero and it'll change the parent name link zero to match chassis
and it does that for each of our corresponding joints.
So I'll go ahead and hit replace all.
So now if we go over to the next link, it should be called Link one.
And this is the first will we put onto our robot.
So if you consider the cluster as a part of the front of the robot, I believe I started with the right
wheel so I can change it as such.
So now notice if we hit this arrow button, we see another link called Link one clone.
Now, that's because I clone the original link, which was our wheel to create a secondary wheel.
So actually what I'll go ahead and do is go to link one and set it to underscore clone so that we only
get two of these matches and set that to our corresponding left wheel link.
And now the normal link one will be our right, we'll link.
And again, it's just the name of the link that's changing and the child parameter within our joints.
Then our last link should be link two, which is our caster, so I can just change it as such.
Great with that.
All of our linked names make a bit more sense.
So now let's take a look back at our joint names from our Diff drive plugin.
So here it's looking for the left joint with a name left wheel joint so we can change this to match
or if we go back to our joints.
We can see here Joint zero, joint one and joint two and what each one is doing.
So we can see chassis joint zero.
He's combining the chassis to the right.
We'll link so we can just simply change the name for simplicity to right wheel joint.
And we can go down to our second joint, which combines the chassis and the left wheel link and we can
just simply change it to left wheel joint.
Now we can make sure that these names match up with what we have here for our ignition gazebo plug in,
which in this case I actually made them a match.
So left wheel joint here corresponds to the left wheel joint that we have here within the model PSD
file, which combines the chassis and left wheel link.
So ideally, this driver will now take control of that particular wheel whenever it needs to.
Last thing I want to do here is set a post for our robot.
Since if you remember when we launched our simulation, our robot was partially in the ground.
So I'll go ahead and save this model file and head over to our wheeled model world file and I will add
a post tag right after the include tag to put us half a metre off the ground in the Z direction.
So again, each number represents X, y, z position followed by roll, pitch, yaw.
All right.
We'll go ahead and save everything and relaunch our wheeled model world simulation file.
So here we see our total ground plane and our wheeled model we created in gazebo.
So I'll go ahead and clear this second screen here.
So we can control this robot by using the ignition topic command we had used earlier.
But change the topic name.
So if I hit up, we can see we use this ignition topic to model vehicle green command velocity.
So by default, if you check out the GitHub repo notes, if you don't specify a topic within the parameters,
this simply gets changed.
The name of our model, which in this case is just called wheeled model here.
So let's go ahead and change the X parameter to 0.5 so that we can drive forward and we will change
vehicle green to wheeled model.
So go ahead and publish that.
Now, of course, to make sure the simulation is playing and we see our robot goes down and starts driving
forward.
And of course we can always stop it by setting this to zero.
And there we go.
The model stops.
Now, currently we are controlling this robot with ignition commands.
So all we have to do to port this over to Ros is use the ignition gazebo bridge and specify the corresponding
topic.
Basically, we are taking the ignition topic and then the ampersand symbol, then the ROS message type,
which in this case is the twist.
Message type is from geometry messages ROS package.
And then I'll include another symbol and then the ignition message type.
Then I'm passing in ros args with the dash r flag which is remapping the topic name from the current
topic name to just command velocity.
Keep in mind the ampersand symbol between the ROS message and the ignition message means that communication
can come over and received between Ros and an ignition over this topic.
Whereas if I only use the left square bracket, that means I can only receive messages from ignition
to ROS.
And the right bracket means only messages from Ros get sent to ignition.
I just do the ampersand symbol for both because it's easier for me to remember.
But just keep that in mind if you ever want to restrict which way data flows.
So I'll go ahead and run this, then open a third terminal window.
And we should be able to see this new command of topic.
Which we do right here.
So for simplicity, I'm going to open up our cut and publish this topic.
So go ahead and close our image plugin from the last lecture.
Head over to topics message publisher and refresh our topic list.
Head over to command, fill the addition symbol.
And now if we hit these dropdowns, we have the linear and angular portions of our topic, so I'll go
ahead and minimize this a bit.
And now let's go ahead and set the speed to say 0.5.
And as soon as I hit the check mark, this will begin publishing and we should see our robot move.
And I can set this back to zero again.
And if we wanted to, we could make our robot spin for fun.
So if I set this Z aspect to one, we should see our robot rotate around.
And if I hit negative one, we will go in the opposite direction.
And of course, we can add multiple components at the same time to have our robot both try to drive
and spin around at the same time.
Now I guess it's wants to spin around more than it wants to move.
So there we go.
We can see it's just slightly reversing and slightly wanting to turn.
And of course, I'm going to set these both to zero.
So congratulations on making it through this lecture.
I know it was quite the stretch from making our model in the Gazebo Classic editor to learning about
the differential drive plug in to then implementing that plug in into our model we made to then bridging
the ignition topic that interacts with the plug in over Ros using the ignition parameter bridge.
Just a reminder that if you want to check out more built in plug ins, check out the gazebo sim and
gazebo sensors, GitHub repos.