ROS handbook

Start ROS

Network Setup - Single Machine Configuration

If you just want to run tests on your local machine, set these environment variables:

$ export ROS_HOSTNAME=localhost
$ export ROS_MASTER_URI=http://localhost:11311

Another way to set ROS_HOSTNAME is to use .local domain

$ export ROS_HOSTNAME=ubuntu.local
$ export ROS_MASTER_URI=http://ubuntu.local:11311

Sometimes, system is unable to resolve to .local domain. When you encounter such issue, apart from following diagnostics mentioned above, check whether your avahi service is running.

$  systemctl is-active avahi-daemon.service

If required, you can restart avahi service as follows:

$  systemctl restart avahi-daemon.service

Basic Structure

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-34ItWRFt-1579395944019)(./assets/StructureOfROSProject.png)]

Create and build a catkin workspace

$ mkdir -p ~/catkin_ws/src
$ cd ~/catkin_ws/
$ catkin_make
$ . ~/catkin_ws/devel/setup.bash
#To add the workspace to your ROS environment you need to source the generated setup file

Before continuing source new setup.*sh file:

$ source devel/setup.bash
#或者直接把它加入到环境变量里,这样每次开终端都会加载
$ echo "source devel/setup.bash " >> ~/.bashrc

To make sure your workspace is properly overlayed by the setup script, make sure ROS_PACKAGE_PATH environment variable includes the directory you’re in.

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

ROS Filesystem

$ rospack find [package_name]
# return the path to package
$ rospack list 
# show all packages
$ rospack depends1 beginner_tutorials 
# These first-order dependencies can now be reviewed with the rospack tool
$ rospack depends1 rospy
# show dependencyrospy's other dependencies

$ roscd [locationname[/subdir]]
# just llike 'cd' command

$ rosls [locationname[/subdir]]
# show information about a package

$ rosed <package_name> <file_name>
# edit the file( just like command 'vim')

$  catkin_create_pkg <package_name> [depend1] [depend2] [depend3]
# create a new package (in src) with three depends 

$ rosdep install <pkg_name>
# install dependencies of a pkg
$ rosdep install --from-paths src --ignore-src --rosdistro=melodic -y

The dependencies for a package are stored in the package.xml file

Building a ROS Package

$ source /opt/ros/melodic/setup.bash 
# source the  environment setup file

# In a catkin workspace
$ catkin_make

ROS Nodes And rqt

$ roscore
# run the master, rosout and parameter server
#If roscore does not initialize and sends a message about lack of permissions, probably the ~/.ros folder is owned by root, change recursively the ownership of that folder with:
$ sudo chown -R <your_username> ~/.ros

#Open up a new terminal if you would like to use **rosnode**
$ rosnode list
# rosnode displays information about the ROS nodes that are currently running. The rosnode list command lists these active nodes

$ rosnode info /[node_name]
# returns information about a specific node

$ rosrun [package_name] [node_name]
# use the package name to directly run a node within a package

$ rosrun [package_name] [node_name] __name:=[new name]
# use a Remapping Argument to change the node's name when re-run it

$ rosnode kill [node_name]
# kill a node

#Run master and  more than one nodes
$ roslaunch [pkg_name] [file_name.launch]

用下面的命令可以利用图形界面查看节点之间的通信

$ rqt_gragh

#Install:
$ sudo apt-get install ros-<distro>-rqt
$ sudo apt-get install ros-<distro>-rqt-common-plugins

#rqt_plot displays a scrolling time plot of the data published on topics.
$ rosrun rqt_plot rqt_plot #输入两次是因为第一个是软件包的名称,第二个是节点的名称

#通过以下两种方法查看两种rqt的使用
$ rqt
$ rosrun rqt_

#常用
rpt_graph
rqt_msg
rqt_topic
rqt_publisher
rqt_plot
rqt_rviz	
rqt_reconfigure	#动态配置参数
rqt_bag	#录制重放

Note: If we still see old node when you use rosnode list, it might mean that you stopped the node in the terminal using ctrl-C instead of closing the window, or that you don’t have the $ROS_HOSTNAMEenvironment variable. we can try cleaning the rosnode list

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值