{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Custom ROS Message for Line Params\n", "All of the following instructions are based on [this](http://wiki.ros.org/ROS/Tutorials/CreatingMsgAndSrv#Creating_a_msg) guide.\n", "\n", "First create the message file using the following commands:\n", "```\n", "cd ~/bwsi-uav/catkin_ws/src/aero_control\n", "mkdir msg\n", "touch msg/Line.msg\n", "gedit msg/Line.msg\n", "```\n", "\n", "In the message file, add:\n", "```\n", "float64 x\n", "float64 y\n", "float64 vx\n", "float64 vy\n", "```\n", "This will enable us to transmit a `P = + t * ` line parameterization. (`t` can be any real number and `P` is a point on the line)\n", "\n", "Each line has the sub-message type followed by the name of the variable.\n", "\n", "## Building the message with catkin\n", "We need to make sure that the msg files are turned into source code for C++, Python, and other languages:\n", "\n", "Open `aero_control/package.xml`, and make sure these two lines are in it and uncommented:\n", "```\n", "message_generation\n", "message_runtime\n", "```\n", "\n", "Open `aero_control/CMakeLists.txt` in your favorite text editor (rosed from the previous tutorial is a good option).\n", "\n", "Add the message_generation dependency to the find_package call which already exists in your CMakeLists.txt so that you can generate messages. You can do this by simply adding message_generation to the list of COMPONENTS such that it looks like this:\n", "```\n", "# Do not just add this to your CMakeLists.txt, modify the existing text to add message_generation before the closing parenthesis\n", "find_package(catkin REQUIRED COMPONENTS\n", " roscpp\n", " rospy\n", " std_msgs\n", " message_generation\n", ")\n", "```\n", "\n", "Also make sure you export the message runtime dependency.\n", "```\n", "catkin_package(\n", " ...\n", " CATKIN_DEPENDS message_runtime ...\n", " ...)\n", "```\n", "\n", "Find the following block of code:\n", "```\n", "# add_message_files(\n", "# FILES\n", "# Message1.msg\n", "# Message2.msg\n", "# )\n", "```\n", "\n", "Uncomment it by removing the # symbols and then replace the stand in Message*.msg files with your .msg file, such that it looks like this:\n", "```\n", "add_message_files(\n", " FILES\n", " Line.msg\n", ")\n", "```\n", "\n", "Now we must ensure the generate_messages() function is called.\n", "\n", "For ROS Hydro and later, you need to uncomment these lines:\n", "\n", "```\n", "# generate_messages(\n", "# DEPENDENCIES\n", "# std_msgs\n", "# )\n", "```\n", "\n", "so it looks like:\n", "```\n", "generate_messages(\n", " DEPENDENCIES\n", " std_msgs\n", ")\n", "```\n", "\n", "\n", "\n", "At the end, run:\n", "```\n", "cd ~/bwsi-uav/catkin_ws/\n", "catkin_make\n", "source devel/setup.bash\n", "```\n", "\n", "To verify that the message was built sucessfully, run\n", "```\n", "rosmsg show aero_control/Line\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Modifying `talker.py` and `listener.py` to use custom messages\n", "Fill out the `TODO` sections in `line_tracker/src/talker.py` and `line_tracker/src/listener.py`.\n", "\n", "You will probabally find the following guide/example code helpful: [link](http://wiki.ros.org/ROS/Tutorials/CustomMessagePublisherSubscriber%28python%29)\n", "\n", "Dont worry about making any files exicutable since we will be using launchfiles\n", "\n", "To run these two files together, use `roslaunch launch/talk_listen.launch` in the `line_tracker` package" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Writing `detector.py`\n", "Fill out the TODO sections in `line_tracker/src/detector.py`, you should be able to reuse code from `line_tracker/src/talker.py`, your line paramaterization notebook, and [this](downward_cam_bag.html?highlight=recording#Integrating-opencv-and-ROS-images) example code.\n", "\n", "To run your code, use `roslaunch aero_control detect_listen.launch` in the `aero_control` package\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.12" } }, "nbformat": 4, "nbformat_minor": 2 }