ROS Robot Operating System
ROS Robot Operating System
for
AGV KGP
by
Jit Ray Chowdhury
Table of Contents
What is ROS?.......................................................................................................................................4
What is ROS not..............................................................................................................................4
ROS Distributions............................................................................................................................4
ROS and its components......................................................................................................................5
ROS Core.........................................................................................................................................5
ROS Stacks & Packages..................................................................................................................5
Packages......................................................................................................................................5
Nodes...............................................................................................................................................5
Build System....................................................................................................................................5
Command Line Tools..................................................................................................................6
Ways to communicate .....................................................................................................................6
Messages..........................................................................................................................................7
Params..............................................................................................................................................7
Launch file.......................................................................................................................................7
Debugging........................................................................................................................................8
ROS graph resources...................................................................................................................8
Rosout.........................................................................................................................................8
Simulation: Stage........................................................................................................................9
Simulation: Gazebo.....................................................................................................................9
Visualizers: rviz...........................................................................................................................9
ROS Play/Record........................................................................................................................9
glc-record....................................................................................................................................9
ROS in more details.........................................................................................................................9
ROS Meta-Filesystem.................................................................................................................9
ROSCPP....................................................................................................................................10
Messages Structure...................................................................................................................10
Services.....................................................................................................................................10
Getting started with ROS....................................................................................................................12
Create a simple node......................................................................................................................12
Why contain your node's functionality in a class?....................................................................12
Using Messages.........................................................................................................................12
Simple Publisher (C++)............................................................................................................12
Simple Subscriber (C++)..........................................................................................................14
Service Server ..........................................................................................................................16
Service Client............................................................................................................................16
Action Definitions.....................................................................................................................17
Example..............................................................................................................................................18
Launch file example.......................................................................................................................18
Stage...............................................................................................................................................18
Initializing Gazebo Simulation......................................................................................................19
Writing a Package in ROS (C++)..................................................................................................19
Communication with a P3DX robot by reading a topic ...........................................................19
Writing a ROS publisher in C++...............................................................................................20
Writing a Simple Image Publisher.................................................................................................20
Our AGV Bot......................................................................................................................................22
Install in Ubuntu 12.04 (Precise)...................................................................................................22
The Plan.........................................................................................................................................23
Miscellaneous................................................................................................................................23
Links...................................................................................................................................................24
Learn.........................................................................................................................................24
Robotics News..........................................................................................................................24
What is ROS?
ROS Distributions
Collection of stacks and roscore
Packages
Stacks
Packages
A folder that contains your code, build files, launch files, etc.
Can contain any number of nodes
'manifest.xml' lists the ROS dependencies & system deps
Should only contain code that is related
ex. laser pipeline, motor controllers, localization, SLAM, forward kinematics, Hokuyo
driver...
Nodes
Build System
Description
roscd
rosls
rosmake
roslaunch
roscreate-pkg
rosdep
roscp
rosed
rostest
Ways to communicate
Cancellation
http://www.ros.org/wiki/actionlib
Goal: For controlling the tilting laser scanner, the goal would contain the
scan parameters (min angle, max angle, speed, etc).
Feedback: For controlling the tilting laser scanner, this might be the time left
until the scan completes.
Result: For controlling the tilting laser scanner, the result might contain a
point cloud generated from the requested scan.
Messages
many standard messages already exist, new messages can be defined with a simple text file
ROS generates a data structure for new message that contains many standard stl type of
functions (size(), resize(),etc.)
Params
a parameter server that stores parameter strings & value pairs which are normally passed as
input to a program
great way to pass around a name of a topic or other info multiple nodes might need to know
Launch file
Written in XML
Asynchronous execution
Change node names, namespaces, topics, and other resource names without recompiling
Debugging
rxgraph: displays a visualization of the ROS graph the ROS nodes that are currently
running and the topics that connect them
rxplot: plot data from one or more ROS topic fields that are currently being published.
rxconsole: brings up a viewer that displays any messages being published to 'rosout'
rostopic
roswtf
rosnode
rosservice
rossrv: get the field names and field types of a service request/reply message
nodes
processes
parameters
topics
services
Rosout
ROS provides mechanisms in all languages for specifying different levels
of human-readable log messages.
The five default levels are:
1. ROS_FATAL(...)
2. ROS_ERROR(...)
3. ROS_WARN(...)
4. ROS_INFO(...)
5. ROS_DEBUG(...)
control by rxconsole
Simulation: Stage
2d simulator
Simulation: Gazebo
3d simulator
Visualizers: rviz
ROS Play/Record
glc-record
record gazebo & rviz windows at the same time to create a multi-window video
manifest.xml
CMakeLists.txt: contains ROS build rules (executables, libraries, custom build flags, etc)
ROSCPP
register at core
set up remappings
set up networking
Messages Structure
int{8,16,32,64}
float{32,64}
string
time
duration
array[]
Example: Point.msg
float64 x
float64 y
float64 z
Services
Defined in package-name/srv/*.srv.
int64 sum
build it
you will have many shared variables that you don't want to pass around as parameters
between functions (publishers,subscribers,transforms, node handles)
have a main function that instantiates the class, and then calls ros::spin() // wait for
shutdown
Using Messages
use 'rosmsg show ' to remind yourself of field names and types (or go to ros.org)
remember to include the message header file with the correct case
<mapping_msgs/CollisionMap.h>
*/
std_msgs::String msg;
std::stringstream ss;
ss << "hello world " << count;
msg.data = ss.str();
ROS_INFO("%s", msg.data.c_str());
/**
* The publish() function is how you send messages. The parameter
* is the message object. The type of this object must agree with
the type
* given as a template parameter to the advertise<>() call, as was
done
* in the constructor above.
*/
chatter_pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
++count;
}
return 0;
}
Service Server
src/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;
}
Service Client
src/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;
}
Action Definitions
Defined in ros-package/action/*.action
more at
http://www.ros.org/wiki/actionlib_tutorials/Tutorials/SimpleActionServer(ExecuteCallbackMethod)
Example
Launch file example
<launch>
<!-- load empty world -->
<include file="$(find pr2_gazebo)/pr2_empty_world.launch"/>
<!-- load planning -->
<include file="$(find sbpl_arm_planner)/launch/sbpl_planning_right_arm.launch"/>
<!-- load common nodes for motion planning tests -->
<include file="$(find
arm_navigation_tests)/tests/motion_planers/common/motion_planning_common_right_arm.
launch"/>
<!-- tuck left arm-->
<node pkg="pr2_experimental_controllers" type="tuckarm.py" args="l" output="screen" >
<param name="planner_service_name" value="/sbpl_planning/plan_path"/>
<param name="planner_id" value="435"/>
</node>
<node name="my_node" pkg="foo" type="bar">
<remap f rom="/base_laser/scan " to="scan " />
<rosparam>
usefoo : True
frameid : base_laser
</rosparam>
</node>
</launch>
Stage
http://www.ros.org/wiki/stage/Tutorials/SimulatingOneRobot
roscore
rosmake stage
src/reader.cpp
#include "ros/ros.h"
#include "nav_msgs/Odometry.h"
void callback(const nav_msgs::Odometry::ConstPtr& str)
{
printf("P3DXReader-> Reading Message %f,%f\n",
str->pose.pose.position.x, str->pose.pose.position.y);
}
int main(int argc, char **argv)
{
ros::init(argc, argv, "reader");
ros::NodeHandle n;
ros::Subscriber sub = n.subscribe("/erratic_odometry/odom", 1000,
callback);
printf("P3DX Reader initialized\n");
ros::spin();
return 0;
}
Add to CmakeLists.txt
rosbuild_add_executable(reader src/reader.cpp)
Can be used with Gazebo
roslaunch p3dx.launch
rosbuild_add_executable(publisher src/publisher.cpp)
#include
#include
#include
#include
<image_transport/image_transport.h>
<opencv/cvwimage.h>
<opencv/highgui.h>
<cv_bridge/CvBridge.h>
roscd
cd sandbox
roscreate-pkg beginner_tutorials std_msgs rospy roscpp
rospack profile
rospack find beginner_tutorials
gedit beginner_tutorials/src/helloROS.cpp
#include <iostream>
using namespace std;
int main()
{
cout<<"Hello";
return 0;
}
gedit beginner_tutorials/CMakeLists.txt
rosbuild_add_executable(hello src/helloROS.cpp)
rosmake beginner_tutorials
rosrun beginner_tutorials hello
The Plan
Param server for setting config like serial port, baudrate for various communication devices
stack Eklavya
modules as packages
packages can contain multiple nodes, msg
Miscellaneous
The TF Library (Transform Frame)
sudo apt-get install ssh ros-fuerte-turtlebot* ros-fuerte-viz
rosmsg list
rosmsg show sensor_msgs/Image
Eclipse IDE
make eclipse-project
cmake -G"Eclipse CDT4 - Unix Makefiles"
http://www.ros.org/wiki/IDEs
Links
Learn
http://www.ros.org/wiki/Courses
http://www.ros.org/wiki/ROS/Tutorials
https://alliance.seas.upenn.edu/~meam620/wiki/index.php?n=Roslab.ROSTutorials
https://wiki.nps.edu/display/~thchung/ROS+--+Gazebo+Simulator
http://www.willowgarage.com/blog/2009/12/01/ros-tutorials-turtles
http://mrl.isr.uc.pt/events/iros2012tutorial/
http://www.ros.org/wiki/tf/Tutorials
http://answers.ros.org/question/12599/ros-beginning/#18583
http://www.ros.org/wiki/turtlebot_follower/Tutorials/Demo
http://www.ros.org/wiki/Robots/TurtleBot
http://www.ros.org/wiki/APIs
http://www.ros.org/wiki/simulator_gazebo/Tutorials/StartingGazebo
http://www.ros.org/wiki/AllTutorials
http://www.ros.org/wiki/navigation/Tutorials/RobotSetup
http://www.willowgarage.com/blog/2012/01/16/capturing-accurate-camera-poses
http://www.pirobot.org/blog/0016/
http://www.ros.org/wiki/IDEs
Robotics News
http://nootrix.com/articles/
http://www.ros.org/news/robots/