... | @@ -18,38 +18,89 @@ colcon build |
... | @@ -18,38 +18,89 @@ 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 expect you to follow that structure.
|
|
|
|
|
|
In ```~/TDDE05/ros2_ws/```, you will know have four directories
|
|
In ```~/TDDE05/ros2_ws/```, you will now have four directories
|
|
|
|
|
|
* ```build```: used to build your modules
|
|
* ```build```: used to build your modules
|
|
* ```install```: directory where your modules are installed
|
|
* ```install```: directory where your modules are installed
|
|
* ```log```: directory with building logs
|
|
* ```log```: directory with building logs
|
|
* ```src```: the directory with the source for your modules
|
|
* ```src```: the directory with the source for your modules
|
|
|
|
|
|
Create a package
|
|
Setup GIT Repository
|
|
----------------
|
|
--------------------
|
|
|
|
|
|
You should go to the source directory in your environment:
|
|
You should go to the source directory in your environment:
|
|
|
|
|
|
```bash
|
|
```bash
|
|
cd ~/TDDE05/ros2_ws/src
|
|
cd ~/TDDE05/ros2_ws/src/
|
|
mkdir labs
|
|
mkdir labs
|
|
cd labs
|
|
cd labs
|
|
git init
|
|
git init
|
|
git remote add origin git@gitlab.liu.se:tdde05-20YY/air-labs-XX.git
|
|
git remote add origin git@gitlab.liu.se:tdde05-20YY/air-labs-XX.git
|
|
```
|
|
```
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
```bash
|
|
|
|
cd ~/TDDE05/ros2_ws/src/labs
|
|
|
|
ros2 pkg create --build-type ament_python air_lab_common
|
|
|
|
```
|
|
|
|
|
|
|
|
Then we will add the screen and rviz configuration:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
cd ~/TDDE05/ros2_ws/src/labs/air_lab_common
|
|
|
|
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:
|
|
|
|
|
|
|
|
```python
|
|
|
|
import glob
|
|
|
|
|
|
|
|
# And modify data_files line so that it looks like this:
|
|
|
|
|
|
|
|
data_files=[
|
|
|
|
('share/ament_index/resource_index/packages',
|
|
|
|
['resource/' + package_name]),
|
|
|
|
('share/' + package_name, ['package.xml']),
|
|
|
|
('share/' + package_name + "/screen", glob.glob('screen/*')),
|
|
|
|
],
|
|
|
|
```
|
|
|
|
|
|
|
|
This will install your screen file and rviz file. You can now run ```tdde05-build``` to install your files and ```start-tdde05``` to reload the configuration.
|
|
|
|
|
|
|
|
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 ```-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]
|
|
|
|
```
|
|
|
|
|
|
|
|
Create a package for Lab2
|
|
|
|
-------------------------
|
|
|
|
|
|
|
|
|
|
To create a python package with a default node:
|
|
To create a python package with a default node:
|
|
|
|
|
|
```bash
|
|
```bash
|
|
cd ~/TDDE05/ros2_ws/src/labs
|
|
cd ~/TDDE05/ros2_ws/src/labs
|
|
ros2 pkg create --build-type ament_python --node-name lab2_node lab2
|
|
ros2 pkg create --build-type ament_python --node-name air_lab2_node lab2
|
|
```
|
|
```
|
|
|
|
|
|
To create a C++ package with a default node:
|
|
To create a C++ package with a default node:
|
|
|
|
|
|
```bash
|
|
```bash
|
|
cd ~/TDDE05/ros2_ws/src/labs
|
|
cd ~/TDDE05/ros2_ws/src/labs
|
|
ros2 pkg create --build-type ament_cmake --node-name lab2_node lab2
|
|
ros2 pkg create --build-type ament_cmake --node-name air_lab2_node lab2
|
|
```
|
|
```
|
|
|
|
|
|
You should go to the top directory in your environment and run the build command:
|
|
You should go to the top directory in your environment and run the build command:
|
... | @@ -89,6 +140,8 @@ At this point, your node is not doing anything interesting. First we will make o |
... | @@ -89,6 +140,8 @@ At this point, your node is not doing anything interesting. First we will make o |
|
|
|
|
|
### Python
|
|
### Python
|
|
|
|
|
|
|
|
Before starting, you should study the [official tutorial](https://docs.ros.org/en/galactic/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Py-Publisher-And-Subscriber.html).
|
|
|
|
|
|
This can be done in python with the following:
|
|
This can be done in python with the following:
|
|
|
|
|
|
```python
|
|
```python
|
... | @@ -132,6 +185,8 @@ while rclpy.ok(): |
... | @@ -132,6 +185,8 @@ while rclpy.ok(): |
|
|
|
|
|
### C+++
|
|
### C+++
|
|
|
|
|
|
|
|
Before starting, you should study the [official tutorial](https://docs.ros.org/en/galactic/Tutorials/Beginner-Client-Libraries/Writing-A-Simple-Cpp-Publisher-And-Subscriber.html).
|
|
|
|
|
|
Listen on a topic
|
|
Listen on a topic
|
|
-----------------
|
|
-----------------
|
|
|
|
|
... | @@ -167,6 +222,8 @@ ros2 run lab2 lab2_node |
... | @@ -167,6 +222,8 @@ ros2 run lab2 lab2_node |
|
|
|
|
|
### Python
|
|
### Python
|
|
|
|
|
|
|
|
Before starting, you should study the [official tutorial](https://docs.ros.org/en/galactic/Tutorials/Beginner-Client-Libraries/Using-Parameters-In-A-Class-Python.html).
|
|
|
|
|
|
Create a parameter called ```linear``` with default value ```0.1``` with the following:
|
|
Create a parameter called ```linear``` with default value ```0.1``` with the following:
|
|
|
|
|
|
```python
|
|
```python
|
... | @@ -183,6 +240,7 @@ Create the other two parameters ```angular``` and ```distance```. And use the pa |
... | @@ -183,6 +240,7 @@ Create the other two parameters ```angular``` and ```distance```. And use the pa |
|
|
|
|
|
### C++
|
|
### C++
|
|
|
|
|
|
|
|
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).
|
|
|
|
|
|
Exploration with a random pattern
|
|
Exploration with a random pattern
|
|
---------------------------------
|
|
---------------------------------
|
... | | ... | |