Beruflich Dokumente
Kultur Dokumente
Yen Chao
2015/08/06
INTRODUCTION
What is ROS?
General Concepts
WHAT IS ROS?
Robot Operating System
It provides the services you would
expect from an operating system:
hardware abstraction
low-level device control
message-passing between processes
package management
WHAT IS ROS?
ROS provides a distributed framework
of processes that enable these
processes
to be designed individually,
to be loosely coupled at runtime,
to be grouped together and be shared to
others.
ROS
Master
Register name,
message and
service
Look up
Nod
e
Topic:
A name used to identify the content of the
message.
E.g. odometry
http://robohub.org/ros-101-intro-to-the-robot-operating-
http://robohub.org/ros-101-intro-to-the-robot-operating-
SUMMARY
ROS is a flexible framework for
writing robot software with useful
tools, librariesetc.
Processes are called nodes in ROS.
Nodes communicate with each other
by
Message
Service
GETTING STARTED
Installation
Understanding Node
Understanding Message
Understanding Service
rosnode
rosnode displays information about the
ROS nodes that are currently running.
rosrun
rosrun allows you to run a node by its
name and package.
UNDERSTANDING MESSAGE :
TURLESIM
Turtle keyboard teleoperation process
rosrun turtlesim turtle_teleop_key
UNDERSTANDING MESSAGE :
RQT_GRAPH
ROS provides rqt_graph to help us
visualize whats going on between
processes.
rosrun rqt_graph rqt_graph
UNDERSTANDING MESSAGE:
ROSTOPIC
rostopic is a tool that help us to
interact with the topics.
rostopicecho
rostopic list
rostopic type [topic]
rosmsg show [msg]
rostopic pub [topic] [msg_type] [args]
UNDERSTANDING SERVICE:
ROSSERVICE
Service:
Request/Response
SUMMARY
roscore = master + rosout +
parameter server
rosnode : ROS tool to get information
about a node.
rosrun: Run a node from a given
package.
rqt_graph : Show the relationship of
nodes.
rostopic : ROS tool to interact with
topics.
WRITING A PROGRAM
Creating a ROS Workspace
Creating a ROS Package
Creating a ROS msg
Writing a Simple Publisher and Subscriber (C++)
Creating a ROS srv
Writing a Simple Server and Client (C++)
std_msgs::String msg;
std::stringstream ss;
ss << "hello world " << count;
msg.data = ss.str();
Initialize argv,
ROS.
ros::init(argc,
listener");
ros::NodeHandle
Create a node
n; handle.
Registersubwith
the master.
ros::Subscriber
= n.subscribe("chatter",
1000, chatterCallback);
Callback function
BUILDING CODES
In CMakeLists.txt, add:
include_directories(include ${catkin_INCLUDE_DIRS})
add_executable(talker src/talker.cpp)
target_link_libraries(talker ${catkin_LIBRARIES})
add_dependencies(talker beginner_tutorials_generate_messages_cpp)
add_executable(listener src/listener.cpp)
target_link_libraries(listener ${catkin_LIBRARIES})
add_dependencies(listener beginner_tutorials_generate_messages_cpp
Build
cd ~/catkin_ws
catkin_make
SUMMARY
Create a workspace
catkin_init_workspace
Create a package
catkin_create_pkg
SUMMARY
Write a program
Initialize ROS.
ros::init(argc, argv, my_node");
ros::NodeHandle n;
add_executable(my_node src/my_node.cpp)
target_link_libraries(my_node ${catkin_LIBRARIES})
add_dependencies(my_node my_package_generate_messages_cpp
APPENDIX
MESSAGING PATTERN
Publish/Subscribe
http://zguide.zeromq.org/page:all
Request/Response
GENERAL CONCEPTS
ROS has three levels of concepts:
The File system level
The Computation Graph level
The Community level.
FILE SYSTEM
ROS resource management
Package
The main unit for organizing software in ROS (e.g. odometer).
Package manifest
Repository (rosbuild stack)
A collection of packages can be released together (e.g.
navigation).
Message type
Service type
COMPUTATION GRAPH
The peer-to-peer network of ROS processes
that are processing data together
Node
ROS Master
Parameter Server
Message
Topic
Service
Bag
INSTALLATION
You can find installation guide on
http://wiki.ros.org/ROS/Installation
The current LTS release of ROS is ROS
Indigo.
ROS IndigoONLYsupports Saucy
(13.10) and Trusty (14.04) for debian
packages.
Installation
sudo apt-get update
sudo apt-get install ros-indigo-desktop-full
Environment setup
echo "source /opt/ros/indigo/setup.bash" >> ~/.bashrc
source ~/.bashrc
Getting rosinstall
sudo apt-get install python-rosinstall
In CMakeLists.txt
Add message_generation to find package function.
Add CATKIN_DEPENDS message_runtime to catkin_package
function.
Initialize ROS.
ros::NodeHandle n;
BUILDING CODES
In CMakeLists.txt, add:
add_executable(add_two_ints_server src/add_two_ints_server.cpp)
target_link_libraries(add_two_ints_server ${catkin_LIBRARIES})
add_dependencies(add_two_ints_server
beginner_tutorials_generate_messages_cpp)
add_executable(add_two_ints_client src/add_two_ints_client.cpp)
target_link_libraries(add_two_ints_client ${catkin_LIBRARIES})
add_dependencies(add_two_ints_client
beginner_tutorials_generate_messages_cpp)
Build
cd ~/catkin_ws
catkin_make
ADD_TWO_INTS_SERVER.CPP
#include "ros/ros.h
#include "beginner_tutorials/AddTwoInts.h
bool add(beginner_tutorials::AddTwoInts::Request &req,
beginner_tutorials::AddTwoInts::Response &res) {
res.sum = req.a + req.b;
ROS_INFO("request: x=%ld, y=%ld", (long int)req.a,
(long int)req.b);
ROS_INFO("sending back response: [%ld]", (long
int)res.sum);
return true;
}
int main(int argc, char **argv) {
ros::init(argc, argv, "add_two_ints_server");
ros::NodeHandle n;
ros::ServiceServer service =
n.advertiseService("add_two_ints", add);
ROS_INFO("Ready to add two ints.");
ros::spin();
return 0;
ADD_TWO_INTS_CLIENT.CPP
#include "ros/ros.h
#include "beginner_tutorials/AddTwoInts.h
#include <cstdlib>
int main(int argc, char **argv) {
ros::init(argc, argv, "add_two_ints_client");
if (argc != 3) {
ROS_INFO("usage: add_two_ints_client X Y");
return 1;
}
ros::NodeHandle n;
ros::ServiceClient client = n.serviceClient<beginner_tutorials::AddTwoInts>("add_two_ints");
beginner_tutorials::AddTwoInts srv;
srv.request.a = atoll(argv[1]);
srv.request.b = atoll(argv[2]);
if (client.call(srv)) {
ROS_INFO("Sum: %ld", (long int)srv.response.sum);
} else {
ROS_ERROR("Failed to call service add_two_ints");
return 1;
}
return 0;
}