The meta-ros layer delivers support for ROS. Additionally, meta-ost-ros provides ost-ros-image to build an image adding ROS Core to ost-image.
Building Images
ROS requires the meta-ost-ros layer that is part of meta-ost.
Follow the Setup and Building guide to set up the build environment. Fetch ROS specific repositories:
meta-ros, github.com/ros/meta-ros.git, branch scarthgap
Next, add the following layers to bblayers.conf
BBLAYERS ?= " \
...
/home/ubuntu/yocto/meta-openembedded/meta-python \
/home/ubuntu/yocto/meta-ost/meta-ost-ros \
/home/ubuntu/yocto/meta-ros/meta-ros-common \
/home/ubuntu/yocto/meta-ros/meta-ros2 \
/home/ubuntu/yocto/meta-ros/meta-ros2-jazzy \
"
Now, build the image with
$ bitbake ost-image
Restrictions for ROS
Some ROS packages fail to compile when building for a 32 bit target on a 64 bit machine, see
https://github.com/ros/meta-ros/issues/1205. Patch meta-ros2/classes/ros_ament_cmake.bbclass manually according to this issue.
A Note about rosdep
rosdep manages ROS dependencies by mapping ROS packages names to the name of their corresponding native package name (e.g. apt packages for ubuntu). This means that while cross compiling ROS2 nodes is fairly straight forward , its dependencies won't be, and ROS(2) must still be present on the host system.
Even compiling ROS2 from source seems to rely on this mechanism to some extent, meaning that even cross compiling all of ROS2 to work within a yocto image is not feasible, or at least not trivial.