Introduction to ROS cross-compilation

What is ROS?

According to Wikipedia, ROS (Robot Operating System, Robot Operating System) is a set of computer operating system architecture designed for robot software development. It is an open source meta-level operating system (post-operating system) that provides services similar to the operating system, including hardware abstract description, underlying driver management, execution of common functions, inter-program message passing, and program distribution package management. Provides tools and libraries for acquiring, building, writing and executing multi-machine fusion programs.

According to my understanding, it is actually a software framework. The core is just to provide a multi-process communication service. However, due to the large number of developers, a lot of function packages have been open sourced to facilitate business development. That’s all, and the operation of linux There is a gap between the systems. ROS runs on linux and belongs to the service category. After a brief understanding of what is ROS, the official website wiki can introduce the installation and use accordingly. There is an introduction to installing from source code, the link is here , but there is no introduction on how to cross-compile, and there are relatively few information on the Internet. Let me explain it below. Let us briefly introduce how to port ROS to an embedded system and how to perform cross-compilation.

What compilation does ROS use?

From the ROS wiki, we can learn that ROS uses catkin to compile, so in order to achieve cross-compilation, we need to first understand what catkin is.

From the catkin wiki , we can learn that catkin relies on tools such as CMake and Python. After tracking down, we can find that catkin is actually a package of CMake. So, let’s transplant catkin first.

And catkin only needs to use CMake to complete the compilation, and catkin is used to build ROS, and the build is cross-compiled on the PC side, so in fact catkin does not need cross-compilation. At the same time, by tracking the implementation of catkin, it is found that it is composed of python scripts, without other binary libraries and executable files, so it is more certain that this catkin does not need to be cross-compiled, and only needs to be compiled on the PC side. That’s it.

How to compile ROS

When compiling ROS packages on the PC side, you can find out carefully that it is the CMake tool that actually manages the compilation operation. As mentioned above, catkin can be understood as adding a layer of packaging to CMake.

By viewing the compilation information, the compilation logic of catkin is to first confirm the ROS components to be compiled according to the package. xml files have corresponding descriptions. After package.xml check, CMakeLists.txt will be invoked by CMake to compile. So, what we really need to do is:

  1. According to the information that appears during compilation, add the corresponding dependency package compilation, and compile the dependent package first;
  2. When compiling, specify the corresponding cross-compilation toolchain;
  3. Handle the dependencies of different packages, and the corresponding package information can be found during compilation;

According to the above introduction, you probably know what needs to be done. The compilation command is given directly below:

cd $(BUILD_DIR) && \										### 进入将要编译包的目录
	$(HOST_DIR)/usr/bin/catkin_make_isolated --install \	### 使用 catkin_make_isolated 进行编译处理
		--source=$(BUILD_DIR) \								### 指定编译的源码目录
		--build=$(BUILD_DIR)/build_isolated \				### 指定编译中间信息保存的目录
		-DCATKIN_DEVEL_PREFIX=$(BUILD_DIR)/devel \			### 指定编译环境???
		 -DCMAKE_INSTALL_PREFIX=$(INSTALL_DIR) \			### 编译完成之后的安装目录
		 -DCMAKE_C_COMPILER="$(TARGET_CC)" \				### 指定 C 交叉编译工具链
		-DCMAKE_CXX_COMPILER="$(TARGET_CXX)" \				### 指定 CXX 交叉编译工具链
		-DCMAKE_PREFIX_PATH="$(TARGET_DIR)/usr"				### 指定 CMake 查看头文件、库文件等的查找路径

According to the above command, you will be able to cross-compile through the catkin command.

Things to note:

The ROS package will have some msg and srv files. When compiling, these files need to be converted into python source files or C++ source files. These operations can be converted through genpy and gencpp.

ROS run

After running the ROS node, you need to run roscore first, and you need to configure the corresponding environment information, just configure the following information:

#!/bin/sh /etc/rc.common
# Copyright (C) 2006-2019 OpenWrt.org

export CMAKE_PREFIX_PATH=/usr
export PKG_CONFIG_PATH=/usr/lib/pkgconfig
export ROS_ROOT=/usr/share/ros
export ROS_PACKAGE_PATH=/usr/share
export ROS_LOG_DIR=/mnt/UDISK
export ROS_HOSTNAME=localhost
export ROS_MASTER_URI=http://localhost:11311
export LD_LIBRARY_PATH=/usr/lib
export ROS_ETC_DIR=/usr/etc/ros
export ROS_DISTRO=kinetic
export ROS_VERSION=1
export ROSLISP_PACKAGE_DIRECTORIES=/usr/share/common-lisp

At the same time, in order to automatically configure the above environment for each terminal, you can add the above configuration file to the /etc/profile.d directory. At this time, each terminal will automatically increase the above environment variables.

Supongo que te gusta

Origin blog.csdn.net/weixin_41944449/article/details/110288858
Recomendado
Clasificación