RZ/V2H ROS2

RZ/V2H ROS2

The RZ/V2H ROS2 Support Package provides the ROS2 installation procedure for RZ/V2H:

RZ/V2H ROS2 Support Package


Note: You can choose to install Yocto Native or Docker container environment.

Case1: ROS2 Core (Yocto Native) / Galactic
Case2: ROS2 Core (Docker container) / Humble



RZ/V2H ROS2 SDK

(Case1: ROS2 / Galactic)

The ROS2 SDK gets prepared with the BSP in yocto and contains all libraries that are available on the device.
If a library is missing in the SDK, that library needs to be added to the BSP and SDK in yocto.

The ROS2 sample application from Renesas gets x-compiled in yocto as well.



To x-compile an application without yocto the stand-alone SDK needs be patched.

Patch instructions:

prepare_ROS2_SDK.bash
#!/bin/bash #-# install SDK #-# path used to install the SDK: export ROS2_SDK_PATH="/opt/poky/3.1.26_RZV2H_ROS2" #-# yocto build directory path (the SDK ROS2 libraries refer to that path) export ROS2_BSP_YOCTO_BUILD_PATH="/home/stefan/rzg_ubuntu-20.04/rzv2h_EVK_v3.0.0_ROS2/build/tmp" export ROS2_SDK_PATH2=${ROS2_SDK_PATH//\//\\/} export ROS2_BSP_YOCTO_BUILD_PATH2=${ROS2_BSP_YOCTO_BUILD_PATH//\//\\/} sudo rm -rf ${ROS2_SDK_PATH} ./poky-glibc-x86_64-core-image-weston-aarch64-rzv2h-evk-ver1-toolchain-3.1.26.sh #-# choose directory: ${ROS2_SDK_PATH} #-# patch SDK for ROS2 #-# Note: Modify the "SDK build path" used for "INTERFACE_LINK_LIBRARIES" to the new path of poky's sysroots. sed -i "s/\/opt\/poky\/3.1.31/$ROS2_SDK_PATH2/g"                     patch_sdk.py sed -i "s/~\/ws\/ros2-install\/build\/tmp/$ROS2_BSP_YOCTO_BUILD_PATH2/g" patch_sdk.py sudo python3 patch_sdk.py #-# target[/opt/poky/3.1.26_RZV2H_ROS2/sysroots/aarch64-poky-linux/usr/share/fastrtps/cmake/fastrtps-dynamic-targets.cmake] #-# target[/opt/poky/3.1.26_RZV2H_ROS2/sysroots/aarch64-poky-linux/usr/share/cartographer/cmake/CartographerTargets.cmake] #-# target[/opt/poky/3.1.26_RZV2H_ROS2/sysroots/aarch64-poky-linux/usr/share/geometric_shapes/cmake/export_geometric_shapesExport.cmake] #-# target[/opt/poky/3.1.26_RZV2H_ROS2/sysroots/aarch64-poky-linux/usr/share/rcl_yaml_param_parser/cmake/rcl_yaml_param_parserExport.cmake] #-# target[/opt/poky/3.1.26_RZV2H_ROS2/sysroots/aarch64-poky-linux/usr/share/v4l2_camera/cmake/export_v4l2_cameraExport.cmake] #-# target[/opt/poky/3.1.26_RZV2H_ROS2/sysroots/aarch64-poky-linux/usr/share/rcl_logging_log4cxx/cmake/rcl_logging_log4cxxExport.cmake] #-# target[/opt/poky/3.1.26_RZV2H_ROS2/sysroots/aarch64-poky-linux/usr/lib/BehaviorTreeV3/cmake/BehaviorTreeV3Config.cmake] #-# target[/opt/poky/3.1.26_RZV2H_ROS2/sysroots/aarch64-poky-linux/usr/lib64/cmake/benchmark/benchmarkTargets.cmake] #-# target[/opt/poky/3.1.26_RZV2H_ROS2/sysroots/aarch64-poky-linux/usr/lib64/cmake/opencv4/OpenCVModules.cmake] #-# target[/opt/poky/3.1.26_RZV2H_ROS2/sysroots/aarch64-poky-linux/usr/lib64/cmake/realsense2/realsense2Targets.cmake] #-# target[/opt/poky/3.1.26_RZV2H_ROS2/sysroots/aarch64-poky-linux/usr/lib64/urdfdom/cmake/urdfdomExport.cmake] ### It may be that the patch script does not modify all files required. ### If you execute the following command and find some files, please correct the INTERFACE_LINK_LIBRARIES paths of all files manually. ### sudo find ${ROS2_SDK_PATH}/ -name "*Export.cmake" | xargs grep -l "build/tmp" | grep INTERFACE_LINK_LIBRARIES #-# => no result #-#   => All files of the current SDK have been patched with the patch_sdk.py script.



Patch script (patch_sdk.py):

patch_sdk.py
import glob import os import sys sdk_path="/opt/poky/3.1.31/sysroots/aarch64-poky-linux" tgt_path=sdk_path #tgt_path="dbg" keyword="INTERFACE_LINK_LIBRARIES" keyword2="~/ws/ros2-install/build/tmp" def search_target(): tgt_files = [] #for file_name in glob.glob(tgt_path + "/**/*Export.cmake", recursive=True): for file_name in glob.glob(tgt_path + "/**/*.cmake", recursive=True): flg = 0 try: file = open(file_name) lines = file.readlines() for line in lines: if (keyword in line): if (keyword2 in line): flg = 1 except Exception as e: print(e) finally: file.close() if flg == 1: tgt_files.append(file_name) return tgt_files def update_target(file_name, shadow): sw_name = shadow wfile = open(sw_name, 'w') try: file = open(file_name) lines = file.readlines() line_idx = 1 for line in lines: line_idx = line_idx + 1 flg = 0 k1 = keyword in line k2 = keyword2 in line if (k1 and k2): line = line.strip() words = line.split(" ") widx = 0 for word in words: word = word.strip() word = word.strip('"') #print("word:",widx, "[" + word + "]") widx = widx + 1 newwords = [] if (keyword2 in word): tokens = word.split(";") tidx = 0 newtokens = [] for token in tokens: #print("token:",tidx, "[" + token + "]") tidx = tidx + 1 if (keyword2 in token): bn = os.path.basename(token) dn = os.path.dirname(token) d1 = os.path.basename(dn) dn1 = os.path.dirname(dn) d2 = os.path.basename(dn1) token = sdk_path + "/" + d2+ "/" + d1 + "/" + bn newtokens.append(token) word = "" index = 0 for nw in newtokens: if index != 0: word = word + ";" + nw else: word = nw index = index + 1 word = '"' + word + '"' #print(word) #newwords.append(word) print(" INTERFACE_LINK_LIBRARIES " + word, file=wfile) #print(" INTERFACE_LINK_LIBRARIES " + word) else: print(line, file=wfile, end="") except Exception as e: print(e) finally: file.close() wfile.close() def swap_file(file_name, shadow): bkup = file_name + ".backup" os.rename(file_name, bkup) os.rename(shadow, file_name) target = search_target() for file_name in target: print("target["+file_name+"]") shadow = file_name + ".shadow" update_target(file_name, shadow) swap_file(file_name, shadow)



example "Hello World ROS2"

(Case1: ROS2 / Galactic)

Simple "Hello World" publisher:

HelloWorld_ROS2.tar.gz



1. cross-compile the "Hello World" example with the following script:
#!/bin/bash #-# path used to install the SDK: export ROS2_SDK_PATH="/opt/poky/3.1.26_RZV2H_ROS2" export ROS2_SDK_PATH2=${ROS2_SDK_PATH//\//\\/} ### ####### cross-compilation on a Linux PC pip install -U colcon-common-extensions #-# start SDK with unset LD_LIBRARY_PATH source ${ROS2_SDK_PATH}/environment-setup-aarch64-poky-linux export PYTHONPATH="${ROS2_SDK_PATH}/sysroots/x86_64-pokysdk-linux/usr/lib/python3.8/site-packages" export PYTHONPATH="${PYTHONPATH}:${ROS2_SDK_PATH}/sysroots/aarch64-poky-linux/usr/lib64/python3.8/site-packages" export CMAKE_PREFIX_PATH="${ROS2_SDK_PATH}/sysroots/x86_64-pokysdk-linux/usr" export CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}:${ROS2_SDK_PATH}/sysroots/x86_64-pokysdk-linux/usr/lib" export CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}:${ROS2_SDK_PATH}/sysroots/x86_64-pokysdk-linux/usr/lib/cmake" export CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}:${ROS2_SDK_PATH}/sysroots/aarch64-poky-linux/usr" export CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}:${ROS2_SDK_PATH}/sysroots/aarch64-poky-linux/usr/lib64" export CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}:${ROS2_SDK_PATH}/sysroots/aarch64-poky-linux/usr/lib64/cmake" export CMAKE_PREFIX_PATH="${CMAKE_PREFIX_PATH}:${ROS2_SDK_PATH}/sysroots/aarch64-poky-linux/usr/share" export AMENT_PREFIX_PATH="${ROS2_SDK_PATH}/sysroots/aarch64-poky-linux/usr" export AMENT_PREFIX_PATH="${AMENT_PREFIX_PATH}:${ROS2_SDK_PATH}/sysroots/aarch64-poky-linux/usr/lib64" export AMENT_PREFIX_PATH="${AMENT_PREFIX_PATH}:${ROS2_SDK_PATH}/sysroots/aarch64-poky-linux/usr/lib64/cmake" PKGARGS="" if [ $# == 1 ] ; then PKGARGS="--packages-select $1" echo $PKGARGS fi #-# ## cd ros2_ws cp -f cross.cmake.tmp cross.cmake sed -i "s/\/opt\/poky\/3.1.31/$ROS2_SDK_PATH2/g" cross.cmake colcon build --merge-install \ --cmake-force-configure \ --cmake-args \ -DCMAKE_TOOLCHAIN_FILE=${PWD}/cross.cmake \ -DCMAKE_MAKE_PROGRAM=/usr/bin/make \ -DENABLE_PRECOMPILED_HEADERS=OFF \ $PKGARGS
2. copy the generated directory "install" to the RZ/V2H EVK:
rsh root@<IP_address_of_RZV2H_EVK> "mkdir -p /home/root/ros2_ws" scp -r install <IP_address_of_RZV2H_EVK>:/home/root/ros2_ws
3. Run the publisher on RZ/V2H EVK:
# login to RZ/V2H EVK and start the following commands: source /etc/profile.d/ros/setup.bash source ~/ros2_ws/install/setup.bash #Start application ros2 run hello_world_publisher publisher_node