ROS 2 사용자 가이드
PX4에서 ROS 2를 설정하고 사용하는 방법을 설명합니다.
필요한 소프트웨어를 설치하고 ROS 2 애플리케이션을 구축하는 방법에 대한 지침과 ROS2-PX4 브리지 아키텍처 및 애플리케이션 파이프라인에 대한 개요를 제공합니다.
개요
ROS 2의 애플리케이션 파이프라인은 기본 통신 미들웨어(DDS/RTPS) 덕분에 매우 간단합니다. microRTPS Bridge는 PX4에서 실행되는 클라이언트와 ROS 컴퓨터에서 실행되는 에이전트로 구성되며, UORB와 ROS 2간의 양방향 메시지 변환을 제공합니다. 이를 통하여, PX4 UORB 데이터에 직접 게시 및 구독하는 ROS 2 리스너 또는 광고주 노드를 생성할 수 있습니다! 이것을 아래 다이어그램에서 설명합니다.
ROS 2는 px4_msgs
및 px4_ros_com
패키지를 사용하여 일치하는 메시지 정의가 클라이언트와 에이전트 코드를 생성하는 데 사용되는지 확인하고(중요함), ROS 코드를 빌드시에는 PX4가 있어야 합니다.
px4_msgs
에는 PX4 클라이언트 메시지 정의가 포함됩니다. 이 프로젝트가 빌드되면 해당 ROS 2 호환 IDL 파일이 생성됩니다.px4_ros_com
contains the microRTPS agent code templates for the agent publishers and subscribers. The build process runs afastddsgen
instance to generate the code for themicrortps_agent
, which compiles into a single executable.
PX4 Autopilot 프로젝트는 (마스터 분기에서) 변경될 때마다, 새 메시지 정의로 px4_msgs
를 자동으로 업데이트합니다.
PX4 firmware contains the microRTPS client based on its build-time message definitions.
설치 및 설정
To setup ROS 2 for use with PX4 you will need to:
설치 상태 확인(선택 사항)
Fast DDS 설치
ROS 2와 해당 종속성을 설치합니다.
이 섹션에서는 홈 디렉토리에서 호스팅되는 ROS 2 작업 공간을 만드는 방법을 보여줍니다(필요에 따라 명령을 수정하여 소스 코드를 다른 곳에 배치). px4_ros_com
및 px4_msg
패키지가 작업 영역 폴더에 복제한 다음, 스크립트를 사용하여 작업 영역을 빌드합니다. :::
ROS2 설치
작업 공간을 만들고 빌드합니다.
ROS 2 브리지 패키지
px4_ros_com
와px4_msgs
를/src
디렉토리에 복제합니다.master
분기는 기본적으로 복제됩니다.eigen3_cmake_module
is also required, since Eigen3 is used on the transforms library:Some Python dependencies must also be installed (using
pip
orapt
):
ROS 2 작업 공간 빌드
모든 스크립트 옵션은 --help
인수를 사용하여 출력합니다. 특히 --verbose
인수는 전체 colcon 빌드 출력을 보여줍니다.
note px4_ros_com/scripts
디렉토리에는 다양한 종류의 작업 공간을 구축하기 위한 여러 스크립트가 포함되어 있습니다. :::
To create and build the workspace:
Create a workspace directory using:
PX4 Autopilot 프로젝트의 루트에서 새 터미널을 열고, PX4 Gazebo 시뮬레이션을 실행합니다.
새 터미널에서 ROS 2 작업 공간을
소싱
한 다음 UDP를 전송 프로토콜로 사용하여micrortps_agent
데몬을 시작합니다.
All script options can be listed by calling it with the --help
argument. In particular the --verbose
argument shows the full colcon build output.
설치 상태 확인
One way to check that the installation/setup succeeded is to test that the bridge can communicate with PX4. We can do this by running the bridge against PX4 running in the simulator.
Setup your PX4 Ubuntu Linux development environment - the default instructions get the latest version of PX4 source and install all the needed tools.
작업 공간을 빌드합니다.
Once PX4 has fully started the terminal will display the NuttShell/System Console. Note also that PX4 SITL will automatically start the
micrortps_client
connected to UDP ports 2019 and 2020.On a new terminal,
source
the ROS 2 workspace and then start themicrortps_agent
daemon with UDP as the transport protocol:Open a new terminal and start a "listener" using the provided launch file:
If the bridge is working correctly you will be able to see the data being printed on the terminal/console where you launched the ROS listener:
You can also verify the rate of the message using ros2 topic hz
. E.g. in the case of sensor_combined
use ros2 topic hz /fmu/sensor_combined/out
:
ROS 2 예제 애플리케이션
ROS 2 리스너 생성
그런 다음 일반 rclcpp::Node
기본 클래스의 하위 클래스인 SensorCombinedListener
클래스를 생성합니다.
이것은 sensor_combined
uORB 메시지가 수신될 때(현재는 RTPS/DDS 메시지로) 콜백 함수를 생성하고 메시지가 수신될 때마다 메시지 필드의 내용을 출력합니다.
아래 줄은 하나 이상의 호환 가능한 ROS 게시자와 일치시킬 수 있는 sensor_combined_topic
에 대한 구독을 만듭니다.
SensorCombinedListener
클래스를 ROS 노드로 인스턴스화하는 작업은 main
함수에서 수행됩니다.
ROS 2 광고주 노드는 DDS/RTPS 네트워크(따라서 PX4 Autopilot)에 데이터를 게시합니다.
px4_ros_com/src/advertisers
아래의 debug_vect_advertiser.cpp
를 예로 들면 먼저 debug_vect
msg 헤더를 포함한 필수 헤더를 가져옵니다.
그런 다음 코드는 일반 rclcpp::Node
기본 클래스의 하위 클래스인 DebugVectAdvertiser
클래스를 생성합니다.
ROS 2 광고주 만들기
A ROS 2 advertiser node publishes data into the DDS/RTPS network (and hence to the PX4 Autopilot).
DebugVectAdvertiser
클래스를 ROS 노드로 인스턴스화하는 작업은 main
함수에서 수행됩니다.
PX4에서 오프보드 제어를 사용하는 전체 예제는 ROS 2 오프보드 제어 예제를 참고하십시오.
note This is provided to help you better understand the build process and how to include the ROS1 workspace. It is not needed to build or use ROS 2. It additionally includes instructions for building the ros1_bridge
package, which is used in ROS (1) via ROS 2 Bridge. :::
This section describes the process to manually setup your workspace and build the px4_ros_com
, px4_msgs
, and ros1_bridge
package. The topic effectively explains the operation of the build_ros2_workspace.bash
script in the installation instructions).
To build the ROS 2 workspace only:
cd
를px4_ros_com_ros2
디렉토리에 넣고 ROS 2 환경을 소싱합니다. 이전 작업 공간이 이전에 설정되었다는 메시지가 표시되더라도 신경 쓰지 마십시오.ROS 2 작업 영역에 빌드할 수 있도록
ros1_bridge
패키지를 복제합니다.
clean_all.bash 스크립트(px4_ros_com/scripts에 있음)는 이 정리 프로세스를 쉽게 하기 위해 제공되며, 이 스크립트는 위에 나열된 모든 작업 공간 옵션 (ROS 2, ROS 1 및 둘 다)을 정리할 수 있습니다.
cd
intopx4_ros_com_ros2
dir and source the ROS 2 environment. Don't mind if it tells you that a previous workspace was set before:Clone the
ros1_bridge
package so it can be built on the ROS 2 workspace:Build the
px4_ros_com
andpx4_msgs
packages, excluding theros1_bridge
package:Then build the ROS(1) packages side. First open a new terminal window and source the ROS(1) environment that was installed on the system:
Build the
px4_ros_com
andpx4_msgs
packages on the ROS end (using the terminal opened in the previous step):Open another new terminal and then source the environments and workspaces in the order listed below:
Finally, build the
ros1_bridge
:
작업 공간 청소
이를 사용하는 가장 일반적인 방법은 ROS(1) 작업 공간 디렉토리 경로를 전달하는 것입니다(일반적으로 기본 경로에 없기 때문에).
Unfortunately colcon does not currently have a way of cleaning the generated build, install and log directories, so these directories must be deleted manually.
The clean_all.bash script (in px4_ros_com/scripts) is provided to ease this cleaning process, this script can be used to clean all of the workspace options listed above (ROS 2, ROS 1, and Both)
The most common way of using it is by passing it the ROS (1) workspace directory path (since it's usually not on the default path):
Like the build scripts, the clean_all.bash
script also has a --help
guide.
추가 정보
Last updated