|
|
Lab 1: Introduction to ROS2 and Turtlebot4
|
|
|
==========================================
|
|
|
|
|
|
<> The aim of this lab is a basic introduction to ROS2 and its main tools. As part of the lab, you will also be introduced to the simulated platform: Turtlebot4.
|
|
|
This lab aims to introduce the basic concepts of ROS2 and its main tools. As part of the lab, you will also be introduced to the simulated environment: Turtlebot4.
|
|
|
|
|
|
Introduction
|
|
|
------------
|
|
|
|
|
|
_The Robot Operating System (ROS) is a flexible framework for writing robot software. It is a collection of tools, libraries, and conventions that aim to simplify the task of creating complex and robust robot behavior across a wide variety of robotic platforms_. More information can be found on the [official web site](https://www.ros.org/). It is commonly use by many robots in research and industry. ROS can transparently interact with real hardware or with a simulator.
|
|
|
_The Robot Operating System (ROS) is a flexible framework for writing robot software. It is a collection of tools, libraries, and conventions that aim to simplify the task of creating complex and robust robot behavior across a wide variety of robotic platforms_. More information can be found on the [official website](https://www.ros.org/). It is commonly used by many robots in research and industry. ROS can transparently interact with real hardware or with a simulator.
|
|
|
|
|
|
Running
|
|
|
-------
|
... | ... | @@ -18,18 +17,18 @@ ROS is already installed on IDA computers, you can find it in the directories ` |
|
|
|
|
|
**thinlinc**
|
|
|
|
|
|
Running on personal computers is currently not supported, however it is possible to use thinlinc to access remotely IDA's computers.
|
|
|
To use thinlinc, follow the installation instruction at http://www.cendio.com/thinlinc/download and connect to the IDA server: ```thinlinc.edu.liu.se```.
|
|
|
Running on personal computers is currently not supported. However, it is possible to use Thinlinc to remotely access IDA's computers.
|
|
|
To use thinlinc, follow the installation instructions at http://www.cendio.com/thinlinc/download and connect to the IDA server: ```thinlinc.edu.liu.se```.
|
|
|
|
|
|
ROS
|
|
|
---
|
|
|
|
|
|
![ros_logo](uploads/4ecd29c35a3bc069188ff0a2d9fee0aa/ros_logo.png)
|
|
|
|
|
|
ROS is a framework composed of a communication middleware and a set of modules providing different functionnalities for robots.
|
|
|
ROS is a framework composed of communication middleware and a set of modules providing different functionalities for robots.
|
|
|
|
|
|
**Middleware:** With ROS the various algorithms, interfaces to hardware and simulators all run in different processes. ROS include communication libraries for various programming languages: C++ ([rclcpp](https://index.ros.org/p/rclcpp/)) or Python (rclpy \url{https://index.ros.org/p/rclpy/}).
|
|
|
There are libraries for more programming languages, but they are not as well supported and it is recommended that you stick to C++ and Python for this course.
|
|
|
**Middleware:** With ROS, the various algorithms, interfaces to hardware, and simulators all run in different processes. ROS includes communication libraries for various programming languages: C++ ([rclcpp](https://index.ros.org/p/rclcpp/)) or Python (rclpy \url{https://index.ros.org/p/rclpy/}).
|
|
|
There are libraries for more programming languages, but they are not as well supported, and it is recommended that you stick to C++ and Python for this course.
|
|
|
|
|
|
ROS programs mainly communicate through the use of topics.
|
|
|
ROS topics follow a multi-publishers/multi-subscribers pattern: ROS programs subscribe to individual topics and they will then receive the messages that are published by other programs on the topic.
|
... | ... | @@ -37,33 +36,33 @@ Topics are associated to a specific type of a ROS message (examples of standard |
|
|
|
|
|
In addition to topics, ROS programs can offer _service calls_, which is the ROS implementation of Remote Procedure Calls (RPC).
|
|
|
|
|
|
**Packaging system:** ROS also provide a standard method for defining software package, using either the [CMake](cmake.org/) or [setupttools](https://setuptools.pypa.io/en/latest/setuptools.html) build systems. This package system allow to easily install any ROS package.
|
|
|
**Packaging system:** ROS also provides a standard method for defining software packages, using either the [CMake](cmake.org/) or [setupttools](https://setuptools.pypa.io/en/latest/setuptools.html) build systems. This package system allows you to easily install any ROS package.
|
|
|
|
|
|
Turtlebot4
|
|
|
----------
|
|
|
|
|
|
![turtlebot4](uploads/235f84cc0850b252a3b5f92327369fb0/turtlebot4.jpeg)
|
|
|
|
|
|
_TurtleBot 4_ is the next-generation of the world’s most popular open source robotics platform for education and research, offering better computing power, better sensors and a world class user experience at an affordable price point.
|
|
|
_TurtleBot 4_ is the next-generation of the world’s most popular open-source robotics platform for education and research, offering better computing power, better sensors, and a world-class user experience at an affordable price point.
|
|
|
|
|
|
For this course, the _Turtlebot 4_ is simulated, using a 2D simulator called _simple simulator_, which can run well in thinlinc or the lab computers. The official project use a 3D simulator, [https://gazebosim.org/](Gazebo), which work poorly on the University computers.
|
|
|
For this course, the _Turtlebot 4_ is simulated, using a 2D simulator called _simple simulator_, which can run well in thinlinc or the lab computers. The official project use a 3D simulator, [https://gazebosim.org/](Gazebo), which works poorly on the University computers.
|
|
|
|
|
|
Setup the environment
|
|
|
---------------------
|
|
|
|
|
|
# First you will need to add the following to your ```.bashrc``` file:
|
|
|
# First, you will need to add the following to your ```.bashrc``` file:
|
|
|
|
|
|
```bash
|
|
|
alias tdde05-start=". /courses/TDDE05/software/bin/tdde05-start.sh"
|
|
|
```
|
|
|
|
|
|
To edit your ```.bashrc``` file you can do the following in a terminal:
|
|
|
To edit your ```.bashrc``` file, you can do the following in a terminal:
|
|
|
|
|
|
```bash
|
|
|
kate ~/.bashrc
|
|
|
```
|
|
|
|
|
|
# you need to set your ROS Domain id
|
|
|
# You need to set your ROS Domain id
|
|
|
|
|
|
To avoid conflict with ROS2, you need to set a unique ROS Domain id:
|
|
|
|
... | ... | @@ -72,7 +71,7 @@ mkdir -p $HOME/TDDE05 |
|
|
kate $HOME/TDDE05/.domain_id
|
|
|
```
|
|
|
|
|
|
And in domain id set your group number, so if you are group 12, it should contain ``12``.
|
|
|
And in the domain id set your group number, so if you are group 12, it should contain ``12``.
|
|
|
|
|
|
# Every time you open a new terminal, before issuing a ROS command, you will need to run:
|
|
|
|
... | ... | @@ -95,10 +94,10 @@ If all went well, the following image should appear: |
|
|
|
|
|
The _red_ dot is the robot. The black square are obstacles and the dots with numbers are semantic objects which are used in an other lab.
|
|
|
|
|
|
Visualisation
|
|
|
Visualization
|
|
|
-------------
|
|
|
|
|
|
The robot is ready to take commands, but the visualisation by the simulator is very limited. However, ROS provides a good visualisation tool called ```RViz```. To start it, in a terminal, run:
|
|
|
The robot is ready to take commands, but the visualization by the simulator is very limited. However, ROS provides a good visualization tool called ```RViz```. To start it, in a terminal, run:
|
|
|
|
|
|
```bash
|
|
|
rviz2
|
... | ... | @@ -108,15 +107,15 @@ It should start empty and look like the following: |
|
|
|
|
|
![rviz_empty](uploads/62e97910ebad5d01376885940c0d48de/rviz_empty.png)
|
|
|
|
|
|
We can add visualisation using the ```add``` button, it should show a display like this:
|
|
|
We can add visualization using the ```add``` button, it should show a display like this:
|
|
|
|
|
|
![rviz_add](uploads/6ed71d5720c80f448f5adb93e1b9a7e2/rviz_add.png)
|
|
|
|
|
|
The first thing to add is called ```TF```, it shows all the frames used by the robot. Too many frames are shown, deselect all of them (uncheck ```all enabled```), and then select ```odom``` and base link. It should show the origin of the world and the current position of the robot.
|
|
|
|
|
|
Then add a 3D model of the robot, using the ```RobotModel``` visualisation, in the parameters, for ```topic``` type ```/robot_description```.
|
|
|
Then add a 3D model of the robot, using the ```RobotModel``` visualization, in the parameters, for ```topic``` type ```/robot_description```.
|
|
|
|
|
|
Then add the map used by the robot to navigate, you can use the ```map``` visualisation and then select the ```/map``` topic.
|
|
|
Then add the map used by the robot to navigate, you can use the ```map``` visualization and then select the ```/map``` topic.
|
|
|
|
|
|
This should show a window that looks like this:
|
|
|
|
... | ... | @@ -124,7 +123,7 @@ This should show a window that looks like this: |
|
|
|
|
|
You can save your Rviz configuration from the file menu.
|
|
|
|
|
|
Send command to the robot
|
|
|
Send a command to the robot
|
|
|
-------------------------
|
|
|
|
|
|
The robot is ready to take command. The first commands you can send to the robot are for docking and undocking, in a terminal:
|
... | ... | @@ -149,7 +148,7 @@ ros2 action send_goal /navigate_to_position irobot_create_msgs/action/NavigateTo |
|
|
Managing topics from the command line
|
|
|
-------------------------------------
|
|
|
|
|
|
The main communication medium for ROS is through the using of _topics_. Topics have a name and a type and follow a publisher-subscriber pattern. You can use the following command to list all available topics:
|
|
|
The main communication medium for ROS is through the use of _topics_. Topics have a name and a type and follow a publisher-subscriber pattern. You can use the following command to list all available topics:
|
|
|
|
|
|
|
|
|
```bash
|
... | ... | @@ -166,20 +165,20 @@ You can listen to a topic from the command line to get the values: |
|
|
ros2 topic echo /odom
|
|
|
```
|
|
|
|
|
|
To check what is happening, run one of the command of the previous section and you should see the position of the robot on the terminal.
|
|
|
To check what is happening, run one of the commands in the previous section, and you should see the position of the robot on the terminal.
|
|
|
|
|
|
And finally you can publish on a topic:
|
|
|
And finally, you can publish on a topic:
|
|
|
|
|
|
```bash
|
|
|
ros2 topic pub --rate 100 /cmd_vel geometry_msgs/msg/Twist "{ linear: { x: 0.4, y: 0.0, z: 0.0}, angular: { x: 0.0, y: 0.0, z: 0.3 } }"
|
|
|
```
|
|
|
|
|
|
After that command, you should be able to see the robot move in circle in RViz or the simulator window. You should also be able to see the position changed when listening to ```/odom```.
|
|
|
After that command, you should be able to see the robot move in a circle in RViz or the simulator window. You should also be able to see the position changed when listening to ```/odom```.
|
|
|
|
|
|
RQT
|
|
|
---
|
|
|
|
|
|
An alternative approach to use the command line for listening or publishing on topics is to use a tool called RQT. You can start it from the command line simply with:
|
|
|
An alternative approach to using the command line for listening or publishing on topics is to use a tool called RQT. You can start it from the command line simply with:
|
|
|
|
|
|
```bash
|
|
|
rqt
|
... | ... | @@ -195,7 +194,7 @@ The window should look like this: |
|
|
|
|
|
![rqt](uploads/93ef754cc99eecd6fa9eeb1b4dfc070a/rqt.png)
|
|
|
|
|
|
If you check the ```/odom``` in topic monitor you can see it change. In the message publisher you can add new topics and set the value to publish, try to add ```/cmd_vel```and to publish the velocity. A more convenient alternative to controlling the velocity is to use the robot steering panel (do note that the robot does not like to move backward).
|
|
|
If you check the ```/odom``` in the topic monitor, you can see it change. In the message publisher you can add new topics and set the value to publish, try to add ```/cmd_vel```and to publish the velocity. A more convenient alternative to controlling the velocity is to use the robot steering panel (do note that the robot does not like to move backward).
|
|
|
|
|
|
You can also use rqt to plot value, add a plot with ```Visualization > Plot```. You can then add ```/diffdrive_controller/cmd_vel_unstamped/linear/x``` and /diffdrive_controller/cmd_vel_unstamped/angular/z```
|
|
|
|
... | ... | @@ -255,13 +254,13 @@ The following shortkeys can be used: |
|
|
In the screen configuration file:
|
|
|
* ```screen 12``` indicates a new tab with number ```12```
|
|
|
* ```title``` indicates the name of the tab (as shown in the list of tabs)
|
|
|
* ```stuff``` indicates the command that is run in the tab, the ```\015``` at the end indicates whether the command is ran when starting the screen or if you have to start it manually
|
|
|
* ```stuff``` indicates the command that is run in the tab, the ```\015``` at the end indicates whether the command is run when starting the screen or if you have to start it manually
|
|
|
|
|
|
As an exercise, adds tab for the action of docking, undocking and moving to a location (do not add ```\015``` at the end of the command line, to make sure you don't start those action every time you start the screen file).
|
|
|
As an exercise, add a tab for the action of docking, undocking, and moving to a location (do not add ```\015``` at the end of the command line, to make sure you don't start those actions every time you start the screen file).
|
|
|
|
|
|
Demonstration
|
|
|
-------------
|
|
|
|
|
|
* Show your ```screen``` file
|
|
|
* Use ```rviz``` and ```rqt```, to show how your robot respond to docking, undocking and moving to a location.
|
|
|
* Use ```rviz``` and ```rqt```, to show how your robot responds to docking, undocking, and moving to a location.
|
|
|
|