Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _docs/tutorials/advanced/nuttx/6lowpan/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The last step is to connect a mini-USB cable to the OTG2 USB port (this USB port

To create and flash the firmware, we are going to use the micro-ROS build system.
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).
For this particular guide, it is necessary yo use the branch `dashing` and the configuration profile `uros_6lowpan`.
For this particular guide, it is necessary to use the branch `dashing` and the configuration profile `uros_6lowpan`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this branch be renamed or copied to include 'Foxy'?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello Ralph, we have been talking about how to manage the two different version dashing and foxy. Francesca has been testing both in order to ensure that everything works following the tutorial step by step, and I think that she has another branch with changes to dashing.

So, what do you think about merging this tutorial in order to have the complete Foxy release (code + tutorials), and then we can work in integrating these Dashing tutorials tested by Francesca with some kind of "selector" where the user can switch between foxy and dashing version.

In a first review there are slightly differences between both: just the URL to code, some docker image names and these kind of things.

What do you think @FranFin @jamoralp?

PD: We have found some critical issues when using Dashing in 20.04 and Foxy in 18.04 because Ubuntu repos have updated Clang-tidy and GCC by some major version steps. So maybe I suggest that we should encourage the user to use the Ubuntu version according the ROS 2 version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very good work. Thank you for updating the whole tutorials to thoroughly. I also appreciate the renaming of the common section files. I've marked few typos only. We might consider merging the Zephyr emulator tutorial with the core/first_application_rtos/zephyr/ tutorial, just to reduce the number of tutorial. Yet, this should be discussed first and may be performed in a separate PR then.

I'd also leave this Zephyr/Zephyr emulator issue for the future. Let's discuss it in the first OFERA meeting and, if we deem it worth the change, we create a separate PR.


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

Expand Down
170 changes: 45 additions & 125 deletions _docs/tutorials/advanced/zephyr_emulator/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,51 @@ title: Zephyr Emulator
permalink: /docs/tutorials/advanced/zephyr_emulator/
---

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)).
## Target platform

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.
Another requirement is that the user has a basic knowledge of micro-ROS and ROS 2.
In this tutorial, you'll learn the use of micro-ROS with a **[Zephyr RTOS](https://www.zephyrproject.org/)**
emulator (also known as [Native POSIX](https://docs.zephyrproject.org/latest/boards/posix/native_posix/doc/index.html))
by testing a Ping Pong application.

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

## Required hardware

This tutorial requires no hardware beyond a Linux host computer.

## Building a Zephyr emulator application

Once the micro-ROS build system is ready, let's create a new Zephyr firmware for the host platform:
{% include first_application_common/build_system.md %}

```bash
# Create firmware step
# Create step
ros2 run micro_ros_setup create_firmware_ws.sh zephyr host
```

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.
{% include first_application_common/zephyr_common.md %}

```bash
# Creating a new app
pushd firmware/zephyr_apps/apps
mkdir host_ping_pong
cd host_ping_pong
mkdir src

touch src/app.c
touch app-colcon.meta
touch CMakeLists.txt
touch prj.conf

popd
```

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).
{% include first_application_common/config.md %}

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:
In this tutorial, we will use a UDP transport that looks for the agent on the port UDP/8888 at localhost, and focus on
the out-of-the-box `ping_pong` application located at `firmware/zephyr_apps/apps/ping_pong`.
To execute this application with the chosen transport, run the configuration command above by specifying the `[APP]`
and `[OPTIONS]` parameters as below:

```bash
# Configure step
ros2 run micro_ros_setup configure_firmware.sh host_ping_pong --transport udp --ip 127.0.0.1 --port 8888
```

You can check the complete content of the `ping_pong` app
[here](https://github.com/micro-ROS/zephyr_apps/tree/foxy/apps/ping_pong).

{% include first_application_common/pingpong_logic.md %}

The contents of the Zephyr app specific files can be found here:
[main.c](https://github.com/micro-ROS/zephyr_apps/blob/foxy/apps/ping_pong/src/main.c),
[app-colcon.meta](https://github.com/micro-ROS/zephyr_apps/blob/foxy/apps/ping_pong/app-colcon.meta),
[CMakeLists.txt](https://github.com/micro-ROS/zephyr_apps/blob/foxy/apps/ping_pong/CMakeLists.txt)
and [host-udp.conf](https://github.com/micro-ROS/zephyr_apps/blob/foxy/apps/ping_pong/host-udp.conf).
A thorough review of these files is illustrative of how to create a micro-ROS app in this RTOS.

## Building the firmware

When the configuring step ends, just build the firmware:

```bash
Expand All @@ -59,117 +56,41 @@ ros2 run micro_ros_setup build_firmware.sh
```

Now you have a Zephyr + micro-ROS app ready to run on your own computer.
Notice that in this case, the steps of flashing the firmware and running the micro-ROS app go together.

## Running the micro-ROS app

The micro-ROS app is ready to connect to a micro-ROS-Agent and start talking with the rest of the ROS 2 world.

First of all, create and build a micro-ROS agent:
{% include first_application_common/agent_creation.md %}

```bash
# Download micro-ROS-Agent packages
ros2 run micro_ros_setup create_agent_ws.sh
## Running the micro-ROS app

# Build micro-ROS-Agent packages, this may take a while.
colcon build
source install/local_setup.bash
```
At this point, you have both the client and the agent correctly installed in your host machine.

Then run the agent:
To give micro-ROS access to the ROS 2 dataspace, run the agent:

```bash
# Run a micro-ROS agent
ros2 run micro_ros_agent micro_ros_agent udp4 --port 8888
```

And run the Zephyr app in another command line (remember sourcing ROS 2 and micro-ROS installation):
## Flashing the firmware

Finally, in order to run the micro-ROS node inside of the Zephyr RTOS emulator,
open a new command shell and execute the flash step by means of the flashing command:

```bash
source /opt/ros/$ROS_DISTRO/setup.bash
source microros_ws/install/local_setup.bash
source /opt/ros/foxy/setup.bash
source install/local_setup.bash

# Flash/run step
ros2 run micro_ros_setup flash_firmware.sh
```

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:

```bash
source /opt/ros/$ROS_DISTRO/setup.bash

# Subscribe to micro-ROS ping topic
ros2 topic echo /microROS/ping
```

You should see the topic messages published by the Ping Pong node every 5 seconds:

```
user@user:~$ ros2 topic echo /microROS/ping
stamp:
sec: 20
nanosec: 867000000
frame_id: '1344887256_1085377743'
---
stamp:
sec: 25
nanosec: 942000000
frame_id: '730417256_1085377743'
---
```

On another command line, let's subscribe to the pong topic

```bash
source /opt/ros/$ROS_DISTRO/setup.bash

# Subscribe to micro-ROS pong topic
ros2 topic echo /microROS/pong
```

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:

```bash
source /opt/ros/$ROS_DISTRO/setup.bash

# Send a fake ping
ros2 topic pub --once /microROS/ping std_msgs/msg/Header '{frame_id: "fake_ping"}'
```

Now, we should see on the ping subscriber our fake ping along with the board pings:

```
user@user:~$ ros2 topic echo /microROS/ping
stamp:
sec: 0
nanosec: 0
frame_id: fake_ping
---
stamp:
sec: 305
nanosec: 973000000
frame_id: '451230256_1085377743'
---
stamp:
sec: 310
nanosec: 957000000
frame_id: '2084670932_1085377743'
---
```

And in the pong subscriber, we should see the board's answer to our fake ping:

```
pgarrido@pgarrido:~$ ros2 topic echo /microROS/pong
stamp:
sec: 0
nanosec: 0
frame_id: fake_ping
---
```
{% include first_application_common/test_app_host.md %}

## Multiple Ping Pong nodes

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

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

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