ROS--5Packages & Catkin Workspaces

ROS与Catkin工作空间搭建
本文详细介绍了如何创建和使用ROS的Catkin工作空间,包括创建工作空间、添加和构建包的过程,以及如何使用rosdep工具自动检查和安装依赖库。

Catkin工作空间本质上是一个目录,可以在这里编写、修改并安装catkin包,通常当你开发基于ROS的机器人或项目时,你需要在单独的工作空间里完成。这个单独的空间需要保存大量不同的catkin包,所有ROS软件组件都以catkin包的形式组织并发布。

Catkin包可能包含节点的源代码,有用的脚本、配置文件等等。


1.Create a Catkin Workspace

Step 1: mkdir -p ~/catkin_ws/src

$ mkdir -p ~/catkin_ws/src

 

Step 2:

$ mkdir -p ~/catkin_ws/src

 

Step3:

$ catkin_init_workspace

 

Step4:

$ cd ~/catkin_ws

 

Step5:

$ catkin_make

 

More in

http://wiki.ros.org/catkin/conceptual_overview

You now have two new directories: build and devel. The aptly named build directory is the build space for C++ packages and, for the most part, you will not interact with it. The devel directory does contain something of interest, a file named setup.bash. This setup.bash script must be sourced before using the catkin workspace.

 

2Add a package

step1:Cloning the simple_arm Package

One of the biggest benefits of using ROS is that it has a really large community of users and developers, so there is a lot of code that you can use.

$ cd ~/catkin_ws/src
$ git clone https://github.com/udacity/simple_arm_01.git simple_arm

step2: Building the simple_arm package

After the repo has finished cloning, you can change directory to the top-level of the ros workspace and build the new package.

$ cd ~/catkin_ws
$ catkin_make

step3: Launch multiple nodes

roslaunch allows you to do the following

  • Launch ROS Master and multiple nodes with one simple command
  • Set default parameters on the parameter server
  • Automatically re-spawn processes that have died

Once the workspace has been built, you can source it’s setup script:

$ source devel/setup.bash

With your workspace sourced you can now launch simple_arm:

$ roslaunch simple_arm robot_spawn.launch

 

3.rosdep 自动检查依赖库

After the last exercise, you might have noticed the following warning line:

The controller spawner couldn’t find the expected controller_manager ROS interface.

ROS packages have two different types of dependencies: build dependencies, and run dependencies. This error message was due to a missing runtime dependency.

The rosdep tool will check for a package's missing dependencies, download them, and install them.

To check for missing dependencies in the simple_arm package:

$ rosdep check simple_arm

 

To have rosdep install packages, invoke the following command from the root of the catkin workspace

$ rosdep install -i simple_arm

Issues with this command may arise when using a VM. If this is the case, please try:

sudo apt-get install ros-kinetic-gazebo-ros-control

Dive Deeper into Packages

$ cd ~/catkin_ws/src

The syntax for creating a catkin package is simply,

$ catkin_create_pkg <your_package_name> [dependency1 dependency2 …]

 

$ catkin_create_pkg first_package

I mentioned earlier that ROS packages have a conventional directory structure. Let’s take a look at a more typical package.

  • scripts (python executables)
  • src (C++ source files)
  • msg (for custom message definitions)
  • srv (for service message definitions)
  • include -> headers/libraries that are needed as dependencies
  • config -> configuration files
  • launch -> provide a more automated way of starting nodes

Other folders may include

  • urdf (Universal Robot Description Files)
  • meshes (CAD files in .dae (Collada) or .stl (STereoLithography) format)
  • worlds (XML like files that are used for Gazebo simulation environments)

There are many packages that you can install. To see a list of available packages for the Kinetic distribution, take some time to explore here.

https://www.ros.org/browse/list.php

catkin_make Base path: /home/bobac3/桌面/ros_workspace Source space: /home/bobac3/桌面/ros_workspace/src Build space: /home/bobac3/桌面/ros_workspace/build Devel space: /home/bobac3/桌面/ros_workspace/devel Install space: /home/bobac3/桌面/ros_workspace/install #### #### Running command: &quot;cmake /home/bobac3/桌面/ros_workspace/src -DCATKIN_DEVEL_PREFIX=/home/bobac3/桌面/ros_workspace/devel -DCMAKE_INSTALL_PREFIX=/home/bobac3/桌面/ros_workspace/install -G Unix Makefiles&quot; in &quot;/home/bobac3/桌面/ros_workspace/build&quot; #### -- Using CATKIN_DEVEL_PREFIX: /home/bobac3/桌面/ros_workspace/devel -- Using CMAKE_PREFIX_PATH: /home/bobac3/ros_workspace/devel;/opt/ros/melodic -- This workspace overlays: /home/bobac3/ros_workspace/devel;/opt/ros/melodic -- Found PythonInterp: /usr/bin/python2 (found suitable version &quot;2.7.17&quot;, minimum required is &quot;2&quot;) -- Using PYTHON_EXECUTABLE: /usr/bin/python2 -- Using Debian Python package layout -- Using empy: /usr/bin/empy -- Using CATKIN_ENABLE_TESTING: ON -- Call enable_testing() -- Using CATKIN_TEST_RESULTS_DIR: /home/bobac3/ros_workspace/build/test_results -- Found gtest sources under &#39;/usr/src/googletest&#39;: gtests will be built -- Found gmock sources under &#39;/usr/src/googletest&#39;: gmock will be built -- Found PythonInterp: /usr/bin/python2 (found version &quot;2.7.17&quot;) -- Using Python nosetests: /usr/bin/nosetests-2.7 -- catkin 0.7.29 -- BUILD_SHARED_LIBS is on -- BUILD_SHARED_LIBS is on -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- ~~ traversing 5 packages in topological order: -- ~~ - bobac3_msgs -- ~~ - robot_control -- ~~ - test_pkg -- ~~ - robot_audio -- ~~ - bobac3_description -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- +++ processing catkin package: &#39;bobac3_msgs&#39; -- ==&gt; add_subdirectory(bobac3_msgs) -- Using these message generators: gencpp;geneus;genlisp;gennodejs;genpy Traceback (most recent call last): File &quot;/opt/ros/melodic/share/catkin/cmake/order_paths.py&quot;, line 43, in &lt;module&gt; main() File &quot;/opt/ros/melodic/share/catkin/cmake/order_paths.py&quot;, line 31, in main ordered_paths = order_paths(args.paths_to_order, spaces) File &quot;/usr/lib/python2.7/dist-packages/catkin_pkg/workspaces.py&quot;, line 85, in order_paths if _is_equal_or_in_parents(prefix, path): File &quot;/usr/lib/python2.7/dist-packages/catkin_pkg/workspaces.py&quot;, line 95, in _is_equal_or_in_parents dir_ = os.path.normcase(os.path.realpath(dir_)) File &quot;/usr/lib/python2.7/posixpath.py&quot;, line 382, in realpath path, ok = _joinrealpath(&#39;&#39;, filename, {{}}) File &quot;/usr/lib/python2.7/posixpath.py&quot;, line 407, in _joinrealpath if not islink(newpath): File &quot;/usr/lib/python2.7/posixpath.py&quot;, line 135, in islink st = os.lstat(path) TypeError: lstat() argument 1 must be encoded string without null bytes, not str CMake Error at /opt/ros/melodic/share/catkin/cmake/safe_execute_process.cmake:11 (message): execute_process(/home/bobac3/桌面/ros_workspace/build/catkin_generated/env_cached.sh &quot;/usr/bin/python2&quot; &quot;/opt/ros/melodic/share/catkin/cmake/order_paths.py&quot; &quot;/home/bobac3/桌面/ros_workspace/build/bobac3_msgs/catkin_generated/ordered_paths.cmake&quot; &quot;--paths-to-order&quot; &quot;/opt/ros/melodic/include&quot; &quot;/usr/include&quot; &quot;--prefixes&quot; &quot;/home/bobac3/桌面/ros_workspace/devel&quot; &quot;/home/bobac3/ros_workspace/devel&quot; &quot;/opt/ros/melodic&quot;) returned error code 1 Call Stack (most recent call first): /opt/ros/melodic/share/catkin/cmake/list_insert_in_workspace_order.cmake:26 (safe_execute_process) /opt/ros/melodic/share/catkin/cmake/catkinConfig.cmake:108 (list_insert_in_workspace_order) bobac3_msgs/CMakeLists.txt:10 (find_package) -- Configuring incomplete, errors occurred! See also &quot;/home/bobac3/桌面/ros_workspace/build/CMakeFiles/CMakeOutput.log&quot;. See also &quot;/home/bobac3/桌面/ros_workspace/build/CMakeFiles/CMakeError.log&quot;. Invoking &quot;cmake&quot; failed
06-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值