Platform: Ubuntu 14.04 & ROS Indigo
NOTICE! This is only a rough summary of ROS tutorials. For further details, please turn to:
http://wiki.ros.org/ROS/Tutorials
目录
Installing and Configuring Your ROS Environment
Installation
Configure your Ubuntu repositories
- restricted
- universe
- multiverse
Setup your sources.list
sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
Set up your keys
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
Installation
sudo apt-get update && sudo apt-get install dpkg
sudo apt-get install ros-indigo-desktop-full
换源以获得更快的下载速度,详见:
Initialize rosdep
sudo rosdep init
rosdep update
Environment setup
echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrc source ~/.bashrc
Getting rosinstall
sudo apt-get install python-rosinstall
Check Your Environment
printenv | grep ROS
Create a ROS Workspace
mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/
catkin_make
source devel/setup.bash
Navigating the ROS Filesystem
Filesystem Tools
help info
<ros_tools> -h
rospack
rospack find [package_name]
roscd
roscd [locationname[/subdir]]
roscd log
rosls
rosls [locationname[/subdir]]
Creating a ROS Package
What makes up a catkin Package?
my_package/
CMakeLists.txt
package.xml
Packages in a catkin Workspace
workspace_folder/ -- WORKSPACE
src/ -- SOURCE SPACE
CMakeLists.txt -- 'Toplevel' CMake file, provided by catkin
package_1/
CMakeLists.txt -- CMakeLists.txt file for package_1
package.xml -- Package manifest for package_1
...
package_n/
CMakeLists.txt -- CMakeLists.txt file for package_n
package.xml -- Package manifest for package_n
Creating a catkin Package
cd ~/catkin_ws/src
catkin_create_pkg <package_name> [depend1] [depend2] [depend3]
Building a catkin workspace and sourcing the setup file
cd ~/catkin_ws
catkin_make
. ~/catkin_ws/devel/setup.bash
注:<.>的作用同source
package dependencies
First-order dependencies
rospack depends1 beginner_tutorials
Indirect dependencies
rospack depends beginner_tutorials
Customizing the package.xml
description tag
<description>The beginner_tutorials package</description>
maintainer tags
<maintainer email="[email protected]">user</maintainer>
license tags
<license>TODO</license>
dependencies tags
<buildtool_depend>catkin</buildtool_depend>
<build_depend>roscpp</build_depend>
<build_depend>rospy</build_depend>
<build_depend>std_msgs</build_depend>
<exec_depend>roscpp</exec_depend>
<exec_depend>rospy</exec_depend>
<exec_depend>std_msgs</exec_depend>
Building a ROS Package
Using catkin_make
cd ~/catkin_ws/
catkin_make
catkin_make install
Understanding ROS Nodes
Quick Overview of Graph Concepts
- Nodes: A node is an executable that uses ROS to communicate with other nodes.
- Messages: ROS data type used when subscribing or publishing to a topic.
- Topics: Nodes can publish messages to a topic as well as subscribe to a topic to receive messages.
- Master: Name service for ROS (i.e. helps nodes find each other)
- rosout: ROS equivalent of stdout/stderr
- roscore: Master + rosout + parameter server (parameter server will be introduced later)
Nodes
A node really isn’t much more than an executable file within a ROS package. ROS nodes use a ROS client library to communicate with other nodes. Nodes can publish or subscribe to a Topic. Nodes can also provide or use a Service.
roscore
roscore
Using rosnode
rosnode list
rosnode info /rosout
rosnode ping [node_name]
Using rosrun
rosrun [package_name] [node_name]
rosrun [package_name] [node_name] __name:=[custom_node_name]
Understanding ROS Topics
Using rqt_graph
rosrun rqt_graph rqt_graph
Introducing rostopic
- rostopic bw display bandwidth used by topic
- rostopic echo print messages to screen
- rostopic hz display publishing rate of topic
- rostopic list print information about active topics
- rostopic pub publish data to topic
- rostopic type print topic type
Using rostopic echo
rostopic echo [topic]
Using rostopic list
rostopic list [topic]
Using rostopic type
rostopic type [topic]
Using rostopic pub
rostopic pub [topic] [msg_type] [args]
Using rostopic hz
rostopic hz [topic]
Using rqt_plot
rosrun rqt_plot rqt_plot
Understanding ROS Services and Parameters
ROS Services
Services are another way that nodes can communicate with each other. Services allow nodes to send a request and receive a response.
Using rosservice
- rosservice list print information about active services
- rosservice call call the service with the provided args
- rosservice type print service type
- rosservice find find services by service type
- rosservice uri print service ROSRPC uri
rosservice list
rosservice list
rosservice type
rosservice type [service]
rosservice call
rosservice call [service] [args]
Using rosparam
- rosparam set set parameter
- rosparam get get parameter
- rosparam load load parameters from file
- rosparam dump dump parameters to file
- rosparam delete delete parameter
- rosparam list list parameter names
rosparam list
rosparam list
rosparam set and rosparam get
rosparam set [param_name] rosparam get [param_name]
rosparam dump and rosparam load
rosparam dump [file_name] [namespace] rosparam load [file_name] [namespace]
Using rqt_console and roslaunch
Using rqt_console and rqt_logger_level
rosrun rqt_console rqt_console
rosrun rqt_logger_level rqt_logger_level
Using roslaunch
roslaunch [package] [filename.launch]
The Launch File
<launch>
<group ns="turtlesim1">
<node pkg="turtlesim" name="sim" type="turtlesim_node"/>
</group>
<group ns="turtlesim2">
<node pkg="turtlesim" name="sim" type="turtlesim_node"/>
</group>
<node pkg="turtlesim" name="mimic" type="mimic">
<remap from="input" to="turtlesim1/turtle1"/>
<remap from="output" to="turtlesim2/turtle1"/>
</node>
</launch>
Using rosed to edit files in ROS
Using rosed
rosed [package_name] [filename]
Editor
The default editor for rosed is vim. The more beginner-friendly editor nano is included with the default Ubuntu install. You can use it by editing your ~/.bashrc file to include:
export EDITOR='nano -w'
Creating a ROS msg and srv
Introduction to msg and srv
- msg: msg files are simple text files that describe the fields of a ROS message. They are used to generate source code for messages in different languages.
- srv: an srv file describes a service. It is composed of two parts: a request and a response.
Using msg
roscd beginner_tutorials
mkdir msg
echo "int64 num" > msg/Num.msg
Open & eidt package.xml:
<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>
Open & eidt CMakeLists.txt:
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs message_generation )
catkin_package( ... CATKIN_DEPENDS message_runtime ... ...)
add_message_files(
FILES
Num.msg
)
generate_messages( DEPENDENCIES std_msgs )
Using rosmsg
rosmsg show [message type]
Using srv
Creating a srv
roscd beginner_tutorials
mkdir srv
Open & eidt package.xml:
<build_depend>message_generation</build_depend> <exec_depend>message_runtime</exec_depend>
Open & eidt CMakeLists.txt:
find_package(catkin REQUIRED COMPONENTS roscpp rospy std_msgs message_generation )
add_service_files( FILES AddTwoInts.srv )
Using rossrv
rossrv show <service type>
Writing a Simple Publisher and Subscriber (Python)
Writing the Publisher Node
roscd beginner_tutorials
The Code
mkdir scripts
cd scripts
nano talker.py
#!/usr/bin/env python
# license removed for brevity
import rospy
from std_msgs.msg import String
def talker():
pub = rospy.Publisher('chatter', String, queue_size=10)
rospy.init_node('talker', anonymous=True)
rate = rospy.Rate(10) # 10hz
while not rospy.is_shutdown():
hello_str = "hello world %s" % rospy.get_time()
rospy.loginfo(hello_str)
pub.publish(hello_str)
rate.sleep()
if __name__ == '__main__':
try:
talker()
except rospy.ROSInterruptException:
pass
chmod +x talker.py
Writing the Subscriber Node
The Code
roscd beginner_tutorials/scripts/
nano listener.py
#!/usr/bin/env python
import rospy
from std_msgs.msg import String
def callback(data):
rospy.loginfo(rospy.get_caller_id() + "I heard %s", data.data)
def listener():
# In ROS, nodes are uniquely named. If two nodes with the same
# name are launched, the previous one is kicked off. The
# anonymous=True flag means that rospy will choose a unique
# name for our 'listener' node so that multiple listeners can
# run simultaneously.
rospy.init_node('listener', anonymous=True)
rospy.Subscriber("chatter", String, callback)
# spin() simply keeps python from exiting until this node is stopped
rospy.spin()
if __name__ == '__main__':
listener()
chmod +x listener.py
Building your nodes
cd ~/catkin_ws
catkin_make
Examining the Simple Publisher and Subscriber
roscore
rosrun beginner_tutorials talker.py
rosrun beginner_tutorials listener.py
Writing a Simple Service and Client (Python)
Writing a Service Node
roscd beginner_tutorials
The Code
#!/usr/bin/env python
from beginner_tutorials.srv import AddTwoInts,AddTwoIntsResponse
import rospy
def handle_add_two_ints(req):
print "Returning [%s + %s = %s]"%(req.a, req.b, (req.a + req.b))
return AddTwoIntsResponse(req.a + req.b)
def add_two_ints_server():
rospy.init_node('add_two_ints_server')
s = rospy.Service('add_two_ints', AddTwoInts, handle_add_two_ints)
print "Ready to add two ints."
rospy.spin()
if __name__ == "__main__":
add_two_ints_server()
Writing the Client Node
The Code
#!/usr/bin/env python
import sys
import rospy
from beginner_tutorials.srv import *
def add_two_ints_client(x, y):
rospy.wait_for_service('add_two_ints')
try:
add_two_ints = rospy.ServiceProxy('add_two_ints', AddTwoInts)
resp1 = add_two_ints(x, y)
return resp1.sum
except rospy.ServiceException, e:
print "Service call failed: %s"%e
def usage():
return "%s [x y]"%sys.argv[0]
if __name__ == "__main__":
if len(sys.argv) == 3:
x = int(sys.argv[1])
y = int(sys.argv[2])
else:
print usage()
sys.exit(1)
print "Requesting %s+%s"%(x, y)
print "%s + %s = %s"%(x, y, add_two_ints_client(x, y))
Building your nodes
cd ~/catkin_ws
catkin_make
Examining the Simple Service and Client
Running the Service
rosrun beginner_tutorials add_two_ints_server.py
Running the Client
rosrun beginner_tutorials add_two_ints_client.py 1 3
Recording and playing back data
Recording all published topics
mkdir ~/bagfiles cd ~/bagfiles rosbag record -a
Examining and playing the bag file
rosbag info <your bagfile>
rosbag play <your bagfile>
Recording a subset of the data
rosbag record [topic1] [topic2]
Getting started with roswtf
roswtf

Awesome post! Keep up the great work! 🙂