Get started on FreeRTOS POSIX
Needs first: Install
Status: Verified on host (daily). From the board support registry:
nros-board-freertos-posix; Board Support Levels explains the words.
This starter puts a talker on the FreeRTOS kernel running as an ordinary program on your Linux machine, and shows its messages arriving in ROS 2. FreeRTOS’s POSIX port runs the kernel’s tasks as threads of one host process, and the talker uses your host’s own sockets, so there is no emulator and no network to set up. It is the quickest way to see a FreeRTOS application talk to ROS 2. You write the talker in Rust, C or C++; pick a tab and every tab on the page follows.
The talker uses Cyclone DDS, which runs inside the talker’s own process and finds its peers on the network the way any ROS 2 node does, so there is no router to start. The board runs zenoh too, through a router on this machine: Zenoh on this board shows how.
What you need
- A Linux host with the install done, so
nrosis on yourPATH, and the C toolchain and CMake the install’s host packages bring. - ROS 2 (Humble on Ubuntu 22.04, Jazzy on 24.04;
which edition), with its Cyclone
DDS middleware, so that
ros2 topic echocan read what the talker publishes. The build also generates the talker’s message code from ROS 2’s message definitions. Both installs on the Install page include Cyclone DDS; for any other ROS 2 install, add it on Debian or Ubuntu:
sudo apt-get install -y ros-humble-rmw-cyclonedds-cpp
Nothing else: no board, no cable, and nothing to keep running beside the talker.
Provision
nros setup freertos-posix --rmw cyclonedds
That fetches the FreeRTOS kernel sources, with its POSIX port, and what
Cyclone DDS needs, into a shared store under ~/.nros. Nothing is installed
system-wide. There is no cross-compiler to fetch: the simulator builds with
your host’s compilers.
Scaffold the project
Source ROS 2 first, in the shell you scaffold from. nros new writes
the ROS 2 edition the project speaks, and it takes it from the sourced
ROS 2; with none sourced, it writes Humble. On Jazzy, source
/opt/ros/jazzy/setup.bash instead:
source /opt/ros/humble/setup.bash
nros new fp_ws --board freertos-posix --template talker --lang rust --rmw cyclonedds
cd fp_ws
nros new fp_ws --board freertos-posix --template talker --lang c --rmw cyclonedds
cd fp_ws
nros new fp_ws --board freertos-posix --template talker --lang cpp --rmw cyclonedds
cd fp_ws
That wrote a workspace with two packages:
fp_ws/
└── src/
├── fp_node/ # the talker: manifest, build file, source
└── fp_node_bringup/ # what it runs on: board, RMW
fp_node is the talker, a library with no main() that names no board. It
publishes std_msgs/String on /chatter once a second. fp_node_bringup
says what the talker runs on: its system.toml holds one image,
[image.freertos], with board = "freertos-posix", and names Cyclone DDS as
the RMW. The FreeRTOS startup task that runs your node is generated from it
when you build.
Run it on this machine
Build and run from the same shell, where ROS 2 is sourced. This first run records the ROS 2 prefix in the workspace, so later runs of it need no sourced shell:
nros run fp_node
nros run builds the talker with CMake (the first build compiles the FreeRTOS
kernel, Cyclone DDS and nano-ros, a few minutes; later builds take seconds)
and runs it. It keeps running until you press Ctrl-C. It prints:
Publishing: 'Hello World: 1'
Publishing: 'Hello World: 2'
See it in ROS 2
Leave nros run going. In a second terminal, ask ROS 2 for the topic over
Cyclone DDS:
source /opt/ros/humble/setup.bash
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
ros2 topic echo /chatter std_msgs/msg/String --qos-reliability best_effort
data: 'Hello World: …'
Both sides use domain 0, the ROS 2 default, so they find each other with no configuration. Asking for best-effort receives from a best-effort or a reliable publisher alike.
Zenoh on this board
To talk over zenoh instead, the talker dials a zenoh router on this machine,
at tcp/127.0.0.1:7447. ROS 2’s zenoh middleware brings the router
nros run starts. Install
added it; the first line below is there for a host that skipped it. Then
provision the board for zenoh:
sudo apt-get install -y ros-humble-rmw-zenoh-cpp
nros setup freertos-posix
Scaffold a second workspace beside the first, this time naming zenoh:
cd ..
nros new fpz_ws --board freertos-posix --template talker --lang rust --rmw zenoh
cd fpz_ws
cd ..
nros new fpz_ws --board freertos-posix --template talker --lang c --rmw zenoh
cd fpz_ws
cd ..
nros new fpz_ws --board freertos-posix --template talker --lang cpp --rmw zenoh
cd fpz_ws
Build and run the talker. nros run starts a zenoh router on
tcp/127.0.0.1:7447 for the run and stops it after, so there is nothing to
start beside it:
source /opt/ros/humble/setup.bash
nros run fpz_node
Publishing: 'Hello World: 1'
Publishing: 'Hello World: 2'
Leave it going. In a second terminal:
source /opt/ros/humble/setup.bash
export RMW_IMPLEMENTATION=rmw_zenoh_cpp
ros2 topic echo /chatter std_msgs/msg/String --qos-reliability best_effort
data: 'Hello World: …'
If it doesn’t work
nros runstops at once and namesAMENT_PREFIX_PATH: this shell has not sourced ROS 2, and no earlier build of the workspace recorded it. Source it and run again.nros runsays the router exited: another zenoh router already holds port 7447 on this machine. Stop it;nros runstarts its own.ros2 topic echoprints nothing: check theRMW_IMPLEMENTATIONline, and that neither shell sets aROS_DOMAIN_IDother than 0. A firewall that drops multicast also stops DDS discovery.- Everything else: Troubleshooting - First 10 Minutes.
Next
- The image’s configuration, and moving it to the emulated board: FreeRTOS POSIX.
- The same talker on an emulated Cortex-M3: mps2-an385 in QEMU (FreeRTOS).
- The project, grown: the Tutorial.