一、安装ROS(参考官网:http://wiki.ros.org/indigo/Installation/Ubuntu)
1.设置计算机接受来自packages.ros.org的软件。
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
2.设置keys
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
3.安装ros
首先更新
sudo apt-get update
再全部安装
sudo apt-get install ros-indigo-desktop-full
apt-cache search ros-indigo
4.安装rosdep
sudo rosdep init
rosdep update
5.环境设置
echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrc
source ~/.bashrc
6.安装rosinstall
sudo apt-get install python-rosinstall
sudo rosdep init
rosdep update
二、创建工作空间catkin
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
三、编译工作空间
cd ~/catkin_ws
catkin_make
四、source路径
source ~/catkin_ws/devel/setup.bash
rospack profile
或者 一次性打印到系统环境中去:
echo "source ~/catkin_ws/devel/setup.bash" >> ~/.bashrc
五、创建一个catkin包
cd ~/catkin_ws/src
catkin_create_pkg package_name
此时包里面含有package.xml和CMakeLists.txt两个文件,在该目录下可以编辑创建source_files.cpp文件
六、编译源程序
1.首先在CMakeLists.txt中声明依赖库,
find_package(catkin REQUIRED COMPONENTS package-names)
2.接着在package.xml 中列出依赖库
3.最后在CMakeLists.txt中声明可执行文件:
add_executable(executable-name source-files.cpp)
target_link_libraries(executable-name ${catkin_LIBRARIES})
4.编译工作区:在工作空间catkin_ws中catkin_make
5.运行节点管理器:roscore
6.Sourcing setup.bash:source devel/setup.bash
这个自动生成的脚本文件设置了若干环境变量,从而使ROS能够找到你创建的功能包和新生成的可执行文件。除非目录结构发生变化,否则你只需要在每个终端执行此命令一次,即使你修改了代码并且用catkin_make 执行了重编译。
7.执行程序:在工作空间catkin_ws 目录下运行 rosrun package_name executable-name