ROS客户端安装和环境配置
乌班图20.04 是ROS Noetic Ninjemys,(我安装的最新的听说维护到2025年)
注意:18.04对应: Melodic 16.04及更早对应:Kinetic
1.1 安装
选择阿里源,或中科大都成功了,推荐阿里源
- 1、安装源
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list'
- 2、安装KEY
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
3、更新源
sudo apt update
- 4、安装ROS(如果部分下载不了就再执行一遍就行了)
sudo apt install ros-noetic-desktop-full
但是输入sudo rosdep init
sudo: rosdep:找不到命令
但是会报错,所以下载了python-rosdep,然后更换hosts文件。
安装
sudo apt install python3-rosdep
如果python2 会安装失败网上推荐安装python2-rosdedp ,从pypi下载 rosdep进行离线安装
sudo gedit /etc/hosts
可以添加下面1行,也可以更换掉整个hosts文件,见这里hosts:
151.101.84.133 raw.githubusercontent.com
然后更新。
sudo rosdep init
成功会
yys@yys:~/catkin_ws/src/beginner_tutorials$ sudo rosdep init
Wrote /etc/ros/rosdep/sources.list.d/20-default.list
Recommended: please run
rosdep update
失败提示
ERROR: default sources list file already exists:
/etc/ros/rosdep/sources.list.d/20-default.list
Please delete if you wish to re-initialize
解决办法
sudo rm /etc/ros/rosdep/sources.list.d/20-default.list
在输入sudo rosdep init 就好了
成功后输入 不要带sudo,不然会失败
rosdep update
结果如下
yys@yys:~/catkin_ws/src/beginner_tutorials$ rosdep update
reading in sources list data from /etc/ros/rosdep/sources.list.d
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-v4.yaml
Skip end-of-life distro "ardent"
Skip end-of-life distro "bouncy"
Skip end-of-life distro "crystal"
Add distro "dashing"
Add distro "eloquent"
Add distro "foxy"
Skip end-of-life distro "groovy"
Skip end-of-life distro "hydro"
Skip end-of-life distro "indigo"
Skip end-of-life distro "jade"
Add distro "kinetic"
Skip end-of-life distro "lunar"
Add distro "melodic"
Add distro "noetic"
Add distro "rolling"
updated cache in /home/yys/.ros/rosdep/sources.cache
- 6、环境变量
echo "source /opt/ros/noetic/setup.bash" >> ~/.bashrc
source ~/.bashrc
7.安装rosinstall
//sudo apt install python3-rosinstall python-rosinstall3-generator python3-wstool build-essential
sudo apt install python3-rosinstall python3-rosinstall-generator python3-wstool build-essential
3. 测试
- 1、启动
roscore
- 2、打开小乌龟
rosrun turtlesim turtlesim_node
- 3、键盘控制小乌龟(鼠标键盘放在这个窗口才可以)
rosrun turtlesim turtle_teleop_key
4.显示ros节点图
rqt_graph
5.列出系统所有节点
rosnode list
yys@yys:~$ rosnode list
/rosout
/teleop_turtle
/turtlesim
6.查看节点信息
rosnode info /turtlesim
--------------------------------------------------------------------------------
Node [/turtlesim]
Publications:
* /rosout [rosgraph_msgs/Log]
* /turtle1/color_sensor [turtlesim/Color]
* /turtle1/pose [turtlesim/Pose]
Subscriptions:
* /turtle1/cmd_vel [geometry_msgs/Twist]
Services:
* /clear
* /kill
* /reset
* /spawn
* /turtle1/set_pen
* /turtle1/teleport_absolute
* /turtle1/teleport_relative
* /turtlesim/get_loggers
* /turtlesim/set_logger_level
contacting node http://yys:39115/ ...
Pid: 13255
Connections:
* topic: /rosout
* to: /rosout
* direction: outbound (56553 - 127.0.0.1:44690) [29]
* transport: TCPROS
* topic: /turtle1/cmd_vel
* to: /teleop_turtle (http://yys:42039/)
* direction: inbound (42040 - yys:58227) [31]
* transport: TCPROS
7.列出所有话题列表
rostopic list
yys@yys:~$ rostopic list
/rosout
/rosout_agg
/turtle1/cmd_vel
/turtle1/color_sensor
/turtle1/pose
8.让海龟自动移动,(输入前一行,按tap下面就出现调位置)
rostopic pub -r 10 /turtle1/cmd_vel geometry_msgs/Twist "linear:
x: 1.0
y: 0.0
z: 0.0
angular:
x: 0.0
y: 0.0
z: 0.0"
显示上面发布命令含义
rosmsg show geometry_msgs/Twist
geometry_msgs/Vector3 linear
float64 x
float64 y
float64 z
geometry_msgs/Vector3 angular
float64 x
float64 y
float64 z
9.查看ros服务所有列表
rosservice list
yys@yys:~$ rosservice list
/clear
/kill
/reset
/rosout/get_loggers
/rosout/set_logger_level
/spawn
/teleop_turtle/get_loggers
/teleop_turtle/set_logger_level
/turtle1/set_pen
/turtle1/teleport_absolute
/turtle1/teleport_relative
/turtlesim/get_loggers
/turtlesim/set_logger_level
10.增加一个乌龟(如图两个海龟name起个名字)
rosservice call /spawn "x: 2.0
y: 2.0
theta: 0.0
name: 'turtle2'"
用rosservice list发现多了一个乌龟
rosservice list
yys@yys:~$ rosservice list
/clear
/kill
/reset
/rosout/get_loggers
/rosout/set_logger_level
/spawn
/teleop_turtle/get_loggers
/teleop_turtle/set_logger_level
/turtle1/set_pen
/turtle1/teleport_absolute
/turtle1/teleport_relative
/turtle2/set_pen
/turtle2/teleport_absolute
/turtle2/teleport_relative
/turtlesim/get_loggers
/turtlesim/set_logger_level
11.记录话题记录
rosbag record -a -o cmd_record
yys@yys:~$ rosbag record -a -o cmd_record
[ INFO] [1598876292.519372598]: Subscribing to /rosout_agg
[ INFO] [1598876292.520818767]: Recording to 'cmd_record_2020-08-31-20-18-12.bag'.
[ INFO] [1598876292.524019296]: Subscribing to /rosout
[ INFO] [1598876292.526969155]: Subscribing to /turtle1/pose
[ INFO] [1598876292.529880191]: Subscribing to /turtle1/color_sensor
[ INFO] [1598876292.533709954]: Subscribing to /turtle1/cmd_vel
[ INFO] [1598876292.536354737]: Subscribing to /turtle2/pose
[ INFO] [1598876292.539900734]: Subscribing to /turtle2/color_sensor
ctrl+c结束后,会保存主目录/home/yys/cmd_record_2020-08-31-20-18-12.bag
rosbag play+路径文件夹名会执行刚才动作(相当于录制脚本)
rosbag play cmd_record_2020-08-31-20-18-12.bag
12.安装软件
显示可选安装包apt search ros-noetic,要想安装用sudo apt-get install XX 就可以了
apt search ros-noetic
安装
sudo apt install ros-noetic-包名
例如
sudo apt install ros-noetic-ros-base
//建在yys目录下
创建工作空间
mkdir -p ~/catkin_ws/src
编译工作空间
cd ~/catkin_ws
catkin_make
目录下会多几个文件
yys@yys:~/catkin_ws$ ls
build devel src
创建安装空间.放最后生成可执行文件在里面
catkin_make install
yys@yys:~/catkin_ws$ ls
build devel install src
去yys目录下打开隐藏文件 .bashrc,执行命令
cd ~
sudo gedit .bashrc
每次运行终端会运行脚本
把
source ~/catkin_ws/devel/setup.bash
写在.bashrc下面
02.导航文件系统
查找ros路径
rospack find roscpp
进入ros目录
roscd roscpp
进入ros子目录
roscd roscpp/cmake
输出当前路径pwd相当于ls
pwd
yys@yys:/opt/ros/noetic/share/roscpp/cmake$ pwd
/opt/ros/noetic/share/roscpp/cmake
显示当前所有文件
rosls
yys@yys:/opt/ros/noetic/share/roscpp/cmake$ rosls
roscppConfig.cmake roscppConfig-version.cmake roscpp-msg-extras.cmake roscpp-msg-paths.cmake
Tab Completion 补全
在yys@yys:~/catkin_ws/src$ 下用命令创建一个包,创建依赖,有python,c++
cd ~/catkin_ws/src
catkin_create_pkg beginner_tutorials std_msgs rospy roscpp
会多beginner_tutorials文件
yys@yys:~/catkin_ws/src$ ls
beginner_tutorials CMakeLists.txt
beginner_tutorials 下面的文件
cd beginner_tutorials/
yys@yys:~/catkin_ws/src/beginner_tutorials$ ls
CMakeLists.txt include package.xml src
package.xml 功能包描述
CMakeLists.txt 描述功能包编译规则
查看功能包环境变量
cho $ROS_PACKAGE_PATH
yys@yys:~/catkin_ws/src/beginner_tutorials$ echo $ROS_PACKAGE_PATH
/home/yys/catkin_ws/src:/opt/ros/noetic/share
现在可以使用rospack工具检查这些一阶依赖关系
进入 beginner_tutorials 文件夹
cd ~/catkin_ws/src/beginner_tutorials
运行命令
rospack depends1 beginner_tutorials
报错
[rospack] Error: no such package beginner_tutorials
输入
source ~/catkin_ws/devel/setup.bash
再次运行 rospack depends1 beginner_tutorials
如果继续报错
[rospack] Error: the rosdep view is empty: call 'sudo rosdep init' and 'rosdep update'
报错解决方法→初始化rosdep
rospack depends1 beginner_tutorials
结果显示这样就成功了yys@yys:~/catkin_ws/src/beginner_tutorials$ rospack depends1 beginner_tutorials
roscpp
rospy
std_msgs
如果报错(下面待研究)
/opt/ros/noetic/lib/rosout/rosout: error while loading shared libraries: libroscpp.so: cannot open shared object file: No such file or directory
重装了ROS但发现问题并没有解决,最后发现其实是装某些库的时候把路径给改了,运行以下命令即可解决:
LD_LIBRARY_PATH=/opt/ros/noetic/lib
6.1 . init报错
the rosdep view is empty: call 'sudo rosdep init' and 'rosdep update'
修复ros录制包的时候,执行某个命令,报这个错误,报错的原因还不明白,暂时找到解决办法,参考:https://blog.csdn.net/u010918541/article/details/50445415
sudo rm /etc/ros/rosdep/sources.list.d/20-default.list
sudo rosdep init
rosdep update
注意:如果是win10 linux18.04子系统,装错源也会安装失败,需要添加对应源点击→2.linux 18.04可以装ros源
7.1设置软件源(清华):
sudo sh -c '. /etc/lsb-release && echo "deb http://mirrors.tuna.tsinghua.edu.cn/ros/ubuntu/ $DISTRIB_CODENAME main" > /etc/apt/sources.list.d/ros-latest.list'
设置最新的密钥:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F42ED6FBAB17C654
sudo apt-get update
sudo apt-get install ros-melodic-desktop-full
sudo apt-get install ros-melodic-rqt*
安装
sudo apt install python-rosdep
sudo vim /etc/hosts
可以添加下面1行,也可以更换掉整个hosts文件:
151.101.84.133 raw.githubusercontent.com
然后更新。
sudo rosdep init
rosdep update
安装rosinstall
sudo apt install python-rosinstall python-rosinstall-generator python-wstool build-essential
设置环境变量:
sudo apt install net-tools
sudo vim ~/.bashrc
# Set ROS melodic
source /opt/ros/melodic/setup.bash
source ~/catkin_ws/devel/setup.bash
# Set ROS Network
#ifconfig查看你的电脑ip地址
export ROS_HOSTNAME=192.168.31.135
export ROS_MASTER_URI=http://${ROS_HOSTNAME}:11311
# Set ROS alias command 快捷指令
alias cw='cd ~/catkin_ws'
alias cs='cd ~/catkin_ws/src'
alias cm='cd ~/catkin_ws && catkin_make'
source ~/.bashrc
运行roscore
roscore
1。如果报错
Command 'roscore' not found, but can be installed with:
解决方案
由[1]可知,指令 “roscore” 之所以能够被执行,首先需要在文件夹 “/opt/ros/indigo/bin/” 里面存在名为 “roscore” 的二进制可执行文件,打开文件夹,检查文件是否存在:
cd /opt/ros/melodic/bin
ls -l
果然没有。
由[2],输入:
sudo apt-get install ros-melodic-desktop
- cd 进去再看,有了!
执行
source ~/.bashrc
- 再次启动ROS
roscore
- 成功了!
2。如果 roslaunch... 报错
source ~/.bashrc
本文作者: 永生
本文链接: https://yys.zone/detail/?id=104
版权声明: 本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明出处!
发表评论
评论列表 (0 条评论)
暂无评论,快来抢沙发吧!