... | ... | @@ -82,25 +82,24 @@ ros2screen air_lab_common [name of screen file] |
|
|
We also would like to load rviz configuration automatically, to do so you can use ```-c``` flag, and modify your screen file to start rviz with the following:
|
|
|
|
|
|
```bash
|
|
|
rviz2 -c $HOME/TDDE05/ros2_ws/src/labs/air_lab_common/rviz/[name of your rviz config]
|
|
|
rviz2 -d $HOME/TDDE05/ros2_ws/src/labs/air_lab_common/rviz/[name of your rviz config]
|
|
|
```
|
|
|
|
|
|
Create a package for Lab2
|
|
|
-------------------------
|
|
|
|
|
|
|
|
|
To create a python package with a default node:
|
|
|
|
|
|
```bash
|
|
|
cd ~/TDDE05/ros2_ws/src/labs
|
|
|
ros2 pkg create --build-type ament_python --node-name air_lab2_node lab2
|
|
|
ros2 pkg create --build-type ament_python --node-name lab2_node air_lab2
|
|
|
```
|
|
|
|
|
|
To create a C++ package with a default node:
|
|
|
To create a C++ package with a default node (only use C++ if you are knowledgeable in C++, otherwise, use Python):
|
|
|
|
|
|
```bash
|
|
|
cd ~/TDDE05/ros2_ws/src/labs
|
|
|
ros2 pkg create --build-type ament_cmake --node-name air_lab2_node lab2
|
|
|
ros2 pkg create --build-type ament_cmake --node-name lab2_node air_lab2
|
|
|
```
|
|
|
|
|
|
You should go to the top directory in your environment and run the build command:
|
... | ... | @@ -109,7 +108,7 @@ You should go to the top directory in your environment and run the build command |
|
|
cd ~/TDDE05/ros2_ws/
|
|
|
colcon build
|
|
|
```
|
|
|
Alternatively you can build using:
|
|
|
Alternatively, from any directory you can build using:
|
|
|
|
|
|
```bash
|
|
|
tdde05-build
|
... | ... | @@ -130,7 +129,7 @@ start-tdde05 |
|
|
You can then run your node with the following command:
|
|
|
|
|
|
```bash
|
|
|
ros2 run lab2 lab2_node
|
|
|
ros2 run air_lab2 lab2_node
|
|
|
```
|
|
|
|
|
|
Publishing on a topic
|
... | ... | @@ -242,13 +241,61 @@ Create the other two parameters ```angular``` and ```distance```. And use the pa |
|
|
|
|
|
Before starting, you should study the [official tutorial](https://docs.ros.org/en/galactic/Tutorials/Beginner-Client-Libraries/Using-Parameters-In-A-Class-CPP.html).
|
|
|
|
|
|
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:
|
|
|
|
|
|
```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:
|
|
|
|
|
|
* ```/global_costmap/costmap``` and chance the colorscheme to costmap
|
|
|
* ```/local_costmap/costmap``` and chance the colorscheme to costmap
|
|
|
* ```/plan/```
|
|
|
* ```/local_plan/``` and change the color to red
|
|
|
|
|
|
If you run the ```NavigateToPose``` action, you should see the following in ```Rviz```:
|
|
|
|
|
|
![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:
|
|
|
|
|
|
* 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```
|
|
|
|
|
|
Now you can select ```Nav2 goal``` tool and click in Rviz to make your robot move.
|
|
|
|
|
|
![rviz2_navigation_2](uploads/6b7d4787d3ff24dfb3f94fed12b10bab/rviz2_navigation_2.png)
|
|
|
|
|
|
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.
|
|
|
|
|
|
### Python
|
|
|
|
|
|
Create a new file in ```$HOME/TDDE05/ros2_ws/src/labs/air_lab2_py/air_lab2_py``` called ```random_exploration.py``` this will be your new node. You need to modify your ```setup.py``` so that it contains the following change to ```entry_points```:
|
|
|
|
|
|
```python
|
|
|
entry_points={
|
|
|
'console_scripts': [
|
|
|
'lab2_node = air_lab2_py.lab2_node:main',
|
|
|
'random_exploration = air_lab2_py.random_exploration:main'
|
|
|
],
|
|
|
},
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
ros2 interface show nav2_msgs/action/NavigateToPose
|
|
|
|
|
|
### C++
|
|
|
|
|
|
|
|
|
|
|
|
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}}}"
|
|
|
|
|
|
|
|
|
|