You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* First micro-ROS app on Linux reviewed.
* Reworking tutorials common sections.
* Significant changes in core tutori+zephyr_emulator tutorials.
* Changes reviewed.
* First micro-ROS app tutorials migrated to foxy.
* Comments addressed.
* Update _docs/tutorials/advanced/zephyr_emulator/index.md
Co-authored-by: Ralph Lange <ralph-lange@users.noreply.github.com>
* Update _docs/tutorials/core/first_application_rtos/zephyr.md
Co-authored-by: Ralph Lange <ralph-lange@users.noreply.github.com>
Co-authored-by: Pablo Garrido <pablogs9@gmail.com>
Co-authored-by: Ralph Lange <ralph-lange@users.noreply.github.com>
This tutorial aims at creating a new micro-ROS application on with **[Zephyr RTOS](https://www.zephyrproject.org/)** emulator (also known as [Native POSIX](https://docs.zephyrproject.org/latest/boards/posix/native_posix/doc/index.html)).
6
+
## Target platform
7
7
8
-
To follow this tutorial, it is assumed that the user is already familiar with the **[First micro-ROS Application on an RTOS](https://micro-ros.github.io/docs/tutorials/core/first_application_rtos/)** tutorial. The target app in this tutorial is the same ping pong app.
9
-
Another requirement is that the user has a basic knowledge of micro-ROS and ROS 2.
8
+
In this tutorial, you'll learn the use of micro-ROS with a **[Zephyr RTOS](https://www.zephyrproject.org/)**
9
+
emulator (also known as [Native POSIX](https://docs.zephyrproject.org/latest/boards/posix/native_posix/doc/index.html))
This tutorial requires no hardware beyond a Linux host computer.
18
-
19
-
## Building a Zephyr emulator application
20
-
21
-
Once the micro-ROS build system is ready, let's create a new Zephyr firmware for the host platform:
16
+
{% include first_application_common/build_system.md %}
22
17
23
18
```bash
24
-
# Create firmware step
19
+
# Create step
25
20
ros2 run micro_ros_setup create_firmware_ws.sh zephyr host
26
21
```
27
22
28
-
micro-ROS apps for Zephyr emulator are located at `firmware/zephyr_apps/apps`. In order to create a new application, create a new folder containing two files: the app code (inside a `src` folder) and the RMW configuration. You will also need some other Zephyr related files: a `CMakeLists.txt` to define the building process and a `prj.conf` where Zephyr is configured. There is a sample proyect [here](https://github.com/micro-ROS/zephyr_apps/tree/dashing/apps/host_ping_pong), for now, it is ok to copy them.
23
+
{% include first_application_common/zephyr_common.md %}
29
24
30
-
```bash
31
-
# Creating a new app
32
-
pushd firmware/zephyr_apps/apps
33
-
mkdir host_ping_pong
34
-
cd host_ping_pong
35
-
mkdir src
36
-
37
-
touch src/app.c
38
-
touch app-colcon.meta
39
-
touch CMakeLists.txt
40
-
touch prj.conf
41
-
42
-
popd
43
-
```
44
-
45
-
The contents of the files can be found here: [app.c](https://github.com/micro-ROS/zephyr_apps/blob/dashing/apps/host_ping_pong/src/main.c), [app-colcon.meta](https://github.com/micro-ROS/zephyr_apps/blob/dashing/apps/host_ping_pong/app-colcon.meta), [CMakeLists.txt](https://github.com/micro-ROS/zephyr_apps/blob/dashing/apps/host_ping_pong/CMakeLists.txt) and [prj.conf](https://github.com/micro-ROS/zephyr_apps/blob/dashing/apps/host_ping_pong/prj.conf).
25
+
{% include first_application_common/config.md %}
46
26
47
-
Once the app folder is created, let's configure our new app with a UDP transport that looks for the agent on the port UDP/8888 at localhost:
27
+
In this tutorial, we will use a UDP transport that looks for the agent on the port UDP/8888 at localhost, and focus on
28
+
the out-of-the-box `ping_pong` application located at `firmware/zephyr_apps/apps/ping_pong`.
29
+
To execute this application with the chosen transport, run the configuration command above by specifying the `[APP]`
and [host-udp.conf](https://github.com/micro-ROS/zephyr_apps/blob/foxy/apps/ping_pong/host-udp.conf).
47
+
A thorough review of these files is illustrative of how to create a micro-ROS app in this RTOS.
48
+
49
+
## Building the firmware
50
+
54
51
When the configuring step ends, just build the firmware:
55
52
56
53
```bash
@@ -59,117 +56,41 @@ ros2 run micro_ros_setup build_firmware.sh
59
56
```
60
57
61
58
Now you have a Zephyr + micro-ROS app ready to run on your own computer.
59
+
Notice that in this case, the steps of flashing the firmware and running the micro-ROS app go together.
62
60
63
-
## Running the micro-ROS app
64
-
65
-
The micro-ROS app is ready to connect to a micro-ROS-Agent and start talking with the rest of the ROS 2 world.
66
-
67
-
First of all, create and build a micro-ROS agent:
61
+
{% include first_application_common/agent_creation.md %}
68
62
69
-
```bash
70
-
# Download micro-ROS-Agent packages
71
-
ros2 run micro_ros_setup create_agent_ws.sh
63
+
## Running the micro-ROS app
72
64
73
-
# Build micro-ROS-Agent packages, this may take a while.
74
-
colcon build
75
-
source install/local_setup.bash
76
-
```
65
+
At this point, you have both the client and the agent correctly installed in your host machine.
77
66
78
-
Then run the agent:
67
+
To give micro-ROS access to the ROS 2 dataspace, run the agent:
79
68
80
69
```bash
81
70
# Run a micro-ROS agent
82
71
ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888
83
72
```
84
73
85
-
And run the Zephyr app in another command line (remember sourcing ROS 2 and micro-ROS installation):
74
+
## Flashing the firmware
75
+
76
+
Finally, in order to run the micro-ROS node inside of the Zephyr RTOS emulator,
77
+
open a new command shell and execute the flash step by means of the flashing command:
86
78
87
79
```bash
88
-
source /opt/ros/$ROS_DISTRO/setup.bash
89
-
sourcemicroros_ws/install/local_setup.bash
80
+
source /opt/ros/foxy/setup.bash
81
+
source install/local_setup.bash
90
82
91
83
# Flash/run step
92
84
ros2 run micro_ros_setup flash_firmware.sh
93
85
```
94
86
95
-
And finally, let's check that everything is working in another command line. We are going to listen to ping topic to check whether the Ping Pong node is publishing its own pings:
96
-
97
-
```bash
98
-
source /opt/ros/$ROS_DISTRO/setup.bash
99
-
100
-
# Subscribe to micro-ROS ping topic
101
-
ros2 topic echo /microROS/ping
102
-
```
103
-
104
-
You should see the topic messages published by the Ping Pong node every 5 seconds:
105
-
106
-
```
107
-
user@user:~$ ros2 topic echo /microROS/ping
108
-
stamp:
109
-
sec: 20
110
-
nanosec: 867000000
111
-
frame_id: '1344887256_1085377743'
112
-
---
113
-
stamp:
114
-
sec: 25
115
-
nanosec: 942000000
116
-
frame_id: '730417256_1085377743'
117
-
---
118
-
```
119
-
120
-
On another command line, let's subscribe to the pong topic
121
-
122
-
```bash
123
-
source /opt/ros/$ROS_DISTRO/setup.bash
124
-
125
-
# Subscribe to micro-ROS pong topic
126
-
ros2 topic echo /microROS/pong
127
-
```
128
-
129
-
At this point, we know that our app is publishing pings. Let's check if it also answers to someone else pings in a new command line:
{% include first_application_common/test_app_host.md %}
169
88
170
89
## Multiple Ping Pong nodes
171
90
172
-
One of the advantages of having an emulator is that you don't need to buy a bunch of hardware in order to test some multi-node micro-ROS apps. So, with the same micro-ROS agent of the last section, let's open four different command lines and run the following on each:
91
+
One of the advantages of having an emulator is that you don't need to buy a bunch of hardware in order to test some
92
+
multi-node micro-ROS apps. So, with the same micro-ROS agent of the last section, let's open four different command
93
+
lines and run the following on each:
173
94
174
95
```bash
175
96
cd microros_ws
@@ -181,13 +102,12 @@ cd microros_ws
181
102
As soon as all micro-ROS node are up and connected to the micro-ROS agent you will see them interacting:
0 commit comments