Difference between revisions of "ROS Tutorials"

From Lofaro Lab Wiki
Jump to: navigation, search
(Using rosed to Edit Files in ROS)
(Creating a ROS msg and srv)
Line 20: Line 20:
 
# [[Using rosed to Edit Files in ROS]]
 
# [[Using rosed to Edit Files in ROS]]
  
==Creating a ROS msg and srv==
+
# [[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 a Simple Publisher and Subscriber (C++)==

Revision as of 18:34, 17 October 2014

Practicing writing a wiki page- all information below is incomplete until otherwise noted.

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 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
  1. Using rosed to Edit Files in ROS
  1. Creating a ROS msg and srv

Writing a Simple Publisher and Subscriber (C++)

Writing the Publisher Node

1) In a terminal, move to your beginner_tutorials folder:

  cd ~/catkin_ws/src/beginner_tutorials 

2) Create the file talker.cpp:

  gedit src/talker.cpp

3) In the gedit editor, paste all from this link. Save the file and close the editor. For information on what is inside this file, see 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:

  cd ~/catkin_ws/src/beginner_tutorials 

2) Create the file listener.cpp:

  gedit src/listener.cpp

3) In the gedit editor, paste all from this link. Save the file and close the editor. For information on what is inside this file, see 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