ROS实践(1)-环境搭建

一 介绍

ROS官网:http://www.ros.org/

ROS中文社区:http://www.robotos.net/forum.php

ROS版本:ROS的版本名称是按字母顺序E-F-G-H-I-J排列的,Electric-->Fuerte-->Groovy-->Hydro–>Indigo–>Jade...,我们采用的是Indigo

ROS客户端:节点需要使用roscpp或rospy的ROS客户端编写,我们采用的是roscpp

 

1 文件系统 stack和package

ROS实践(1)-环境搭建_第1张图片

二 安装

  1. 环境:4核 8G内存 1T硬盘 dell主机 ubuntu 14.04.3 (U盘安装,开机按F12选择U盘启动),环境ok后,继续下面步骤;
  2. 设置安装源(确保你的main源是ubuntu的官方源,切换阿里云、163等源可能存在问题)
    sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
  3. 设置key
    sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net --recv-key 0xB01FA116
  4. 安装完整版ros,选择版本indigo
    sudo apt-get update
    sudo apt-get install ros-indigo-desktop-full
    echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrc
    source ~/.bashrc
  5. 初始化ros依赖
    sudo rosdep init
    sudo rosdep update
    sudo apt-get install python-rosinstall python-rosdep

 

三 运行

报错:

yangkai04@yangkai04-Inspiron-3650:~$ roscore

Traceback (most recent call last):

  File "/opt/ros/indigo/lib/python2.7/dist-packages/roslaunch/__init__.py", line 257, in main

    write_pid_file(options.pid_fn, options.core, options.port)

  File "/opt/ros/indigo/lib/python2.7/dist-packages/roslaunch/__init__.py", line 110, in write_pid_file

    with open(pid_fn, "w") as f:

IOError: [Errno 13] Permission denied: '/home/yangkai04/.ros/roscore-11311.pid'



解决:

yangkai04@yangkai04-Inspiron-3650:~/project/baidu/adu/perception$ sudo passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
yangkai04@yangkai04-Inspiron-3650:~/project/baidu/adu/perception$ ls
autotest    build.log       COMAKE          obstacle       production
BCLOUD      build.sh        error.log       obstacle_mock  README.md
BCLOUD.cov  cmake           lib             onboard        tools
build       CMakeLists.txt  local_build.sh  output         traffic_light
yangkai04@yangkai04-Inspiron-3650:~/project/baidu/adu/perception$ su root
Password:
root@yangkai04-Inspiron-3650:/home/yangkai04/project/baidu/adu/perception# vim ~/.bashrc
添加:source /opt/ros/indigo/setup.bash

root@yangkai04-Inspiron-3650:/home/yangkai04/project/baidu/adu/perception# source ~/.bashrc
root@yangkai04-Inspiron-3650:/home/yangkai04/project/baidu/adu/perception#roscore
... logging to /root/.ros/log/d448ba6c-a498-11e6-bcd2-f48e38af57c0/roslaunch-yangkai04-Inspiron-3650-12974.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://yangkai04-Inspiron-3650:40229/
ros_comm version 1.11.20


SUMMARY
========

PARAMETERS
 * /rosdistro: indigo
 * /rosversion: 1.11.20

NODES

auto-starting new master
process[master]: started with pid [12986]
ROS_MASTER_URI=http://yangkai04-Inspiron-3650:11311/

setting /run_id to d448ba6c-a498-11e6-bcd2-f48e38af57c0
process[rosout-1]: started with pid [12999]
started core service [/rosout]


 

四 ROS文件系统导览

root@yangkai04-Inspiron-3650:/home/yangkai04/project/baidu/adu/perception#rospack find turtlesim
/opt/ros/indigo/share/turtlesim

root@yangkai04-Inspiron-3650:/home/yangkai04/project/baidu/adu/perception#rosls turtlesim
cmake  images  msg  package.xml  srv

root@yangkai04-Inspiron-3650:/home/yangkai04/project/baidu/adu/perception#roscd turtlesim
root@yangkai04-Inspiron-3650:/opt/ros/indigo/share/turtlesim# pwd
/opt/ros/indigo/share/turtlesim

 

五 创建工作空间

root@yangkai04-Inspiron-3650:/home/yangkai04/dev/rosbook/chapter2_tutorials# echo $ROS_PACKAGE_PATH
/opt/ros/indigo/share:/opt/ros/indigo/stacks
root@yangkai04-Inspiron-3650:/home/yangkai04/dev/rosbook/chapter2_tutorials# cd ~
root@yangkai04-Inspiron-3650:~# mkdir -p dev/rosbook
root@yangkai04-Inspiron-3650:~# echo "export ROS_PACKAGE_PATH=~/dev/rosbook:${ROS_PACKAGE_PATH}" >> ~/.bashrc
root@yangkai04-Inspiron-3650:~# tail -n 2 ~/.bashrc


export ROS_PACKAGE_PATH=~/dev/rosbook:/opt/ros/indigo/share:/opt/ros/indigo/stacks
root@yangkai04-Inspiron-3650:~# source ~/.bashrc

 

六 创建ROS功能包

root@yangkai04-Inspiron-3650:~# cd ~/dev/rosbook/

root@yangkai04-Inspiron-3650:~/dev/rosbook# ls

root@yangkai04-Inspiron-3650:~/dev/rosbook# roscreate-pkg chapter2_tutorialsstd_msgs rospy roscpp

Created package directory /root/dev/rosbook/chapter2_tutorials

Created include directory /root/dev/rosbook/chapter2_tutorials/include/chapter2_tutorials

Created cpp source directory /root/dev/rosbook/chapter2_tutorials/src

Created package file /root/dev/rosbook/chapter2_tutorials/Makefile

Created package file /root/dev/rosbook/chapter2_tutorials/manifest.xml

Created package file /root/dev/rosbook/chapter2_tutorials/CMakeLists.txt

Created package file /root/dev/rosbook/chapter2_tutorials/mainpage.dox

Please edit chapter2_tutorials/manifest.xml and mainpage.dox to finish creating your package

root@yangkai04-Inspiron-3650:~/dev/rosbook# rospack find chapter2_tutorials
/root/dev/rosbook/chapter2_tutorials
root@yangkai04-Inspiron-3650:~/dev/rosbook# rospack depends chapter2_tutorials
[rospack] Error: the rosdep view is empty: call 'sudo rosdep init' and 'rosdep update'

root@yangkai04-Inspiron-3650:~/dev/rosbook# sudo rosdep init
ERROR: default sources list file already exists:
    /etc/ros/rosdep/sources.list.d/20-default.list
Please delete if you wish to re-initialize

root@yangkai04-Inspiron-3650:~/dev/rosbook# rosdep update
reading in sources list data from /etc/ros/rosdep/sources.list.d
Warning: running 'rosdep update' as root is not recommended.
  You should run 'sudo rosdep fix-permissions' and invoke 'rosdep update' again without sudo.
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index.yaml
Add distro "groovy"
Add distro "hydro"
Add distro "indigo"
Add distro "jade"
Add distro "kinetic"
updated cache in /root/.ros/rosdep/sources.cache

root@yangkai04-Inspiron-3650:~/dev/rosbook# rospack depends chapter2_tutorials
cpp_common
rostime
roscpp_traits
roscpp_serialization
catkin
genmsg
genpy
message_runtime
std_msgs
gencpp
genlisp
message_generation
rosbuild
rosconsole
rosgraph_msgs
xmlrpcpp
roscpp
rosgraph
rospack
roslib
rospy

root@yangkai04-Inspiron-3650:~/dev/rosbook#rosls chapter2_tutorials

CMakeLists.txt  include  mainpage.dox  Makefile  manifest.xml  src

root@yangkai04-Inspiron-3650:~/dev/rosbook#roscd chapter2_tutorials

root@yangkai04-Inspiron-3650:~/dev/rosbook/chapter2_tutorials# pwd

/root/dev/rosbook/chapter2_tutorials

root@yangkai04-Inspiron-3650:~/dev/rosbook/chapter2_tutorials#


 

七 编译ROS功能包

root@yangkai04-Inspiron-3650:~/dev/rosbook/chapter2_tutorials#rosmake chapter2_tutorials

........................

[ rosmake ] Results:                                                            

[ rosmake ] Built 25 packages with 0 failures.                                  

[ rosmake ] Summary output to directory                                         

[ rosmake ] /root/.ros/rosmake/rosmake_output-20161108-154400

 

八 启动ROS

root@yangkai04-Inspiron-3650:~/dev/rosbook/chapter2_tutorials# roscore
... logging to /root/.ros/log/abddcc94-a587-11e6-bcd2-f48e38af57c0/roslaunch-yangkai04-Inspiron-3650-20120.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.

started roslaunch server http://yangkai04-Inspiron-3650:40461/
ros_comm version 1.11.20

SUMMARY
========

PARAMETERS
 * /rosdistro: indigo
 * /rosversion: 1.11.20

NODES

auto-starting new master
process[master]: started with pid [20132]
ROS_MASTER_URI=http://yangkai04-Inspiron-3650:11311/

setting /run_id to abddcc94-a587-11e6-bcd2-f48e38af57c0
process[rosout-1]: started with pid [20145]
started core service [/rosout]

九 停止ROS

^C[rosout-1] killing on exit

[master] killing on exit

shutting down processing monitor...

... shutting down processing monitor complete

done


root@yangkai04-Inspiron-3650:/home/yangkai04#rosnode list
ERROR: Unable to communicate with master!
root@yangkai04-Inspiron-3650:/home/yangkai04#rosnode list
ERROR: Unable to communicate with master!

你可能感兴趣的:(ROS原创)