Académique Documents
Professionnel Documents
Culture Documents
-prakash raj
First, you'll need to learn some Basic Concepts
Before starting to learn anything, you always need to first be introduced to some
basic concepts. For instance, you can't learn to run before you know how to walk.
And you can't learn to sing before you know how to talk. Right?
The very first thing you need to know in order to learn ROS is how to
work with topics. Topics are, probably, the most important part of
ROS, so you will need to learn them carefully.
ROS handles almost all its communications through topics. Even more
complex communication systems, such as services or actions, rely, at
the end, on topics. That's why they are so important! Through ROS topics,
you will, for instance, be able to communicate with your robot in order to
make it move, to read your robot's sensor readings, and more.
Examples:
WebShell number #1 in order to start moving the Kobuki
robot.
$ roslaunch publisher_example move.launch
Whenever you want to stop moving the robot, and in order to stop the
i
program, just press Ctrl + C in the WebShell .
Note:You will notice that, even after stopping the program, the robot will
still keep moving. In order to stop it, you will have to execute another
command.
>>roslaunch publisher_example stop.launch
Reason:Even after terminating the command with Ctrl+C, the robot will
still keep moving. This is because the robot will keep listening to the last
message that you published on the topic. You will understand what this
means later.
Awesome, right? You'll probably have a lot of questions about how this
whole process works... What you've actually done is to launch a Publisher,
which is a ROS program that writes a message into a topic, in this case
into the /cmd_vel topic. This topic is the one used to send velocity
commands to the base of the robot. So, by sending a message through
this topic, you've made the robot start moving.
As you can imagine, the answer is NO. Of course! ROS also provides
services. Services allow you to code a specific functionality for your
robot, and then provide for anyone to call it. For instance, you could create
a service that makes your robot move for a specific period of time, and
then stop.
Services are a little bit more complex than topics since they are structured
in two parts. On one side, you have the Service Server, which provides the
functionality to anyone who wants to use it (call it). On the other side, you
have the Service Client, which is the one who calls/requests the service
functionality.
$ roslaunch service_demo service_launch.launch
$ rosservice call /service_demo "{}"
Navigating through the ROS filesystem:
/opt/ros/kinetic/share:/opt/ros/kinetic/stacks
$ mkdir –p ~/dev/catkin_ws/src
$ cd ~/dev/catkin_ws/src
$ catkin_init_workspace
$ cd ~/dev/catkin_ws
$ catkin_make
Once you have your package created and you have some code,it
is necessary to build the package. When the package is
built, the code contained in it is compiled; this includes
not only
the code added by the user, but also the code generated
from the messages and services.
$ cd ~/dev/catkin_ws/
$ catkin_make
$ roscd chapter2_tutorials/
$ catkin_make
When you are in the chapter2_tutorials folder and try
to build the package using
catkin_make , you will get the following error:
The specified base path
"/home/your_user/dev/catkin_ws/src/chapter2_tutorials"
contains a CMakeLists.txtbut "catkin_make"must be invoked
in the root of
workspace
If you execute catkin_make in the catkin_ws folder, you
will obtain a good compilation.
$ catkin_make -–pkg <package name>
As we explained in the Nodes and nodelets section,
nodes are executable programs and, once
built, these executables can be found in the devel
space. To practise and learn about nodes, we
are going to use a typical package called
turtlesim .
If you have installed the desktop installation, you will
have the turtlesim package
preinstalled; if not, install it with the following
command:
$ sudo apt-get install ros-kinetic-ros-tutorials
$ roscore
To get information on nodes,
$ rosnode
Using info ping.. e.t.c you can get the information
$ rosrun turtlesim turtlesim_node
$ rosnode info / turtlesim
we can see the Publications (topics), Subscriptions (topics),
and Services (srv) that the node has and the unique
nameof each.
i
Learning how to interact with topics
rostopic echo TOPIC : This prints messages to the
screen
rostopic find TOPIC : This finds topics by their type
rostopic hz TOPIC : This displays the publishing rate of
topics
rostopic info TOPIC : This prints information about
active topics
rostopic list : This lists the active topics
rostopic pubs TOPIC : This publishes data to the topic
rostopic type TOPIC : This prints the topic type
new terminal
$ rosnode info /teleop_turtle
$ rostopic list
$ rostopic echo /turtle1/cmd_vel
$ rostopic type /turtle1/cmd_vel
$ rosmsg showgeometry_msgs/Twist
-l, --latch
-r RATE
-1, --once
-f FILE
$ rostopic pub -1 /cmd_vel geometry_msgs/Twist ‘{linear: {x:
0.1, y:0.0, z:0.0}, angular: {x: 0.1, y:0.0, z:0.0}}’
Learning how to use services:
rosparam list
$ rosparam get /background_b
$ rosparam set /background_b 100
$ rosparam dump save.yaml
$ rosparam load load.yaml namespace