Difference between revisions of "ROS Tutorials"

From Lofaro Lab Wiki
Jump to: navigation, search
(Understanding ROS Services and Parameters)
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
Practicing writing a wiki page- all information below is incomplete until otherwise noted.
+
This tutorial assumes that you will be working in ROS-hydro on Ubuntu 12.04.
  
Aside to editor, to improve:
 
 
This tutorial assumes that you will be working in ROS-hydro on Ubuntu 12.04.
 
 
This wiki is based on the tutorials given [http://wiki.ros.org/ROS/Tutorials here].
 
This wiki is based on the tutorials given [http://wiki.ros.org/ROS/Tutorials here].
  
Line 15: Line 12:
 
# [[Understanding ROS Nodes]]
 
# [[Understanding ROS Nodes]]
 
# [[Understanding ROS Topics]]
 
# [[Understanding ROS Topics]]
 +
# [[Understanding ROS Services and Parameters]]
 +
# [[Using rqt_consol and roslaunch]]
 +
# [[Using rosed to Edit Files in ROS]]
 +
# [[Creating a ROS msg and srv]]
 +
# [[Writing a Simple Publisher and Subscriber (C++)]]
 +
# [[Writing a Simple Publisher and Subscriber (Python)]]
 +
# [[Examining the Simple Publisher and Subscriber]]
 +
# [[Writing a Simpler Service and Client (C++)]]
 +
# [[Writing a Simpler Service and Client (Python)]]
 +
# [[Examining the Simpler Service and Client]]
 +
# [[Recording and Playing Back Data]]
 +
# [[Getting Started with roswtf]]
 +
# [[Navigating the ROS wiki]]
 +
# [[Where Next?]]
  
[[Understanding ROS Services and Parameters]]
+
=Intermediate Level=
  
==Using rqt_consol and roslaunch==
+
Open the terminal. To complete each step, type in the following commands in the order shown.
 +
# [[Creating a ROS Package by Hand]]
 +
# [[Managing System Dependencies]]
 +
# [[Roslaunch Tips for Large Projects]]
 +
# [[Running ROS Across Multiple Machines]]
 +
# [[Defining Custom Messages]]
  
If you have not installed the turtle sim and rqt packages do so before continuing:
 
  <nowiki>sudo apt-get install ros-hydro-rqt ros-hydro-rqt-common-plugins ros-hydro-turtlesim</nowiki>
 
  
1) In a terminal, start roscore:
+
=Advanced=
  <nowiki>roscore</nowiki>
+
* [[Setting up RGBDSLAM with ROS in Gazebo]]
 
+
* [[Setting up RGBDSLAM with ROS in the real world]]
1) '''In a new terminal''' (terminal 2), start the ros_console:
+
* [[Raspberry_Pi_and_Arducopter_connections_through_ROS]]
  <nowiki>rosrun rqt_console rqt_console</nowiki>
+
* [[Ros_on_Raspberry_pi]]
A window will pop up.
+
 
+
2) '''In a new terminal''' (terminal 3) begin the logger:
+
  <nowiki>rosrun rqt_logger_level rqt_logger_level</nowiki>
+
A window will pop up.
+
 
+
3) '''In a new terminal''' (terminal 4) begin the turtle simulation:
+
  <nowiki>rosrun turtlesim turtlesim_node</nowiki>
+
 
+
4) Change the logger level to Warn by refreshing the nodes in the rqt_logger_level window and selecting Warn.
+
 
+
5) '''In a new terminal''' (terminal 5) send a command to the sim:
+
  <nowiki>rostopic pub /turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, 0.0]'</nowiki>
+
The logger will begin to print several warnings as expected.
+
 
+
6) Kill the simulation. Close terminal 5. Navigate to the beginners_tutorial package:
+
  <nowiki>roscd beginner_tutorials</nowiki>
+
 
+
6b) If roscd says similar to roscd: No such package/stack 'beginner_tutorials' , you will need to source the environment
+
  <nowiki>cd ~/catkin_ws
+
  source devel/setup.bash
+
  roscd beginner_tutorials</nowiki>
+
'''This must be done for each terminal you use'''
+
 
+
7) Make a launch directory:
+
  <nowiki>mkdir launch
+
  cd launch</nowiki>
+
 
+
8) Create a newe file titled turtlemimic.launch and paste in the following:
+
  <nowiki><launch>
+
 
+
    <group ns="turtlesim1">
+
      <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
+
    </group>
+
 
+
    <group ns="turtlesim2">
+
      <node pkg="turtlesim" name="sim" type="turtlesim_node"/>
+
    </group>
+
 
+
    <node pkg="turtlesim" name="mimic" type="mimic">
+
      <remap from="input" to="turtlesim1/turtle1"/>
+
      <remap from="output" to="turtlesim2/turtle1"/>
+
    </node>
+
 
+
  </launch></nowiki>
+
 
+
9) In terminal 4, use <nowiki>roslaunch [package] [filename.launch]</nowiki> to run launch files that contain nodes:
+
  <nowiki>roslaunch beginner_tutorials turtlemimic.launch</nowiki>
+
Two turtlesims will appear.
+
 
+
10) '''In a new terminal''' (terminal 5) send a command to the first simulation:
+
  <nowiki>rostopic pub /turtlesim1/turtle1/cmd_vel geometry_msgs/Twist -r 1 -- '[2.0, 0.0, 0.0]' '[0.0, 0.0, -1.8]'</nowiki>
+
The command sent to the first turtle is mimicked by the second.
+
 
+
==Using rosed to Edit Files in ROS==
+
1) Close all current terminals. In a new terminal, edit your bash file to use nano (an editor):
+
  <nowiki>export EDITOR='nano -w'</nowiki>
+
Use
+
  <nowiki>echo $EDITOR</nowiki>
+
And see a line print to the terminal to make sure the bash file change was successful.
+
 
+
2) Use rosed [package_name] [filename] to edit a file within a package:
+
  <nowiki>rosed roscpp Logger.msg</nowiki>
+
 
+
This works similarly to other editors in a terminal. If running into trouble, try gedit.
+
 
+
==Creating a ROS msg and srv==
+
*msg: msg files are simple text files that describe the fields of a ROS message. They are used to generate source code for messages in different languages.
+
*srv: an srv file describes a service. It is composed of two parts: a request and a response.
+
 
+
'''Creating a msg'''
+
 
+
1) Move into the beginner_tutorials folder, create a msg directory, and create a new msg file:
+
  <nowiki>cd ~/catkin_ws/src/beginner_tutorials
+
  mkdir msg
+
  echo "int64 num" > msg/Num.msg</nowiki>
+
 
+
1b) Use <nowiki>rosmsg show [message type]</nowiki> to make sure ROS sees the new msg:
+
  <nowiki>rosmsg show beginner_tutorials/Num</nowiki>
+
Or
+
  <nowiki>rosmsg show Num</nowiki>
+
The message int64 num will display. The second option is if you do not have the name of the package. If int64 num does not display, see [http://wiki.lofarolabs.com/index.php/ROS_Core_Tutorials#Using_rqt_consol_and_roslaunch step 6b] in Using rqt_console and roslaunch and try again.
+
 
+
'''Creating a srv'''
+
1) Move into your beginner_tutorials folder and create a src folder:
+
  <nowiki>roscd beginner_tutorials
+
  mkdir srv</nowiki>
+
 
+
2) Use roscp [package_name] [file_to_copy_path] [copy_path] to copy files from one folder to another:
+
  <nowiki>roscp rospy_tutorials AddTwoInts.srv srv/AddTwoInts.srv</nowiki>
+
This will copy a premade srv file into the srv folder.
+
 
+
2b) Use <nowiki>rossrv show <service type></nowiki> to make sure ROS sees the new srv:
+
  <nowiki>rossrv show beginner_tutorials/AddTwoInts</nowiki>
+
The message with two int64 a and b will show, then a '---' line, followed by an int64 sum.
+
 
+
'''Farther Notes'''
+
 
+
1) Once you have made the msg and srv, you will need to rebuild the package:
+
  <nowiki>rosmake beginner_tutorials</nowiki>
+
 
+
==Writing a Simple Publisher and Subscriber (C++)==
+
'''Writing the Publisher Node'''
+
 
+
1) In a terminal, move to your beginner_tutorials folder:
+
  <nowiki>cd ~/catkin_ws/src/beginner_tutorials</nowiki>
+
 
+
2) Create the file talker.cpp:
+
  <nowiki>gedit src/talker.cpp</nowiki>
+
 
+
3) In the gedit editor, paste all from [https://raw.githubusercontent.com/ros/ros_tutorials/groovy-devel/roscpp_tutorials/talker/talker.cpp this link].
+
Save the file and close the editor. For information on what is inside this file, see [http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29#roscpp_tutorials.2BAC8-Tutorials.2BAC8-WritingPublisherSubscriber.The_Code_Explained this link]. In a nutshell, it initializes the ROS system, advertise what we are doing, and finally loop what we are doing.
+
 
+
'''Writing the Subscriber Node'''
+
 
+
1) In a terminal, move to your beginner_tutorials folder:
+
  <nowiki>cd ~/catkin_ws/src/beginner_tutorials</nowiki>
+
 
+
2) Create the file listener.cpp:
+
  <nowiki>gedit src/listener.cpp</nowiki>
+
 
+
3) In the gedit editor, paste all from [https://raw.githubusercontent.com/ros/ros_tutorials/groovy-devel/roscpp_tutorials/listener/listener.cpp this link].
+
Save the file and close the editor. For information on what is inside this file, see [http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28c%2B%2B%29#roscpp_tutorials.2BAC8-Tutorials.2BAC8-WritingPublisherSubscriber.The_Code_Explained-1 this link]. In a nutshell, it initializes the ROS system, subscribes to the topic 'chatter', spin (wait for messages), when message arrives call the chatterCallback() function.
+
 
+
'''Building Nodes'''
+
 
+
==Writing a Simple Publisher and Subscriber (Python)==
+
==Examining the Simple Publisher and Subscriber==
+
==Writing a Simpler Service and Client (C++)==
+
==Writing a Simpler Service and Client (Python)==
+
==Examining the Simpler Service and Client==
+
==Recording and Playing Back Data==
+
==Getting Started with roswtf==
+
==Navigating the ROS wiki==
+
==Where Next?==
+
 
+
=Intermediate Level=
+

Latest revision as of 17:23, 30 October 2014

This tutorial assumes that you will be working in ROS-hydro on Ubuntu 12.04.

This wiki is based on the tutorials given here.

Beginner Level

Open the terminal. To complete each step, type in the following commands in the order shown.

  1. Installing and configuring your ROS environment
  2. Navigating the ROS Filesystem
  3. Creating a ROS Package
  4. Building a ROS Package
  5. Understanding ROS Nodes
  6. Understanding ROS Topics
  7. Understanding ROS Services and Parameters
  8. Using rqt_consol and roslaunch
  9. Using rosed to Edit Files in ROS
  10. Creating a ROS msg and srv
  11. Writing a Simple Publisher and Subscriber (C++)
  12. Writing a Simple Publisher and Subscriber (Python)
  13. Examining the Simple Publisher and Subscriber
  14. Writing a Simpler Service and Client (C++)
  15. Writing a Simpler Service and Client (Python)
  16. Examining the Simpler Service and Client
  17. Recording and Playing Back Data
  18. Getting Started with roswtf
  19. Navigating the ROS wiki
  20. Where Next?

Intermediate Level

Open the terminal. To complete each step, type in the following commands in the order shown.

  1. Creating a ROS Package by Hand
  2. Managing System Dependencies
  3. Roslaunch Tips for Large Projects
  4. Running ROS Across Multiple Machines
  5. Defining Custom Messages


Advanced