Tutorial ROS (Lectura 2)
Tutorial ROS (Lectura 2)
Tutorial ROS (Lectura 2)
Introduction to ROS
Course 2
Exercise 1 Exercise 5
Exercise 2 Exercise 3 Exercise 4
package_name package_name_msgs
§ ROS software is organized into
packages, which can contain config action
source code, launch files, Parameter files (YAML) Action definitions
configuration files, message include/package_name msg
C++ include headers Message definitions
definitions, data, and launch srv
documentation *.launch files Service definitions
§ A package that builds up src CMakeLists.txt
on/requires other packages (e.g. Source files Cmake build file
message definitions), declares test package.xml
Unit/ROS tests Package information
these as dependencies
CMakeLists.txt
To create a new package, use CMake build file
> catkin_create_pkg package_name package.xml More info
{dependencies} Package information http://wiki.ros.org/Packages
package.xml
§ The package.xml file defines the <?xml version="1.0"?>
properties of the package <package format="2">
<name>ros_package_template</name>
§ Package name <version>0.1.0</version>
<description>A template for ROS packages.</description>
§ Version number <maintainer email="pfankhauser@e…">Peter Fankhauser</maintainer>
§ Authors <license>BSD</license>
<url type="website">https://github.com/ethz-asl/ros_best_pr…</url>
§ Dependencies on other packages <author email="[email protected]">Peter Fankhauser</author>
§ … <buildtool_depend>catkin</buildtool_depend>
<depend>roscpp</depend>
<depend>sensor_msgs</depend>
</package>
More info
http://wiki.ros.org/catkin/package.xml
More info
http://catkin-tools.readthedocs.io/en/latest/verbs/catkin_config.html
https://github.com/ethz-asl/ros_best_practices/wiki#catkin-build-flags
The Eclipse
workspace
is already
set in the
provided
installation.
Recommended
1. Default (public) node handle: /namespace/topic
nh_ = ros::NodeHandle();
2. Private node handle: /namespace/node/topic
nh_private_ = ros::NodeHandle("~");
3. Namespaced node handle:
/namespace/eth/topic
nh_eth_ = ros::NodeHandle("eth");
recommended
4. Global node handle:
Not
nh_global_ = ros::NodeHandle("/"); /topic
More info
http://wiki.ros.org/roscpp/Overview/NodeHandles
Péter Fankhauser | 20.02.2018 | 15
ROS C++ Client Library (roscpp)
Logging
§ Mechanism for logging human readable text Debug Info Warn Error Fatal
!
§ Supports both printf- and stream-style formatting To see the output in the console, set the output
ROS_INFO("Result: %d", result); configuration to screen in the launch file
ROS_INFO_STREAM("Result: " << result); <launch>
<node name="listener" … output="screen"/>
§ Further features such as conditional, throttled, </launch>
delayed logging etc. More info
http://wiki.ros.org/rosconsole
http://wiki.ros.org/roscpp/Overview/Logging
Péter Fankhauser | 20.02.2018 | 16
ROS C++ Client Library (roscpp)
Subscriber
listener.cpp
my_package_node.cpp
#include <ros/ros.h>
#include "my_package/MyPackage.hpp" MyPackage.hpp Algorithm.hpp
int main(int argc, char** argv)
{ MyPackage.cpp Algorithm.cpp
ros::init(argc, argv, "my_package");
ros::NodeHandle nodeHandle("~");
class MyPackage class Algorithm
my_package::MyPackage myPackage(nodeHandle);
Main node class Class implementing the
ros::spin(); providing ROS interface algorithmic part of the
return 0;
}
(subscribers, parameters, node
timers etc.) Note: The algorithmic part of the
code could be separated in a
!
(ROS-independent) library
Specify a function handler to a method from within the class as
subscriber_ = nodeHandle_.subscribe(topic, queue_size, More info
&ClassName::methodName, this); http://wiki.ros.org/roscpp_tutorials/Tutorials/
UsingClassMethodsAsCallbacks
Péter Fankhauser | 20.02.2018 | 19
ROS Parameter Server
config.yaml
§ Nodes use the parameter server to store and
retrieve parameters at runtime camera:
left:
§ Best used for static data such as name: left_camera
exposure: 1
configuration parameters right:
name: right_camera
§ Parameters can be defined in launch files or exposure: 1.1
separate YAML files
List all parameters with package.launch
> rosparam list <launch>
<node name="name" pkg="package" type="node_type">
Get the value of a parameter with <rosparam command="load"
file="$(find package)/config/config.yaml" />
> rosparam get parameter_name </node>
</launch>
Set the value of a parameter with
> rosparam set parameter_name value More info
http://wiki.ros.org/rosparam