Homework 2 will test your ability to create ROS packages, create ROS nodes, and integrate your code into existing infrastructure.

In Homework 1, you sent and received messages to a ROS node manually, using rostopic. In this homework, you will create one new node to send messages to the homework 1 node and one new node to receive messages from it. These nodes are described below. You can follow the instructions below to do this or do it your own way, as long as the objectives are met. All messages should be sent through nodes in this homework, there should be no need to send anything using rostopic when it is graded.

Objectives

This homework requires that you create:

  1. A package
  2. A node to publish to mystery_node
  3. A node to subscribe to one output of mystery_node
  4. A launch file to start everything.

In the end, your nodes should look something like this:

Package

Your package will depend on rospy, roscpp, std_msgs, and mystery_package (optional, for the custom message used in mystery_node). You may name it whatever you like.

Publisher Node

This node should publish to the topic that mystery_node subscribes to. You should have found this topic in HW1. If not, see the instructor. This node should publish the Fibonacci sequence to mystery_node. Note that periodically ROS nodes will start at different times, so mystery_node may miss the first few numbers. This is acceptable.

Subscriber Node

This node should subscribe to one topic that mystery_node publishes. You can choose which topic to subscribe to. The topic that uses the “Float32” message type is recommended. In your callback function, use the ROS log functions to display these messages at the INFO level of priority. If using Python, use rospy.loginfo(<message>) to do this. This log message should take the following format: “<topic> published <msg>”. Feel free to format the message contents <msg> as you wish, as long as it is clear. Make sure to clean up any debug log messages such that these are the ONLY log messages seen in rqt_console.

Launch File

Your launch file should start everything needed to demonstrate your code. Specifically, it should include the launch file used in Homework 1 to start mystery_node and start both of your nodes. The instructor should be able to start this launch file and then grade your homework based solely on the log output.

Submission Instructions

Submit a PDF to blackboard with:

  1. Your name, repo URL, and the tag for this assignment
  2. The command that starts your nodes for this assignment, ie:
    roslaunch <package> <launch_file>
  3. The name of:
    1. The package you created for this assignment
    2. The nodes you created
  4. Any difficulties you had with this assignment

Rubric

10 points – Publisher node meets objectives
10 points – Listener node meets objectives
6 points – Package creation meets objectives
6 points – Launch file meets objectives
2 points – Tag applied in git
6 points – Answers given in PDF

Detailed Instructions

If you like, you can use these detailed instructions to complete this assignment. In general, you may find the instructions for developing homework assignments helpful.

  1. Open a terminal and change to your repository directory, then start your class container using
    $ dts devel run -M -X --cmd bash
  2. Create a new ROS package in your repo. First, make sure you are in your packages folder in your container: /code/catkin_ws/src/<your_repo>/packages You can change the name of the package below, “learning_ros”, to whatever name you would like to call the package.
    $ catkin_create_pkg learning_ros std_msgs rospy roscpp mystery_package

    Reference slides and http://wiki.ros.org/ROS/Tutorials/CreatingPackage for help

  3. Change the permissions of this folder so that you can access it outside the container:
    $ chmod -R a+rw <package_folder>
  4. Rebuild and re-source:
    $ catkin build
    
    $ source /code/catkin_ws/devel/setup.bash
  5. Outside of your container, create a new Python file in <your_repo>/packages/<hw2 package>/src using the text editor of your choice. The easiest way to do this is to start from a terminal in the correct folder and run:
    $ gedit <node_name>.py

    You should replace <node_name> with whatever you want to call the node.

  6. Write your publisher node here.
  7. Go back to your class container terminal. First, we need to make this file executable so that Linux knows it is a program and not just a text file. You should see that the file exists in your package if you run:
    $ ls /code/catkin_ws/src/<your_repo>/packages/<hw2 package>/src

    To make this file executable, run:

    $ chmod +x /code/catkin_ws/src/<your_repo>/packages/<hw2 package>/src/<file_name>
  8. Now you can test this file! Start up a new connection to your class container by running this command from your Linux system (outside of your class container but inside your repository folder)
    $ dts devel run attach
  9. Start roscore here (or skip ahead, make your launch file, and run that here)
    $ roscore
  10. Back in your original class container terminal, start up your node:
    $ rosrun <package> <node>
  11. If there are no errors, start a new terminal like in step 8 and listen for the correct topic values using
    $ rostopic echo <topic>
  12. Fix any issues you see above. If you don’t see messages on that topic, check that the topic name is correct. To ensure your node is executing as expected, you can put some log messages in the publisher node.
  13. Repeat the steps in 6, 7, 8 for your subscriber node and test it as well. In your subscriber node, make sure you output the required values to the log. You can view the log by running rqt_console in any terminal connected with your class container. You can connect as many terminals to your container as you like.
  14. Now create your launch file in <your_repo>/packages/<hw2 package>/launch. You may have to create the launch directory first:
    $ mkdir <your_repo>/packages/<hw2 package>/launch

    but then you can edit the file just like you edit node files:

    $ gedit <your_repo>/packages/<hw2 package>/launch/<launch_file>.launch
  15. Test your code and launch files thoroughly. Ensure that everything can be started with one launch file and no manual input.
  16. Commit and push your code to your repo:
    1. Check which files changed:
      $ git status
    2. Add them to this staged commit:
      $ git add <files>
    3. Make the commit
      $ git commit -m <message>
    4. Push it to your repo on GitHub:
      $ git push
    5. Tag it with something like “hw2”:
      $ git tag <tag_name>
    6. Push the tag to GitHub:
      $ git push origin <tag_name>
    7. Verify on GitHub.com that your submission is there, in the correct tag.