ớng dẫni đặt ROS 2 cho ArduPilot
ROS 2
Kh năng c a ArduPilot có th đ c m r ng v i ROS (Robot Operating System). ượ
ROS cung c p th vi n, công c , tr u t ng ph n c ng, trình đi u khi n thi t b , công c ư ượ ế
tr c quan hóa, truy n tin nh n, qu n lý gói và nhi u th khác đ giúp l p trình viên phát
tri n ng d ng robot. ROS hi n đã đ c thay th b i ROS 2, và ArduPilot hi n h tr ROS 2 ượ ế
m t cách g c thông qua th vi n AP_DDS. ư
Điều kiện tiên quyết
- H c cách s d ng ArduPilot tr c, theo wiki phù h p v i Rover, Copter ho c Plane. ướ
- Đ m b o ph ng ti n ho t đ ng t t các ch đ Manual và Autonomous nh Guided và ươ ế ư
Auto tr c khi s d ng ROS.ướ
- H c ROS 2 thông qua các tutorial dành cho ng i m i b t đ u. ườ
- N u g p s c v ROS, nên h i trên các di n đàn c ng đ ng ROS (ho c tìm l i đó trên ế
Google).
- N u g p l i khi s d ng ROS 2 v i ArduPilot, hãy báo cáo l i trên issues c a ArduPilot, ế
ng i b o trì sẽ thêm nhãn ROS vào.ườ
Hi n t i ch h tr ROS 2 Humble. Đ m b o b n đã cài ROS 2 Humble thành công.
Cài đặt trên Ubuntu
1. T o workspace và clone repo:
mkdir -p ~/ardu_ws/src
cd ~/ardu_ws
vcs import --recursive --input
https://raw.githubusercontent.com/ArduPilot/ardupilot/master/Tools/ros2/ros2.repos
src
2. Cài đ t các ph thu c:
cd ~/ardu_ws
sudo apt update
rosdep update
source /opt/ros/humble/setup.bash
rosdep install --from-paths src --ignore-src -r -y
3. Cài MicroXRCEDDSGen:
sudo apt install default-jre
cd ~/ardu_ws
git clone --recurse-submodules https://github.com/ardupilot/Micro-XRCE-DDS-Gen.git
cd Micro-XRCE-DDS-Gen
./gradlew assemble
echo "export PATH=$PATH:$PWD/scripts" >> ~/.bashrc
4. Ki m tra cài đ t:
source ~/.bashrc
microxrceddsgen -help
L u ý: Tránh cài đ t FastDDS ho c FastDDSGen toàn c c đ tránh xung đ t th vi n.ư ư
5. Build workspace:
cd ~/ardu_ws
colcon build --packages-up-to ardupilot_dds_tests
N u l i, ch y v i ch đ verbose:ế ế
colcon build --packages-up-to ardupilot_dds_tests --event-handlers=console_cohesion+
6. Test ROS 2 ArduPilot:
cd ~/ardu_ws
source ./install/setup.bash
colcon test --executor sequential --parallel-workers 0 --base-paths src/ardupilot --event-
handlers=console_cohesion+
colcon test-result --all --verbose
Cài đặt trên MacOS
1. Clone repo:
cd ~/ardu_ws
vcs import --recursive --input
https://raw.githubusercontent.com/ArduPilot/ardupilot/master/Tools/ros2/
ros2_macos.repos src
2. Cài dependencies:
cd ~/ardu_ws
source /{path_to_your_ros_distro_workspace}/install/setup.zsh
3. Build microxrcedds_gen:
cd ~/ardu_ws/src/microxrcedds_gen
./gradlew assemble
export PATH=$PATH:$(pwd)/scripts
4. Build workspace:
cd ~/ardu_ws
colcon build --symlink-install --cmake-args \
-DBUILD_TESTING=ON \
-DCMAKE_BUILD_TYPE=RelWithDebInfo \
-DCMAKE_MACOSX_RPATH=FALSE \
-DUAGENT_SOCKETCAN_PROFILE=OFF \
-DUAGENT_LOGGER_PROFILE=OFF \
-DUAGENT_USE_SYSTEM_LOGGER=OFF \
-DUAGENT_USE_SYSTEM_FASTDDS=ON \
-DUAGENT_USE_SYSTEM_FASTCDR=ON \
--event-handlers=desktop_notification-
5. Test cài đ t:
cd ~/ardu_ws
colcon test \
--pytest-args -s -v \
--event-handlers console_cohesion+ desktop_notification- \
--packages-select ardupilot_dds_tests
Cài đặt bằng Docker
1. Clone ArduPilot Docker:
git clone https://github.com/ArduPilot/ardupilot_dev_docker.git
2. Build container:
cd ~/ardupilot_dev_docker/docker
docker build -t ardupilot/ardupilot-dev-ros -f Dockerfile_dev-ros .
3. Kh i đ ng container:
docker run -it --name ardupilot-dds ardupilot/ardupilot-dev-ros
4. Truy c p t terminal khác:
docker container exec -it ardupilot-dds /bin/bash
5. Cài MAVProxy n u c n:ế
pip install -U MAVProxy