Cài đặt & build
Làm một lần, xong là dùng cho mọi module. Các bài học từ đây trở đi giả định đúng bước đã làm trong trang này: workspace đã build, terminal đã source.
Sau bài này bạn sẽ có
- ROS 2 Humble và Gazebo Fortress chạy được trên máy
- Repo
atlas_simđã clone và build sạch bằngcolcon - Một lệnh mẫu chạy thành công để xác nhận mọi thứ đúng
1. Hệ điều hành
Cần Ubuntu 22.04 (cài trực tiếp, dual-boot, hoặc WSL2 trên Windows). Các bước dưới đây chạy trong terminal của Ubuntu đó.
2. Cài ROS 2 Humble
Bỏ qua bước này nếu máy đã có ROS 2 Humble (echo $ROS_DISTRO ra humble).
locale # kiểm tra UTF-8, nếu thiếu thì chạy 3 dòng dưới
sudo apt update && sudo apt install locales
sudo locale-gen en_US en_US.UTF-8
sudo update-locale LC_ALL=en_US.UTF-8 LANG=en_US.UTF-8
sudo apt install software-properties-common
sudo add-apt-repository universe
sudo apt update && sudo apt install curl -y
sudo curl -sSL https://raw.githubusercontent.com/ros/rosdistro/master/ros.key -o /usr/share/keyrings/ros-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/ros-archive-keyring.gpg] http://packages.ros.org/ros2/ubuntu $(. /etc/os-release && echo $UBUNTU_CODENAME) main" | sudo tee /etc/apt/sources.list.d/ros2.list > /dev/null
sudo apt update
sudo apt install ros-humble-desktop ros-dev-tools
source /opt/ros/humble/setup.bash
Đây là quy trình chuẩn của ROS 2 tại thời điểm viết bài. Nếu một lệnh báo lỗi do phía ROS đổi key/URL, tìm "ros2 humble install ubuntu debian" để lấy bản cập nhật.
3. Cài Gazebo Fortress và các gói Atlas cần
Atlas dùng Gazebo Fortress qua ros-humble-ros-gz — không phải Gazebo Classic (ros-humble-gazebo-*, tên gần giống nhưng là bản cũ, không tương thích).
sudo apt-get update
sudo apt-get install -y ros-humble-ros-gz ros-humble-gz-ros2-control \
ros-humble-slam-toolbox ros-humble-navigation2 ros-humble-nav2-bringup \
ros-humble-teleop-twist-keyboard ros-humble-joy ros-humble-teleop-twist-joy \
ros-humble-twist-mux
4. Clone và build repo
git clone https://github.com/is-buiquocdoanh/atlas_sim.git ~/atlas_sim
cd ~/atlas_sim
source /opt/ros/humble/setup.bash
colcon build
source install/setup.bash
source install/setup.bash chỉ có tác dụng cho terminal hiện tại. Mở terminal mới thì phải chạy lại — hoặc thêm 2 dòng source vào cuối ~/.bashrc để khỏi gõ lại mỗi lần.
5. Kiểm tra mọi thứ đúng
Lệnh này chỉ mở RViz xem robot, chưa cần Gazebo — nhẹ, phù hợp để kiểm tra nhanh:
ros2 launch atlas_description display.launch.py
Thấy cửa sổ RViz hiện lên với mô hình robot Atlas là build đã đúng. Đóng cửa sổ (Ctrl+C trong terminal) rồi thử tiếp bước nặng hơn — mở Gazebo thật:
ros2 launch atlas_control controller.launch.py world:=maze.sdf
Thấy robot đứng trong mê cung ở Gazebo là máy đã sẵn sàng cho toàn bộ khóa học.
Quy ước dùng trong mọi bài học
Từ Module 1 trở đi, mọi lệnh ros2 giả định: bạn đang ở thư mục ~/atlas_sim, trong một terminal đã source install/setup.bash. Khi một bài cần chạy nhiều lệnh cùng lúc (ví dụ một lệnh giữ terminal chạy mãi), bài học sẽ ghi rõ "Terminal 1", "Terminal 2" — mở đúng số terminal đó rồi copy từng khối lệnh vào đúng chỗ.
Lỗi hay gặp lúc cài đặt
gz sim. Dùng ign gazebo thay thế.python3-colcon-common-extensions: sudo apt install python3-colcon-common-extensionssource install/setup.bash ở terminal đang dùng, hoặc chưa colcon build xong.