42
ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September 16th, 2014

ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

  • Upload
    others

  • View
    17

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

ROS: Robot Operating System

Presented by: Anqi Xu

COMP-417, McGill UniversityTuesday September 16th, 2014

Page 2: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Overview

Features & Philosophies

Core elements Development

pipeline Useful ROS

nodes / tools

Page 3: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

What is ?

Meta operating system (or middleware) Developed and Maintained by the Open

Source Robotics Foundation (OSRF) “The primary goal of ROS is to support code

reuse in robotics research and development.”

Page 4: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

ROS Philosophies

Modular & peer-to-peer

Language independent

Thin

Free & open-source

Page 5: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

ROS Philosophy:Modularity & Peer-to-Peer

Page 6: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

ROS Philosophy:Language Independence

Client interfaces: Stable: rospy, roscpp, roslisp Experimental: rosjava, roslua Contributed: rosserial (Arduino), roshask, ros4mat

(MATLAB), ros4ios, etc... Common message-passing layer

Interface Definition Language (IDL)

Page 7: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

ROS Philosophy: Thin

Library-style interaction Facilitates integration with other common libraries,

e.g.: OpenCV, PCL, bullet, etc... Minimal dependencies

Linked against (lean) ROS core + necessary message meta-libraries + specific libraries

“The preferred development model is to write ROS-agnostic libraries with clean functional interfaces.”

Page 8: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

ROS Philosophy:Free & Open-Source

Source code publicly available ROS Core & first-party tools under BSD

license Contributed tools under variety of open-source

(& few closed-source) licenses Promotes code-reuse and community-building

Page 9: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

ROS: Core Elements

Nodes Messages, topics, and services ROS Master (Parameters) Bags

Page 10: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Nodes

Single-purposed executable programs e.g. sensor driver(s), actuator driver(s), mapper,

planner, UI, etc... Modular design

Individually compiled, executed, and managed Nodelets

Page 11: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Messages

Strictly-typed data structures for inter-node communication

Interface Definition Language (IDL) Basic types: bool, [u]int{8,16,32,64},

float{32/64}, string, time, duration, etc... Arrays Nested messages: image, GPS, IMU, etc...

Page 12: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Topics

Unidirectional (& often repeated) inter-node communication

Publish/Subscribe model: 1-to-N broadcasting Examples:

– provide sensor readings– provide actuator states / robot feedback

Page 13: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Services

Synchronous inter-node transactions / RPC Service/Client model: 1-to-1 request-response Examples:

– carry out remote computation– trigger functionality / behavior– update dynamic parameter

Page 14: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

ROS Master

Naming & registration services for nodes, topics, services, etc...

“The role of the Master is to enable ROS nodes to locate one another.”

Critical environment variable: $ROS_MASTER_URI=http://[HOST]:[PORT]

Page 15: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

ROS: Topic Subscription

(0)

(1)

(2)

(3)(4)(5)

(6)

Page 16: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

ROS: Service Call

Page 17: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

ROS Parameters

Configurable setting Node-specific Launch-time

Unique name Typed(XMLRPC) Can beremapped atruntime

Page 18: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

ROS Bags

Standardized logging & playback mechanism Single-file container for serialized messages

Playback using simulated / real clock (Near-)real-time message playback (w/ < ~1ms

offsets due to file IOs during bagging)

Page 19: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

rosbuild vs. catkin

rosbuild: highly customized CMake-derived build toolchain (fuerte or older distro, uses rosmake) Stack: collection of packages with single theme (e.g.

for a single platform, from a single lab, etc…); requires stack.xml

catkin: near-stock Cmake build toolchain (groovy or later distro, uses catkin_make) Meta-package: any folder with one or more packages Catkin workspace = single CMake project; all

include subfolders are shared! “Rising tide”

Page 20: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

rosbuild vs. catkin (cont.)

rosbuild workspace

catkin workspace

How to tell them apart? manifest.xml = rosbuild; package.xml = catkin

Page 21: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

ROS Development Pipeline

Navigate: roscd, rosed

Setup: catkin_init_workspace, catkin_create_pkg

Configure: package.xml, CmakeLists.txt

Build: catkin_make

Execute: roscore, rosrun, roslaunch (, rosparam)

Inspect: rosnode, rostopic, rosservice

Debug: roswtf, rqt_graph (, rostest)

Log & Analyze: rosbag, rqt_bag

Page 22: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Navigate: roscd / rosed

Provides fast navigation to ROS folders / files

roscd stage rosed wall_follow wall_follower.py export EDITOR='emacs -nw'

Page 23: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Setup: catkin_create_pkg

Creates ROS catkin package catkin_create_pkg my_catkin_pkg roscpp std_msgs

←compiled binaries←CMake build folder←dynamic reconfigure settings←C++ headers / auto-generated headers←roslaunch files

←message types←Python nodes

←C++ source files← service types

← CMake project file← ros.org documentation page (rosbuild)

← CMake-generated makefile← node settings / dependencies (rosbuild)

Page 24: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Configure: package.xml Lists properties and ROS node dependencies

<package><name>camera_calibration</name><version>1.11.6</version><description> camera_calibration allows easy calibration of cameras […] </description><author>James Bowman</author><author>Patrick Mihelich</author><maintainer email="[email protected]">Vincent Rabaud</maintainer>

<buildtool_depend version_gte="0.5.68">catkin</buildtool_depend>

<test_depend>rostest</test_depend>

<run_depend>cv_bridge</run_depend><run_depend>image_geometry</run_depend><run_depend>message_filters</run_depend><run_depend>opencv2</run_depend><run_depend>rospy</run_depend><run_depend>std_srvs</run_depend><run_depend>sensor_msgs</run_depend>

<license>BSD</license><url>http://www.ros.org/wiki/camera_calibration</url>

<export><rosdoc config="rosdoc.yaml" />

</export></package>

Page 25: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Configure: CMakeLists.txt

Configures build environment & lists non-ROS dependencies

cmake_minimum_required(VERSION 2.8.3)project(my_catkin_package)

find_package(catkin REQUIRED)find_package(Boost REQUIRED COMPONENTS system)

add_message_files( FILES Message1.msg Message2.msg )add_service_files( FILES Service1.srv Service2.srv )generate_messages( DEPENDENCIES std_msgs )

catkin_package(INCLUDE_DIRS includeLIBRARIES my_catkin_packageCATKIN_DEPENDS other_catkin_pkgDEPENDS system_lib

)

include_directories(include)

add_library(my_library src/${PROJECT_NAME}/lib.cpp )

add_executable(my_node src/node.cpp)add_dependencies(my_node

my_catkin_package_generate_messages_cpp)target_link_libraries(my_node

${catkin_LIBRARIES} {Boost_LIBRARIES} my_library)

install(TARGETS my_library my_nodeARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION}RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION}

)install(DIRECTORY include/${PROJECT_NAME}/

DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION}FILES_MATCHING PATTERN "*.h"PATTERN ".svn" EXCLUDE

)

catkin_add_gtest(${PROJECT_NAME}-test test/test_my_node.cpp)if(TARGET ${PROJECT_NAME}-test)

target_link_libraries(${PROJECT_NAME}-test ${PROJECT_NAME})endif()

Page 26: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Build: catkin_make

Builds all ROS nodes in catkin workspace All include folders from packages are shared, so

use subfolders to prevent name clashes (e.g. catkin_ws/my_pkg/include/my_pkg/file.h)

rosmake alternative: rosmake wall_follow ~= roscd wall_follow; mkdir build; cd build;

cmake ..

Page 27: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Build: catkin_make

Builds all ROS nodes in catkin workspace All include folders from packages are shared, so

use subfolders to prevent name clashes (e.g. catkin_ws/my_pkg/include/my_pkg/file.h)

Page 28: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Execute: roscore

Starts ROS master Only 1 master per machine Hostname (cat /etc/hostname) must be defined in

/etc/hosts

Connecting to another ROS master over network Both hostnames defined in both machines’ /etc/hosts export ROS_MASTER_URI=http://remote:11311

Page 29: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Execute: rosrun

Executes ROS node– namespace remappings– node-specific parameters (use '--' to delineate)

rosrun image_view image_view image:=/camera/image_raw -- compressed

Page 30: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Execute: roslaunch

Executes multiple ROS nodes concurrently Launch files should have .launch extension, to be

indexed automatically Will initialize ROS master automatically if needed

roslaunch image_proc image_proc.launch<roslaunch><namespace “galapagos”>

<node pkg=”turtlesim” node=”turtlesim_node” required=”true” /><node pkg=”turtlesim” node=”turtle_teleop_key” output=”screen”><param name=“scale_linear” value=“100.0” />

</node></namespace>

</roslaunch>

Page 31: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Execute: rosparam

Absolute parameters: /node/param Local parameters: ~param YAML syntax

rosparam list rosparam set /foo "['1', 1, 1.0]"

rosrun camera1394 camera1394_node __video_mode=”640x480_mono8”

Page 32: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Inspect: rosnode, rostopic, rosservice

Lists nodes/topics/services and provides information on their states

rosnode list rostopic echo /turtle1/pose rostopic pub -1 /text_listener std_msgs/String --

"Hello World" rostopic hz /camera/image_raw rosservice call /kill

Page 33: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Debug: rostest

Executes unit test on ROS node– C++: gtest, Python: unittest– In CmakeLists.txt:

catkin_add_gtest(test1 test/test1.cpp)– ROSLaunch: <test test-name=”test1”

pkg=”my_pkg” type=”test1” />

rostest mypkg test1.test

Page 34: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Debug: Python unittest

#!/usr/bin/env pythonPKG = 'mypkg'import roslib; roslib.load_manifest(PKG)

import sysimport unittest

## A sample python unit testclass TestBareBones(unittest.TestCase):

## test 1 == 1def test_one_equals_one(self):

self.assertEquals(1, 1, "1!=1")

if __name__ == '__main__':import rostestrostest.rosrun(PKG, 'test_bare_bones', TestBareBones)

Page 35: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Debug: roswtf & rqt_graph

roswtf: finds trivial mistakes (e.g. ROS node not responding, missing publisher, etc...)

rqt_graph: visualize nodes & messages

Page 36: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Log & Analyze: rosbag

Records and plays back sets of messages

rosbag record -a rosbag record rosout tf turtle1/pose rosbag play -r 1.5 -s 30 -l yesterday.bag rosbag compress *.bag rosbag reindex *.bag

Page 37: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Log & Analyze: rqt_bag

GUI for visualizing rosbag content

Page 38: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Tool: rqt_reconfigure

Changes parameters dynamically in runtime– NOT the same as (static) ROS parameters!

rosrun rqt_reconfigure rqt_reconfigure

Page 39: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Tools: rviz

Fully-featured 3D visualization environment

Page 40: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Tools: tf

Abstraction & manipulation of multiple coordinate frames

– (Timed) conversion between different frames– Distributed broadcaster/listener model

Page 41: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Tool: actionlib

Lengthy / complex /multi-step services– Goal: desired end-result– Feedback: incremental progress towards goal– Result: feedback upon completion of goal

Page 42: ROS: Robot Operating System - McGill CIMdudek/417/comp417_fall2014_intro_ros.pdf · ROS: Robot Operating System Presented by: Anqi Xu COMP-417, McGill University Tuesday September

Next Steps

wiki.ros.org/ROS/Tutorials answers.ros.org [email protected]