... | ... | @@ -14,7 +14,7 @@ cd ~/TDDE05/ros2_ws/ |
|
|
colcon build
|
|
|
```
|
|
|
|
|
|
**It is strongly advised that you use the exact directory structure.** A number of scripts are provided by the course and expect you to follow that structure.
|
|
|
**It is strongly advised that you use the exact directory structure.** A number of scripts are provided by the course, and we expect you to follow that structure.
|
|
|
|
|
|
In ```~/TDDE05/ros2_ws/```, you will now have four directories
|
|
|
|
... | ... | @@ -36,10 +36,10 @@ git init |
|
|
git remote add origin git@gitlab.liu.se:tdde05-20YY/air-labs-XX.git
|
|
|
```
|
|
|
|
|
|
Create a package for screen and rviz
|
|
|
Create a package for screen and Rviz
|
|
|
------------------------------------
|
|
|
|
|
|
We will create a package ```air_lab_common``` to add files that are common to all the labs, such as the screen file to start commands and the rviz configuration.
|
|
|
We will create a package ```air_lab_common``` to add common files among all the labs, such as the screen file to start commands and the Rviz configuration.
|
|
|
|
|
|
```bash
|
|
|
cd ~/TDDE05/ros2_ws/src/labs
|
... | ... | @@ -54,7 +54,7 @@ mkdir screen |
|
|
mkdir rviz
|
|
|
```
|
|
|
|
|
|
Then copy in ```screen``` and ```rviz``` the files that you created in *lab1*. You will need to modify the ```setup.py``` file to include the following:
|
|
|
Then copy in ```screen``` and ```rviz``` the files you created in *lab1*. You will need to modify the ```setup.py``` file to include the following:
|
|
|
|
|
|
```python
|
|
|
import glob
|
... | ... | @@ -78,13 +78,13 @@ git commit -m "import air_lab_common" |
|
|
```
|
|
|
|
|
|
You can now run ```tdde05-build``` to install your files and ```tdde05-start``` to reload the configuration.
|
|
|
And you can now start your screen file with:
|
|
|
You can now start your screen file with:
|
|
|
|
|
|
```bash
|
|
|
ros2screen air_lab_common [name of screen file]
|
|
|
```
|
|
|
|
|
|
We also would like to load rviz configuration automatically, to do so you can use ```-d``` flag, and modify your screen file to start rviz with the following:
|
|
|
We also would like to load Rviz configuration automatically. To do so you can use ```-d``` flag, and modify your screen file to start Rviz with the following:
|
|
|
|
|
|
```bash
|
|
|
rviz2 -d $HOME/TDDE05/ros2_ws/src/labs/air_lab_common/rviz/[name of your rviz config]
|
... | ... | @@ -93,7 +93,7 @@ rviz2 -d $HOME/TDDE05/ros2_ws/src/labs/air_lab_common/rviz/[name of your rviz co |
|
|
Create a package for Lab2
|
|
|
-------------------------
|
|
|
|
|
|
To create a python package with a default node:
|
|
|
To create a Python package with a default node:
|
|
|
|
|
|
```bash
|
|
|
cd ~/TDDE05/ros2_ws/src/labs
|
... | ... | @@ -119,7 +119,7 @@ Alternatively, from any directory you can build using: |
|
|
tdde05-build
|
|
|
```
|
|
|
|
|
|
Then you need to source the environment with:
|
|
|
Then, you need to source the environment with:
|
|
|
|
|
|
```bash
|
|
|
source install/local_setup.bash
|
... | ... | @@ -140,15 +140,15 @@ ros2 run air_lab2 lab2_node |
|
|
Publishing on a topic
|
|
|
---------------------
|
|
|
|
|
|
At this point, your node is not doing anything interesting. First we will make our node send a message on a topic, we will make it send a velocity on ```/cmd_vel```.
|
|
|
At this point, your node is not doing anything interesting. First, we will make our node send a message on a topic. We will make it send a velocity on ```/cmd_vel```.
|
|
|
|
|
|
Before starting, you should study the [official python tutorial](https://docs.ros.org/en/galactic/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Py-Publisher-And-Subscriber.html) or the [official C++ tutorial](https://docs.ros.org/en/galactic/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Cpp-Publisher-And-Subscriber.html).
|
|
|
Before starting, you should study the [official Python tutorial](https://docs.ros.org/en/galactic/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Py-Publisher-And-Subscriber.html) or the [official C++ tutorial](https://docs.ros.org/en/galactic/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Cpp-Publisher-And-Subscriber.html).
|
|
|
|
|
|
Modify the publisher example to instead publish a ```geometry_msgs/msg/Twist``` (you can import it from ```import geometry_msgs.msg```) with a linear velocity of ```0.1``` and angular velocity of ```0.05```. We strongly advise that you follow the an incremental approach:
|
|
|
Modify the publisher example to instead publish a ```geometry_msgs/msg/Twist``` (you can import it from ```import geometry_msgs.msg```) with a linear velocity of ```0.1``` and angular velocity of ```0.05```. We strongly advise that you follow an incremental approach:
|
|
|
|
|
|
* Copy/paste the publisher example from the respective tutorials into your ```lab2_node.py``` or ```lab2_node.cpp```
|
|
|
* Make sure you understand what is happening, if you have doubts, ask questions to your lab assistant
|
|
|
* Build your project with ```tdde05_build``` and then use ```ros2 run ...``` to start your node. Alternatively for python, you can start the script directly from the source directory.
|
|
|
* Build your project with ```tdde05_build``` and then use ```ros2 run ...``` to start your node. Alternatively, for Python, you can start the script directly from the source directory.
|
|
|
* Check that it runs properly, you can use ```ros2 topic echo ...``` or ```rqt``` to check that a message is published by the node, it should be a string.
|
|
|
* Modify the script to publish a ```geometry_msgs/msg/Twist``` on ```/cmd_vel``` with a linear velocity of ```0.1``` and angular velocity of ```0.05```.
|
|
|
|
... | ... | @@ -157,18 +157,18 @@ The documentation for ```geometry_msgs/Twist``` can be found online at [geometry |
|
|
Listen on a topic
|
|
|
-----------------
|
|
|
|
|
|
In the previous part, we have created a node that publish on a topic and make your robot move, but it never stops. In this part, we will listen to the ```/odom``` topic and use that information to stop when the robot has moved more than 1.0 meter away from its start position.
|
|
|
In the previous part, we have created a node that publishes on a topic and makes your robot move, but it never stops. In this part, we will listen to the ```/odom``` topic and use that information to stop when the robot has moved more than 1.0 meter away from its start position.
|
|
|
|
|
|
Check in the Python or C++ tutorial to see how you can subscribe on a topic. You will have to somehow combine together the publisher and subscriber classes. We strongly advise that you follow the an incremental approach:
|
|
|
Check in the Python or C++ tutorial to see how you can subscribe to a topic. You will have to somehow combine together the publisher and subscriber classes. We strongly advise that you follow an incremental approach:
|
|
|
|
|
|
* Add a subscriber to your ```lab2_node```. **You should have a single class**, so add the `subscribe` and `callback` to your existing class. By default, the `spin` function is blocking and accept a single `node` as argument.
|
|
|
* Add a subscriber to your ```lab2_node```. **You should have a single class**, so add the `subscribe` and `callback` to your existing class. By default, the `spin` function is blocking and accepts a single `node` as an argument.
|
|
|
* Add a printout in the callback to check that you receive a message.
|
|
|
* Modify your program so that it exit once the distance has been computed.
|
|
|
* Modify your program so that it exits once the distance has been computed.
|
|
|
|
|
|
Parameters
|
|
|
----------
|
|
|
|
|
|
For now we have hard coded parameters, such as the velocity and the distance. To make our node more effective, we should set those as parameters on the command line.
|
|
|
For now, we have hard-coded parameters, such as the velocity and the distance. To make our node more effective, we should set those as parameters on the command line.
|
|
|
|
|
|
So that we can run our program this way:
|
|
|
|
... | ... | @@ -176,23 +176,23 @@ So that we can run our program this way: |
|
|
ros2 run air_lab2 lab2_node --ros-args -p linear:=0.5 -p angular:=0.1 -p distance:=0.4
|
|
|
```
|
|
|
|
|
|
Before starting, you should study the [official python tutorial](https://docs.ros.org/en/galactic/Tutorials/Beginner-Client-Libraries/Using-Parameters-In-A-Class-Python.html) or the [official C++ tutorial](https://docs.ros.org/en/galactic/Tutorials/Beginner-Client-Libraries/Using-Parameters-In-A-Class-CPP.html).
|
|
|
Before starting, you should study the [official Python tutorial](https://docs.ros.org/en/galactic/Tutorials/Beginner-Client-Libraries/Using-Parameters-In-A-Class-Python.html) or the [official C++ tutorial](https://docs.ros.org/en/galactic/Tutorials/Beginner-Client-Libraries/Using-Parameters-In-A-Class-CPP.html).
|
|
|
|
|
|
Create a ```linear```, ```angular``` and ```distance``` parameter.
|
|
|
|
|
|
Navigation and path planning
|
|
|
----------------------------
|
|
|
|
|
|
The turtlebot4 include a motion planner that can navigate and avoid obstacles. This is implemented as an action that can be started from the terminal with the following command:
|
|
|
The turtlebot4 includes a motion planner that can navigate and avoid obstacles. This is implemented as an action that can be started from the terminal with the following command:
|
|
|
|
|
|
```bash
|
|
|
ros2 action send_goal /navigate_to_pose nav2_msgs/action/NavigateToPose "pose: {header: {frame_id: map}, pose: {position: {x: 6.0, y: 2.0, z: 0.0}, orientation:{x: 0.0, y: 0.0, z: 0, w: 1.0000000}}}"
|
|
|
```
|
|
|
|
|
|
It can also be started from RViz. Before we start, you should add the following visualisation:
|
|
|
It can also be started from RViz. Before we start, you should add the following visualizations:
|
|
|
|
|
|
* ```/global_costmap/costmap``` and chance the colorscheme to costmap
|
|
|
* ```/local_costmap/costmap``` and chance the colorscheme to costmap
|
|
|
* ```/global_costmap/costmap``` and change the colorscheme to costmap
|
|
|
* ```/local_costmap/costmap``` and change the colorscheme to costmap
|
|
|
* ```/plan/```
|
|
|
* ```/local_plan/``` and change the color to red
|
|
|
|
... | ... | @@ -200,7 +200,7 @@ If you run the ```NavigateToPose``` action, you should see the following in ```R |
|
|
|
|
|
![rviz_path_planning](uploads/1276ecebbfd573d82fd7bd64ae3c076f/rviz_path_planning.png)
|
|
|
|
|
|
We can also send ```NavigateToPose``` requests directly from ```Rviz```, to do so we need to add the following:
|
|
|
We can also send ```NavigateToPose``` requests directly from ```Rviz```. To do so we need to add the following:
|
|
|
|
|
|
* In ```Panels``` menu, select ```Add new panel``` and then ```Navigation 2```
|
|
|
* In the toolbar, click on the plus, then select ```GoalTool``` under ```nav2_rviz_plugin```
|
... | ... | @@ -212,7 +212,7 @@ Now you can select ```Nav2 goal``` tool and click in Rviz to make your robot mov |
|
|
Exploration with a random pattern
|
|
|
---------------------------------
|
|
|
|
|
|
We will now create a new node that will send the robot to random location to explore the map. We will need to create a new node in the ```air_lab2``` module.
|
|
|
We will now create a new node that will send the robot to a random location to explore the map. We will need to create a new node in the ```air_lab2``` module.
|
|
|
|
|
|
### Python
|
|
|
|
... | ... | @@ -227,7 +227,7 @@ entry_points={ |
|
|
},
|
|
|
```
|
|
|
|
|
|
We will use the ```NavigateToPose``` action, you can check its type with:
|
|
|
We will use the ```NavigateToPose``` action. You can check its type with:
|
|
|
|
|
|
```bash
|
|
|
ros2 interface show nav2_msgs/action/NavigateToPose
|
... | ... | @@ -301,14 +301,14 @@ if __name__ == '__main__': |
|
|
main()
|
|
|
```
|
|
|
|
|
|
Extend that class so that you keep going to a new random location, either when the robot has reached its current location, or when it is failing to reach it, instead of basing yourself on time, you should check using feedback if the robot is moving. There are at least two approaches to solve that problem, one is much easier to implement than the other, so look carefully at the message structure.
|
|
|
Extend that class so that you keep going to a new random location, either when the robot has reached its current location or when it is failing to reach it, instead of basing yourself on time, you should check using feedback if the robot is moving. There are at least two approaches to solving that problem. One is much easier to implement than the other, so look carefully at the message structure.
|
|
|
|
|
|
### C++
|
|
|
|
|
|
Create a new file in ```$HOME/TDDE05/ros2_ws/src/labs/air_lab2/src``` called ```random_exploration.cpp``` this will be your new node. You need to modify your ```CMakeLists.txt```, to duplicate what is available for ```lab2_node```.
|
|
|
|
|
|
|
|
|
We will use the ```NavigateToPose``` action, you can check its type with:
|
|
|
We will use the ```NavigateToPose``` action. You can check its type with:
|
|
|
|
|
|
```bash
|
|
|
ros2 interface show nav2_msgs/action/NavigateToPose
|
... | ... | @@ -441,7 +441,7 @@ int main(int argc, char * argv[]) |
|
|
}
|
|
|
```
|
|
|
|
|
|
Extend that class so that you keep going to a new random location, either when the robot has reached its current location, or when it is failing to reach it, instead of basing yourself on time, you should check using feedback if the robot is moving. There are at least two approaches to solve that problem, one is much easier to implement than the other, so look carefully at the message structure.
|
|
|
Extend that class so that you keep going to a new random location, either when the robot has reached its current location or when it is failing to reach it, instead of basing yourself on time, you should check using feedback if the robot is moving. There are at least two approaches to solving that problem. One is much easier to implement than the other, so look carefully at the message structure.
|
|
|
|
|
|
Demonstration
|
|
|
--------------
|
... | ... | |