Skip to content

autonomoussystemsengineering/intro_to_ros

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 

Repository files navigation

Intro to ROS

The objective of the following exercises is to help you practice the most commonly used concepts in ROS. We provide a quick reference document and pointers to relevant documentations. Feel free to use all the resources available to you to learn the concepts as thoroughly as possible and complete the exercises as efficiently as possible.

Although you're encouraged to collaborate with others if you are stuck, the lab should be completed individually so you can get practice with skills that will be essential later on in the course. If you have general questions, please post on Lernraum so other students can benefit from the answer.

Grading

You're meant to complete all excercises by testing your code and verifying the results on your own, as you would do in real life. Once you are confident in your answers, call the supervisor to get your results checked. However, the excercises are not graded.

References

The following are selected chapters from the ROS Wiki Documentation and Tutorials. If you understand all the concepts covered in these exercises, you should be ready for the following exercises and for most of the ROS related tasks you will be performing throughout the first few labs. For more on ROS, visit the ROS Wiki section and follow the links to learn more.

Additionally, reference this amazing ROS cheatsheet to get an overview of all the keywords here! (source).

  1. Catkin
  2. Catkin Workspace
    a. Catkin workspaces
    b. Creating Catkin workspace
  3. Packages
    a. ROS package
    b. Creating ROS package
  4. Messages
    a. ROS Messages
    b. Creating custom messages
    c. The rosmsg command-line tools
    d. Common ros message categories
  5. Topics
    a. ROS Topics
    b. Rostopic Command-Line tool
  6. Nodes
    a. ROS Nodes
    b. The rosnode command-line tools
    c. Writing Publisher and Subscriber(Python)
  7. Launch Files
    a. ROS Launch
    b. Command-line Tools
    c. XML Format
    d. Tips for Large Projects
  8. Parameter server
    a. Parameter server
    b. rosparam
  9. Visualization Tools
    a. RQT
    - RQT
    - RQT_GRAPH
    b. RVIZ
    - User Guide
    - Interactive Markers
    - Tutorials
  10. TF
  11. Rosbag
    a. Rosbag
    b. Command-Line Tools

ROS Exercises

Create a package and build it

By following the instructions from the reference or instructions of your finding, create a catkin workspace and package named catkin_ws/ and ros_exercises/ respectively, and make sure that your workspace is built (using catkin_make) before and after the package was added. Your package (ros_exercises) should live in the /src/ directory, where you add other packages (such as other labs later on). After creating the workspace and the package, you should have the following directory layout.

  • /catkin_ws[your catkin workspace]
    • /src
      • /ros_exercises[Your catkin package]
      • [other ros related files and packages if any]
    • /devel[automatically generated by catkin_make]
    • /build[automatically generated by catkin_make]

Additionally, everytime you make an edit to your files, make sure to run catkin_make and source your setup.bash file.

Question 1: Create Simple Publisher in C++

Your task in this exercise is to create a simple ROS node that publishes a random number between 0 and 10.0. Before you start the following exercise, please make sure that your package is built properly. Note that this file will reside inside of the /ros_exercises folder of your newly created package.

Node Specification

Description: Publishes a random number between 0 and 10.
File name: simple_publisher.cpp
Node Name: simple_publisher
Published topic names: my_random_float
Message type: Float32
Subscription topic names: None
Publish rate: 20hz

Result Specification

When your node works properly, take a screenshot of rqt_graph visualization of your node(s) and topic(s). Name your screenshot simple_publisher_rqt.jpeg and save it in ros_exercises/rqt (create the rqt/ directory). Note: ros_exercises/ is the ros package you created at the beginning of this section.

Question 2: Create Simple Subscriber in C++

In this exercise, you will write a listener (subscriber) that listens to the topic my_random_float, which is published on to by the previous node. The node takes the natural log of the message on my_random_float and publishes it to random_float_log.

Node Specification

Description: Subscribes to the topic published on by the simple_publisher and publishes the natural log of the received messages.
File name: simple_subscriber.cpp
Node Name: simple_subscriber
Published topic names: random_float_log
Message type: Float32
Subscription topic names: my_random_float

Result Specification

Again, take a screenshot of rqt_graph showing your nodes running, name it simple_subscriber_rqt.jpeg, and save it in the same folder as the previous exercise.

Question 3: Create more Complex Publisher in C++

In this exercise, you will write a node that publishes fake laser scan data as specified below.

Node Specification

Description: Publish a LaserScan message with random ranges between 1 and 10.
File name: fake_scan_publisher.cpp
Node Name: fake_scan_publisher
Published topic names: fake_scan
Message type: LaserScan
Subscription topic names: None
Publish Rate: 20hz

LaserScan Parameter Specifications

Header:
- Timestamp: Current ros time
- Frame_id: “base_link”
Angle_min: (-2/3)pi
Angle_max: (2/3)pi
Angle_increment: (1/300)pi
Time_increment: Leave it unset if you wish
Scan_time: The time difference in seconds between consecutive scans. Range_min: 1.0
Range_max: 10.0
Ranges: One dimensional array with elements of random floats between range_min and range_max, Use angle_min, angle_max, and angle_increment to determine the length.
Intensities: Leave it unset if you wish

Result Specification

  1. When your node works properly, visualize the published laser scan data using rviz. Take a screenshot of your visualized laser scan data and name it fake_scan_rviz.jpeg. Save the image in ros_exercises/rviz
  2. Record a bag file of your laser scan data and call the file fake_scan_bag.bag, save it in ros_exercises/rosbag.

Question 4: Create a more complex Subscriber in C++

Create a node that subscribes to the fake laser scan data and outputs the longest range from the laser scan ranges and its corresponding angle.

Node Specification

Description: Subscribes to the fake_scan topic published on by the fake_scan_publisher from the previous exercises, and finds the longest return (the range element with the greatest value) and publishes the corresponding angle and return value or distance.
File name: open_space_publisher.cpp Node Name: open_space_publisher
Published topic names: open_space/distance and open_space/angle
Message type: Float32
Subscription topic names: fake_scan
Publish rate: 20hz

Result Specification

Again, take a screenshot of rqt_graph showing your nodes running, named it open_space_rqt.jpeg, and save it in ros_exercises/rqt.

Question 5: Create a custom Message and Publish it

The publisher from the previous exercise was publishing two related pieces of data on two separate topics (open_space/distance and open_space/angle). In this exercise, we ask you to create a custom message that encapsulates the two pieces of data, the same way the LaserScan message type combines multiple pieces of data, and name your custom message file OpenSpace.msg. After creating and compiling your custom message, modify the publisher from the previous exercise to publish this message type on the topic open_space. Hint: Don't forget to modify your CMakeLists.txt and package.xml files.

Result Specification

You now should have additional config/meta files, and your custom message file as well any supporting files.

Question 6: Using launch files

If you have been running your publisher(s), subscriber(s), and roscore separately using the rosrun command, there’s a more organized way to run multiple nodes at same time with one command.

In this exercise, we ask you to write a single launch file called my_first_launch.launch containing all 4 nodes that you have written thus far.

Result Specification

You now should have additional files inside a folder called launch inside the src folder of your package.

Question 7: Use ROS parameters

When writing the last publisher (fake_scan_publisher), you had a couple of variables with default values including angle_min, angle_max, range_min, range_max, etc. With the current setup, if you want to change the value of one of those variables you will have to edit the Python code. For hundreds of lines of code, finding where each of such variables is defined can be tedious. The rosparam server provides a way to set those parameters on the terminal when running your program and in launch or config files. You task here is to parameterize the following variables from the last two nodes.

  1. Fake Scan Publisher
    • Publish topic
    • Publish rate
    • Angle_min
    • Angle_max
    • Range_min
    • Range_max
    • Angle_increment
  2. Open Space Publisher
    • Subscriber topic
    • Publisher topic

Result Specification

You now should have modified nodes which can interact with the parameter server.

Question 8: Playing with bag files

In question 3, we asked you to visualize your laserscan data on rviz and record a bag file. The rviz visualization was probably meaningless and ugly because you’re publishing random data. Don’t be alarmed, real laserscan data is a lot prettier and informative. Download these bagfiles, follow the instructions here, and visualize the laser scan data on rviz. Try it with multiple coordinate frames.

Note: the provided bag files are from an MIT course of driving cars in the basement of the Stata center.

Debugging Hints

Here are some helpful tools to use when trying to debugging your code.

Helpful debugging tools (once a node is running):

  1. rostopic list A running node should be publishing or subscribing to different topics. To check that these topics are being listened/talked to, the command rostopic list, which will list all topics that are currently active (either being subscribed to, published to, or both).

  2. rostopic echo /topic_name Once you know that a command is being published/subscribed to, you can echo its contents, which can show whether or not any information is being passed across this topic or if you are not sending what you expect.

  3. rostopic hz /topic_name This command can tell you the rate at which messages are being published. This tool is helpful to verify if you are publishing messages at a certain frequency.

This page, http://wiki.ros.org/rostopic, from the ROS documentation can provide many other tools to debug your ROS node setup.

  1. rqt graph: This is a tool to display graphs of running ROS nodes with connecting topics and package dependencies. Allows you to visualize your entire framework! Another helpful technique is to look at the RQT_GRAPH (http://wiki.ros.org/rqt_graph) which shows the interactions between nodes for your system.

  2. rviz: This is a 3D visualizer tool for displaying sensor data and state information from ROS. You will be using it more extensively in future labs.

About

Fork from mit-rss/intro_to_ros

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published