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
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
+
Once the command is executed, a folder named `firmware` must be present in your workspace.
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
25
+
This step is in charge, among other things, of creating a set of micro-ROS apps for the specific platform you are
26
+
addressing.
27
+
In the case of Zephyr, these are located at `firmware/zephyr_apps/apps`.
28
+
Each app is represented by a folder containing the following files:
36
29
37
-
touch src/app.c
38
-
touch app-colcon.meta
39
-
touch CMakeLists.txt
40
-
touch prj.conf
30
+
*`src/main.c`: This file contains the logic of the application.
31
+
*`app-colcon.meta`: This file contains the micro-ROS app specific colcon configuration. Detailed info on how to
*`CMakeLists.txt`: This is the CMake file containing the script to compile the application.
35
+
*`prj.conf`: This is a Zephyr specific app configuration file.
41
36
42
-
popd
43
-
```
37
+
For the user to create its custom application, a folder `<my_app>` will need to be registered in this location,
38
+
containing the four files just described.
44
39
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).
40
+
{% include first_application_common/config.md %}
46
41
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:
42
+
In this tutorial, we will use a UDP transport that looks for the agent on the port UDP/8888 at localhost, and focus on
43
+
the out-of-the-box `host_ping_pong` application located at `firmware/zephyr_apps/apps/host_ping_pong`.
44
+
To execute this application with the chosen transport, run the configuration command above by specifying the `[APP]`
and [prj.conf](https://github.com/micro-ROS/zephyr_apps/blob/dashing/apps/host_ping_pong/prj.conf).
62
+
A thorough review of these files is illustrative of how to create a micro-ROS app in this RTOS.
63
+
64
+
## Building the firmware
65
+
54
66
When the configuring step ends, just build the firmware:
55
67
56
68
```bash
@@ -59,43 +71,64 @@ ros2 run micro_ros_setup build_firmware.sh
59
71
```
60
72
61
73
Now you have a Zephyr + micro-ROS app ready to run on your own computer.
74
+
Notice that in this case, the steps of flashing the firmware and running the micro-ROS app go together
62
75
63
-
## Running the micro-ROS app
76
+
## Flashing the firmware
64
77
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.
78
+
Now you can run the flash step by means of the flashing command:
66
79
67
-
First of all, create and build a micro-ROS agent:
80
+
```bash
81
+
# Flash/run step
82
+
ros2 run micro_ros_setup flash_firmware.sh
83
+
```
84
+
85
+
Notice that this command also has the effect of running the micro-ROS node.
86
+
87
+
## Creating the micro-ROS agent
88
+
89
+
The micro-ROS app is now ready to be connected to a micro-ROS agent to start talking with the rest of the ROS 2
90
+
world.
91
+
92
+
To do that, let's open a new command line and create a micro-ROS agent
93
+
(remember sourcing the ROS 2 and micro-ROS installations):
68
94
69
95
```bash
70
96
# Download micro-ROS-Agent packages
97
+
source /opt/ros/dashing/setup.bash
98
+
source install/local_setup.bash
99
+
71
100
ros2 run micro_ros_setup create_agent_ws.sh
101
+
```
102
+
103
+
Now, let's build the agent packages and, when this is done, source the installation:
72
104
73
-
# Build micro-ROS-Agent packages, this may take a while.
105
+
```bash
106
+
# Build step
74
107
colcon build
75
108
source install/local_setup.bash
76
109
```
77
110
78
-
Then run the agent:
111
+
## Running the micro-ROS app
112
+
113
+
At this point, you have both the client and the agent correctly installed in your host machine.
114
+
115
+
To start micro-ROS, you just need to run the agent:
79
116
80
117
```bash
81
118
# Run a micro-ROS agent
82
119
ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888
83
120
```
84
121
85
-
And run the Zephyr app in another command line (remember sourcing ROS 2 and micro-ROS installation):
86
-
87
-
```bash
88
-
source /opt/ros/$ROS_DISTRO/setup.bash
89
-
source microros_ws/install/local_setup.bash
122
+
## Testing the micro-ROS app
90
123
91
-
# Flash/run step
92
-
ros2 run micro_ros_setup flash_firmware.sh
93
-
```
124
+
At this point, the micro-ROS app is built and flashed and the board is connected to a micro-ROS agent.
125
+
We now want to check that everything is working.
94
126
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:
127
+
Open a new command line. We are going to listen to the `ping` topic
128
+
with ROS 2 to check whether the micro-ROS Ping Pong node is correctly publishing the expected pings:
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:
226
+
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
227
+
multi-node micro-ROS apps. So, with the same micro-ROS agent of the last section, let's open four different command
0 commit comments