ROS-I Basic Developers Training - Session 2 PDF
ROS-I Basic Developers Training - Session 2 PDF
ROS-I Basic Developers Training - Session 2 PDF
Training Class
• Services
• Actions
• Launch Files
• Parameters
3
Day 1 Progression
4
Services
5
Services : Overview
Client Server
Request
Joint Pos: [J1, J2, ...]
Forward
My Application
Kinematics
Response
ToolPos: [X, Y, Z, ...]
6
Services: Details
• Typical Uses:
– Algorithms: kinematics, perception
– Closed-Loop Commands: move-to-position, open gripper
7
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.
LocatePart.srv
Comment #Locate Part
Request Data
string base_frame
Divider ---
9
Services: Syntax
• Service Server
– Defines associated Callback Function
– Advertises available service (Name, Data Type)
10
Services: Syntax
• Service Client
– Connects to specific Service (Name / Data Type)
– Fills in Request data
– Calls Service
ros::NodeHandle nh;
ros::ServiceClient client = nh.serviceClient<LocatePart>(“find_box");
11
Exercise 2.0
Exercise 2.0
Creating and Using a Service
fake_ar_pub myworkcell_node
LocalizePart
vision_node
descartes_node
?
myworkcell_support
myworkcell_moveit_cfg ur5_driver
12
Day 1 Progression
13
Actions
14
Actions : Overview
Client My Application
Dest Pos
Curr Pos
Feedback
Success
Cancel
Goal
Result
Execute Motion
Server
Robot Motion
15
Actions: Detail
• 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
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.
FollowJointTrajectory.action
# Command Robot Motion
Goal Data traj_msgs\JointTrajectory trajectory
---
int32 error_code
Result Data
string error_string
---
uint8 status
Feedback Data
traj_msgs\JointTrajectoryPoint actual
17
“Real World” – Actions
• FollowJointTrajectoryAction
– command/monitor robot trajectories
– use rqt_msg to view Goal, Result, Feedback
• Should be an Action…
– GetMotionPlan
18
Actions: Syntax
• Action Server
– Defines Execute Callback
– Periodically Publish Feedback
– Advertises available action (Name, Data Type)
Callback Function Goal Data (IN)
Feedback as_.publishFeedback(…);
Action Name Callback Ref
}
Result as_.setSucceeded(result_);
}
SimpleActionServer<JointTrajectoryAction> as_ (“move_robot”, &executeCB);
Server Object
19
Actions: Syntax
• Action Client
– Connects to specific Action (Name / Data Type)
– Fills in Goal data
– Initiate Action / Waits for Result
Action Type Client Object Action Name
SimpleActionClient<JointTrajectoryAction> ac(“move_robot");
JointTrajectoryGoal goal;
Goal Data
goal.trajectory = <sequence of points>;
20
Exercise 2.1
Exercise 2.1
Creating and Using an Action
We’ll skip this exercise.
Work through it on your own time later, if desired.
Client calcFibonacci_client
seq: 0 1 1
Feedback
seq: 0 1 1 2 3
Cancel
order: 6
Result
Goal
21
Message vs. Service vs. Action
22
Launch Files
23
Launch Files: Motivation
24
Launch Files: Overview
Motion Planner
Load Load
Robot Robot Robot Control
System
Parameter
Server
25
Launch Files: Overview
26
Launch Files: Notes
27
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
<launch>
<rosparam param=“/robot/ip_addr“>192.168.1.50</rosparam>
28
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.
<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>
29
“Real World” – Launch Files
30
Exercise 2.2
fake_ar_pub myworkcell_node
vision_node
descartes_node
myworkcell_support
myworkcell_moveit_cfg ur5_driver
31
Day 1 Progression
32
Parameters
33
Parameters: Overview
Parameter Server
\debug
\robot_1\ipAddr: “192.168.1.21” Node
\robot_1\ipAddr
\robot_2\ipAddr
\home_pos\x
\home_pos\y
\home_pos\z \home_pos: [X, Y, Z]
Config File
34
ROS Parameters
• Typically configuration-type values
– robot kinematics
– workcell description
– algorithm limits / tuning
roscore
35
Setting Parameters
– Command Line
rosrun my_pkg load_robot _ip:=“192.168.1.21”
rosparam set “/debug” true
– Programs
nh.setParam(“name”, “left”);
36
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
box
.weight /box/weight
.center /box/center/x
.x /box/center/y
.y
37
Namespaces
/debug
/rt_camera
/rt_camera/ipAddr
camera_node ipAddr, exposure /rt_camera/exposure
38
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
Parameters: C++ API
• Fixed namespace:
ros::NodeHandle fixed(“/myApp”);
“/myApp/test”
fixed.getParam(“test”);
• Private namespace:
ros::NodeHandle priv(“~”);
“/myNode/test”
priv.getParam(“test”);
40
Parameters: C++ API (cont’d)
41
Dynamic reconfigure
42
ROS Param Practical Examples
43
Exercise 2.3
Exercise 2.3
Param: base_frame
ROS Parameters
fake_ar_pub myworkcell_node
vision_node
descartes_node
myworkcell_support
myworkcell_moveit_cfg ur5_driver
44
Review/Q&A
Session 1 Session 2
Intro to ROS Services
Installing ROS/Packages Actions
Packages Launch Files
Nodes Parameters
Messages/Topics
45