Programming For Robotics ROS For Beginners - ETH Z

Transcription

Programming for RoboticsIntroduction to ROSCourse 1Dominic Jud, Martin Wermelinger, Marko Bjelonic, Péter FankhauserProf. Dr. Marco HutterDominic Jud 18.02.2019 1

Overview Course 1 ROS architecture & philosophyROS master, nodes, and topicsConsole commandsCatkin workspace and build systemLaunch-filesGazebo simulator Course 2 ROS package structureIntegration and programming with EclipseROS C client library (roscpp)ROS subscribers and publishersROS parameter serverRViz visualization Course 3 TF Transformation Systemrqt User InterfaceRobot models (URDF)Simulation descriptions (SDF) Course 5 Case study Course 4 ROS servicesROS actions (actionlib)ROS timeROS bagsDominic Jud 18.02.2019 2

Course StructureCourse 1Course 2Course 3Course 4Course 5Deadline for Ex. 1.Deadline for Ex. 2.Deadline for Ex. 3.Deadline for Ex. 4.Lecture 2Lecture 3Lecture 4Multiple Choice TestExercise 2 Intro.Exercise 3 Intro.Exercise 4 Intro.Lecture 1Exercise 1 Intro.Case StudyExercise 5 Intro.Exercise 1Exercise 2Exercise 3Exercise 4Exercise 5Deadline for Ex. 5.Dominic Jud 18.02.2019 3

Evaluation – Exercises Each exercise has several check questions Each exercise counts for 10% of the final grade (50 % in total) We encourage team work, but every student has to show the results on his ownPC and is evaluated individually Exercises are checked by the teaching assistants when you are ready, but latestthe following course day in the morning (08:15–08:45, except for exercise 5) Let the teaching assistant know once you are ready to present your results The lectures start at 08:45Dominic Jud 18.02.2019 4

Evaluation – Multiple Choice Test The test counts for 50 % of the final grade The multiple choice test takes place at the last course day:01.03.2019 at 08:45, HG G1Dominic Jud 18.02.2019 5

Overview Course 1 ROS architecture & philosophyROS master, nodes, and topicsConsole commandsCatkin workspace and build systemLaunch-filesGazebo simulatorDominic Jud 18.02.2019 6

What is ROS?ROS Robot Operating Systemros.org Processmanagement Inter-processcommunication Device drivers Simulation Visualization Graphical userinterface Data logging ControlPlanningPerceptionMappingManipulation Package organizationSoftware distributionDocumentationTutorialsDominic Jud 18.02.2019 7

History of ROS Originally developed in 2007 at theStanford Artificial IntelligenceLaboratory Since 2013 managed by OSRF Today used by many robots,universities and companies De facto standard for robotprogrammingros.orgDominic Jud 18.02.2019 8

ROS Philosophy Peer to peerIndividual programs communicate over defined API (ROS messages, services, etc.). DistributedPrograms can be run on multiple computers and communicate over the network. Multi-lingualROS modules can be written in any language for which a client library exists (C , Python,MATLAB, Java, etc.). Light-weightStand-alone libraries are wrapped around with a thin ROS layer. Free and open-sourceMost ROS software is open-source and free to use.Dominic Jud 18.02.2019 9

ROS Master Manages the communication between nodes (processes) Every node registers at startup with the masterROS MasterStart a master with roscoreMore infohttp://wiki.ros.org/MasterDominic Jud 18.02.2019 10

ROS Nodes Single-purpose, executable program Individually compiled, executed, andmanaged Organized in packagesRun a node withROS MasterRegistrationNode 1RegistrationNode 2 rosrun package name node nameSee active nodes with rosnode listRetrieve information about a node with rosnode info node nameMore infohttp://wiki.ros.org/rosnodeDominic Jud 18.02.2019 11

ROS TopicsROS Master Nodes communicate over topics Nodes can publish or subscribe to a topic Typically, 1 publisher and n subscribersRegistrationInforms aboutconnection Topic is a name for a stream of messagesNode 1List active topics with rostopic listSubscribe and print the contents of a topic withRegistrationMessagesPublisherPublishNode 2SubscribertopicSubscribeSubscribe rostopic echo /topicShow information about a topic with rostopic info /topicMore infohttp://wiki.ros.org/rostopicDominic Jud 18.02.2019 12

ROS Messages Data structure defining the type of a topic Comprised of a nested structure of integers,floats, booleans, strings etc. and arrays ofobjects Defined in *.msg filesROS MasterRegistrationRegistrationNode 1Node 2PublisherSubscriberSee the type of a topic rostopic type /topicPublishSubscribePublish a message to a topic rostopic pub /topic type datatopicSubscribe*.msgMessage definitionint numberdouble widthstring descriptionetc.More infohttp://wiki.ros.org/MessagesDominic Jud 18.02.2019 13

ROS MessagesPose Stamped Examplegeometry msgs/Point.msgfloat64 xfloat64 yfloat64 zsensor msgs/Image.msgstd msgs/Header headeruint32 seqtime stampstring frame iduint32 heightuint32 widthstring encodinguint8 is bigendianuint32 stepuint8[] datageometry msgs/PoseStamped.msgstd msgs/Header headeruint32 seqtime stampstring frame idgeometry msgs/Pose posegeometry msgs/Point positionfloat64 xfloat64 yfloat64 zgeometry msgs/Quaternion orientationfloat64 xfloat64 yfloat64 zfloat64 wDominic Jud 18.02.2019 14

ExampleConsole Tab Nr. 1 – Starting a roscoreStart a roscore with roscoreDominic Jud 18.02.2019 15

ExampleConsole Tab Nr. 2 – Starting a talker nodeRun a talker demo node with rosrun roscpp tutorials talkerDominic Jud 18.02.2019 16

ExampleConsole Tab Nr. 3 – Analyze talker nodeSee the list of active nodes rosnode listShow information about the talker node rosnode info /talkerSee information about the chatter topic rostopic info /chatterDominic Jud 18.02.2019 17

ExampleConsole Tab Nr. 3 – Analyze chatter topicCheck the type of the chatter topic rostopic type /chatterShow the message contents of the topic rostopic echo /chatterAnalyze the frequency rostopic hz /chatterDominic Jud 18.02.2019 18

ExampleConsole Tab Nr. 4 – Starting a listener nodeRun a listener demo node with rosrun roscpp tutorials listenerDominic Jud 18.02.2019 19

ExampleConsole Tab Nr. 3 – AnalyzeSee the new listener node with rosnode listShow the connection of the nodes over thechatter topic with rostopic info /chatterDominic Jud 18.02.2019 20

ExampleConsole Tab Nr. 3 – Publish Message from ConsoleClose the talker node in console nr. 2 with Ctrl CPublish your own message with rostopic pub /chatter std msgs/String"data: 'ETH Zurich ROS Course'"Check the output of the listener in console nr. 4Dominic Jud 18.02.2019 21

ROS Workspace Environment Defines context for the current workspace Default workspace loaded with source /opt/ros/kinetic/setup.bashThis isalreadysetup in theprovidedinstallation.Overlay your catkin workspace with cd /catkin ws source devel/setup.bashSee setup with cat /.bashrcCheck your workspace with echo ROS PACKAGE PATHMore uhttp://wiki.ros.org/catkin/workspacesDominic Jud 18.02.2019 22

catkin Build System catkin is the ROS build system to generateexecutables, libraries, and interfaces We suggest to use the Catkin Command Line Tools Use catkin build instead of catkin makeNavigate to your catkin workspace withThe catkincommand linetools are preinstalled in theprovidedinstallation. cd /catkin wsBuild a package with catkin build package name!Whenever you build a new package, update your environment source devel/setup.bashMore tkin-tools.readthedocs.io/Dominic Jud 18.02.2019 23

catkin Build SystemThe catkin workspace contains the following spacesWork hereThe source space containsthe source code. This is whereyou can clone, create, andedit source code for thepackages you want to build.Don’t touchThe build space is whereCMake is invoked to build thepackages in the sourcespace. Cache information andother intermediate files arekept here.Don’t touchThe development (devel)space is where built targetsare placed (prior to beinginstalled).If necessary, clean the entire build and devel space with catkin cleanMore infohttp://wiki.ros.org/catkin/workspacesDominic Jud 18.02.2019 24

catkin Build SystemThe catkin workspace setup can be checked with catkin configFor example, to set the CMake build type to Release(or Debug etc.), use catkin build --cmake-args-DCMAKE BUILD TYPE ReleaseMore erbs/catkin atest/cheat sheet.htmlAlreadysetup in theprovidedinstallation.Dominic Jud 18.02.2019 25

ExampleOpen a terminal and browse to your git folderhttps://github.com/leggedrobotics/ros best practices cd /gitClone the Git repository with git clone https://github.com/leggedrobotics/ros best practices.gitSymlink the new package to your catkin workspace ln -s /git/ros best practices/ /catkin ws/src/Note: You could also directly clone to your catkin workspace, but using acommon git folder is convenient if you have multiple catkin workspaces.Dominic Jud 18.02.2019 26

ExampleGo to your catkin workspace cd /catkin wsBuild the package with catkin build ros package templateRe-source your workspace setup source devel/setup.bashLaunch the node with roslaunch ros package templateros package template.launchDominic Jud 18.02.2019 27

ROS LaunchExample console output forroslaunch roscpp tutorials talker listener.launch launch is a tool for launching multiple nodes(as well as setting parameters) Are written in XML as *.launch files If not yet running, launch automatically startsa roscoreBrowse to the folder and start a launch file with roslaunch file name.launchStart a launch file from a package with roslaunch package name file name.launchMore infohttp://wiki.ros.org/roslaunchDominic Jud 18.02.2019 28

ROS LaunchFile Structuretalker listener.launch!Attention when copy & pasting code from the internet launch node name "listener" pkg "roscpp tutorials" type "listener" output "screen"/ node name "talker" pkg "roscpp tutorials" type "talker" output "screen"/ /launch !Notice the syntax differencefor self-closing tags: tag /tag and tag/ launch: Root element of the launch filenode: Each node tag specifies a node to be launchedname: Name of the node (free to choose)pkg: Package containing the nodetype: Type of the node, there must be a corresponding executable with the same nameoutput: Specifies where to output log messages (screen: console, log: log file)More 20larger%20projectsDominic Jud 18.02.2019 29

ROS LaunchArgumentsrange world.launch (simplified) Create re-usable launch files with arg tag,which works like a parameter (default optional) arg name "arg name" default "default value"/ Use arguments in launch file with (arg arg name) When launching, arguments can be set with roslaunch launch file.launch arg name: value ?xml version "1.0"? launch arg name "use sim time" default "true"/ arg name "world" default "gazebo ros range"/ arg name "debug" default "false"/ arg name "physics" default "ode"/ group if " (arg use sim time)" param name "/use sim time" value "true" / /group include file " (find gazebo ros)/launch/empty world.launch" arg name "world name" value " (find gazebo plugins)/test/test worlds/ (arg world).world"/ arg name "debug" value " (arg debug)"/ arg name "physics" value " (arg physics)"/ /include /launch More infohttp://wiki.ros.org/roslaunch/XML/argDominic Jud 18.02.2019 30

ROS LaunchIncluding Other Launch Filesrange world.launch (simplified) Include other launch files with include tag toorganize large projects include file "package name"/ Find the system path to other packages with (find package name) Pass arguments to the included file arg name "arg name" value "value"/ ?xml version "1.0"? launch arg name "use sim time" default "true"/ arg name "world" default "gazebo ros range"/ arg name "debug" default "false"/ arg name "physics" default "ode"/ group if " (arg use sim time)" param name "/use sim time" value "true" / /group include file " (find gazebo ros)/launch/empty world.launch" arg name "world name" value " (find gazebo plugins)/test/test worlds/ (arg world).world"/ arg name "debug" value " (arg debug)"/ arg name "physics" value " (arg physics)"/ /include /launch More ic Jud 18.02.2019 31

Gazebo Simulator Simulate 3d rigid-body dynamicsSimulate a variety of sensors including noise3d visualization and user interactionIncludes a database of many robots andenvironments (Gazebo worlds) Provides a ROS interface Extensible with pluginsObject treeToolbar (to navigate and new objects)Run Gazebo with rosrun gazebo ros gazeboPropertiesStart and pause simulationMore rialsDominic Jud 18.02.2019 32

Further References ROS Wiki http://wiki.ros.org/ Installation http://wiki.ros.org/ROS/Installation Tutorials http://wiki.ros.org/ROS/Tutorials Available packages http://www.ros.org/browse/ ROS Cheat Sheet ng-system-cheat-sheet/ https://kapeli.com/cheat ex ROS Best Practices https://github.com/leggedrobotics/ros best practices/wiki ROS Package Template https://github.com/leggedrobotics/ros bestpractices/tree/master/ros package templateDominic Jud 18.02.2019 33

Contact InformationETH ZurichRobotic Systems LabProf. Dr. Marco HutterLEE H 303Leonhardstrasse 218092 ZurichSwitzerlandLecturersDominic Jud (dominic.jud@mavt.ethz.ch)Martin Wermelinger (martin.wermelinger@mavt.ethz.ch)Marko Bjelonic (marko.bjelonic@mavt.ethz.ch)Péter Fankhauser (pfankhauser@anybotics.com)Course website: ros.htmlhttp://www.rsl.ethz.chDominic Jud 18.02.2019 34

ROS modules can be written in any language for which a client library exists (C , Python, MATLAB, Java, etc.). Light-weight Stand-alone libraries are wrapped around with a thin ROS layer. Free and open-source Most ROS software is open-source and free to use. Dominic Jud 9 ROS Philosophy 18.02.2019