To visualize the robot model and laser scan, click add at the left bottom corner and select robot model and laser scan. Select topic /scan in the laser scan and make sure you choose a proper size.
Then we add two map visualization by clicking add and set one to visualize the global cost map and another to visualize the local cost map.
To visualize the path plan, we add two Path visualization. Notice: choose correct topics
Now if you close the Rviz, every setting you’ve done will disappear!
Step 3. Save Rviz settings
let’s create a package named husky_nav_rviz by type the following command under ~/catkin_ws/src directory
$ catkin_create_pkg husky_nav_rviz
and create a rviz folder under it.
Then we back to rviz and select File -> save config as to save the path_planning.rviz config file under the folder we just created.
You can close RViz once you are sure the path_planning.rviz is in the folder.
Step 4. Load Rviz settings
By select the path_planning.rviz file from File -> Open Config you can get all your settings back, or you can use the following command
In this video, we are going to answer a question found at ROS answers (https://goo.gl/ws2Whw). The person is asking why he cannot show the laser data of a fake laser given that he is publishing the proper frame and even a static transform from the laser to map. Very simple and surprise answer!
Step 1. Create project
Instead of installing and configuring a ROS environment locally, we can easily reproduce this question in ROS Development Studio. You can register an account for free now! After signing up and creating a new project, we can clone the repo provided in the question into the workspace. Open a Shell window in the Tools tab and type the following command:
Step 3. Check if the topic is publishing correctly
To check if the node we just launched really publishing something, we open another shell and type
$ rostopic echo -n1 /fakeScan
The fakeScan topic is publishing.
Let’s check it further with Rviz by typing.
$ rosrun rviz rviz
1.In order to see Rviz running in the RDS, open the Graphical Tools in the Tools Tab.
2.Add a LaserScan visualization.
3. The visualization is not showing due to some problems with the frame.
4. Let’s change the fixed frame to the fake_laser_frame
Now everything looks fine but the laserscan still not showing.
How come?
It turns out, in this particular example, it’s not showing simply because the size of the visualization is too small to be seen. Let’s change the size.
Takeaway Today:
You can check if one topic is publishing correctly by typing rostopic echo /TOPICNAME
If you want to check the topic in RViz, remember to select correct topic type, correct frame and choose a proper size!
If you want to learn more about ROS, we have ROS courses for different levels available in Robot Ignite Academy. You can preview any of them for free.
Edit by Tony Huang
[irp posts=”7406″ name=”ROS Q&A | How to merge data from two different lasers”]
From the URDF model, we’re going to define the first two links and visualize them in RViz. Up to the end of the video, we’ll have a basic model, a launch file to visualize it and a RViz configuration file for this specific project.
ROS Inside!
ROS Inside
Before anything else, if you want to use the logo above on your own robot or computer, feel free to download it and attach it to your robot. It is really free. Find it in the link below:
In order to follow this tutorial, we need to have ROS installed in our system, and ideally a ROS Workspace (it can be named simulation_ws). To make your life easier, we have already prepared a rosject with a simulation for that: https://app.theconstructsim.com/l/5a5b6f9f/.
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).
My Robotic Manipulator #1: Basic URDF & RViz – Run rosject (example of the RUN button)
After pressing the Run button, you should have the rosject loaded. Now, let’s head to the next section to get some real practice.
Compiling the workspace
As you may already know, instead of using a real robot, we are going to use a simulation. In order to see that simulated robot, we need to have our workspace compiled, and for that, we need a terminal.
Let’s open a terminal by clicking the Open a new terminal button.
Open a new Terminal
Once inside the first terminal, let’s run the commands below, to compile the workspace
cd ~/simulation_ws/
catkin_make
source devel/setup.bash
How the mrm_description package was created
If you check the contents of the ~/simulation_ws/src folder using the Code Editor or the terminal, you will see that it already contains a package named mrm_description there (mrm stands for My Robotic Manipulator). In case you want to know the commands we used to create that package, the commands were the following (you don’t need to run these commands if you already have the rosject).
To create the package that has the urdf package as a dependency, the commands were the following after opening a terminal:
cd ~/simulation_ws/src
catkin_create_pkg mrm_description urdf
We then created a urdf folder inside the mrm_description package with:
cd mrm_description/
mkdir urdf
After the folder was created, we created a file named mrm.xacro using these commands:
cd urdf/
touch mrm.xacro
and we also created the rviz.launch file, used for launching RViz (Robot Visualization tool) with the following commands:
cd ~/simulation_ws/src/mrm_description/
mkdir launch
touch rviz.xacro
You can see the content of these files using the Code Editor, also known as IDE (Integraded Development Environment). In order to open the IDE, just click the Code Editor button, as we can see in the image below:
Open the IDE – Code Editor
Once the Code Editor is open, just navigate to simulation_ws/src/mrm_description/launch/rviz.launhc and simulation_ws/src/mrm_description/urdf/mrm.xacro to see the content of those files.
After opening the IDE, you can browse through folders by double-clicking them. In case you want to create a new folder, right click on the parent folder and choose the option New Folder and type in the name you want to give to the folder.
The mrm.xacro file (My Robot Manipulator xacro file)
If we check the content of the mrm.xacro file, be it using the Code Editor or using the terminal (cat ~/simulation_ws/src/mrm_description/urdf/mrm.xacro), we will find the following:
Then we define a link named base_link , with his visual being a box of width, depth, and height of 1 meter. The origin of the base_link is at the center of the simulated world, at position 0 0 0:
Then we create a joint to connect the base_link we just created, with a link named link_01 that we are about to create. The joint was defined with this code:
In summary, this xacro file is a description of our robot in xml language. The robot is composed of various links and joints. In the above xacro we have two links base_link and link1. The base_link is fixed to the ground. It is connected to the link1 with a revolute joint. The joint allows the link1 to rotate about z-axis. We are defining the visual properties in this file.
The geometry property controls the appearance and origin property controls the positioning of the elements.
The joint element has an axis property which defines the degree of freedom of the links connected with joint. In addition to the axis property, the joint element has limit property to control the range of motion, parent and child property to control the relative motion (the child link moves with respect to the parent link).
Now that we have our robot defined, we need a way of launhcing it. For that, we have the rviz.launch file mentioned earlier. Let understand it:
The rviz.launch file
The content of the rviz.launch file that we created in the previous sections can be seen either using the Code Editor or through the terminal using this command:
In the fist line we start the definition of the launch file using the <launch> tag.
In the second line, we load a ROS parameter called robot_description using the content of of the urdf/mrm.xacro file that is found on the mrm_description package. It is basically the xacro file explained in the previous section.
In order to “put the robot pieces together“, we use the robot_state_publisher:
We also launch RViz in that launch file, and tell it to load the launch/config.rviz file that is also inside our package. Having that config.rviz file, we don’t have to reconfigure the RViz displays each time we open RViz.
Finally, we load the Joint State Publisher that allows us to move/rotate the links of our robot using a Graphical Tool:
To summarize, this launch file helps in the task of launching different nodes together. The rviz.launch file above creates three nodes. The first node is for publishing the robot state, the second node starts RViz and the last node starts a GUI tool that helps in manipulating the joint angle of the robot. The first line (param) helps in locating and loading the xacro file that contains the robot description.
Compiling the workspace
Now that we have everything in place, we need to compile our workspace. For that, we use the following commands:
cd ~/simulation_ws/
catkin_make
If everything went well, you should have an output similar to the following:
...
-- catkin 0.8.10
-- BUILD_SHARED_LIBS is on
-- BUILD_SHARED_LIBS is on
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- ~~ traversing 1 packages in topological order:
-- ~~ - mrm_description
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-- +++ processing catkin package: 'mrm_description'
-- ==> add_subdirectory(mrm_description)
-- Configuring done
-- Generating done
-- Build files have been written to: /home/user/simulation_ws/build
####
#### Running command: "make -j8 -l8" in "/home/user/simulation_ws/build"
####
Lauching RViz to see our robot model
In the previous sections we already learned how to open a terminal.
Now, in order to launch RViz, let’s run the following commands in the first terminal:
After running this launch file, you should have seen RViz and the Joint State Publisher. If RViz does not open automatically, just click the Graphical Tools button on the bottom bar of The Construct Desktop. If you don’t know which button is, just hover your mouse over the buttons to know which one opens the Graphical Tools.
After having the Graphical Tools open, feel free to move the joining using the Joint State Publisher. It is going to be difficult to see the joint moving because it has the same red color as the base link, but if you look at RViz closely, you will see it moving.
The GUI tool is like a remote desktop, when it starts you can see there are two tabs at the bottom. One is the RViz tool, and the other is the joint_state_publisher GUI as shown below:
In the RViz window, we should have everything in place. We shouldn’t have the red errors like in the image above, because in the rosject we already provided the config.rviz in the launch file, if you remember well.
What we did for creating that config.rviz file was the following, in RViz:
Changed Fixed Frame to base_link
Added an Axis element
Added a RobotModel element
The images below show the operations described above:
Congratulations. Now you know how to create a basic robot with two links and a joint using Xacro files.
We hope this post was really helpful to you. If you want a live version of this post with more details, please check the video in the next section. Although the video was recorded in a previous version of The Construct platform, it still adds a lot of value:
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 video, we show how to visualize the inflation layer in RViz for ROS (Robot Operating System) Navigation.
Step 1. Create a project in ROS Development Studio(ROSDS)
ROSDS helps you follow our tutorial in a fast pace without dealing without setting up an environment locally. If you haven’t had an account yet, you can create a free account here. Let’s call the project inflation_radius.
Step 2. Clone the simulation
Please clone the husky simulation into the simulation_ws
cd ~/simulation_ws/src
git clone https://bitbucket.org/theconstructcore/husky.git
cd ..
catkin_make
source devel/setup.bash
Then we launch the simulation from Simulations->select launch file->main.launch
You should see the husky robot appear in a room.
We also need to launch the navigation stack with the following command
roslaunch husky_navigation move_base_demo.launch
This launch file will launch the AMCL and movebase package.
Step 3. Visualize the inflation layer
We can visualize the navigation with the Rviz tool with the following command
rosrun rviz rviz
Then we have to open the graphical tool from Tools->geaphical tool. We click add to add Robot model and map in the visualization. In the map visualization, please change the map to global cost map and the color scheme to cost map.
To configure the radius of inflation layer, you have to change the inflation_radius value in the husky_navigation/config/costmap_common.yaml file. You can make the layer small by reducing the value here.
Want to learn more?
If you are interested in this topic, please check our ROS navigation in 5 days course for more information.