{"id":14,"date":"2017-03-14T22:09:16","date_gmt":"2017-03-14T21:09:16","guid":{"rendered":"http:\/\/marvinferber.net\/?p=14"},"modified":"2017-04-09T20:41:46","modified_gmt":"2017-04-09T19:41:46","slug":"ros-and-node-red-part-1-getting-started","status":"publish","type":"post","link":"https:\/\/marvinferber.net\/?p=14","title":{"rendered":"ROS and Node-RED Part 1: Getting started"},"content":{"rendered":"<p>I started to discover the power of wiring tasks in Node-RED recently. Since I am a passionate ROS programmer, I was wondering if this flow tool could also help to make robot programming more transparent and reproducible. I was surprised how much more sense I could add to robotic programming by using this visual tool. I am now using my <a href=\"http:\/\/www.turtlebot.com\/\">Turtlebot 2<\/a> together with ROS indigo and Node-RED. This BLOG post shall be the first of a small series of posts with the intent to share my experiences with a greater community. This first post is about setting up the software. Furthermore, I want to give a very small example how to view a Turtlebots odometry in a Node-RED flow.<\/p>\n<h2>Installing the Software<\/h2>\n<ul>\n<li><a href=\"http:\/\/wiki.ros.org\/indigo\/Installation\/Ubuntu\">ROS indigo (on Ubuntu 14.04 )<\/a><\/li>\n<li>Kobuki and <a href=\"http:\/\/wiki.ros.org\/turtlebot\/Tutorials\/indigo\/Turtlebot%20Installation\">Turtlebot packages<\/a> (either from .deb or<a href=\"https:\/\/github.com\/turtlebot\"> Github<\/a>)<\/li>\n<li><a href=\"http:\/\/wiki.ros.org\/rosbridge_suite\/Tutorials\/RunningRosbridge\">ROSbridge for Robot Web Tools<\/a><\/li>\n<li><a href=\"https:\/\/nodejs.org\/en\/download\/package-manager\/#debian-and-ubuntu-based-linux-distributions\">NodeJS (V6.10)<\/a><\/li>\n<li><a href=\"https:\/\/nodered.org\/docs\/getting-started\/installation\">Node-RED<\/a><\/li>\n<li>Node-RED extra nodes: <a href=\"https:\/\/www.npmjs.com\/package\/node-red-contrib-ros\">node-red-contrib-ros<\/a><\/li>\n<\/ul>\n<p>I assume you already have a basic knowledge of using ROS and, thus, I only link to the installation instructions at this point. The Kobuki and Turtlebot ROS packages can either be installed from the corresponding Ubuntu packages or they can be cloned from the Github repositories directly into your Catkin workspace. I also added a section on how to use this tutorial in the ROS Gazebo simulator only. So, you do not need a real Turtlebot to play around. However, the battery state visualization will not work in the simulator. To enable ROS message transfer for Web interfaces, we also need to install the ROSbridge package.<\/p>\n<ol>\n<li>The following commands will install all necessary ROS packages from Ubuntu package source.\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">apt-get install ros-indigo-turtlebot*\r\napt-get install ros-indigo-rosbridge-suite<\/pre>\n<\/li>\n<li>NodeJS version 6 was used in this tutorial. Do not install the very old .deb packaged Version of NodeJS that comes with the Ubuntu 14.04 sources. Install commands for version 6 are given below.\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">curl -sL https:\/\/deb.nodesource.com\/setup_6.x | sudo -E bash -\r\nsudo apt-get install -y nodejs<\/pre>\n<\/li>\n<li>Once installed, NodeJS includes the Node Package Manager NPM. Use NPM to install Node-RED as a global module to be available for all users. You can already start Node-RED without ROS support after installation.\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">sudo npm install -g --unsafe-perm node-red\r\nnode-red<\/pre>\n<\/li>\n<li>Node-RED automatically uses the default workspace directory ~\/.node-red\/ to store flows and additional nodes. The ROS node can be installed to this workspace directly using the command below.\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">cd ~\/.node-red\/\r\nnpm install node-red-contrib-ros<\/pre>\n<\/li>\n<\/ol>\n<h2>Booting the Software Stack<\/h2>\n<p>We need to startup the ROS nodes necessary to control our (real) Turtlebot. Also, we start the Node-RED environment and use the ROS node (inside Node-RED) to send and receive ROS messages. You may find it confusing to use the word node for ROS programs as well as for graphical representations in a workflow at the same time. Unfortunately, I am not fully able to avoid this confusion, but I will try to use the word node mostly in the context of Node-RED, not ROS. Let&#8217;s boot!<\/p>\n<ol>\n<li>Start the Turtlebot bringup package to startup your robot.\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">roslaunch turtlebot_bringup minimal.launch<\/pre>\n<\/li>\n<li>Start the ROS bridge and for Web access. This will run rosbridge and create a WebSocket on port 9090 by default.\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">roslaunch rosbridge_server rosbridge_websocket.launch<\/pre>\n<\/li>\n<li>Start Node-RED and create a configuration node in order to communicate with the ROS master.\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">node-red<\/pre>\n<div class='content-column one_third'><figure id=\"attachment_37\" aria-describedby=\"caption-attachment-37\" style=\"width: 350px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-37\" src=\"http:\/\/marvinferber.net\/wp-content\/uploads\/2017\/03\/Screenshot-at-2017-03-13-222200-e1489440361120.png\" width=\"350\" height=\"647\" srcset=\"https:\/\/marvinferber.net\/wp-content\/uploads\/2017\/03\/Screenshot-at-2017-03-13-222200-e1489440361120.png 465w, https:\/\/marvinferber.net\/wp-content\/uploads\/2017\/03\/Screenshot-at-2017-03-13-222200-e1489440361120-162x300.png 162w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><figcaption id=\"caption-attachment-37\" class=\"wp-caption-text\">ROS node contrib<\/figcaption><\/figure><\/div>\n<div class='content-column one_third'><figure id=\"attachment_40\" aria-describedby=\"caption-attachment-40\" style=\"width: 350px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-40\" src=\"http:\/\/marvinferber.net\/wp-content\/uploads\/2017\/03\/Screenshot-at-2017-03-13-222912-e1489440636128.png\" width=\"350\" height=\"375\" srcset=\"https:\/\/marvinferber.net\/wp-content\/uploads\/2017\/03\/Screenshot-at-2017-03-13-222912-e1489440636128.png 528w, https:\/\/marvinferber.net\/wp-content\/uploads\/2017\/03\/Screenshot-at-2017-03-13-222912-e1489440636128-280x300.png 280w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><figcaption id=\"caption-attachment-40\" class=\"wp-caption-text\">Edit subscription node<\/figcaption><\/figure><\/div>\n<div class='content-column one_third last_column'><figure id=\"attachment_41\" aria-describedby=\"caption-attachment-41\" style=\"width: 350px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-41\" src=\"http:\/\/marvinferber.net\/wp-content\/uploads\/2017\/03\/Screenshot-at-2017-03-13-222926-e1489440741197.png\" width=\"350\" height=\"417\" srcset=\"https:\/\/marvinferber.net\/wp-content\/uploads\/2017\/03\/Screenshot-at-2017-03-13-222926-e1489440741197.png 547w, https:\/\/marvinferber.net\/wp-content\/uploads\/2017\/03\/Screenshot-at-2017-03-13-222926-e1489440741197-252x300.png 252w\" sizes=\"auto, (max-width: 350px) 100vw, 350px\" \/><figcaption id=\"caption-attachment-41\" class=\"wp-caption-text\">Edit ROS server config node<\/figcaption><\/figure><\/div><div class='clear_column'><\/div><\/li>\n<\/ol>\n<p>Congratulations, we have managed to make contact with the ROS system from a Node-RED flow. In the next step, we will subscribe to a topic and process the data we get.<\/p>\n<h2>The first flow that contains a ROS subscription<\/h2>\n<p>In this paragraph, we subscribe to the \/odom topic and show the output in a debug view. You can copy\/paste the flow from below to try a simple \/odom subscriber.<\/p>\n<div style=\"overflow: auto; max-height: 600px;\">\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"json\">[\r\n    {\r\n        \"id\": \"f0068d88.1517f\",\r\n        \"type\": \"tab\",\r\n        \"label\": \"Odom Subscription\"\r\n    },\r\n    {\r\n        \"id\": \"f41b7a35.858bf\",\r\n        \"type\": \"ros-subscribe\",\r\n        \"z\": \"f0068d88.1517f\",\r\n        \"server\": \"81037215.2ccc8\",\r\n        \"topicname\": \"\/odom\",\r\n        \"x\": 170,\r\n        \"y\": 300,\r\n        \"wires\": [\r\n            [\r\n                \"64ec1ad3.029844\"\r\n            ]\r\n        ]\r\n    },\r\n    {\r\n        \"id\": \"31cd161a.2f6dda\",\r\n        \"type\": \"debug\",\r\n        \"z\": \"f0068d88.1517f\",\r\n        \"name\": \"print pose\",\r\n        \"active\": false,\r\n        \"console\": \"false\",\r\n        \"complete\": \"payload\",\r\n        \"x\": 720,\r\n        \"y\": 300,\r\n        \"wires\": []\r\n    },\r\n    {\r\n        \"id\": \"64ec1ad3.029844\",\r\n        \"type\": \"delay\",\r\n        \"z\": \"f0068d88.1517f\",\r\n        \"name\": \"\",\r\n        \"pauseType\": \"rate\",\r\n        \"timeout\": \"5\",\r\n        \"timeoutUnits\": \"seconds\",\r\n        \"rate\": \"1\",\r\n        \"nbRateUnits\": \"1\",\r\n        \"rateUnits\": \"second\",\r\n        \"randomFirst\": \"1\",\r\n        \"randomLast\": \"5\",\r\n        \"randomUnits\": \"seconds\",\r\n        \"drop\": true,\r\n        \"x\": 370,\r\n        \"y\": 300,\r\n        \"wires\": [\r\n            [\r\n                \"1461f4bb.3a3073\"\r\n            ]\r\n        ]\r\n    },\r\n    {\r\n        \"id\": \"1461f4bb.3a3073\",\r\n        \"type\": \"function\",\r\n        \"z\": \"f0068d88.1517f\",\r\n        \"name\": \"filter pose\",\r\n        \"func\": \"msg.payload = msg.payload.pose;\\nreturn msg;\",\r\n        \"outputs\": 1,\r\n        \"noerr\": 0,\r\n        \"x\": 560,\r\n        \"y\": 300,\r\n        \"wires\": [\r\n            [\r\n                \"31cd161a.2f6dda\"\r\n            ]\r\n        ]\r\n    },\r\n    {\r\n        \"id\": \"81037215.2ccc8\",\r\n        \"type\": \"ros-server\",\r\n        \"z\": \"\",\r\n        \"url\": \"ws:\/\/127.0.0.1:9090\"\r\n    }\r\n]<\/pre>\n<\/div>\n<figure id=\"attachment_45\" aria-describedby=\"caption-attachment-45\" style=\"width: 1228px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-45 size-full\" src=\"http:\/\/marvinferber.net\/wp-content\/uploads\/2017\/03\/Screenshot-at-2017-03-14-213001-e1489523453769.png\" width=\"1228\" height=\"326\" srcset=\"https:\/\/marvinferber.net\/wp-content\/uploads\/2017\/03\/Screenshot-at-2017-03-14-213001-e1489523453769.png 1228w, https:\/\/marvinferber.net\/wp-content\/uploads\/2017\/03\/Screenshot-at-2017-03-14-213001-e1489523453769-300x80.png 300w, https:\/\/marvinferber.net\/wp-content\/uploads\/2017\/03\/Screenshot-at-2017-03-14-213001-e1489523453769-768x204.png 768w, https:\/\/marvinferber.net\/wp-content\/uploads\/2017\/03\/Screenshot-at-2017-03-14-213001-e1489523453769-1024x272.png 1024w\" sizes=\"auto, (max-width: 1228px) 100vw, 1228px\" \/><figcaption id=\"caption-attachment-45\" class=\"wp-caption-text\">Simple \/odom subscriber flow<\/figcaption><\/figure>\n<p>The image above shows a flow that processes and shows \/odom messages from a ROS-based robot:<\/p>\n<ul>\n<li>subscribe to odom &#8211;&gt; each \/odom messages is inject into the flow from the left<\/li>\n<li>limit the potentially high rate of \/odom to reasonable 1\/s<\/li>\n<li>filter only the pose from \/odom message leaving twist, etc. out<\/li>\n<li>print the pose object in a debug view on the right<\/li>\n<\/ul>\n<h2>Using the Gazebo simulator instead of a real Turtlebot 2<\/h2>\n<p>The exact same commands as shown above can also be used when you do not have a real robot. Only one command has to be changed in order to get data from a Turtlebot 2 in the Gazebo simulator. If you have a look at the &#8220;Boot the Software Stack&#8221; paragraph. Substitute the first command (bringup package) by:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"shell\">roslaunch turtlebot_gazebo turtlebot_world.launch<\/pre>\n<p>That&#8217;s it! Happy hacking \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>I started to discover the power of wiring tasks in Node-RED recently. Since I am a passionate ROS programmer, I was wondering if this flow <a class=\"mh-excerpt-more\" href=\"https:\/\/marvinferber.net\/?p=14\" title=\"ROS and Node-RED Part 1: Getting started\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":56,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,2,4],"tags":[],"class_list":["post-14","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-nodered","category-ros","category-turtlebot"],"jetpack_featured_media_url":"https:\/\/marvinferber.net\/wp-content\/uploads\/2017\/03\/Screenshot-at-2017-03-14-220757-e1489525736378.png","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/marvinferber.net\/index.php?rest_route=\/wp\/v2\/posts\/14","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/marvinferber.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/marvinferber.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/marvinferber.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/marvinferber.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14"}],"version-history":[{"count":30,"href":"https:\/\/marvinferber.net\/index.php?rest_route=\/wp\/v2\/posts\/14\/revisions"}],"predecessor-version":[{"id":85,"href":"https:\/\/marvinferber.net\/index.php?rest_route=\/wp\/v2\/posts\/14\/revisions\/85"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/marvinferber.net\/index.php?rest_route=\/wp\/v2\/media\/56"}],"wp:attachment":[{"href":"https:\/\/marvinferber.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/marvinferber.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/marvinferber.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}