Homework 2 will test your ability to create ROS packages, create a ROS node, 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 a new node to send messages to the homework 1 turtlesim node as 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 commands to the turtlesim/sim node.
  3. A launch file to start everything.
  4. An updated launcher script to run your code.

Package

Your package will depend on rospy, roscpp, std_msgs, and geometry_msgs. You may name it whatever you like.

Publisher Node

This node should publish to the topic that turtlesim subscribes to. You should have found this topic in HW1. If not, see the instructor. This node should publish velocities to make the turtle move in a square at least 2 units (as output from the pose topic) in each dimension. Note that periodically, ROS nodes will start at different times, so consider adding a slight delay before publishing commands.

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 turtlesim/sim and start your node. The instructor should be able to start this launch file and then grade your homework based solely on the nodes launched.

Launcher Script

Edit the file in <your_repo>/launchers/launch-hw2.sh so that it starts your code when run. Refer to lecture slides and this page if you have any questions.

Submission Instructions

Submit to Qualtrics:

  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 node you created
  4. Any difficulties you had with this assignment

Rubric

6 points – Publisher node meets objectives
6 points – Package creation meets objectives
6 points – Launch file/launcher meets objectives
4 points – Tag applied in git
18 points – Answers given

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 geometry_msgs

    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. 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
  14. In your launch file, make sure you:
    1. Include the turtlesim_helper package launch file with the <include> tag
    2. Start the node you made her
  15. Edit the homework 2 script in the launcher folder:
    $ gedit <your_repo>/launchers/launch-hw2.sh
    Change the first two lines to match whatever you called your package and launch file:

    HW_PACKAGE=<your package name>
    HW_LAUNCH=<your launch file name>
  16. Test your code and launch files thoroughly. Ensure that everything can be started after a rebuild with the launcher script and no manual input:
    $ dts devel build
    $ dts devel run -X -L launch-hw2
  17. 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.