In this post, we will learn how to use a simulator other than Gazebo in ROS. We are going to use the Webots Simulator, whose code is available at https://github.com/cyberbotics/webots
ROS Inside!
ROS inside
Before anything else, in case you want to use the logo above on your own robot, feel free to download it for free and attach it to your robot. It is really free. Find it in the link below:
In order to work with Webots with ROS 2, we need to have ROS2 installed in our system, and ideally a ros2_ws (ROS2 Workspace). To make your life easier, we already prepared a rosject with a simulation for that: https://app.theconstructsim.com/l/5020588f/.
You can download the rosject on your own computer if you want to work locally, but just by copying the rosject (clicking the link), you will have a setup already prepared for you.
After the rosject has been successfully copied to your own area, you should see a Run button. Just click that button to launch the rosject (below you have a rosject example).
Learn ROS2 Topics vs Service vs Action – Run rosject (example of the RUN button)
After pressing the Run button, you should have the rosject loaded. Let’s now head to the next section to really get some real practice.
Opening the Code Editor
Let’s start by opening the Code Editor by clicking on the second link:
Open the IDE – Code Editor
Once the Code Editor is open, you should be able to see that we have the webots folder in the root.
In order to start Webots using the command line, let’s start by opening a terminal:
Open a new Terminal
Now, to open Webots we only need the two following commands:
cd ~/webots
./webots
After a few seconds, you should have a pop-up with a Webots ROS2 Simulation (by default it shows the last simulation we used). If the pop-up doesn’t open, you can have it by clicking on the 4th Icon of the bottom bar.
Webots ROS2 Simulation
Ok, now that you know how to open Webots manually, feel free to close the simulator by pressing CTRL+C on the command line, or manually pressing the Close Webots button available on the top right corner of the simulator.
Launching a Webots world
As you may have noticed, we have a workspace named ros2_ws. That workspace contains ROS2 packages ready for Webots.
Let’s launch a simulation using the following command:
ros2 launch webots_ros2_epuck robot_launch.py
That command will basically load the world that we saw in the previous picture.
You can now go to a second terminal and check the topics with:
ros2 topic list
If you want to move a robot, you would need external controllers, but that is a topic for another post.
Another simulation you could launch with Webots is Turtlebot:
ros2 launch webots_ros2_turtlebot robot_launch.py
It may take a while to load because Webots downloads the assets in the background. But after a while, you should have the Turtlebot simulation up and running:
You can list the ros2 topics just as you did for the previous simulation:
ros2 topic list
You can even load a Tesla simulation with Webots, in which you have a Tesla in a city:
ros2 launch webots_ros2_turtlebot robot_launch.py
Testa Simulation in Webots
Webots guided tour
You can also follow the Webots Guided Tour by clicking Help -> Webots Guided Tour, although most of the tours right now are still for ROS (ROS1).
Congratulations. You have just learned the basics of how to start a Webots simulation using ROS2. We hope this post was really helpful to you. If you want a live version of this post, please check the video in the next section.
Youtube video
So this is the post for today. Remember that we have the live version of this post on YouTube. If you liked the content, please consider subscribing to our youtube channel. We are publishing new content ~every day.
Keep pushing your ROS Learning.
Related Courses & Training
If you want to learn more about ROS and ROS2, we recommend the following courses:
In this post, you will learn how to create and use your own ros2 C++ library. I’ll show you how to create the library and then use it in a demo package.
Step 1: Fire up a system with ROS2 installation
“Hey, do you mean I have to install ros2 first?” Absolutely not! Just log in to The Construct to get access to virtual machines pre-installed with ROS.
Once logged in, click on My Rosjects, then Create a New Rosject, supply the information as shown in the video and click Create. Then RUN the rosject.
You might also want to try this on a local PC if you have ros2 installed. However, please note that we cannot support local PCs and you will have to fix any errors you run into on your own. The rest of the instruction assumes that you are working on The Construct; please adapt them to your local PC and ros2 installation.
Step 2: Create a new package that contains the library’s source code (logic)
Open a web shell and run the following commands to create the package.
Now that your package is created, we need to create a header file for the library. Move inside the include/my_value_converter_library directory and create a header file named library_header.h.
cd ~/ros2_ws/src/my_value_converter_library/include/my_value_converter_library
touch library_header.h
Now head over to the Code Editor to make changes to the header file. Check the image below for how to open the Code Editor.
Locate the header file in the code editor: ros2_ws > src > my_value_converter_library > include > my_value_converter_library > library_header.h and paste in the following code.
Now we need to edit the CMakeLists.txt file of our package to recognize the source code we have just added. Open the file ros2_ws > src > my_value_converter_library > CMakeLists.txt and add the following lines before the ament_package() call.
# let the compiler search for headers in the include folder
include_directories(include)
# define a library target called my_value_converter_library
add_library(my_value_converter_library src/my_value_converter_library.cpp)
# this line to exports the library
ament_export_targets(my_value_converter_library HAS_LIBRARY_TARGET)
# install the include/my_cpp_library directory to the install/include/my_cpp_library
install(
DIRECTORY include/my_value_converter_library
DESTINATION include
)
install(
TARGETS my_value_converter_library
EXPORT my_value_converter_library
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include
)
So much for all the hard work – now is the time to see if it works. Time to compile the code. In the same web shell, run the following commands:
cd ~/ros2_ws
colcon build
Success! We have now created our library. Next, we are going to use it!
PS: if your code did not compile correctly, please go over the instructions and ensure you have created the files in the exact locations specified.
Step 3: Create a new package that uses the library you just created
Create the new package in the open shell. Note that my_value_converter_library is passed as a dependency during the creation of the new package. This will simplify some of the work that needs to be done when modifying the CMakeLists.txt file.
Now verify that the dependencies have been properly added. If the build runs successfully, it is so. If not, please correct the errors before you proceed.
cd ~/ros2_ws
colcon build
If you got to this point, great! Now we will create the C++ source code that will use your library.
cd ~/ros2_ws/src/my_value_converter_node/src
touch my_value_converter_node.cpp
Now locate the my_value_converter_node.cpp file in the code editor and paste in the following source code.
#include <memory>
#include <string>
#include "my_value_converter_library/library_header.h"
#include "rclcpp/rclcpp.hpp"
#include "std_msgs/msg/float32.hpp"
class ConverterNode : public rclcpp::Node {
public:
explicit ConverterNode() : Node("converter_node") {
auto callback =
[this](const std_msgs::msg::Float32::SharedPtr input_msg) -> void {
RCLCPP_DEBUG(this->get_logger(), "I heard: [%f]", input_msg->data);
// Use the library
// Map an value from 0 - 1023 range to -1.0 to +1.0 range
double new_value = map_value(input_msg->data, 0, 1023, -1.0, 1.0);
output_msg_ = std::make_unique<std_msgs::msg::Float32>();
output_msg_->data = new_value;
RCLCPP_DEBUG(this->get_logger(), "Publishing: '%f'", output_msg_->data);
pub_->publish(std::move(output_msg_));
};
sub_ = create_subscription<std_msgs::msg::Float32>("output_topic", 10,
callback);
// Create a publisher
rclcpp::QoS qos(rclcpp::KeepLast(7));
pub_ = this->create_publisher<std_msgs::msg::Float32>("input_topic", qos);
}
private:
std::unique_ptr<std_msgs::msg::Float32> output_msg_;
rclcpp::Publisher<std_msgs::msg::Float32>::SharedPtr pub_;
rclcpp::Subscription<std_msgs::msg::Float32>::SharedPtr sub_;
};
int main(int argc, char *argv[]) {
rclcpp::init(argc, argv);
auto node = std::make_shared<ConverterNode>();
RCLCPP_INFO(node->get_logger(), "My value converter node started.");
rclcpp::spin(node);
rclcpp::shutdown();
return 0;
}
As you might have expected, we need to modify the CMakeLists.txt file for our new package. Locate the ros2_ws > src > my_value_converter_node > CMakeLists.txt in the code editor and paste in the following code before the ament_package() call.
# define the binary to be built and identify the source files with with which to build it
add_executable(main src/my_value_converter_node.cpp)
# tell CMake that the executable "main" depends on the library "my_value_converter_library"
ament_target_dependencies(main my_value_converter_library rclcpp std_msgs)
# install the executable in the lib folder to make it detectable through setup.bash
install(TARGETS
main
DESTINATION lib/${PROJECT_NAME}/
)
Now build and use your package!
cd ~/ros2_ws
colcon build
source install/setup.bash
ros2 run my_value_converter_node main
Step 4: Check your learning
Do you understand how to create a ros2 C++ library? If you don’t know it yet, please go over the post again, more carefully this time.
(Extra) Step 5: Watch the video to understand how to install a ros2 binary package
Here you go:
Feedback
Did you like this post? Do you have any questions about how to create a ros2 C++ library? Please leave a comment in the comments section below, so we can interact and learn from each other.
If you want to learn about other ROS2 topics, please let us know in the comments area and we will do a video or post about it.
How to create a ros/rosdistro source entry so that your package can be released with ROS. Something like: sudo apt-get install ros-humble-my-package-name
ROS2, the improved version of ROS (ROS1), is quickly becoming the standard for developing robotics applications.
In this post, we will learn the second part on how to release a ROS2 package as a binary file. Binary files are pre-built executables. They are easier to install because they do not require building from the source code. Binary files are perfect if you want to easily distribute a package to other people.
You can easily install them with apt-get install PKG_NAME, or sudo dpkg -i pkg-name.deb, for example.
It is highly recommended that you follow that Part 1, since it is a requirement for following this post:
Before anything else, in case you want to use the logo above on your own robot or laptop, feel free to download it for free and attach it to your robot. It is really free. Find it in the link below:
In order to release a ROS 2 binary package, we need to have ROS2 installed in our system, and it is also useful to have some simulations. To make your life easier, we already prepared a rosject with a simulation for that: https://app.theconstructsim.com/l/50995c4e/.
You can download the rosject on your own computer if you want to work locally, but just by copying the rosject (clicking the link), you will have a setup already prepared for you.
After the rosject has been successfully copied to your own area, you should see a Run button. Just click that button to launch the rosject (below you have a rosject example).
How to release a ROS 2 binary package – Run rosject (example of the RUN button)
After pressing the Run button, you should have the rosject loaded. Let’s now head to the next section to really get some real practice.
Assumptions
Existing ROS2 Package, publicly available for everyone to use
Started a new release team (pull request is pending)
Installed the tools required on our machine
Created a GIT access token to authenticate
Open a terminal
You will need to clone a repository soon, so, in order to do that, you will need a terminal. If you are new to the platform, you can easily open a terminal by clicking on the first button on the bottom left.
Open a new Terminal
Create a ros/rosdistro source entry
What is ros/rosdistro? https://github.com/ros/rosdistro is a GitHub repository that maintains information describing ROS packages and repositories. The build process accesses this information to build packages.
The rosdistro repository also stores the rules used by rosdep to install external dependencies.
When you create a ros/rosdistro source entry for a package that you release for the very first time, your repository will be reviewed to check whether it conforms to some basic rules.
Here is an example of some of the validations performed:
Now, go back to the rosdistro root directory and run the following command:
rosdistro_reformatfile://"$(pwd)"/index.yaml
This will make the files comply with rosdistro’s special formatting rules.
Check the differences made by the script you just ran:
gitdiffdistribution.yaml
which should show something like this:
git diff
If everything looks good, you are ready to commit your changes:
gitcommit-m"Add wall_follower_ros2 repo"
Push your changes to your remote GitHub repository:
gitpushoriginmaster
Create and Submit a pull request on GitHub to the rosdistro project to add your source entry to the indexer.
To create a new request, go to your repository and click the Contribute -> Open pull request button:
Open a Pull Request for rosdistro
After that, git a title to the Pull Request. Title example:
Addwall_follower_ros2repotohumble
Then the body of the Pull Request goes like this:
Addingnewrepository:https://github.com/rfzeg/wall_follower_ros2.gittohumbleasrequestedinhttps://github.com/ros2-gbp/ros2-gbp-github-org/issues/99forthepurposeofreleasingthepackagewall_follower_ros2
# Checks
[x] All packages have a declared license in the package.xml
[x] This repository a LICENSE file
[x] This package is expected to build on the submitted rosdistro
Remember that after submitting your pull request, some changes may be requested, and since the reviews are done asynchronously, it can sometimes take a few days until the review is completed.
Now, if they ask you to modify anything, you just go ahead and do the modifications.
You may now want to go ahead and check how to build a Debian file locally:
Congratulations. We have finished the second part about the release of a ROS2 Binary package. We hope this post was really helpful to you. We soon may have an extra part related to this subject.
Please bear in mind that the third part of this series can be found in the link below:
So this is the post for today. Remember that we have the live version of this post on YouTube. If you liked the content, please consider subscribing to our youtube channel. We are publishing new content ~every day.
Keep pushing your ROS Learning.
Related Courses & Training
If you want to learn more about ROS and ROS2, we recommend the following courses:
ROS2, the improved version of ROS (ROS1), is quickly becoming the standard for developing robotics applications.
In this post, we will learn how to release a ROS2 package as a binary file. Binary files are pre-built executables. They are easier to install because they do not require building from the source code. Binary files are perfect if you want to easily distribute a package to other people.
You can easily install them with apt-get install PKG_NAME, or sudo dpkg -i pkg-name.deb, for example.
Before anything else, in case you want to use the logo above on your own robot, feel free to download it for free and attach it to your robot. It is really free. Find it in the link below:
In order to release a ROS 2 binary package, we need to have ROS2 installed in our system, and it is also useful to have some simulations. To make your life easier, we already prepared a rosject with a simulation for that: https://app.theconstructsim.com/l/4f2b155e/.
You can download the rosject on your own computer if you want to work locally, but just by copying the rosject (clicking the link), you will have a setup already prepared for you.
After the rosject has been successfully copied to your own area, you should see a Run button. Just click that button to launch the rosject (below you have a rosject example).
How to release a ROS 2 binary package – Run rosject (example of the RUN button)
After pressing the Run button, you should have the rosject loaded. Let’s now head to the next section to really get some real practice.
Assumptions
We assume you have a GitHub account. If you don’t have it yet, you can easily create it by following this link: https://github.com/signup
Creating a ‘release repository’
When a release process runs, it outputs files for instance .md and .yaml files. This output is known as release artifacts. In ROS2, these artifacts need to be stored in a separate repository from the source code files. This repository is what we call the release repository.
So, if your repository name is wall_follower_ros2, you have to create a new repository that you can call, for instance, wall_follower_ros2-release to be used as a release repository for your package.
The ROS2 release process will use that repository to store artifacts as the automated release process runs.
Here, we will assume that no release team exists for our package yet. To request a new release team to be created we must complete the New Release Team issue template.
This form will allow you to create a new release team and add the release repository to your new team in one go.
Below we have an example of the New Release Team issue filled:
Starting a new ros2 release team on GitHub
After creating the issue, you submit it and wait for the ROS2 team to take it into account.
Installing the tools required on your machine
In order to install the required tools, we need to have a terminal. If you are on The Construct, after having opened a rosject, let’s open a terminal:
Open a new Terminal
Let’s take the chance and also open the Code Editor to be easier to modify our files:
Open the IDE – Code Editor
Now, let’s go to the terminal and use apt to install bloom together with the python3-catkin-pkg modules.
The package should have been installed with no problems.
Let’s now move to the next step.
Creating a GIT access token to authenticate
Every time you interact with a remote Git repository on the command line (for example, doing a pull, or push operation), you are asked for your GitHub username and password. In this step, we create a Git Access Token to prevent Git from repeatedly prompting for your username and password during the release operation.
You can create an Access Token by clicking the “Generate new token” button in the link below:
When filling out the form, set Note to a descriptive name such as Bloom, set Expiration to No expiration, and select the public_repo and workflow checkboxes.
After clicking on Generate token the page will display a string like CTA2AK1UMAPKSJGSZDR8HWS3GVRAFIQYYETWELT4.
This string is the token, copy it to your clipboard. Make sure to store it safely since you can’t display the token again in the GitHub interface.
In case you need more information on personal access tokens, please follow the link below:
Since hidden files do not appear by default in the Code Editor, you have to click File Open in order to find the .config folder.
Please remember to save your ~/config/boom file by pressing CTRL+S (or File -> Save)
Congratulations. We are halfway through the release of a ROS2 Binary package. We hope this post was really helpful to you. The second post is coming soon. If you want a live version of this post, please check the video in the next section.
Youtube video
So this is the post for today. Remember that we have the live version of this post on YouTube. If you liked the content, please consider subscribing to our youtube channel. We are publishing new content ~every day.
Keep pushing your ROS Learning.
Related Courses & Training
If you want to learn more about ROS and ROS2, we recommend the following courses:
In this post, you will learn how to install a ros2 binary package and make it available for use. This post was written in response to this question on ROS Answers.
Step 1: Fire up a system with ROS2 installation
“Hey, do you mean I have to install ros2 first?” Absolutely not! Just login to The Construct to get access to virtual machines pre-installed with ROS.
Once logged in, click on My Rosjects, then Create a New Rosject, supply the information as shown in the video and click Create. Then RUN the rosject.
You might also want to try this on a local PC if you have ros2 installed. However, please note that we cannot support local PCs and you will have to fix any errors you run into on your own. The rest of the instruction assumes that you are working on The Construct; please adapt them to your local PC and ros2 installation.
Step 2: Check the ros2 binaries currently installed
Open a web shell and run the following commands. You should see a long list of many binaries!
cd /opt/ros/foxy/share/
ls -al
ROS binaries are stored in /opt/ros/{distro}/share/ If you would like to check if some binary is already installed without going through the long list, use grep. In this case we want to check binaries related to joint_state.
Heck, if you were the user in this post, you wouldn’t need to install anything. “What would I do then?!” Read on to find out!
Step 3: Install the ros2 binary package
We will demo this with the same package the user was struggling with: ros-foxy-joint-state-publisher-gui. Since the package is already installed in our case, we need to uninstall it first, just to demonstrate. Run the following on the current shell:
The user got an error when they tried to launch the GUI binary. Let’s see what we get (fingers crossed).
ros2 run joint_state_publisher_gui joint_state_publisher_gui
You should get a GUI like the image below pop up, confirming that the binary is really there. Cheers!
Step 5: Check your learning
Do you understand how to install a ros2 binary package and make it available for use? The magic word here is source.
If you didn’t get the point above, please go over the post again, more carefully this time.
(Extra) Step 6: Watch the video to understand how to install a ros2 binary package
Here you go:
Feedback
Did you like this post? Do you have any questions about how to install a ros2 binary package? Please leave a comment on the comments section below, so we can interact and learn from each other.
If you want to learn about other ROS2 topics, please let us know in the comments area and we will do a video or post about it.