# Simulation
Class of Professor Khalid
# Assessments
# Resources
Robotic Systems Lab course on Youtube
# Setting up the environment
Install Virtual box
Install Ubuntu
WARNING
Install 18.04
- Install ROS
WARNING
ROS Melodic Morenia is the only one supported by Ubuntu 18.4
# ROS Workspace enviroment
Defines context for the current workspace
Default workspace loaded with:
> source /opt/ros/indigo/setup.bash
Overlay your catkin workspace with:
> cd ~/catkin_ws
> source devel/setup.bash
2
Check your workspace with:
> echo $ROS_PACKAGE_PATH
See Setup with:
> cat ~/.bashrc
# ROS Master
- Manages the communication between nodes
- Every node registers at startup with the master
Start ROS Master with:
> roscore
# ROS Nodes
- Single-purpose, executable program
- Individually compiled, executed, and managed
- Organized in packages

Run a node with:
> rosrun package_name node_name
See active nodes with:
> rosnode list
Retrieve information about a node with:
> rosnode info node_name
# ROS Topics
- Nodes communicate over topics
Nodes can publish or subscribe to a topic
Typically, 1 publisher and subscribers
- Topic is a name for a stream of messages

List active topics with:
> rostopic list
Subscribe and print the contents of a topic with:
> rostopic echo /topic
Show information about a topic with:
> rostopic info /topic
# ROS Messages
- Data structure defining the type of a topic
- Compromised of a nested structure of integers, floats, booleans, strings etc. and arrays of objects
- Defined in *.msg files

See the type of a topic:
> rostopic type /topic
Publish a message to a topic:
> rostopic pub /topic type args
# Pose Stamped message

# Using Ros
# Initializing ROS
thiago@thiago-VirtualBox:~$ roscore
... logging to /home/thiago/.ros/log/dd82e8a4-b1ca-11e9-87cc-0800278d4206/roslaunch-thiago-VirtualBox-1884.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://thiago-VirtualBox:45789/
ros_comm version 1.14.3
SUMMARY
========
PARAMETERS
* /rosdistro: melodic
* /rosversion: 1.14.3
NODES
auto-starting new master
process[master]: started with pid [1895]
ROS_MASTER_URI=http://thiago-VirtualBox:11311/
setting /run_id to dd82e8a4-b1ca-11e9-87cc-0800278d4206
process[rosout-1]: started with pid [1906]
started core service [/rosout]
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Running the Talker node
thiago@thiago-VirtualBox:~$ rosrun roscpp_tutorials talker
[ INFO] [1565160735.971909673]: hello world 0
[ INFO] [1565160736.077159865]: hello world 1
[ INFO] [1565160736.172827461]: hello world 2
[ INFO] [1565160736.274575420]: hello world 3
[ INFO] [1565160736.372053985]: hello world 4
[ INFO] [1565160736.472595307]: hello world 5
[ INFO] [1565160736.572918746]: hello world 6
[ INFO] [1565160736.673787624]: hello world 7
[ INFO] [1565160736.772383059]: hello world 8
[ INFO] [1565160736.872002586]: hello world 9
[ INFO] [1565160736.972747258]: hello world 10
2
3
4
5
6
7
8
9
10
11
12
13
# Analizing Talker Node
See the list of active nodes:
thiago@thiago-VirtualBox:~$ rosnode list
/rosout
/talker
2
3
Show information about the Talker node:
thiago@thiago-VirtualBox:~$ rosnode info /talker
--------------------------------------------------------------------------------
Node [/talker]
Publications:
* /chatter [std_msgs/String]
* /rosout [rosgraph_msgs/Log]
Subscriptions: None
Services:
* /talker/get_loggers
* /talker/set_logger_level
contacting node http://thiago-VirtualBox:34005/ ...
Pid: 31732
Connections:
* topic: /rosout
* to: /rosout
* direction: outbound
* transport: TCPROS
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
See information about the chatter topic:
thiago@thiago-VirtualBox:~$ rostopic info /chatter
Type: std_msgs/String
Publishers:
* /talker (http://thiago-VirtualBox:34005/)
Subscribers: None
2
3
4
5
6
7
8
Check the type of the chatter topic:
thiago@thiago-VirtualBox:~$ rostopic type /chatter
std_msgs/String
2
Show the message contents of the topic:
thiago@thiago-VirtualBox:~$ rostopic echo /chatter
data: "hello world 4549"
---
data: "hello world 4550"
---
data: "hello world 4551"
---
data: "hello world 4552"
---
data: "hello world 4553"
---
data: "hello world 4554"
---
data: "hello world 4555"
---
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Analyze the frequency:
thiago@thiago-VirtualBox:~$ rostopic hz /chatter
subscribed to [/chatter]
average rate: 10.006
min: 0.099s max: 0.101s std dev: 0.00049s window: 9
average rate: 9.988
min: 0.092s max: 0.109s std dev: 0.00318s window: 19
average rate: 10.001
min: 0.092s max: 0.109s std dev: 0.00287s window: 29
average rate: 9.985
min: 0.092s max: 0.109s std dev: 0.00279s window: 39
average rate: 9.999
min: 0.087s max: 0.113s std dev: 0.00400s window: 49
^Caverage rate: 9.996
min: 0.087s max: 0.113s std dev: 0.00388s window: 52
2
3
4
5
6
7
8
9
10
11
12
13
14
# Running the Listener node
thiago@thiago-VirtualBox:~$ rosrun roscpp_tutorials listener
[ INFO] [1565162666.434110685]: I heard: [hello world 17033]
[ INFO] [1565162666.534412739]: I heard: [hello world 17034]
[ INFO] [1565162666.634633464]: I heard: [hello world 17035]
[ INFO] [1565162666.733759107]: I heard: [hello world 17036]
[ INFO] [1565162666.834027140]: I heard: [hello world 17037]
[ INFO] [1565162666.938725867]: I heard: [hello world 17038]
[ INFO] [1565162667.034015007]: I heard: [hello world 17039]
[ INFO] [1565162667.134342493]: I heard: [hello world 17040]
[ INFO] [1565162667.235322108]: I heard: [hello world 17041]
[ INFO] [1565162667.339167399]: I heard: [hello world 17042]
[ INFO] [1565162667.440111956]: I heard: [hello world 17043]
[ INFO] [1565162667.535440167]: I heard: [hello world 17044]
[ INFO] [1565162667.637785599]: I heard: [hello world 17045]
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Analysing the Listener and the Talker nodes interation
See the new listener node:
thiago@thiago-VirtualBox:~$ rosnode list
/listener
/rosout
/talker
2
3
4
Show the connection of the nodes over the chatter topic:
thiago@thiago-VirtualBox:~$ rostopic info /chatter
Type: std_msgs/String
Publishers:
* /talker (http://thiago-VirtualBox:34005/)
Subscribers:
* /listener (http://thiago-VirtualBox:35467/)
2
3
4
5
6
7
8
9
# Publish Message from Console
Close the talker node in console nr. 2 with Ctrl + C
Publish your own message:
thiago@thiago-VirtualBox:~$ rostopic pub /chatter std_msgs/String "data: 'Thiago is the best'"
publishing and latching message. Press ctrl-C to terminate
2
3
Verify on the Listener the message:
[ INFO] [1565163149.392779957]: I heard: [hello world 21859]
[ INFO] [1565163149.493627417]: I heard: [hello world 21860]
[ INFO] [1565163149.590489392]: I heard: [hello world 21861]
[ INFO] [1565163149.690647992]: I heard: [hello world 21862]
[ INFO] [1565163779.387343592]: I heard: [Thiago is the best]
2
3
4
5

# catkin Build System
# Starting a CATKIN Workspace
catkin is the ROS build system to generate executables, libraries, and interfaces
Updating tools for catkin is necessary to use the command catkin build, which is recommended instead of catkin_make. To update is simple, few commands found on google research.
Navigate to your catkin workspace with:
> cd ~/catkin_ws
Build a package with:
> catkin build package_names
Whenever you build a new package, update your environment
> source devel/setup.bash
catkin build system:
Building:
thiago@thiago-VirtualBox:~/catkin_ws2$ catkin build
[build] Error: Unable to find source space `/home/thiago/catkin_ws2/src`
thiago@thiago-VirtualBox:~/catkin_ws2$ mkdir src
thiago@thiago-VirtualBox:~/catkin_ws2$ dir
src
thiago@thiago-VirtualBox:~/catkin_ws2$ catkin build
------------------------------------------------------------
Profile: default
Extending: [env] /opt/ros/melodic
Workspace: /home/thiago/catkin_ws2
------------------------------------------------------------
Build Space: [exists] /home/thiago/catkin_ws2/build
Devel Space: [exists] /home/thiago/catkin_ws2/devel
Install Space: [unused] /home/thiago/catkin_ws2/install
Log Space: [missing] /home/thiago/catkin_ws2/logs
Source Space: [exists] /home/thiago/catkin_ws2/src
DESTDIR: [unused] None
------------------------------------------------------------
Devel Space Layout: linked
Install Space Layout: None
------------------------------------------------------------
Additional CMake Args: None
Additional Make Args: None
Additional catkin Make Args: None
Internal Make Job Server: True
Cache Job Environments: False
------------------------------------------------------------
Whitelisted Packages: None
Blacklisted Packages: None
------------------------------------------------------------
Workspace configuration appears valid.
NOTE: Forcing CMake to run for each package.
------------------------------------------------------------
[build] No packages were found in the source space '/home/thiago/catkin_ws2/src'
[build] No packages to be built.
[build] Package table is up to date.
Starting >>> catkin_tools_prebuild
Finished <<< catkin_tools_prebuild [ 4.4 seconds ]
[build] Summary: All 1 packages succeeded!
[build] Ignored: None.
[build] Warnings: None.
[build] Abandoned: None.
[build] Failed: None.
[build] Runtime: 4.4 seconds total.
thiago@thiago-VirtualBox:~/catkin_ws2$ catkin build Thiago
------------------------------------------------------------
Profile: default
Extending: [env] /opt/ros/melodic
Workspace: /home/thiago/catkin_ws2
------------------------------------------------------------
Build Space: [exists] /home/thiago/catkin_ws2/build
Devel Space: [exists] /home/thiago/catkin_ws2/devel
Install Space: [unused] /home/thiago/catkin_ws2/install
Log Space: [exists] /home/thiago/catkin_ws2/logs
Source Space: [exists] /home/thiago/catkin_ws2/src
DESTDIR: [unused] None
------------------------------------------------------------
Devel Space Layout: linked
Install Space Layout: None
------------------------------------------------------------
Additional CMake Args: None
Additional Make Args: None
Additional catkin Make Args: None
Internal Make Job Server: True
Cache Job Environments: False
------------------------------------------------------------
Whitelisted Packages: None
Blacklisted Packages: None
------------------------------------------------------------
Workspace configuration appears valid.
------------------------------------------------------------
[build] No packages were found in the source space '/home/thiago/catkin_ws2/src'
[build] Given package 'Thiago' is not in the workspace
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
After the setup.bash command has to be called to update the system
thiago@thiago-VirtualBox:~/catkin_ws2$ source devel/setup.bash
2
catkin config
thiago@thiago-VirtualBox:~/catkin_ws2$ catkin config
------------------------------------------------------------
Profile: default
Extending: [env] /opt/ros/melodic
Workspace: /home/thiago/catkin_ws2
------------------------------------------------------------
Build Space: [exists] /home/thiago/catkin_ws2/build
Devel Space: [exists] /home/thiago/catkin_ws2/devel
Install Space: [unused] /home/thiago/catkin_ws2/install
Log Space: [exists] /home/thiago/catkin_ws2/logs
Source Space: [exists] /home/thiago/catkin_ws2/src
DESTDIR: [unused] None
------------------------------------------------------------
Devel Space Layout: linked
Install Space Layout: None
------------------------------------------------------------
Additional CMake Args: None
Additional Make Args: None
Additional catkin Make Args: None
Internal Make Job Server: True
Cache Job Environments: False
------------------------------------------------------------
Whitelisted Packages: None
Blacklisted Packages: None
------------------------------------------------------------
Workspace configuration appears valid.
------------------------------------------------------------
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
TIP
For example, to set the CMake build type to Release (or Debug etc.), use:
catkin build --cmake-args-DCMAKE_BUILD_TYPE=Release
# catkin dynamics
Open a terminal and browse to your git folder
> cd ~/git
Clone the Git repository with:
> git clone https://github.com/ethzasl/ros_best_practices.git
Symlink the new package to your catkin workspace
> ln -s ~/git/ros_best_practices/ ~/catkin_ws/src/
Go to your catkin workspace:
> cd ~/catkin_ws
Build the package with:
> catkin build ros_package_template
Re-source your workspace setup:
> source devel/setup.bash
Launch the node with:
> roslaunch ros_package_template ros_package_template.launch
Cloning a Github Package
thiago@thiago-VirtualBox:~/catkin_ws2$ git clone https://github.com/leggedrobotics/ros_best_practices.git
Cloning into 'ros_best_practices'...
remote: Enumerating objects: 152, done.
remote: Total 152 (delta 0), reused 0 (delta 0), pack-reused 152
Receiving objects: 100% (152/152), 127.02 KiB | 313.00 KiB/s, done.
Resolving deltas: 100% (75/75), done.
thiago@thiago-VirtualBox:~/catkin_ws2$
2
3
4
5
6
7
8
Making a new package from the downloaded git:
thiago@thiago-VirtualBox:~$ cd catkin_ws2
thiago@thiago-VirtualBox:~/catkin_ws2$ catkin build ros_package_template
------------------------------------------------------------
Profile: default
Extending: [cached] /opt/ros/melodic
Workspace: /home/thiago/catkin_ws2
------------------------------------------------------------
Build Space: [exists] /home/thiago/catkin_ws2/build
Devel Space: [exists] /home/thiago/catkin_ws2/devel
Install Space: [unused] /home/thiago/catkin_ws2/install
Log Space: [exists] /home/thiago/catkin_ws2/logs
Source Space: [exists] /home/thiago/catkin_ws2/src
DESTDIR: [unused] None
------------------------------------------------------------
Devel Space Layout: linked
Install Space Layout: None
------------------------------------------------------------
Additional CMake Args: None
Additional Make Args: None
Additional catkin Make Args: None
Internal Make Job Server: True
Cache Job Environments: False
------------------------------------------------------------
Whitelisted Packages: None
Blacklisted Packages: None
------------------------------------------------------------
Workspace configuration appears valid.
------------------------------------------------------------
[build] Found '1' packages in 0.0 seconds.
[build] Package table is up to date.
Starting >>> ros_package_template
Finished <<< ros_package_template [ 0.4 seconds ]
[build] Summary: All 1 packages succeeded!
[build] Ignored: None.
[build] Warnings: None.
[build] Abandoned: None.
[build] Failed: None.
[build] Runtime: 0.4 seconds total.
thiago@thiago-VirtualBox:~/catkin_ws2$ source devel/setup.bash
thiago@thiago-VirtualBox:~/catkin_ws2$ roslaunch ros_package_template
RLException: [ros_package_template] is not a launch file name
The traceback for the exception was written to the log file
thiago@thiago-VirtualBox:~/catkin_ws2$ roslaunch ros_package_template ros_package_template.launch
... logging to /home/thiago/.ros/log/3dd6f436-b255-11e9-87cc-0800278d4206/roslaunch-thiago-VirtualBox-7538.log
Checking log directory for disk usage. This may take awhile.
Press Ctrl-C to interrupt
Done checking log file disk usage. Usage is <1GB.
started roslaunch server http://thiago-VirtualBox:41149/
SUMMARY
========
PARAMETERS
* /ros_package_template/subscriber_topic: /temperature
* /rosdistro: melodic
* /rosversion: 1.14.3
NODES
/
ros_package_template (ros_package_template/ros_package_template)
ROS_MASTER_URI=http://localhost:11311
process[ros_package_template-1]: started with pid [7553]
[ INFO] [1564452430.302864885]: Successfully launched node.
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# ROS 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 starts a roscore
Browse to the folder and start a launch file with
> roslaunch file_name.launch
Start a launch file from a package with
> roslaunch package_name file_name.launch
# ROS Launch - Arguments
# ROS Launch - Including Other Launch Files
# Examples
# Cloning the 3DX rotob to a catkin workspace
git clone package
create workspace folder catkin_ws
create src folder
simulate git from ~/git to ~/catkin_ws:
ln -s ~/git/ros_best_practices/ ~/catkin_ws/src/
- built the catkin
catkin_build
WARNING
- Re-source your workspace setup
> source devel/setup.bash
then roslaunch
# Launching the p3dx
https://github.com/mario-serna/pioneer_p3dx_model
To clean the builds and build everything together :
catkin clean
To build the packages
catkin_make
ctrl + shift + T for a new tab on the terminal
On the new tab:
roscore
ctrl + shift + T for a new tab on the terminal update the system: We have to do this all the time before every launch
source devel/setup.bash
Launching Gazebo
roslaunch gazebo_ros empty_world.launch
Launching p3dx
roslaunch p3dx_gazebo p3dx.launch
launch teleop (if needed)
rosrun teleop_twist_keyboard teleop_twist_keyboard.py cmd_vel:=/p3dx/cmd_vel
To show the graph:
rqt_graph
Running Rviz
rosrun rviz rviz
# Class 04/10/2019
# Adding hosts
sudo gedit /etc/hosts
# to shh to another computer
sudo apt-get install openshh-server
To allow access --> InBound Rules for firewall
# To access the computer
On the host computer:
ssh karif@192.168.0.146
Password
On the other computer
Export ROS_MASTER_URI = http://192.168.0.146:11311
Then
rostopic list
On the host computer:
On the other computer
Rosrun robot robot-teleop
Rosrun image_view image_view image:/
See servicerobots.co.nz/rosweb
robot web tools github:
github.com/EESC-LabRom
# Update all the time
sudo apt update
# Gulp for Rosweb
For this error:
internal/util/inspect.js:31
const types = internalBinding('types');
^
ReferenceError: internalBinding is not defined
at internal/util/inspect.js:31:15
at req_ (/home/thiago/Webserver/rosweb/node_modules/natives/index.js:137:5)
at require (/home/thiago/Webserver/rosweb/node_modules/natives/index.js:110:12)
at util.js:25:21
at req_ (/home/thiago/Webserver/rosweb/node_modules/natives/index.js:137:5)
at require (/home/thiago/Webserver/rosweb/node_modules/natives/index.js:110:12)
at fs.js:42:21
at req_ (/home/thiago/Webserver/rosweb/node_modules/natives/index.js:137:5)
at Object.req [as require] (/home/thiago/Webserver/rosweb/node_modules/natives/index.js:54:10)
at Object.<anonymous> (/home/thiago/Webserver/rosweb/node_modules/graceful-fs/fs.js:1:37)
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
run:
npm install natives@1.1.6
then:
sudo apt update
# Creating a action server
# Client-Server Interaction
The ActionClient and ActionServer communicate via a "ROS Action Protocol", which is built on top of ROS messages. The client and server then provide a simple API for users to request goals (on the client side) or to execute goals (on the server side) via function calls and callbacks.

# Action Specification: Goal, Feedback, & Result
In order for the client and server to communicate, we need to define a few messages on which they communicate. This is with an action specification. This defines the Goal, Feedback, and Result messages with which clients and servers communicate:
Goal To accomplish tasks using actions, we introduce the notion of a goal that can be sent to an ActionServer by an ActionClient. In the case of moving the base, the goal would be a PoseStamped message that contains information about where the robot should move to in the world. For controlling the tilting laser scanner, the goal would contain the scan parameters (min angle, max angle, speed, etc).
Feedback Feedback provides server implementers a way to tell an ActionClient about the incremental progress of a goal. For moving the base, this might be the robot's current pose along the path. For controlling the tilting laser scanner, this might be the time left until the scan completes.
Result A result is sent from the ActionServer to the ActionClient upon completion of the goal. This is different than feedback, since it is sent exactly once. This is extremely useful when the purpose of the action is to provide some sort of information. For move base, the result isn't very important, but it might contain the final pose of the robot. For controlling the tilting laser scanner, the result might contain a point cloud generated from the requested scan.
# The package
A package for the action server was created with dependency on the actionlib_msgs
catkin_create_pkg actions_thiago actionlib_msgs std_msgs roscpp rospy
Inside the package on a directory called action we have the .action File:
# Goal
int32 number_of_minutes
---
# Result
string[] sticks_fetched
---
# Feedback
string last_stick_fetched
2
3
4
5
6
7
8
After follow the instructions inside the Cmake file to configure the package we have our actions messages created and compiled.
To verify that the action messages worked we can execute a simple python request to import the messages:
~/catkin_ws$ python -c 'from actions_thiago.msg import FetchTheStickAction; print "It Worked"'
It Worked
~/catkin_ws$
2
3
This means that we can import the message from the package
We can also grep for Fetch and have the result:
~/catkin_ws$ rosmsg list | grep Fetch
actions_thiago/FetchTheStickAction
actions_thiago/FetchTheStickActionFeedback
actions_thiago/FetchTheStickActionGoal
actions_thiago/FetchTheStickActionResult
actions_thiago/FetchTheStickFeedback
actions_thiago/FetchTheStickGoal
actions_thiago/FetchTheStickResult
~/catkin_ws$
2
3
4
5
6
7
8
9