useful ROS command memo
Create packages
Create a package:
# catkin_create_pkg <package_name> [depend1] [depend2] [depend3]
$ catkin_create_pkg pkg_name std_msgs rospy roscpp
Package dependencies are stored in package.xml Navigate to the package directory:
# roscd <package_name>
$ roscd pkg_name
Copy files from other package:
$ roscp [package_name] [file_to_copy_path] [copy_from_this_path]
Publishing and subscribing
Publish using command line
$ rostopic pub <name of the topic> <type of the topic> [args...]
# press TAB after rostopic pub <name of the topic> <type of the topic>, it auto fills the information needed
Publisher, subscriber and other examples in python are available. Download as follows:
$ wget https://raw.github.com/ros/ros_tutorials/kinetic-devel/rospy_tutorials/001_talker_listener/talker.py
$ chmod +x talker.py
$ wget https://raw.github.com/ros/ros_tutorials/kinetic-devel/rospy_tutorials/001_talker_listener/listener.py
$ chmod +x listener.py
For the Service and Client samples in the tutorial, I got error: “ImportError: No module named beginner_tutorials.srv” when trying to run it, found this link helpful.
Build workspace
Build the workspace:
$ cd ~/catkin_ws
$ catkin_make # need to do this everytime after changing the folder structure
# to build only one package
$ catkin_make [--only-pkg-with-deps]() <target_package>
Run node
After starting ROS with roscore in a terminal, Run your node in another terminal:
# rosrun <package_name> <file_name>
$ rosrun beginner_tutorials talker.py
Checking information from command line
# show all ros topic
$ rostopic list
# to check specific topic
$ rostopic list | grep <topic_name>
# show message type, subscriber, publisher
$ rostopic info <name of the topic>
# to measure the frequency of the image topic
$ rostopic hz <topic_name>
# show what is included in a topic
$ rosmsg show <a topic type>
# to display an image
$ rqt_image_view <topic_name>
# check ros launch logs (especially when there is an error), this shows the directory
$ roslaunch-logs
# to open the directory in GUI
$ nautilus <directory>
Launch file
<group>: launch a group of nodes. Use ns attribute to push nodes into a separate namespace.
<param>: <rosparam command="load" file="FILENAME" /> to load a YAML file.
<if="" name="" value="">, change a parameter to some value if a condition is meet.