ROS Handbook and Notes for Ubuntu
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
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_HOSTNAME
environment variable. we can try cleaning the rosnode list