Skip to content

examples/microros_sub: Add minimal Int32 subscriber example.#3521

Merged
lupyuen merged 1 commit into
apache:masterfrom
arjav1528:microros-sub-example
Jun 4, 2026
Merged

examples/microros_sub: Add minimal Int32 subscriber example.#3521
lupyuen merged 1 commit into
apache:masterfrom
arjav1528:microros-sub-example

Conversation

@arjav1528

Copy link
Copy Markdown
Contributor

Summary

Phase 7 of the micro-ROS on NuttX integration. Adds apps/examples/microros_sub,
a minimal Int32 subscriber that mirrors the microros_pub example merged in
#3512 for the receive direction.

The example creates a nuttx_sub_node, subscribes to /nuttx_sub with
std_msgs/msg/Int32, registers a callback via rclc_executor_add_subscription,
and enters rclc_executor_spin. Each received value is printed via NSH. It
exercises the rclc_executor + subscription callback path on top of the
NuttX-native microros_transport library that was wired up in Phase 6.

Depends on:

Impact

  • User: new opt-in EXAMPLES_MICROROS_SUB Kconfig entry under
    Application Configuration > Examples, gated on SYSTEM_MICROROS.
    Default n; existing configs are unaffected.
  • Build: no changes to the libmicroros build pipeline; reuses the existing
    microros_transport library and SYSTEM_MICROROS include layout.
  • Hardware: none. Sim and any board with the existing micro-ROS transport
    enabled (UDP via NuttX sockets or serial via TERMIOS) can run the example.
  • Docs / security / compatibility: none.

Testing

Host: Ubuntu 22.04.5 LTS (jammy), x86_64, Linux 6.8.0-1055-aws,
gcc 11.4.0, AWS EC2 m7i-flex.large (2 vCPU, 7.6 GB RAM).

Target: NuttX sim:nsh on Linux, UDP transport over TAP.

1. checkpatch

$ ./tools/checkpatch.sh -f ../apps/examples/microros_sub/microros_sub_main.c
(clean)

2. Build with pub + sub both enabled

$ tools/configure.sh sim:nsh
$ cat ~/microros_extra_config >> .config
$ make olddefconfig
$ make -j2
...
LD: nuttx
SIM elf with dynamic libs archive in nuttx.tgz

Result: nuttx ELF produced, both microros_pub_main and microros_sub_main
linked.

3. Sub-only build (pub disabled)

Verifies the new example does not regress when the existing publisher example
is turned off and that microros_transport still links cleanly with just the
subscriber as a consumer.

$ kconfig-tweak --disable EXAMPLES_MICROROS_PUB
$ kconfig-tweak --enable  EXAMPLES_MICROROS_SUB
$ make olddefconfig && make -j2
...
LD: nuttx
SIM elf with dynamic libs archive in nuttx.tgz
$ nm nuttx | grep -E 'microros_sub_main|sub_callback'
00000000400a9d89 T microros_sub_main
00000000400a9d30 t sub_callback

4. End-to-end runtime against a micro-ROS agent

Agent (host, separate terminal):

$ docker run -it --rm --network host microros/micro-ros-agent:jazzy \
      udp4 --port 8888
[INFO] [Root.Agent]: Running.

NuttX sim:

nsh> ifconfig
eth0    Link encap:Ethernet HWaddr 42:0a:bc:cd:ef:02 at UP
        inet addr:192.168.10.2 DRaddr:192.168.10.1 Mask:255.255.255.0
nsh> microros_sub &
microros_sub: starting
microros_sub: spinning on /nuttx_sub

Host publishes (in another terminal):

$ ros2 topic pub --once /nuttx_sub std_msgs/msg/Int32 "{data: 42}"
$ for v in 100 200 300 400 500; do
    ros2 topic pub --once /nuttx_sub std_msgs/msg/Int32 "{data: $v}"; done

NuttX sim output:

microros_sub: got 42
microros_sub: got 42
microros_sub: got 42
microros_sub: got 42
microros_sub: got 42
microros_sub: got 42
microros_sub: got 42
microros_sub: got 100
microros_sub: got 200
microros_sub: got 300
microros_sub: got 400
microros_sub: got 500

All values delivered in order to the registered callback via
rclc_executor_spin, confirming the agent → client direction of the
NuttX-native transport plus the rclc_executor subscription path works
end-to-end.

Mirror of microros_pub for the receive direction.  Creates a node,
subscribes to /nuttx_sub with std_msgs/Int32, drives an rclc_executor
spin loop, and prints each received value.  Exercises the new
rclc_executor + subscription callback path on top of the
microros_transport library shipped in apps/system/microros.

Validates the NuttX-native transport in the agent->client direction
end-to-end against a micro-ROS agent + ros2 topic pub on the host.

Signed-off-by: Arjav Patel <arjav1528@gmail.com>
@lupyuen

lupyuen commented Jun 4, 2026

Copy link
Copy Markdown
Member

FYI: I restarted the CI Build to fix the Docker Image

@lupyuen lupyuen merged commit c106a02 into apache:master Jun 4, 2026
61 of 79 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants