RVIZ2 Tutorials Episode1: Learn TF

RVIZ2 Tutorials Episode1: Learn TF

What we are going to learn

  1. How to use RVIZ2 step by step
  2. How to add the TFs of a simulation
  3. How to add the TFs of a real robot
  4. How to connect to a real robot through our robot lab
  5. Start the ros1 bridge to be able to see TF data from ROS1 in ROS2

List of resources used in this post

  1. Use the project: https://app.theconstructsim.com/#/l/47f74f81/
  2. ROS Development Studio (ROSDS) —▸ http://rosds.online
  3. ROS2 Tutorials –▸
    1. ROS2 Basics in 5 Days (Python): https://app.theconstructsim.com/#/Course/73
    2. ROS2 Basics in 5 Days (C++): https://app.theconstructsim.com/#/Course/61

Welcome

Hi, and Welcome to this new series of posts.

In this series, we are going to explain how to add elements to RViz2. We will start with TF, then we will continue with Robots Description, then Cameras, PointClouds, Lasers, and so on.

In this first post, we are going to see how to add TFs in RViz2.

Opening the rosject

In order to learn how to add TFs in RViz2, we need to have ROS installed. We already prepared a rosject ready for that: https://app.theconstructsim.com/#/l/47f74f81/. 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.

Run rosject: RVIZ2 Tutorials Episode1: TF

Run rosject: RVIZ2 Tutorials Episode1: TF

Running the rosject

After you have clicked the Run button, the rosject should load and you should see a notebook that is open automatically:

Notebook - Run rosject: RVIZ2 Tutorials Episode1: TF

Notebook – Run rosject: RVIZ2 Tutorials Episode1: TF

The notebook contains the instructions to launch a simulation.

Launching the BOX_BOT simulation

In order to launch the simulation, let’s start by opening a new terminal:

Open a new Terminal

Open a new Terminal

After having the first terminal open, let’s run the following commands to launch a simulation:

cd ~/ros2_ws/
colcon build --packages-select box_bot_description box_bot_gazebo ;

source install/setup.bash ;

ros2 launch box_bot_gazebo start_world_launch.py

 

The commands we just executed only launch the world, but there is no robot on it yet.

Now, in a second terminal, let’s spawn the robot with the commands below:

cd ~/ros2_ws/

source install/setup.bash

ros2 launch box_bot_gazebo spawn_robot_ros2.launch.py

 

Now that the robot has been successfully spawned, let’s now open RViz2. For that, let’s run the following commands in a third terminal.

cd ~/ros2_ws/

source install/setup.bash

rviz2

 

See the simulation

In order to see the simulation, you can click on the Open Gazebo button:

Open Gazebo by clicking Open Gazebo

Click Open Gazebo to view the Gazebo simulation

Click Open Gazebo to view the Gazebo simulation

The final image you get should be similar to the following:

Open Gazebo - RVIZ2 Tutorials Episode1 TF

Open Gazebo – RVIZ2 Tutorials Episode1 TF

See rviz2 in the Graphical Tools

In order to see rviz2 (RViz2), you have to click the Open Graphical Tools button, in case the graphical window did not open automatically:

Open Graphical Tools / rviz

Open Graphical Tools / rviz

 

Now that you can see rviz2, let’s set the fixed frame on the top left to /odom (Odometry), then let’s click the Add button on the bottom left and add a TF.

Once TF is added, let’s disable the “All Enabled” option to avoid getting confused with all those TFs that are shown. Let’s shown only specific frames: chassis, left_wheel, odom, right_wheel. In the end, our rviz2 should look similar to the following:

Specific Frames - RVIZ2 Tutorials Episode1_ TF 3

Specific Frames – RVIZ2 Tutorials Episode1_ TF 3

 

We must also click Show Names to show the frame names in RViz2.

Moving the robot with teleop

In order to see the frames of the robot moving in rviz2, let’s run the Keyboard Teleop in a fourth terminal using the following commands:

cd ~/ros2_ws/

source install/setup.bash

ros2 run teleop_twist_keyboard teleop_twist_keyboard

 

If you now press the keys to move the robot around, you should be able to see the robot moving in the simulation, and you should also see the TFs moving in RViz2.

Moving the robot with teleop - Specific Frames - RVIZ2 Tutorials Episode1 TF

Moving the robot with teleop – Specific Frames – RVIZ2 Tutorials Episode1 TF

Connecting to a real robot

In order to see the TFs of a real robot, let’s click on the Real Robot Lab button that is available when you are not on the “Desktop” page of The Construct. After clicking Real Robot Lab, please select a robot and click Book Now. It’s free.

Real Robot Lab - Make a reservation

Real Robot Lab – Make a reservation

 

When you have the robot available for you, open the rosject and click on the button to connect to the real robot.

Connecting to the Real Robot Lab

Connecting to the Real Robot Lab

 

After the connection is successfully established, you should have something similar to the following:

Real Robot Lab connected

Real Robot Lab connected

Launch ros1_bridge

Before loading ros1_bridge, let’s load the parameters that we want to do the bridge.

Open a terminal and type the following:

cd ~/catkin_ws

roslaunch load_params load_params.launch

 

The command above loads basically the instructions saying: Hey, ros1, publish these specific topics because I want them to be available on ROS2.

Now, let’s run the parameter_bridge in a second terminal:

cd ~/ros2_ws/

source /opt/ros/foxy/setup.bash

source install/setup.bash

ros2 run ros1_bridge parameter_bridge

Now that ros1_bridge is running, we should be able to easily see ros2 topics in a third terminal:

cd ~/ros2_ws/

source install/setup.bash

ros2 topic list

You should see some topics listed, and the one we are most interested in today is the /tf topic.

If we now just open rviz2:

rviz2

we should now do the same procedure that we did previously, in order to see the TF data in RViz. Please refer to the section See rviz2 in the Graphical Tools already explained above (set /odom as the Fixed frame, and add the TF panel).

Moving the robot with ROS1

Now that we are connected to our robot and we have RViz2 setup ready, we can move the robot either with ROS1 or ROS2.

Let’s move it with ROS1, by running the following commands in a fourth terminal:

source ~/catkin_ws/devel/setup.bash

rosrun teleop_twist_keyboard teleop_twist_keyboard.py

 

If you now move the robot by following the instructions, you should see the reflections in the camera of the Real Robot, and also in the RViz2:

Seeing real robot TFs in RVIZ2

Seeing real robot TFs in RVIZ2

Congratulations. You now know how to see TF data in RViz2.

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:

ROS1 or ROS2 for your Robotics Product?

ROS1 or ROS2 for your Robotics Product?

Overview

This post tries to answer the following question: ROS1 vs ROS2: Which one is the best for launching faster a better product?

The post is an intro to the webinar where we discussed which version of ROS to use (ROS1 or ROS2) for your next robotics product.

We analyzed the question from the point of view of a company that wants to deliver a professional product, not from the point of view of a ROS Developer.

Would you like to make your team ROS-ready? Quickly and effectively transform your IT developers into robot app developers online. Please have a look at the ROS & Robotics Online Training Solutions For Enterprise.

Quick and Dirty answer

  • Use ROS1: if your product is going to be released before the end of 2021
  • Use ROS2: if you plan to release your product after 2021

Longer answer (Using ROS1)

The reason why ROS1 may be a good choice for you is that ROS1 is already really mature, which allows you to move really fast since it has a ton of mature features ready to use.

The ideal would be: You make the robot available with ROS1, check if it is successful. If that is the case, you can always make a transition from ROS1 to ROS2 in the next years, once you know from the market that your product is something valid.

Longer answer (Using ROS2)

If you are planning to release your product after 2021, go and take ROS2.

The reason why you should ideally start already with ROS2 is that ROS2 is the future of ROS, therefore, the future of robotics. Your robot will already be ready for what is coming for the next years.

ROS1 vs ROS2 Evaluation Questions for Companies

If you want to know the answers for deeper ROS-related important questions for companies, like the ones below:

  1. Which ROS version has all the technical requirements that my product needs?
  2. Which ROS version for product development?
  3. Which ROS version for product release?

Please, take our Full Webinar available at The Construct for enterprise: https://www.theconstruct.ai/ros-team-training-3/

Important things you have to know before starting with ROS2:

  • Doing everything in ROS2 is going to be a little more difficult than if you were to do with ROS1. You will need more time to do anything in ROS2.
  • The reason is the same already explained: ROS1 is more mature, so, it is very likely that whatever you want to do in ROS1, someone may have already done it, therefore, you don’t have to reinvent the wheel, whereas in ROS2, is less likely to have everything that you need already implemented.

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:

[ROS2 Q&A] 228 – How to work with rosbags and laser_assembler in ROS2

[ROS2 Q&A] 228 – How to work with rosbags and laser_assembler in ROS2

What we are going to learn

  1. How to record your own rosbag
  2. How to use laser_assembler package
  3. How to visualize results from ROS2

List of resources used in this post

  1. Use the rosject: https://app.theconstructsim.com/#/l/4733ef97/
  2. ROS Development Studio (ROSDS) —▸ http://rosds.online
  3. Robot Ignite Academy –▸ https://www.robotigniteacademy.com
  4. [ROS Q&A] 047 – How to use the laser_assembler package: https://www.youtube.com/watch?v=MyA0as18Wkk
  5. ROS2 Tutorials –▸
    1. ROS2 Basics in 5 Days (C++): https://app.theconstructsim.com/#/Course/61
    2. ROS2 Navigation: https://app.theconstructsim.com/#/Course/50
    3. Get ROS2 Industrial Ready 3-Day Online Workshop
  6. The question that this post answers: https://answers.ros.org/question/393958/unable-to-visualize-point-cloud-in-rviz-using-rosbag-in-ros2/

Creating a rosject

In order to learn how to see data coming from ROSBags in ros2 depth camera data, we need to have ROS installed. We already prepared a rosject ready for that: https://app.theconstructsim.com/#/l/4733ef97/. You can download the rosject on your own computer if you prefer to work locally.

If you want to create your own rosject instead of using the link we just provided, you can do it also. We are going to use The Construct (https://www.theconstruct.ai/) for this tutorial, but if you have ROS2 installed on your own computer, you should be able to do ~everything on your own computer, except this creating a rosject part.

Let’s start by opening The Construct (https://www.theconstruct.ai/) and logging in. You can easily create a free account if you still don’t have one.

Once inside, let’s create My Rosjects and then, Create a new rosject if you decided taking this route:

My Rosjects

My Rosjects

 

Create a new rosject

Create a new rosject

For the rosject, let’s select ROS2 Foxy for the ROS Distro, let’s name the rosject as you want. You can leave the rosject public. You should see the rosject you just created in your rosjects list (the name is certainly different from the example below that was added just for learning purposes)

List of rosjects - Using Depth camera in ROS2 to determine object distance

List of rosjects – Using Depth camera in ROS2 to determine object distance

If you mouse over the recently created rosject, you should see a Run button. Just click that button to launch the rosject.

Launching the laser_scan_assember server to convert from laser scan to point cloud

Assuming you have a copy of the rosject, after opening it by clicking the Run button mentioned earlier, let’s open the IDE (Code Editor) to see its content.

Open the IDE - Code Editor

Open the IDE – Code Editor

You should see a rosbag file named 2022-01-17-11-40-32.bag, which is a rosbag for the turtlebot simulation.

In order to launch the laser_scan_assembler, we need a launch file. If you check carefully, you may notice that we already have a launch file under the path ~/catkin_ws/src/laser_assembler_demo/launch/assembler.launch.

Its content is as follows:

<launch>
    <node type="laser_scan_assembler" pkg="laser_assembler" name="my_assembler">
      <!-- <remap from="scan" to="tilt_scan"/> -->
      <param name="max_scans" type="int" value="400" />
      <param name="fixed_frame" type="string" value="base_footprint" />
    </node>
</launch>

Well, before launching that file, let’s learn how to record a rosbag file, in case you want at some point create your own:

Creating a rosbag file

In order to create a rosbag file, let’s start by opening a new terminal:

Open a new Terminal

Open a new Terminal

After opening the shell, let’s source ROS Noetic:

source /opt/ros/noetic/setup.bash

Let’s also source the simulation_ws (simulation workspace), because it is where we have the turtlebot simulation

source simulation_ws/devel/setup.bash

rospack profile

Now, let’s launch a turtlebot simulation with the following commands:

export TURTLEBOT3_MODEL=burger

roslaunch turtlebot3_gazebo turtlebot3_world.launch

You can click Open Gazebo to make sure the simulation is running (although for you it may not show the blue laser in gazebo)

Click Open Gazebo to view the Gazebo simulation

Click Open Gazebo to view the Gazebo simulation

You can now open a new web shell and list the topics with the following command:

source /opt/ros/noetic/setup.bash

rostopic list

The list of topics should be something like the following:

/clock
/cmd_vel
/gazebo/link_states
/gazebo/model_states
/gazebo/parameter_descriptions
/gazebo/parameter_updates
/gazebo/performance_metrics
/gazebo/set_link_state
/gazebo/set_model_state
/imu
/joint_states
/odom
/rosout
/rosout_agg
/scan
/tf

So, in order to record all topics in a  rosbag file, you can just run the rosbag record -a command. You can press CTRL+C to stop recording, or youcan also especify the –duration param if you want to record only for a few seconds or minutes (because rosbag files grow really fast):

rosbag record -a --duration=1m

The logs should be similar to the following:

[ INFO] [1643640738.398965449, 298.390000000]: Recording to '2022-01-31-14-52-18.bag'.
[ INFO] [1643640738.402667915, 298.395000000]: Subscribing to /rosout_agg
[ INFO] [1643640738.408196688, 298.402000000]: Subscribing to /rosout
[ INFO] [1643640738.417414694, 298.406000000]: Subscribing to /clock
[ INFO] [1643640738.492442317, 298.422000000]: Subscribing to /gazebo/link_states
[ INFO] [1643640738.511223062, 298.468000000]: Subscribing to /gazebo/model_states
[ INFO] [1643640738.518154757, 298.481000000]: Subscribing to /gazebo/performance_metrics
[ INFO] [1643640738.526057506, 298.488000000]: Subscribing to /gazebo/parameter_descriptions
[ INFO] [1643640738.598167676, 298.535000000]: Subscribing to /gazebo/parameter_updates
[ INFO] [1643640738.784914410, 298.633000000]: Subscribing to /scan
[ INFO] [1643640738.795856579, 298.650000000]: Subscribing to /joint_states
[ INFO] [1643640738.806535006, 298.665000000]: Subscribing to /tf
[ INFO] [1643640738.817849095, 298.673000000]: Subscribing to /odom
[ INFO] [1643640738.901146360, 298.732000000]: Subscribing to /imu

Let’s use the rosbag file that already exists, called 2022-01-17-11-40-32.bag.

Playing a rosbag file

Now that we have learned how to record a rosbag file, let’s play the one that we already had, called 2022-01-17-11-40-32.bag.

Before that, let’s kill the simulation we launched previously (pressing CTRL+C in the terminal where we launched the simulation).

If we now check the topics again, we should have only the following 3 topics:

rostopic list

  /clock
  /rosout
  /rosout_agg

Let’s first start roscore:

roscore &

If you wait about ~5 seconds, roscore will be running. After that, we can run rosbag:

rosbag  play 2022-01-17-11-40-32.bag

The output would be similar to the following:

setting /run_id to 5cbe4c68-82c9-11ec-bbc7-0242c0a86007
[ INFO] [1643656195.261386757]: Connected to master at [1_xterm:11311]
[ INFO] [1643656195.265748530]: Opening 2022-01-17-11-40-32.bag
process[rosout-1]: started with pid [1430]
started core service [/rosout]

Waiting 0.2 seconds after advertising topics... done.

Hit space to toggle paused, or 's' to step.
[RUNNING]  Bag Time:    345.418104   Duration: 13.739104 / 70.197000

If we now check the topics again in another terminal, we will have the topics listed again:

source /opt/ros/noetic/setup.bash

rostopic list

which would give us:

/clock
/gazebo/link_states
/gazebo/model_states
/gazebo/parameter_descriptions
/gazebo/parameter_updates
/gazebo/performance_metrics
/imu
/joint_states
/odom
/rosout
/rosout_agg
/scan
/tf
/tf_static

You can now kill the rosbag play process, now that you learned how to play it and how it works.

Launching the laser_scan_assember server to convert from laser scan to point cloud

Let’s start by opening 6 terminals. If you want, you can name them like the names below to easily know what each terminal is doing:

  • 1 – roscore
  • 2 – rosbag
  • 3 – assembler
  • 4 – call_assembler
  • 5 – bridge
  • 6 – rviz2

In the end, you would have something like the following image:

How to work with rosbags and laser_assembler in ROS2 14-36

How to work with rosbags and laser_assembler in ROS2 14-36

Let’s launch roscore in the first terminal (named roscore) if you have killed it:

source /opt/ros/noetic/setup.bash

roscore

Now let’s run rosbag play in the second terminal:

source /opt/ros/noetic/setup.bash

while true; do rosbag play 2022-01-17-11-40-32.bag; sleep 1; done

The reason why we are running inside a while loop is because it finishes after ~70 seconds, which is the duration of the rosbag file. By being inside the while loop, it keeps running “forever” until we stop it with CTRL+C.

Now in the third terminal, let’s run the laser assembler:

source ~/catkin_ws/devel/setup.bash

roslaunch laser_assembler_demo assembler.launch

Let’s now in the 4th terminal and list the services:

source ~/catkin_ws/devel/setup.bash

rosservice list

You should see the services running.:

/assemble_scans
/assemble_scans2
/build_cloud
/build_cloud2
/my_assembler/get_loggers
/my_assembler/set_logger_level
/play_1643657183488619006/get_loggers
/play_1643657183488619006/pause_playback
/play_1643657183488619006/set_logger_level
/rosout/get_loggers
/rosout/set_logger_level

Still in the 4th terminal, we can now run the node used to call the assembler:

 rosrun laser_assembler_demo call_assembler.py

The output you should get must be similar to the following:

Got cloud with 2592000 points
Got cloud with 2592000 points
Got cloud with 2592000 points
Got cloud with 2592000 points
...

Everything so far was running in ROS1. Let’s now run ros1_bridge in the 5th terminal to be able to see the topics in ROS2.

source /opt/ros/noetic/setup.bash

source /opt/ros/foxy/setup.bash

ros2 run ros1_bridge  dynamic_bridge --bridge-all-topics

Among other text output, you should see the following:

created 1to2 bridge for topic '/clock' with ROS 1 type 'rosgraph_msgs/Clock' and ROS 2 type 'rosgraph_msgs/msg/Clock'
created 1to2 bridge for topic '/gazebo/link_states' with ROS 1 type 'gazebo_msgs/LinkStates' and ROS 2 type 'gazebo_msgs/msg/LinkStates'
created 1to2 bridge for topic '/gazebo/model_states' with ROS 1 type 'gazebo_msgs/ModelStates' and ROS 2 type 'gazebo_msgs/msg/ModelStates'
created 1to2 bridge for topic '/imu' with ROS 1 type 'sensor_msgs/Imu' and ROS 2 type 'sensor_msgs/msg/Imu'
created 1to2 bridge for topic '/joint_states' with ROS 1 type 'sensor_msgs/JointState' and ROS 2 type 'sensor_msgs/msg/JointState'
created 1to2 bridge for topic '/laser_pointcloud' with ROS 1 type 'sensor_msgs/PointCloud2' and ROS 2 type 'sensor_msgs/msg/PointCloud2'
created 1to2 bridge for topic '/odom' with ROS 1 type 'nav_msgs/Odometry' and ROS 2 type 'nav_msgs/msg/Odometry'
created 1to2 bridge for topic '/rosout' with ROS 1 type 'rosgraph_msgs/Log' and ROS 2 type 'rcl_interfaces/msg/Log'
created 1to2 bridge for topic '/rosout_agg' with ROS 1 type 'rosgraph_msgs/Log' and ROS 2 type 'rcl_interfaces/msg/Log'
created 1to2 bridge for topic '/scan' with ROS 1 type 'sensor_msgs/LaserScan' and ROS 2 type 'sensor_msgs/msg/LaserScan'
created 1to2 bridge for topic '/tf' with ROS 1 type 'tf2_msgs/TFMessage' and ROS 2 type 'tf2_msgs/msg/TFMessage'
created 1to2 bridge for topic '/tf_static' with ROS 1 type 'tf2_msgs/TFMessage' and ROS 2 type 'tf2_msgs/msg/TFMessage

Now, let’s launch rviz2 in the 6th terminal:

rviz2

If you now open the Graphical Tools, you should be able to see rviz:

Open Graphical Tools / rviz

Open Graphical Tools / rviz

Once you have opened the Graphical Tools, let’s change the Fixed Frame in rviz2 to /base_footprint  instead of /map.

Let’s also click Add (in the left bottom of rviz2) and select a Point Cloud2. After the PointCloud2 was added, let’s select the topic /laser_pointcloud (as defined on ~/catkin_ws/src/laser_assembler_demo/src/call_assembler.py):

Now, you should be able to see the laser being shown in rviz2 (in red).

Laser Pointcloud being output in rviz2 with ros1_bridge

Laser Pointcloud being output in rviz2 with ros1_bridge

Congratulations. You now know how to work with rosbags and laser_assembler in ROS2.

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:

Pin It on Pinterest