... | ... | @@ -12,12 +12,18 @@ To setup your environment: |
|
|
|
|
|
```bash
|
|
|
mkdir -p ~/TDDE05/ros2_ws/src
|
|
|
cd ~/TDDE05/ros2_ws/src
|
|
|
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.
|
|
|
|
|
|
TODO: explain the structure of the environment src/ build inst...
|
|
|
In ```~/TDDE05/ros2_ws/```, you will know have four directories
|
|
|
|
|
|
* ```build```: used to build your modules
|
|
|
* ```install```: directory where your modules are installed
|
|
|
* ```log```: directory with building logs
|
|
|
* ```src```: the directory with the source for your modules
|
|
|
|
|
|
Create a package
|
|
|
----------------
|
... | ... | @@ -26,18 +32,24 @@ You should go to the source directory in your environment: |
|
|
|
|
|
```bash
|
|
|
cd ~/TDDE05/ros2_ws/src
|
|
|
mkdir labs
|
|
|
cd labs
|
|
|
git init
|
|
|
git remote add origin git@gitlab.liu.se:tdde05-20YY/air-labs-XX.git
|
|
|
```
|
|
|
|
|
|
To create a C++ package with a default node:
|
|
|
To create a python package with a default node:
|
|
|
|
|
|
```bash
|
|
|
ros2 pkg create --build-type ament_cmake --node-name lab2_node lab2
|
|
|
cd ~/TDDE05/ros2_ws/src/labs
|
|
|
ros2 pkg create --build-type ament_python --node-name lab2_node lab2
|
|
|
```
|
|
|
|
|
|
To create a python package with a default node:
|
|
|
To create a C++ package with a default node:
|
|
|
|
|
|
```bash
|
|
|
ros2 pkg create --build-type ament_python --node-name lab2_node lab2
|
|
|
cd ~/TDDE05/ros2_ws/src/labs
|
|
|
ros2 pkg create --build-type ament_cmake --node-name lab2_node lab2
|
|
|
```
|
|
|
|
|
|
You should go to the top directory in your environment and run the build command:
|
... | ... | @@ -46,6 +58,11 @@ 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:
|
|
|
|
|
|
```bash
|
|
|
tdde05-build
|
|
|
```
|
|
|
|
|
|
Then you need to source the environment with:
|
|
|
|
... | ... | @@ -56,7 +73,7 @@ source install/local_setup.bash |
|
|
or run:
|
|
|
|
|
|
```bash
|
|
|
tdde05_setup
|
|
|
start-tdde05
|
|
|
```
|
|
|
|
|
|
You can then run your node with the following command:
|
... | ... | @@ -65,4 +82,47 @@ You can then run your node with the following command: |
|
|
ros2 run lab2 lab2_node
|
|
|
```
|
|
|
|
|
|
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}}}" |
|
|
\ No newline at end of file |
|
|
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```.
|
|
|
|
|
|
### Python
|
|
|
|
|
|
This can be done in python with the following:
|
|
|
|
|
|
```python
|
|
|
# Import the robot communication library python module
|
|
|
import rclpy
|
|
|
|
|
|
# Import message used for velocity control
|
|
|
import geometry_msgs.msg
|
|
|
|
|
|
# Initialise rclpy
|
|
|
rclpy.init(args=sys.argv)
|
|
|
|
|
|
# Create a ROS Node
|
|
|
node = rclpy.create_node('lab2')
|
|
|
|
|
|
# Create a publisher
|
|
|
publisher = node.create_publisher(geometry_msgs.msg.Twist, topic, 10)
|
|
|
|
|
|
# Create a message to publish
|
|
|
twist = geometry_msgs.msg.Twist()
|
|
|
twist.... # Check the
|
|
|
|
|
|
```
|
|
|
|
|
|
The documentation for ```geometry_msgs/Twist``` can be found online at [https://docs.ros2.org/galactic/api/geometry_msgs/msg/Twist.html](geometry_msgs/Twist) or by running ```ros2 msg info geometry_msgs/Twist```.
|
|
|
|
|
|
|
|
|
### C+++
|
|
|
|
|
|
|
|
|
Starting an action
|
|
|
------------------
|
|
|
|
|
|
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}}}"
|
|
|
|
|
|
|
|
|
|