(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Cài đặt và cấu hình môi trường cho ROS

Description: Hướng dẫn cài đặt và cấu hình môi trường cho ROS trên máy tính.

Tutorial Level: BEGINNER

Next Tutorial: Navigating the ROS Filesystem

Cài đặt ROS

Trước khi bắt đầu vui lòng hoàn thành cài đặt theo hướng dẫn ROS installation instructions.

Chú ý: Nếu bạn đã cài đặt ROS từ trình quản lý gói như apt, thì các gói đó sẽ không có quyền ghi vào hoặc chỉnh sửa bởi người dùng. Khi làm việc với gói ROS từ nguồn hoặc khi tạo gói ROS mới, bạn nên luôn luôn làm việc trong một thư mục mà bạn có quyền truy cập, chẳng hạn như thư mục chính của bạn.

Quản lý môi trường

Trong quá trình cài đặt ROS, bạn sẽ được nhắc thiết lập nguồn trong một số tập tin . * Sh, hoặc thậm chí thêm 'sourcing' vào tập lệnh khởi động shell của bạn. Điều này là cần thiết vì ROS dựa vào khái niệm kết hợp không gian sử dụng môi trường của sheel. Điều này làm cho hạn chế sự không tương thích các phiên bản khác nhau của ROS hoặc các gói khác nhau của các gói dễ dàng hơn.

Nếu bạn gặp phải vấn đề khi tìm kiếm hoặc sử dụng các gói ROS của mình, đảm bảo rằng bạn đã thiết lập đúng môi trường. Một cách tốt để kiểm tra là đảm bảo rằng environment variables(biến môi trường) hoặc ROS_ROOTROS_PACKAGE_PATH(đường dẫn đến các gói ROS) đã được cài đặt đúng:

$ printenv | grep ROS

Nếu thiết lập không đúng, cần phải thiết lập "nguồn" một số tập tin * sh . Các tệp thiết lập môi trường được tạo ra tự động, nhưng có thể đến từ những nguồn khác nhau:

  • ROS packages installed with package managers provide setup.*sh files
  • rosbuild workspaces provide setup.*sh files using tools like rosws

  • Setup.*sh files are created as a by-product of building or installing catkin packages

Chú ý: Trong suốt các hướng dẫn, bạn sẽ thấy tài liệu tham khảo tới rosbuildcatkin. Đây là hai phương pháp để tổ chức và xây dựng mã ROS của bạn. Nói chung, rosbuild rất dễ sử dụng và đơn giản, trong đó catkin sử dụng các tiêu chuẩn của CMake, vì vậy nó phức tạp hơn nhưng cung cấp tính linh hoạt hơn đặc biệt cho những người muốn tích hợp các cơ sở mã bên ngoài hoặc muốn phát hành phần mềm của họ. Để có thông tin đầy đủ tham khảo catkin hoặc rosbuild.

Nếu bạn chỉ cài đặt ROS từ apt trên Ubuntu thì tập tin cài đặt setup.*sh sẽ nằm trong '/opt/ros/<distro>/', và phải cài đặt nguồn như sau:

$ source /opt/ros/<distro>/setup.bash

Dùng tên viết gọn của các phiên bản ROS thay cho <distro>

Nếu bạn cài ROS Kinetic, sẽ giống như sau:

$ source /opt/ros/kinetic/setup.bash

Bạn sẽ cần phải chạy lệnh này trên mỗi trình shell mới bạn mở để có quyền truy cập vào các lệnh ROS, trừ khi bạn thêm dòng này vào bashrc của bạn. Quá trình này cho phép bạn cài đặt một số phiên bản của ROS (ví dụ như indigo và kinetic) trên cùng một máy tính và chuyển đổi giữa chúng.Trên các nền tảng khác, bạn sẽ tìm thấy những thiết lập này các tập tin .*sh bất cứ nơi nào bạn cài đặt ROS.

Trên các nền tảng khác, bạn sẽ tìm thấy những thiết lập này các tập tin .*sh bất cứ nơi nào bạn cài đặt ROS.

Tạo một không gian làm việc(Workspace) cho ROS

Hướng dẫn sau đay cho ROS Groovy và phiên bản mới hơn. Cho ROS Fuerte và phiên bản cũ hơn, lựa chọn rosbuild.

Bắt đầu tạo catkin workspace:

$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/src

Mặc dù workspace trống (không có gói nào trong đường dẫn 'src' , chỉ có duy nhất tập tin (file) CMakeLists.txt ) bạn vẫn có thể "build" workspace:

$ cd ~/catkin_ws/
$ catkin_make

Lệnh catkin_make là một công cụ hữu ích dùng trong catkin workspaces. Nếu nhìn từ đường dẫn hiện tại bạn sẽ thấy đường dẫn hai thư mục 'build' và 'devel' . Trong thư mục 'devel' bạn sẽ thấy một vài tập tin setup.*sh . Thiết lập mã nguồn (Sourcing) bất kỳ các tập tin này sẽ làm chồng lên không gian làm việc trên môi trường của bạn. Để hiểu thêm về điều này, xem tài liệu : catkin. Trước khi thiết lập mã nguồn mới của bạn trên tâp tin setup.*sh:

$ source devel/setup.bash

Để đảm bảo không gian làm việc của bạn được xắp sếp đúng đắn bởi tập lệnh cài đặt, kiểm tra biến môi trường ROS_PACKAGE_PATH xem thư mục bạn đang đứng.

$ echo $ROS_PACKAGE_PATH
/home/youruser/catkin_ws/src:/opt/ros/kinetic/share

When working with ROS source code, it is often useful to do so in a "workspace". For the following ROS tutorials you will need an area for working on tutorials and creating new ROS stacks and packages.

rosws is a tool that provides a uniform interface to various version control systems such as SVN, Git and Mercurial and for managing all packages installed in a ROS overlay. An extensive tutorial on rosws can be found here.

Creating a new workspace

The following command creates a new workspace in ~/fuerte_workspace which extends the set of packages installed in /opt/ros/fuerte:

rosws init ~/fuerte_workspace /opt/ros/fuerte

Note: rosws is part of the rosinstall package, which is not installed by default. The following command downloads it using the Ubuntu package manager:

sudo apt-get install python-rosinstall

Creating a sandbox directory for new packages

New packages need to be put in a path that is in the variable ROS_PACKAGE_PATH. All directories that are managed by rosws, i.e. that have been added using rosws are automatically added to the ROS_PACKAGE_PATH when the file setup.bash of the corresponding workspace is sourced. Although new packages should always be put in repositories that have been installed using rosws, it can be very convenient to have a sandbox directory where for instance packages created during the tutorials can be put without requiring any additional rosws commands. For that we create a new directory sandbox and add it to the hidden .rosinstall file with rosws:

mkdir ~/fuerte_workspace/sandbox
rosws set ~/fuerte_workspace/sandbox

Every time the entries in the workspace change, it is necessary to re-source ~/fuerte_workspace/setup.bash to make sure that the updated ROS_PACKAGE_PATH is used.

source ~/fuerte_workspace/setup.bash

It is very common to replace the line source /opt/ros/fuerte/setup.bash to source the setup.bash in ~/fuerte_workspace or whichever workspace you use most often.

A more complete ROS Workspace tutorial can be found here.

Confirmation

To confirm that your package path has been set, echo the ROS_PACKAGE_PATH variable.

$ echo $ROS_PACKAGE_PATH

You should see something similar to:

/home/your_user_name/fuerte_workspace/sandbox:/opt/ros/fuerte/share:/opt/ros/fuerte/stacks

Bạn đã cài đặt xong môi trường làm việc với ROS, kế tiếp là tập tin hệ thống ROS file system tutorial.

Wiki: vn/ROS/Tutorials/InstallingandConfiguringROSEnvironment (last edited 2017-03-31 11:08:19 by HoangGiang88)