{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Communication Pipeline\n", "\n", "In this unit we will gain understanding and practice on how information is passed between different components of the drone such as the onboard computer (Aero Compute Board) and the flight controller (AeroFC).\n", "\n", "You should have already been exposed to the basic concepts of the Robot Operating System (ROS) during the online portion of this class. These concepts including things like nodes, topics, messages, services, etc. If you are unsure/uncomfortable with what these concepts imply, there are great tutorials online for walking you through the basics of ROS. Please see:\n", "\n", "- [Intro to ROS](ros_introduction.html)\n", "- https://erlerobotics.com/blog/ros-introduction/\n", "- http://wiki.ros.org/ROS/Tutorials" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Talker - Listener\n", "\n", "We are going to put some of basic tools of ROS into practice on the Intel RTF Drone. We are going to start by creating and sending a simple message in one ROS node (i.e. talker) and receiving it in another. This portion relates to [this ROS tutorial](http://wiki.ros.org/ROS/Tutorials/WritingPublisherSubscriber%28python%29), but adapted to our needs.\n", "\n", "First make sure you have the most recent codebase on the drone.\n", "\n", "_On drone:_\n", "\n", "```\n", "cd ~/bwsi-uav/catkin_ws/src/aero_control\n", "git pull upstream master\n", "cd ~/bwsi-uav/catkin_ws/src/aero_control/communication_pipeline\n", "```\n", "\n", "If you try to run `simple_talker.py` and or `simple_listener.py` you will receive an error stating \n", "\n", "`Exception: CODE INCOMPLETE! Delete this exception and replace with your own code`" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 1: Complete Talker\n", "\n", "In your preferred text editor, open `simple_talker.py` and replace/fill in the following code block with your own code:\n", "\n", "```\n", "'''TODO-START: FILL IN CODE HERE \n", "* create a string message that contains \"Hello World\" and the iteration number i\n", "'''\n", "raise Exception(\"CODE INCOMPLETE! Delete this exception and replace with your own code\")\n", "'''TODO-END '''\n", "```\n", "\n", "Once complete, you can run the talker node\n", "\n", "_Terminal 1:_\n", "```\n", "roscore\n", "```\n", "\n", "_Terminal 2:_\n", "```\n", "python simple_talker.py\n", "```\n", "\n", "After answering the following questions, you can kill the processes by hitting `Ctrl-c` in each terminal\n", "\n", "#### Questions Set 1:\n", "\n", "1. List all rosnodes that exist after running talker.py\n", "2. List all rostopics that are being present after running talker.py\n", "3. What command do I run to see what is being published to the `/chatter` topic?\n", "4. What would I change in `simple_talker.py` to make it publish messages more frequently?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 2: Complete Listener\n", "\n", "Now we will incorporate a second rosnode to subscribe to the topic created by `simple_talker.py` and listen to the messages passed. Open `simple_listener.py` and replace/fill in the appropriate code block.\n", "\n", "Once complete, you can run the talker and listener nodes\n", "\n", "_Terminal 1:_\n", "```\n", "roscore\n", "```\n", "\n", "_Terminal 2:_\n", "```\n", "python simple_talker.py\n", "```\n", "\n", "_Terminal 3:_\n", "```\n", "python simple_listener.py\n", "```\n", "\n", "After answering the following questions, you can kill these processes by hitting `Ctrl-C` in each terminal. You will also want to commit the progress you have made so you can later push it to your team's MIT GitHub repositories:\n", "\n", "```\n", "cd ~/bwsi-uav/catkin_ws/src/aero_control/communication_pipeline/src\n", "git add -u\n", "git commit -m \"filling in code for talker and listener\"\n", "```\n", "\n", "#### Questions Set 2:\n", "\n", "1. List all rosnodes that exist after running simple_talker.py and simple_listener.py\n", "2. List all rostopics that are being present after running simple_talker.py and simple_listener.py\n", "3. In terminal I ran simple_listener.py I see information being printed. Does this mean simple_listner.py is publishing to a topic?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Step 3: Launch Talker and Listener\n", "\n", "It's a cumbersome to be opening a different terminal for every different rosnode you want to start. Instead of doing this, we can use launch files.\n", "\n", "#### Create Package\n", "\n", "Before we make a launch file, we need to more properly set up our catkin workspace by turning `aero_control` into a ROS Package and indicate it's dependencies on `std_msgs` and `rospy`\n", "\n", "```\n", "cd ~/bwsi-uav/catkin_ws/src\n", "catkin_create_pkg aero_control std_msgs rospy\n", "```\n", "\n", "