Skip to content

Commit 0b74937

Browse files
FranFinpablogs9ralph-lange
authored
Feature/foxy revision (#187)
* 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>
1 parent 994ee9e commit 0b74937

26 files changed

Lines changed: 661 additions & 737 deletions

File tree

_docs/tutorials/advanced/nuttx/6lowpan/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ The last step is to connect a mini-USB cable to the OTG2 USB port (this USB port
5454

5555
To create and flash the firmware, we are going to use the micro-ROS build system.
5656
You can find the instructions at the micro-ros-build's [README](https://github.com/micro-ROS/micro-ros-build/blob/dashing/micro_ros_setup/README.md).
57-
For this particular guide, it is necessary yo use the branch `dashing` and the configuration profile `uros_6lowpan`.
57+
For this particular guide, it is necessary to use the branch `dashing` and the configuration profile `uros_6lowpan`.
5858

5959
Once you follow all the instructions in the build system and flash the board, everything is ready.
6060

_docs/tutorials/advanced/zephyr_emulator/index.md

Lines changed: 45 additions & 125 deletions
Original file line numberDiff line numberDiff line change
@@ -3,54 +3,51 @@ title: Zephyr Emulator
33
permalink: /docs/tutorials/advanced/zephyr_emulator/
44
---
55

6-
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
77

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))
10+
by testing a Ping Pong application.
1011

1112
<div>
1213
<img width="300" style="padding-right: 25px;" src="imgs/4.jpg">
1314
</div>
1415

15-
## Required hardware
16-
17-
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 %}
2217

2318
```bash
24-
# Create firmware step
19+
# Create step
2520
ros2 run micro_ros_setup create_firmware_ws.sh zephyr host
2621
```
2722

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 %}
2924

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 %}
4626

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]`
30+
and `[OPTIONS]` parameters as below:
4831

4932
```bash
5033
# Configure step
5134
ros2 run micro_ros_setup configure_firmware.sh host_ping_pong --transport udp --ip 127.0.0.1 --port 8888
5235
```
5336

37+
You can check the complete content of the `ping_pong` app
38+
[here](https://github.com/micro-ROS/zephyr_apps/tree/foxy/apps/ping_pong).
39+
40+
{% include first_application_common/pingpong_logic.md %}
41+
42+
The contents of the Zephyr app specific files can be found here:
43+
[main.c](https://github.com/micro-ROS/zephyr_apps/blob/foxy/apps/ping_pong/src/main.c),
44+
[app-colcon.meta](https://github.com/micro-ROS/zephyr_apps/blob/foxy/apps/ping_pong/app-colcon.meta),
45+
[CMakeLists.txt](https://github.com/micro-ROS/zephyr_apps/blob/foxy/apps/ping_pong/CMakeLists.txt)
46+
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+
5451
When the configuring step ends, just build the firmware:
5552

5653
```bash
@@ -59,117 +56,41 @@ ros2 run micro_ros_setup build_firmware.sh
5956
```
6057

6158
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.
6260

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 %}
6862

69-
```bash
70-
# Download micro-ROS-Agent packages
71-
ros2 run micro_ros_setup create_agent_ws.sh
63+
## Running the micro-ROS app
7264

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.
7766

78-
Then run the agent:
67+
To give micro-ROS access to the ROS 2 dataspace, run the agent:
7968

8069
```bash
8170
# Run a micro-ROS agent
8271
ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888
8372
```
8473

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:
8678

8779
```bash
88-
source /opt/ros/$ROS_DISTRO/setup.bash
89-
source microros_ws/install/local_setup.bash
80+
source /opt/ros/foxy/setup.bash
81+
source install/local_setup.bash
9082

9183
# Flash/run step
9284
ros2 run micro_ros_setup flash_firmware.sh
9385
```
9486

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:
130-
131-
```bash
132-
source /opt/ros/$ROS_DISTRO/setup.bash
133-
134-
# Send a fake ping
135-
ros2 topic pub --once /microROS/ping std_msgs/msg/Header '{frame_id: "fake_ping"}'
136-
```
137-
138-
Now, we should see on the ping subscriber our fake ping along with the board pings:
139-
140-
```
141-
user@user:~$ ros2 topic echo /microROS/ping
142-
stamp:
143-
sec: 0
144-
nanosec: 0
145-
frame_id: fake_ping
146-
---
147-
stamp:
148-
sec: 305
149-
nanosec: 973000000
150-
frame_id: '451230256_1085377743'
151-
---
152-
stamp:
153-
sec: 310
154-
nanosec: 957000000
155-
frame_id: '2084670932_1085377743'
156-
---
157-
```
158-
159-
And in the pong subscriber, we should see the board's answer to our fake ping:
160-
161-
```
162-
pgarrido@pgarrido:~$ ros2 topic echo /microROS/pong
163-
stamp:
164-
sec: 0
165-
nanosec: 0
166-
frame_id: fake_ping
167-
---
168-
```
87+
{% include first_application_common/test_app_host.md %}
16988

17089
## Multiple Ping Pong nodes
17190

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:
17394

17495
```bash
17596
cd microros_ws
@@ -181,13 +102,12 @@ cd microros_ws
181102
As soon as all micro-ROS node are up and connected to the micro-ROS agent you will see them interacting:
182103

183104
```
184-
pgarrido@pgarrido$ ./firmware/build/zephyr/zephyr.exe
105+
user@user:~$ ./firmware/build/zephyr/zephyr.exe
185106
*** Booting Zephyr OS build zephyr-v2.2.0-492-gc73cb85b4ae9 ***
186-
UDP mode => ip: 127.0.0.1 - port: 8888
187107
Ping send seq 1711620172_1742614911 <---- This micro-ROS node sends a ping with ping ID "1711620172" and node ID "1742614911"
188-
Pong for seq 1711620172_1742614911 (1) <---- The first mate pongs my ping
189-
Pong for seq 1711620172_1742614911 (2) <---- The second mate pongs my ping
190-
Pong for seq 1711620172_1742614911 (3) <---- The third mate pongs my ping
108+
Pong for seq 1711620172_1742614911 (1) <---- The first mate pongs my ping
109+
Pong for seq 1711620172_1742614911 (2) <---- The second mate pongs my ping
110+
Pong for seq 1711620172_1742614911 (3) <---- The third mate pongs my ping
191111
Ping received with seq 1845948271_546591567. Answering. <---- A ping is received from a mate identified as "546591567", let's pong it.
192112
Ping received with seq 232977719_1681483056. Answering. <---- A ping is received from a mate identified as "1681483056", let's pong it.
193113
Ping received with seq 1134264528_1107823050. Answering. <---- A ping is received from a mate identified as "1107823050", let's pong it.

0 commit comments

Comments
 (0)