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.
This homework requires that you create:
In the end, your nodes should look something like this:
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.
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 a random number between 0 and 10 (inclusive) 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.
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 from your code (messages from unit listener are fine) seen in rqt_console.
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. It should also start rqt_graph and rqt_console. The instructor should be able to start this launch file and then grade your homework based solely on the nodes launched.
Submit a PDF to blackboard with:
roslaunch <package> <launch_file>
10 points – Publisher node meets objectives
10 points – Listener node meets objectives
6 points – Package creation meets objectives
6 points – Launch file/launcher meets objectives
2 points – Tag applied in git
6 points – Answers given in PDF
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.
$ dts devel run -M -X --cmd bash
$ catkin_create_pkg learning_ros std_msgs rospy roscpp mystery_package
Reference slides and http://wiki.ros.org/ROS/Tutorials/CreatingPackage for help.
$ chmod -R a+rw <package_folder>
$ catkin build $ source /code/catkin_ws/devel/setup.bash
$ gedit <node_name>.py
You should replace <node_name> with whatever you want to call the node.
$ 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>
$ dts devel run attach
$ roscore
$ rosrun <package> <node>
$ rostopic echo <topic>
$ 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
<node pkg="rqt_graph" name="rqt_graph" type="rqt_graph" />
<node pkg="rqt_console" name="rqt_console" type="rqt_console" />
HW_PACKAGE=<your package name> HW_LAUNCH=<your launch file name>
$ dts devel build $ dts devel run -X -L launch-hw2
$ git status
$ git add <files>
$ git commit -m <message>
$ git push
$ git tag <tag_name>
$ git push origin <tag_name>