training class fileros day 1 progression install ros create workspace add “resources” create...

45
ROS-Industrial Basic Developer’s Training Class Southwest Research Institute 1

Upload: others

Post on 30-Oct-2019

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

ROS-Industrial Basic Developer’s Training Class

Southwest Research Institute

1

Page 2: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Session 2: ROS Basics Continued

Southwest Research Institute

2

Page 3: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Outline

• Services

• Actions

• Launch Files

• Parameters

3

Page 4: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

ROS

Day 1 Progression

Install ROS

Create Workspace

Add “resources”

Create Package

Create Node Basic ROS Node

Interact with other nodes Messages

Services

Run Node rosrun

roslaunch

Catkin Workspace

My Package

Node

Resource

Package

4

Page 5: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Services

5

Page 6: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Services : Overview

6

Services are like Function Calls

My Application

Client

Forward Kinematics

Server

Joint Pos: [J1, J2, ...]

Request

ToolPos: [X, Y, Z, ...]

Response

Page 7: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Services: Details

• Each Service is made up of 2 components: – Request : sent by client, received by server

– Response : generated by server, sent to client

• Call to service blocks in client – Code will wait for service call to complete

– Separate connection for each service call

• Typical Uses: – Algorithms: kinematics, perception

– Closed-Loop Commands: move-to-position, open gripper

7

Page 8: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Services: Syntax

• Service definition – Defines Request and Response data types

• Either/both data type(s) may be empty. Always receive “completed” handshake.

– Auto-generates C++ Class files (.h/.cpp), Python, etc.

8

#Locate Part string base_frame --- geometry_msgs/Pose pose

LocatePart.srv

Request Data

Divider

Response Data

Comment

Page 9: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

“Real World” – Services

• Use rqt_srv / rqt_msg to view: – moveit_msgs/GetPositionIK

– roscpp/SetLoggerLevel

– moveit_msgs/GetMotionPlan

9

Page 10: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

• Service Server

– Defines associated Callback Function

– Advertises available service (Name, Data Type)

Services: Syntax

10

bool findPart(LocatePart::Request &req, LocatePart::Response &res) {

res.pose = lookup_pose(req.base_frame);

return true;

}

ros::ServiceServer service = n.advertiseService(“find_box", findPart);

Callback Function Request Data (IN) Response Data (OUT)

Server Object Service Name Callback Ref

Page 11: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

• Service Client – Connects to specific Service (Name / Data Type)

– Fills in Request data

– Calls Service

Services: Syntax

11

ros::NodeHandle nh;

ros::ServiceClient client = nh.serviceClient<LocatePart>(“find_box");

LocatePart srv;

srv.request.base_frame = “world”;

client.call(srv);

ROS_INFO_STREAM(“Response: “ << srv.response);

Client Object Service Type Service Name

Service Data includes both Request and Response

Call Service

Page 12: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Exercise 2.0

Exercise 2.0 Creating and Using a Service

12

fake_ar_pub

vision_node

myworkcell_support

myworkcell_moveit_cfg ur5_driver

myworkcell_node

descartes_node

LocalizePart

?

Page 13: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

ROS

Day 1 Progression

Install ROS

Create Workspace

Add “resources”

Create Package

Create Node Basic ROS Node

Interact with other nodes Messages

Services

Run Node rosrun

roslaunch

Catkin Workspace

My Package

Node

Resource

Package

13

Page 14: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

14

Actions

Page 15: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Actions : Overview

15

Actions manage Long-Running Tasks

My Application Client

Robot Motion

Des

t Po

s

Server Execute Motion

Go

al

C

ance

l

Cu

rr P

os

Fee

db

ack

Succ

ess

Res

ult

Page 16: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Actions: Detail

• Each action is made up of 3 components: – Goal, sent by client, received by server

– Result, generated by server, sent to client

– Feedback, generated by server

• Non-blocking in client – Can monitor feedback or cancel before completion

• Typical Uses: – “Long” Tasks: Robot Motion, Path Planning

– Complex Sequences: Pick Up Box, Sort Widgets

16

Page 17: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Actions: Syntax

• Action definition – Defines Goal, Feedback and Result data types

• Any data type(s) may be empty. Always receive handshakes.

– Auto-generates C++ Class files (.h/.cpp), Python, etc.

17

# Command Robot Motion

traj_msgs\JointTrajectory trajectory --- int32 error_code string error_string --- uint8 status traj_msgs\JointTrajectoryPoint actual

FollowJointTrajectory.action

Goal Data

Result Data

Feedback Data

Page 18: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

“Real World” – Actions

• FollowJointTrajectoryAction – command/monitor robot trajectories

– use rqt_msg to view Goal, Result, Feedback

• Should be an Action…

– GetMotionPlan

• Should not be an Action…

– GripperCommandAction

18

Page 19: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

• Action Server – Defines Execute Callback

– Periodically Publish Feedback

– Advertises available action (Name, Data Type)

Actions: Syntax

19

void executeCB(const JointTrajectoryGoalConstPtr &goal) {

loop {

if (as_.isPreemptRequested() || !ros::ok())

as_.setPreempted();

as_.publishFeedback(…);

}

as_.setSucceeded(result_);

}

SimpleActionServer<JointTrajectoryAction> as_ (“move_robot”, &executeCB);

Callback Function Goal Data (IN)

Check for Cancel

Feedback

Result

Server Object

Action Name Callback Ref

Page 20: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

• Action Client – Connects to specific Action (Name / Data Type)

– Fills in Goal data

– Initiate Action / Waits for Result

Actions: Syntax

20

SimpleActionClient<JointTrajectoryAction> ac(“move_robot");

JointTrajectoryGoal goal;

goal.trajectory = <sequence of points>;

ac.sendGoal(goal);

ac.waitForResult();

Client Object Action Type Action Name

Goal Data

Initiate Action

Block Waiting

Page 21: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Exercise 2.1

Exercise 2.1

Creating and Using an Action

21

calcFibonacci_client Client

calcFibonacci_server

ord

er: 6

Server Calculate Fibonacci Sequence

Go

al

C

ance

l

seq

: 0 1

1

Feed

bac

k

seq

: 0 1

1 2

3

Res

ult

We’ll skip this exercise. Work through it on your own time later, if desired.

Page 22: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Message vs. Service vs. Action

22

Type Strengths Weaknesses

Message •Good for most sensors (streaming data) •One - to - Many

•Messages can be dropped without knowledge •Easy to overload system with too many messages

Service •Knowledge of missed call •Well-defined feedback

•Blocks until completion •Connection typically re-established for each service call (slows activity)

Action •Monitor long-running processes •Handshaking (knowledge of missed connection)

•Complicated

Page 23: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

23

Launch Files

Page 24: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Launch Files: Motivation

• ROS is a Distributed System

– often 10s of nodes, plus configuration data

– painful to start each node “manually”

24

Page 25: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Launch Files: Overview

25

Launch Files are like Startup Scripts

Load Robot

System

Launch File Camera Driver Load

Perception Image Processing

Nodes

Motion Planner Load

Robot Robot Control

Parameter Server

Page 26: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Launch Files: Overview

• Launch files automate system startup

• XML formatted script for running nodes and setting parameters

• Ability to pull information from other packages

• Will automatically start/stop roscore

26

Page 27: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Launch Files: Notes

• Can launch other launch files

• Executed in order, without pause or wait* * Parameters set to parameter server before nodes are launched

• Can accept arguments

• Can perform simple IF-THEN operations

• Supported parameter types:

– Bool, string, int, double, text file, binary file

27

Page 28: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Launch Files: Syntax (Basic)

• <launch> – Required outer tag

• <rosparam> or <param> – Set parameter values

– including load from file (YAML)

• <node> – start running a new node

• <include> – import another launch file

28

<launch>

<rosparam param=“/robot/ip_addr“>192.168.1.50</rosparam>

<param name="robot_description“ textfile="$(find robot_pkg)/urdf/robot.urdf"/>

<node name=“camera_1" pkg=“camera_aravis” type=“camnode" />

<node name=“camera_2" pkg=“camera_aravis“ type=“camnode“ />

<include file=“$(find robot_pkg)/launch/start_robot.launch” />

</launch>

Page 29: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Launch Files: Syntax (Adv.)

• <arg> – Pass a value into a launch file

• if= or unless= – Conditional branching

– extremely limited. True/False only (no comparisons).

• <group> – group commands, for if/unless or namespace

• <remap> – rename topics/services/etc.

29

<launch>

<arg name="robot" default="sia20" />

<arg name="show_rviz" default="true" />

<group ns="robot" >

<include file="$(find lesson)/launch/load_$(arg robot)_data.launch" />

<remap from=“joint_trajectory_action” to=“command” />

</group>

<node name="rviz" pkg="rviz" type="rviz“ if="$(arg show_rviz)“ />

</launch>

Page 30: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

“Real World” – Launch Files

• Explore a typical robot launch file

– motoman_sia20d_moveit_cfg

• moveit_planning_exec.launch

30

<launch> <rosparam command="load" file="$(find motoman_support)/config/joint_names.yaml"/><arg name="sim" default="true" /><arg name="robot_ip" unless="$(arg sim)" /><arg name="controller" unless="$(arg sim)" /><include file="$(find motoman_sia20d_moveit_config)/launch/planning_context.launch" >

<arg name="load_robot_description" value="true" /></include><group if="$(arg sim)">

<include file="$(find industrial_robot_simulator)/launch/robot_interface_simulator.launch" /></group><group unless="$(arg sim)">

<include file="$(find motoman_sia20d_support)/launch/robot_interface_streaming_sia20d.launch" ><arg name="robot_ip" value="$(arg robot_ip)"/><arg name="controller" value="$(arg controller)"/>

</include></group><node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" /><include file="$(find motoman_sia20d_moveit_config)/launch/move_group.launch">

<arg name="publish_monitored_planning_scene" value="true" /></include>

Page 31: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Exercise 2.2 - Launch Files

Exercise 2.2

31

fake_ar_pub

vision_node

myworkcell_support

myworkcell_moveit_cfg ur5_driver

myworkcell_node

descartes_node

Page 32: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

ROS

Day 1 Progression

Install ROS

Create Workspace

Add “resources”

Create Package

Create Node Basic ROS Node

Interact with other nodes Messages

Services

Run Node rosrun

roslaunch

Catkin Workspace

My Package

Node

Resource

Package

32

Page 33: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Parameters

33

Page 34: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Parameters: Overview

34

Parameters are like Global Data

\debug

\robot_1\ipAddr

\robot_2\ipAddr

\home_pos\x

\home_pos\y

\home_pos\z

Parameter Server

Node \robot_1\ipAddr: “192.168.1.21”

\home_pos: [X, Y, Z] Config File

Page 35: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

ROS Parameters

• Typically configuration-type values – robot kinematics

– workcell description

– algorithm limits / tuning

• Accessed through the Parameter Server. – Typically handled by roscore

35

roscore

ROS Master

Parameter Server

rosout logging

Page 36: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Setting Parameters

• Can set from:

– YAML Files

– Command Line

– Programs

36

manipulator_kinematics:

solver: kdl_plugin/KDLKinematics

search_resolution: 0.005

timeout: 0.005

attempts: 3

rosrun my_pkg load_robot _ip:=“192.168.1.21”

rosparam set “/debug” true

nh.setParam(“name”, “left”);

Page 37: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Parameter Datatypes

• Native Types – int, real, boolean, string

• Lists (vectors) – can be mixed type: [1, str, 3.14159]

– but typically of single type: [1.1, 1.2, 1.3]

• Dictionaries (structures) – translated to “folder” hierarchy on server

37

box

.weight

.center

.x

.y

/box/weight

/box/center/x

/box/center/y

Page 38: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Namespaces

• Folder Hierarchy allows Separation: – Separate nodes can co-exist, in different “namespaces”

– relative vs. absolute name references

38

camera_node

/left_camera Parameter Server

/left_camera/ipAddr

/left_camera/exposure

/debug

/rt_camera/ipAddr

/rt_camera/exposure

ipAddr, exposure

camera_node

/rt_camera

ipAddr, exposure

Page 39: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Parameter Commands

• rosparam

– rosparam set <key> <value> • Set parameters

– rosparam get <key> • Get parameters

– rosparam delete <key> • Delete parameters

– rosparam list • List all parameters currently set

– rosparam load <filename> [<namespace>] • Load parameters from file

39

Page 40: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Parameters: C++ API

• Accessed through ros::NodeHandle object

– also sets default Namespace for access

• Relative namespace:

• Fixed namespace:

• Private namespace:

40

ros::NodeHandle relative;

relative.getParam(“test”);

“/<ns>/test”

ros::NodeHandle fixed(“/myApp”);

fixed.getParam(“test”);

“/myApp/test”

ros::NodeHandle priv(“~”);

priv.getParam(“test”);

“/myNode/test”

Page 41: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Parameters: C++ API (cont’d)

• NodeHandle object methods – nh.hasParam(key)

Returns true if parameter exists

– nh.getParam(key, &value) Gets value, returns T/F if exists.

– nh.param(key, &value, default) Get value (or default, if doesn’t exist)

– nh.setParam(key, value) Sets value

– nh.deleteParam(key) Deletes parameter

41

Page 42: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Dynamic reconfigure

• Parameters must be read explicitly by nodes – no on-the-fly updating

– typically read only when node first started

• ROS package dynamic_reconfigure can help – nodes can register callbacks to trigger on change

– outside the scope of this class, but useful

42

Page 43: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

ROS Param Practical Examples

• Let’s see what parameters the UR5 driver uses:

– Prefix

– robot_ip_address

– max_velocity

– servoj_time

– Etc…

43

Page 44: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Exercise 2.3

Exercise 2.3 ROS Parameters

44

fake_ar_pub

vision_node

myworkcell_support

myworkcell_moveit_cfg ur5_driver

myworkcell_node

descartes_node

Param: base_frame

Page 45: Training Class fileROS Day 1 Progression Install ROS Create Workspace Add “resources” Create Package Create Node Basic ROS Node Interact with other nodes

Review/Q&A

Session 1

Intro to ROS

Installing ROS/Packages

Packages

Nodes

Messages/Topics

Session 2

Services

Actions

Launch Files

Parameters

45