Harmonic And Jazzy Tutorial
Installing ROS2 Jazzy
Introduction and explanation
What software are we using and why
All of these instructions have been tested using the current version of Ubuntu: Noble Numbat.We are going to use two packages: Gazebo for the physics based Simulator and ROS2 (Robot Operating System) for the control system. There are many releases of each of these, and only some combinations are mutually compatible. Also, since we are focusing on a stable development platform, we will use the Long Term Support (LTS) versions that are current at the time we are posting this. As of 29Aug2024, this means we will use Gazebo Harmonic which is supported until 2028.
How will the demonstration proceed.We will go through 7 steps: 1) Install Gazebo Fortress and confirm that it is correct. 2) Examine an empty world 3) Build a simple robot and test it using keyboard controls. 4) Build a 'world' for our robot to explore. 5) Install ROS2 (and its components) and confirm the installation. 6) Add Lidar to the robot 7) Write control software in ROS2 to make the robot autonomous.
This post covers Step 5 Starting world description (from the last tutorial) hjn-pong-world-3.sdf
How will the demonstration proceed.We will go through 7 steps: 1) Install Gazebo Fortress and confirm that it is correct. 2) Examine an empty world 3) Build a simple robot and test it using keyboard controls. 4) Build a 'world' for our robot to explore. 5) Install ROS2 (and its components) and confirm the installation. 6) Add Lidar to the robot 7) Write control software in ROS2 to make the robot autonomous.
This post covers Step 5 Starting world description (from the last tutorial) hjn-pong-world-3.sdf
Installing Jazzy
All right, at the end of the last tutorial we have an sdf file that sets up a fully controllable robot and an arena to play in.
But we want to do more than just drive the robot around, right? We want an autonomous robot that can drive itself.
There are a number of steps to get everything set up:
1) Setup the environment to allow ROS2 and Gazebo to talk
2) Install ROS2
3) Install the bridge between ROS2 and Gazebo
4) Test the system using some built in ROS2 utilities to send commands to the simulated robot
5) Add some sensors to the robot to send simulated data over to ROS2
Let's get started.
Set up Locales
One or more of the programs needs to look up the LC_ALL to get the correct character set. Check LocalesIn a terminal window type “locale”you should see: LANG=en_US.UTF-8 LANGUAGE= LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=en_US.UTF-8If Ubuntu complains about not finding locales, you can install it by typing • sudo apt update && sudo apt install locales
Generally, the locale that is missing is the last one LC_ALL, it is often blank.If the locale does not match the locale above, you will have to generate a new locale and change the values. • sudo locale-gen en_US en_US.UTF-8 • The response should be ◦ Generating locales (this might take a while)... ◦ en_US.ISO-8859-1... done ◦ en_US.UTF-8... done ◦ Generation complete. • Then modify the locale ◦ sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8 • Export the Locale ◦ export LANG=en_US.UTF-8 • Reboot ◦ Type locale and it should show you the above locale
Nowwe are ready to install ROS2
Install ROS2
Set up the repository
We will add the ubuntu universe repository:
Pull down the pgp key
Connect to the repository
Update and install ROS2
Initialize some support code
Step 1: Initialize the ROS2 dependency Manager (rosdep)
The rosdep tool should have been installed when you instaled ROS2, but it needs to be initialized:
> sudo rosdep init
> rosdep update
Note, if rosdep is not install Ubuntu will give you instructions to install it - follow them.
Step 2: confirm that ColCon is installed
The easiest way to do this is to type:
> colcon -h
If you get the usage file, you are good to go.
If you don't get the usage file, you may need to re-install ROS2
Let's put ROS2 to work
At this point we have ROS2 installed.
One thing that you need to remember - every time you want to use ROS2 you must use the setup.bash script to set things up (enviroment variable, etc.)
this means every time you open a new terminal window - you need to source the script:
> source /opt/ros/jazzy/setup.bash
You can add this line to your personal setup script so that it runs everytime you open a terminal, if you wish.
But don't forget!
Now, let's get ROS2 and Gazebo talking to each other.
The ROS2 dev tools come with a nifty little system to bridge between ROS2 and Gazebo. Think of it like a translator. The first thing we will do is test the set up.
To do that we are going to:
1) Launch our Gazebo simulation of the robot.
2) Launch a bridge between ROS2 and Gazebo.
3) Use a built in ROS2 utility to send keystrokes to the simulator
Last session, we lauched the simulator and used a tool in Gazebo (Key Publisher) to listen for key presses and publish them so the robot could react. This time we will use ROS2 to listen for the key presses, and the ROS2 / Gazebo bridge to publish them for the robot can react. It will act the same - but there is one big difference.
Once we enable ROS2 to send commands to the robot, we can write software running under ROS2 to control the robot. We can make the robot autonomous rather than human operated.
Then we can add bridges from the simulator to the software to enable sensor data to be available. That means we can make an intelligent, autonomous robot.
Shall we get started?
1) Launch our Gazebo simulation of the robot.
Okay, this part is just like the last session, with one exception. You won't need to remember to start the Key Publisher, since we will do that over in ROS.
1) Start the simulator with: > gz sim hjn-pong-world-3.sdf2) Press the run simulator button in the lower left (play arrow)
Now the simultor is running, let's build a bridge
2) Launch a bridge between ROS2 and Gazebo.
The bridge is a program that listens one one side, translates what it hears into another format, and then sends the newly formatted message out.
How does this work?
Back when we build the simple robot we added the plugins for movement, they looked like this:
When you look at the code there is the line labeled input type. It specifies a message type (gz.msgs.Int32) and a topic (/keyboard/keypress).
So we want to create a bridge that will supply that message type to that topic on the Gazebo side, and an equivalent message type from the ROS2 side.
First Bridge from ROS2 to Gazebo
First we will send a keyboard command directly to the robot movement plugin.
We have Gazebo running in one terminal window, we will launch the bridge is a new terminal window:In a new terminal window, source the ros setup, then start a ros_gz_bridge for keyboard messages
When you run the command, you should see a response like:
[INFO] [1724950397.816853284] [ros_gz_bridge]: Creating ROS->GZ Bridge: [/keyboard/keypress (std_msgs/msg/Int32) -> /keyboard/keypress (gz.msgs.Int32)] (Lazy 0)
The second item in [] is a time stamp, it will change.
This sets up a translator from ROS2 keypress topic to gazebo keypress topic.
Note that this creates a one directional bridge from ROS2 to Gazebo – this is controlled by the character between the message type specifiers: • @ - set up two bridges, one in each direction ◦ /keyboard/keypress@std_msgs/msg/Int32@gz.msgs.Int32 • ] - set up one bridge from ROS2 to Gazebo ◦ /keyboard/keypress@std_msgs/msg/Int32]gz.msgs.Int32 • [ - set up one bridge from Gazebo to ROS2 ◦ /keyboard/keypress@std_msgs/msg/Int32[gz.msgs.Int32
At this point, The Harmonic simulation is listening for keypresses published on the keypress topic.AndThe bridge is ready to translate ROS2 keypresses into gazebo keypresses.So, let’s send a keypress!
ROS2 provides some very low level utilities. One of them is a simple command line publisher
You tell it what topic name to use, what message type to send, and what data should be in the message.
Since it is a command line application, we will need to launch another terminal window to use it.
In a new terminal window, source the ros setup and send a keypress:
This will cause 1. ROS2 to send a left arrow keypress to the ROS2 keyboard/keypress topic, 2. The bridge will hear that ROS2 keypress and translate it into a Harmonic keypress and publish it on the Gazebo keypress topic. 3. The robot model plugin for rotate right will hear the keypress and publish a Twist message. 4. The Differential Drive plugin on the robot will hear the Twist message and simulate the wheel rotations causing the robot to spin in place. 5. Finally, the simulator will determine what changes will happen in the simulated world and display them.
For more information on the ROS2 topic command check out this summary from The Robotics Back-End.
If you want to stop the robot from spinning, you can send a stop command by changing the value of the character you send. The robot is always listening for key presses and the command to stop is a lower case 's' - ASCII value 83.
So if you send an 83 the robot it will stop.
Okay, That sets up communication between the ROS2 environment and the Simulator.
But if our little robot is going to be controlled, we also need to get the data from the Simulator over to ROS2.
So, let's do a quick test of that cabability.
First step is to close the current gz bridge, with a CTRL-c
Send data from the Simulator to ROS2
We will do this in the same basic way:
1. Launch a new bridge from Gazebo to ROS2
2. In the simulator, we will set it up to publish keypresses
3. Launch a ROS2 utility to monitor and display whatever gets published on the topic.
We will use the terminal that had the gazebo to ros bridge over again, to set up a bridge going the other way: from Gazebo to ROS2
Notice that this is very similar to the original bridge - the only difference is the direction indicated by the square bracket '[' it now points from the gz.msgs.Int32 towards the ROS2 stdmsgs/msg/Int32
Go back to the Simulator window and use the pull down menu to start a key publisher (open the three dots in the upper right, select Key Publisher)
Go to the ROS2 terminal you used to send keypress,
Now we are going to use a new tool: the ROS2 topic echo app. All this does is subscribe to a topic and echo any messages that get published to the screen.
So, now we have
The simulator running and the Key publisher will publish any key presses to the Gazebo KeyPress topic
The Gazebo ROS2 bridge is subscribed to the gazebo KeyPress topic and will translate any key presses into ROS2 KeyPress messages and publish them on the ROS KeyPress topic.
The ROS2 echo app is subscribed to the ROS KeyPress topic and will echo any messagfes to the terminal window.
So, put the mouse cursor in the Simulation window and type on the keyboard.
In the screen shot below,
The Bridge is running in the top terminal
Gazebo was launched in the next terminal down, and the Client is below that
The ROS2 echo app is running in the terminal on the right
I typed 'robot' in the Simulator and you can see the ASCII values echoed on the ROS2 side
What we did
This has been a long one, but we got a lot done:
We have:
1) We set up the environment to work with ROS2
2) Installed the ROS2 robot operating system and its tools
3) Launched the Gazebo simulated world and connected it to a ROS2/Gazebo bridge
4) Used the ROS2 topic utility to send commands to out simulated robot
5) Used the ROS2 echo utility to get information from the simulator
Next step - Create an autonomous robot
Previous Step | Current Step | Next Step |
Install ROS2 |