You are on page 1of 29

Smart Mobility Service

(ISE4134)

Week 4 Lecture
ISE Department
Prof. Mehdi Pirahandeh

School of Global Convergence Studies


Basic
ROS Programming

Textbook
P. 148~193

School of Global Convergence Studies


Goals

I. Learning theoretical concepts related to ROS Server Parameters


II. Practices a robot car project related to ROS Server Parameters
III. Improving student’s skills by providing feedback

School of Global Convergence Studies


Contents

I. Things to know before programming ROS


II. What is Server Parameters?
III. Why do we need server parameters?
IV. Server parameters ROS wiki page contents
V. Server parameters in Action (Terminal)
VI. Server parameters in Action (YAML)
VII.Adding the server parameter functionality to our previous example
VIII.Summary

School of Global Convergence Studies


Things to know before programming ROS
Things to know before programming ROS

Quantity Unit Quantity Unit


• Standard unit angle radian length meter
frequency hertz
• SI unit force newton
mass kilogram

time second
power watt
current ampere
• Coordinate representation
voltage volt
temperature celsius

• x: forward, y: left, z: up

• Right-hand rule

School of Global Convergence Studies


Things to know before programming ROS

Quantity Unit Quantity Unit


• Standard unit angle radian length meter
frequency hertz
• SI unit force newton
mass kilogram

time second
power watt
current ampere
• Coordinate representation
voltage volt
temperature celsius
Object Naming rule example

• x: forward, y: left, z: up Package under_scored Ex) first_ros_package


Topic, service under_scored Ex) raw_image

• Right-hand rule
File under_scored Ex) turtlebot3_fake.cpp
Namespace under_scored Ex) ros_awesome_package
Variable under_scored Ex) string table_name;
type CamelCased Ex) typedef int32_t PropertiesNumber;

• Programing rules Class CamelCased Ex) class UrlTable


Structure CamelCased Ex) struct UrlTableProperties
Enumeration type CamelCased Ex) enum ChoiceNumber
Function camelCased Ex) addTableEntry();
Method camelCased Ex) void setNumEntries(int32_t num_entries)
Constant ALL_CAPITALS Ex) const uint8_t DAYS_IN_A_WEEK = 7;

School of Global Convergence Studies


Types of message communication

8
ROS Message communication

Message communication
Node1
(Topics, Services, Actions, Parameters) Node2
Topic
Publisher Subscriber

Service request
Service server Service client
Service response
Deliver action goals
Action server Action client
Deliver action feedback
Deliver action result

Parameter
parameter parameter
server
(ROS Master)

write read

School of Global Convergence Studies


Topic

Node1 Node2

Topic
Publisher Subscriber

School of Global Convergence Studies


Service

Node1 Node2

Service request
Service server Service client
Service response

School of Global Convergence Studies


Action

Node1 Node2

Deliver action goals


Deliver action feedback
Action server Action client
Deliver action result

School of Global Convergence Studies


Parameter

Node1 Node2

Parameter
parameter parameter
server
(ROS Master)

write read

School of Global Convergence Studies


Server Parameters

1) What is Server Parameters?

 The ROS parameter server is a


centralized place to store values of
variables.

Server Parameters

School of Global Convergence Studies


Server Parameters

Server Parameters
1) What is Server Parameters?

 The ROS parameter server is a


centralized place to store values of
variables.
 (1) The variables are generally
related to a physical attribute of our
robot.

School of Global Convergence Studies


Server Parameters

1) What is Server Parameters?

 The ROS parameter server is a


centralized place to store values of
variables.
 (1) The variables are generally
related to a physical attribute of our
robot.
 (2) We can just use the parameter
server values to accommodate any
calc_velocity.cpp
changes of our robot in our code.

School of Global Convergence Studies


Server Parameters

1) What is Server Parameters?

 The ROS parameter server is a


centralized place to store values of
variables.
 (1) The variables are generally
related to a physical attribute of our
robot.
 (2) We can just use the parameter
server values to accommodate any
calc_velocity.cpp
changes of our robot in our code.

School of Global Convergence Studies


Server Parameters

2) Why do we need server parameters?


Example code
 In this example, we created a node
that estimates the speed of our
robot based on how fast the
wheels were turning.
 The problem is that if you had a
whole software suite with dozens of
files or calls to your wheel radius,
this could get quite tiresome to find
and change all of those values
spread across all those different
calc_velocity.cpp
files.
 There is a need for recompiling the
whole project to change the
variable value.

School of Global Convergence Studies


Server Parameters

Example code

calc_velocity.cpp

School of Global Convergence Studies


Server Parameters

3) Server parameters ROS wiki


page contents

1.YAML Format
2.roslaunch API
3.rosparam command-line tool
1.rosparam list
2.rosparam get
3.rosparam set
4.rosparam delete
5.rosparam dump
6.rosparam load
4.Roadmap http://wiki.ros.org/rosparam
5.See Also

School of Global Convergence Studies


Server Parameters

4) Server parameters in Action (Terminal)

a) Run roscore

ros@ubuntu:~/catkin_ws$ roscore
... logging to /home/ros/.ros/log/21f74694-4a06-11ec-
a233-7913a6ed022c/roslaunch-ubuntu-63183.log
… c) Get the value of a parameter

ros@ubuntu:~/catkin_ws$ rosparam get /run_id


21f74694-4a06-11ec-a233-7913a6ed022
b) List the existing (default) parameters ros@ubuntu:~/catkin_ws$

ros@ubuntu:~/catkin_ws$ rosparam list


/rosdistro
/roslaunch/uris/host_ubuntu__36605
/rosversion
/run_id
ros@ubuntu:~/catkin_ws$

School of Global Convergence Studies


Server Parameters

4) Server parameters in Action (Terminal)

a) Set the value of a parameter

ros@ubuntu:~/catkin_ws$ rosparam set /wheel_radius


0.184
ros@ubuntu:~/catkin_ws$
c) Get the value of a parameter

ros@ubuntu:~/catkin_ws$ rosparam get


/wheel_radius
b) List the existing parameters 0.184
ros@ubuntu:~/catkin_ws$
ros@ubuntu:~/catkin_ws$ rosparam list
/rosdistro
/roslaunch/uris/host_ubuntu__36605
/rosversion
/run_id
/wheel_radius

School of Global Convergence Studies


Server Parameters

5) Server parameters in Action (YAML)

a) Create a YAML file to save and load ROS parameters

ros@ubuntu:~/catkin_ws$ rosparam dump


pub_param.yaml
ros@ubuntu:~/catkin_ws$ ls
project1_ws pub_param.yaml

b) View the created YAML file

ros@ubuntu:~/catkin_ws$ nano pub_param.yaml


ros@ubuntu:~/catkin_ws$

School of Global Convergence Studies


Server Parameters

5) Server parameters in Action (YAML)

a) Change the value of wheel_radius param in YAML file using NANO editor

b) Validate the change in YAML file

ros@ubuntu:~/catkin_ws$ rosparam get /wheel_radius


0.184 It did not
ros@ubuntu:~/catkin_ws$ update
c) Load the YAML file

ros@ubuntu:~/catkin_ws$ rosparam load


pub_param.yaml
ros@ubuntu:~/catkin_ws$
d) Again, validate the change in YAML file

ros@ubuntu:~/catkin_ws$ rosparam get /wheel_radius


0.106
ros@ubuntu:~/catkin_ws$ Updated!

School of Global Convergence Studies


Server Parameters

6) Adding the server parameter


functionality to our previous example

e) Set the wheel_radius

ros@ubuntu:~/catkin_ws$ rosparam set wheel_radius


0.5
ros@ubuntu:~/catkin_ws$

School of Global Convergence Studies


Server Parameters

6) Adding the server parameter


functionality to our previous example

f) Set again the wheel_radius value


ros@ubuntu:~/catkin_ws$ rosparam set wheel_radius
0.5
ros@ubuntu:~/catkin_ws$ rosparam set wheel_radius
0.125
ros@ubuntu:~/catkin_ws$

School of Global Convergence Studies


Server Parameters

Server
Parameters
7) Exercise using YAML file

 The ROS parameter server is a centralized


place to store start_odometer and
end_odometer variables, and trip distance
variables.
 The ROS parameter server used a centralized
place to calculate the trip distance, store the
value in the trip_distance variable, and finally
retrieve this value.
calc_trip_distance.cpp

School of Global Convergence Studies


Server Parameters

Server
Parameters
8) Recap

 rosparam list
 rosparam get <param_name>
 rosparam set <param_name> <value>
 rosparam dump <file name> <param_1> <param_2>
 rosparam load <file name>

calc_velocity.cpp

School of Global Convergence Studies


Brief break (if on schedule)

Q&A?
Prof. Mehdi Pirahandeh
E-mail : mehdi@inha.ac.kr

School of Global Convergence Studies

You might also like