<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by ROS2JsGuy on Medium]]></title>
        <description><![CDATA[Stories by ROS2JsGuy on Medium]]></description>
        <link>https://medium.com/@ros2jsguy?source=rss-58e0e88c1fc9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*LPt77d_WVcwAdn5tr6cL2A.png</url>
            <title>Stories by ROS2JsGuy on Medium</title>
            <link>https://medium.com/@ros2jsguy?source=rss-58e0e88c1fc9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 20:07:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ros2jsguy/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Autonomous Drone Flight with Behavior Trees, AirSim-js and Nodejs]]></title>
            <link>https://ros2jsguy.medium.com/autonomous-drone-flight-with-behavior-trees-airsim-js-and-nodejs-8f11f55e7d7a?source=rss-58e0e88c1fc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/8f11f55e7d7a</guid>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[drones]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[robotics]]></category>
            <category><![CDATA[behavior-trees]]></category>
            <dc:creator><![CDATA[ROS2JsGuy]]></dc:creator>
            <pubDate>Thu, 20 Oct 2022 15:06:51 GMT</pubDate>
            <atom:updated>2022-10-20T17:04:54.828Z</atom:updated>
            <content:encoded><![CDATA[<h4>Using behavior trees for autonomous drone mission execution</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*PZYFCw54DzykXVsd" /><figcaption>Photo by <a href="https://unsplash.com/@dose?utm_source=medium&amp;utm_medium=referral">Dose Media</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Recently I needed to define and execute several missions for a multirotor drone in the AirSim simulation environment. My plan, use Nodejs and the open-source AirSim-js client library to connect with and control autonomous drones hosted in an AirSim session. That was the easy part. Next I needed a strategy for defining and executing mission flight plans. Initially I considered finite state machines (FSM). But then I remembered reading about behavior trees to implement AI in gaming and robotics. Bingo! In this article I will share how behavior trees greatly simplified my development of drone mission plans and their execution.</p><blockquote>Initially I considered finite state machines (FSM). But then I remembered reading about behavior trees. Bingo!</blockquote><h3>Brief Introduction to Behavior Trees</h3><p>To provide some context for this article here is a video of a drone flying a short mission in a neighborhood environment. The mission is implemented and executed as a behavior tree.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FkVGZGAY5fa4&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DkVGZGAY5fa4&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=google" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/e9f7296f4b1a0dd274acc052df55dc27/href">https://medium.com/media/e9f7296f4b1a0dd274acc052df55dc27/href</a></iframe><p>So what is a behavior tree?</p><p>According to Wikipedia:</p><blockquote>A <strong>behavior tree</strong> is a mathematical model of plan execution used in computer science, robotics, control systems and video games. They describe switching between a finite set of tasks in a modular fashion. Their strength comes from their ability to create very complex tasks composed of simple tasks, without worrying how the simple tasks are implemented. … Its ease of human understanding that make behavior trees less error prone and very popular in the game developer community.</blockquote><p>If you’re familiar with tree data structures, behavior trees are pretty easy to grasp.</p><p>For my application of a behavior tree, each step in a mission flight plan is implemented as either an action node or a control flow node. Sequences of actions and flow control are ordered to create behaviors. Behaviors are structured hierarchically in the form of a tree that are executed in depth-first order.</p><p>For a deeper dive into behavior trees check out the follow resources:</p><p><a href="https://www.gamedeveloper.com/programming/behavior-trees-for-ai-how-they-work">Behavior trees for ai: How they work</a><br><a href="https://opsive.com/support/documentation/behavior-designer/what-is-a-behavior-tree/">What is a Behavior Tree</a><br><a href="https://arxiv.org/pdf/1709.00084.pdf">Behavior Trees in Robotics and AI</a></p><h3>Blueshell TypeScript Behavior Trees</h3><p>A number of JavaScript implementations of behavior trees can be found in the <a href="https://www.npmjs.com/search?q=behavior%20tree">npm library</a>. I reviewed several of them and settled on the open-source <a href="https://www.npmjs.com/package/blueshell">Blueshell TypeScript behavior tree library</a>.</p><p>Blueshell provides a comprehensive collection of action, conditional, composite and decorator node types.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/704/1*CiTDTrO2w7CBLxF8OMkoUA.png" /></figure><p>To make Blueshell easier to learn I forked the Github repo and used typedoc to publish the api online at <a href="https://ros2jsguy.github.io/blueshell-docs/modules.html">https://ros2jsguy.github.io/blueshell-docs</a></p><p>For this article we will be using the Blueshell node types:</p><ul><li><strong>RunningAction </strong>— used to wrap promise-based AirSim-js api.</li><li><strong>Sequence </strong>(latched option) — an ordered list of behavior nodes that only succeeds when all of it’s child nodes succeed. Think of this node like an AND logic operator over all it’s children nodes.</li><li><strong>Selector </strong>(latched option) — similar to a Sequence except this node succeeds upon it’s first successful child node. Think of this node like an OR logic operator over all of it’s children nodes.</li></ul><p>A behavior tree propagates events from a root node down through the tree to be handled by it’s child nodes. The path that events flow is typically a depth-first traversal. At the bottom of the tree are the Action nodes, a.k.a. Tasks nodes. Actions do most of the work within the tree. The nodes above the Action nodes are either control-flow nodes or decorator nodes. Decorator nodes usually perform a transform of some type on either events or results flowing up and down through the tree respectively.</p><pre>/**<br> * Handles the event by processing it directly<br> * or dispatching to child nodes.<br> */<br>public handleEvent(state: S, event: E): ResultCode {<br>...<br>}</pre><p>The latched option for Sequence and Selector configures the node to preserve an execution history such that future invocations of the node will resume execution at the child node that running in the most recent execution.</p><h3>Drone Mission Behavior Trees</h3><p>The mission behavior tree is designed with 2 main subtrees of behaviors, the main FlightPath subtree and an emergency AbortSequence subtree.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*7Jtfu1IX3Dec2KSJJrla0w.png" /></figure><p>The Mission node is a Selector that only needs one of it’s child nodes to succeed. Since events flow downward from the Mission node to its child nodes in a depth-first order, FlightPath is the main path to which events will flow. If all of it’s child nodes succeed the flight has completed successfully. The AbortSequence subtree will only be invoked if the FlightPath tree fails for some reason. At the bottom of the tree are custom Action nodes that are designed to support long-running behaviors, e.g., 1 second to minutes.</p><p>Following is a snippet of the mission code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ddb749ccc86467887a0a09be15851ca/href">https://medium.com/media/4ddb749ccc86467887a0a09be15851ca/href</a></iframe><p>A special note aboutFlightPlanSequence. It is a subclass of LatchedSequence that persists in a FAILURE state once it has seen an ‘abort’ event. The effect is to fail-fast and force the flow of events to the AbortProcedure behaviors.</p><h3>Actions</h3><p>In a behavior tree, Action nodes do most of the work. The following class diagram illustrates actions available for creating a Mission behavior tree. Notice the AirSimAction class which maintains references to an AirSim-js session and drone vehicle. It uses Promises to execute long running api calls to AirSim.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/964/1*cVxzGtQEKjLallOuHkLLGA.png" /></figure><h3>Tic’ing and Abort Events</h3><p>Blueshell requires an external event source to drive a behavior tree. For this, generictic events are sent to the Mission node every 500 milliseconds (2 Hz). On each tic event, the Mission node passes the event to the FlightPath node. In the nominal case, FlightPath will pass the event to it’s most recent running child node, e.g., MoveToPos to be processed. When invoked with an event, a node returns a result of either SUCCESS, FAILURE, ERROR or RUNNING. Since we are using long running Actions the RUNNING result is most frequently observed result returned by Mission.</p><p>If FlightPath has previously processed an ‘abort’ event it will immediately return a FAILURE result to the Mission node. Being a Selector node, Mission will next send the event to the AbortSequence subtree. This process will continue until the Mission returns any result other than RUNNING.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/478ae90f7c9d4b197763a48a7f74bddd/href">https://medium.com/media/478ae90f7c9d4b197763a48a7f74bddd/href</a></iframe><h3>Putting it all together</h3><p>At the heart of the program is the MissionControl class. MissionControl is instantiated with a Mission behavior tree. When launched an internal timer generates tic events which are dispatched to the Mission tree. If the a mission anomally is detected an abort method is available to generate and dispatch an ‘abort’ event to the tree to initiate the abort procedure. Frequently actions need to adapt to the state of the mission. For this a MissionState data object containing configuration properties and current state information is passed into the behavior tree on each tic.</p><h3>Wrapping Up</h3><p>I found behavior trees simple to learn and apply. Their power is derived from their ability to create complex yet intuitive behaviors from smaller simpler hierarchies of behaviors. The Blueshell behavior tree library took me a little more time than it should have to get started. But once I got my head around the node types and their api I was up and running. The AirSim-js of which I’m the author is simple to use and was easily integrate into custom Blueshell Action nodes.</p><p>If you have interest in learning more about AirSim-js or Blueshell check out the links below. And finally you can find the code for the full demo <a href="https://github.com/ros2jsguy/airsim-js-drone-mission">here</a>.</p><p>Thanks for checking out this AirSim-js introduction. If you liked this article please give it a Thumbs Up and a share on twitter. You can reach me on Twitter at <a href="https://twitter.com/ros2jsguy">@ros2jsguy</a> and find code that I’ve developed or working on at my GitHub account: <a href="https://github.com/ros2jsguy">https://github.com/ros2jsguy</a></p><h4>Resources</h4><p><a href="https://ros2jsguy.medium.com/introducing-airsim-js-b4d340536908">Introducing AirSim-js</a><br><a href="https://github.com/ros2jsguy/airsim-js-drone-mission">airsim-js-drone-mission Github repo</a><br><a href="https://ros2jsguy.github.io/blueshell-docs/index.html">Blueshell API docs</a><br><a href="https://www.npmjs.com/package/blueshell">Blueshell npm</a><br><a href="https://github.com/6RiverSystems/blueshell">Blueshell Github repo</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8f11f55e7d7a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What’s new in AirSim-js 0.3 for TypeScript]]></title>
            <link>https://ros2jsguy.medium.com/whats-new-in-airsim-js-0-3-for-typescript-e33df151503d?source=rss-58e0e88c1fc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/e33df151503d</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[robotics-simulation]]></category>
            <category><![CDATA[linear-algebra]]></category>
            <category><![CDATA[airsim]]></category>
            <dc:creator><![CDATA[ROS2JsGuy]]></dc:creator>
            <pubDate>Wed, 31 Aug 2022 06:06:51 GMT</pubDate>
            <atom:updated>2022-08-31T13:49:56.755Z</atom:updated>
            <content:encoded><![CDATA[<p>AirSim-js 0.3 was released yesterday (20220830) with several enhancements to simplify working with the AirSim TypeScript api. In this article we will introduce the key improvements of version 0.3.0.</p><p>If you are new to AirSim-js see this getting-started <a href="https://ros2jsguy.medium.com/introducing-airsim-js-b4d340536908">introduction</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SrEwI3Ezm-sr0cLbNi5OUw.png" /><figcaption>New cameraLookAt() &amp; plotArrow() methods</figcaption></figure><h3>AirSim constructor arguments</h3><p>Let’s start by looking at an improvement in the AirSim client constructor arguments. Now you have the following constructor overloads to choose from:</p><pre>constructor(<br>  vehicleClass: Constructor&lt;T&gt;,<br>  port?: number);</pre><pre>constructor(<br>  vehicleClass: Constructor&lt;T&gt;,<br>  ipAddress?: string);</pre><pre>constructor(<br>  vehicleClass: Constructor&lt;T&gt;,<br>  port?: number,<br>  ipAddress?: string);</pre><p>Examples</p><pre>new AirSim(Vehicle)<br>new AirSim(Car, &#39;127.0.0.1&#39;)<br>new AirSim(Multirotor, 80)<br>new AirSim(Multirotor, 80, &#39;127.0.0.1&#39;)</pre><h3>Integrated use of threejs-math classes</h3><p>The <a href="https://threejs.org/">Three.js 3D graphics library</a> includes a rich set of linear algebra and geometry classes. Recently I forked and repackaged these math classes into the NPM <a href="https://www.npmjs.com/package/threejs-math"><strong>threejs-math package</strong></a>, e.g., Vector3, Quaternion, Matrix4…, for stand-alone use in any Node.js package. In this release, I have fully replaced the AirSim server-side math types such as Vector3r with their much more capable threejs-math counterpart classes. You can identify native AirSim server-side types as they have the Raw prefix, e.g., RawVector3, RawCameraInfo… and are most prevalent on the Session api.</p><p>The new threejs-math classes used internally and exported by AirSim-js are:</p><pre>Euler<br>MathUtils<br>Matrix<br>Matrix3<br>Matrix4<br>Plane<br>Quaternion<br>Ray<br>Vector<br>Vector2<br>Vector3</pre><h3>New types: Color, ColorName and CameraName</h3><p>In previous releases, color was represented exclusively as an RGBA tuple, e.g., red =[1,0,0,1]. With the deeper integration of threejs-math, I’ve taken advantage of the three.js Color class and CSS color names to introduce a Color union type of either an RGBA tuple or a CSS color name.</p><pre>type CSSColorName = &#39;aliceblue&#39;,&#39;antiquewhite&#39;,&#39;aqua&#39;,&#39;aquamarine&#39;,&#39;azure&#39;,&#39;beige&#39;,&#39;bisque&#39;,&#39;black&#39;,&#39;blanchedalmond&#39;,&#39;blue&#39;,&#39;blueviolet&#39;,&#39;brown&#39;,&#39;burlywood&#39;,&#39;cadetblue&#39;,&#39;chartreuse&#39;,&#39;chocolate&#39;,&#39;coral&#39;,&#39;cornflowerblue&#39;,&#39;cornsilk&#39;,&#39;crimson&#39;,&#39;cyan&#39;,&#39;darkblue&#39;,&#39;darkcyan&#39;,&#39;darkgoldenrod&#39;,&#39;darkgray&#39;,&#39;darkgreen&#39;,&#39;darkgrey&#39;,&#39;darkkhaki&#39;,&#39;darkmagenta&#39;,&#39;darkolivegreen&#39;,&#39;darkorange&#39;,&#39;darkorchid&#39;,&#39;darkred&#39;,&#39;darksalmon&#39;,&#39;darkseagreen&#39;,&#39;darkslateblue&#39;,&#39;darkslategray&#39;,&#39;darkslategrey&#39;,&#39;darkturquoise&#39;,&#39;darkviolet&#39;,&#39;deeppink&#39;,&#39;deepskyblue&#39;,&#39;dimgray&#39;,&#39;dimgrey&#39;,&#39;dodgerblue&#39;,&#39;firebrick&#39;,&#39;floralwhite&#39;,&#39;forestgreen&#39;,&#39;fuchsia&#39;,&#39;gainsboro&#39;,&#39;ghostwhite&#39;,&#39;gold&#39;,&#39;gold&#39;,&#39;goldenrod&#39;,&#39;gray&#39;,&#39;green&#39;,&#39;greenyellow&#39;,&#39;grey&#39;,&#39;honeydew&#39;,&#39;hotpink&#39;,&#39;indianred&#39;,&#39;indigo&#39;,&#39;ivory&#39;,&#39;khaki&#39;,&#39;lavender&#39;,&#39;lavenderblush&#39;,&#39;lawngreen&#39;,&#39;lemonchiffon&#39;,&#39;lightblue&#39;,&#39;lightcoral&#39;,&#39;lightcyan&#39;,&#39;lightgoldenrodyellow&#39;,&#39;lightgray&#39;,&#39;lightgreen&#39;,&#39;lightgrey&#39;,&#39;lightpink&#39;,&#39;lightsalmon&#39;,&#39;lightseagreen&#39;,&#39;lightskyblue&#39;,&#39;lightslategray&#39;,&#39;lightslategrey&#39;,&#39;lightsteelblue&#39;,&#39;lightyellow&#39;,&#39;lime&#39;,&#39;limegreen&#39;,&#39;linen&#39;,&#39;magenta&#39;,&#39;maroon&#39;,&#39;mediumaquamarine&#39;,&#39;mediumblue&#39;,&#39;mediumorchid&#39;,&#39;mediumpurple&#39;,&#39;mediumseagreen&#39;,&#39;mediumslateblue&#39;,&#39;mediumspringgreen&#39;,&#39;mediumturquoise&#39;,&#39;mediumvioletred&#39;,&#39;midnightblue&#39;,&#39;mintcream&#39;,&#39;mistyrose&#39;,&#39;moccasin&#39;,&#39;navajowhite&#39;,&#39;navy&#39;,&#39;oldlace&#39;,&#39;olive&#39;,&#39;olivedrab&#39;,&#39;orange&#39;,&#39;orangered&#39;,&#39;orchid&#39;,&#39;palegoldenrod&#39;,&#39;palegreen&#39;,&#39;paleturquoise&#39;,&#39;palevioletred&#39;,&#39;papayawhip&#39;,&#39;peachpuff&#39;,&#39;peru&#39;,&#39;pink&#39;,&#39;plum&#39;,&#39;powderblue&#39;,&#39;purple&#39;,&#39;rebeccapurple&#39;,&#39;red&#39;,&#39;rosybrown&#39;,&#39;royalblue&#39;,&#39;saddlebrown&#39;,&#39;salmon&#39;,&#39;sandybrown&#39;,&#39;seagreen&#39;,&#39;seashell&#39;,&#39;sienna&#39;,&#39;silver&#39;,&#39;skyblue&#39;,&#39;slateblue&#39;,&#39;slategray&#39;,&#39;slategrey&#39;,&#39;snow&#39;,&#39;springgreen&#39;,&#39;steelblue&#39;,&#39;tan&#39;,&#39;teal&#39;,&#39;thistle&#39;,&#39;tomato&#39;,&#39;turquoise&#39;,&#39;violet&#39;,&#39;wheat&#39;,&#39;white&#39;,&#39;whitesmoke&#39;,&#39;yellow&#39;,&#39;yellowgreen&#39;</pre><pre>type RGBA = [number, number, number, number];</pre><pre>type Color = RGBA | CSSColorName;<br></pre><p>The following table provides a color sample for each color name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*zvcnZJzb4LOLxF89AtYbeQ.png" /><figcaption>Color Names <a href="https://htmlcss.fandom.com/wiki/Color_Codes">https://htmlcss.fandom.com/wiki/Color_Codes</a></figcaption></figure><p>I also merged the 2 forms for referencing a camera into a single CameraNameunion type.</p><pre>type CameraName = string | 0 | 1 | 2 | 3 | 4;</pre><h3>New Vehicle cameraLookAt() method</h3><p>The Vehicle class has a new cameraLookAt(target: Vector3) method that simplifies the aiming of any vehicle camera at a target location.</p><pre>/**<br>* Rotate a camera to point towards a target position.<br>* @param cameraName - The name or id of the camera to move.<br>* @param target - The position to point camera towards.<br>* @param rearFacing - Set True when camera is mounting<br>* looking towards the rear of the vehicle, default = false.<br>* @returns A Promise&lt;Pose&gt; with the camera rotation..<br>*/<br>async cameraLookAt(<br>        cameraName: CameraName,<br>        target: Vector3,<br>        isRearFacing = false<br>): Promise&lt;Pose&gt;</pre><p>See the <a href="https://github.com/ros2jsguy/airsim-js/blob/master/examples/lookat.ts">examples/lookat.ts</a> program that demonstrates the use of this method to keep the orange ball in the Blocks environment centered in the front_center camera.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*jXmO1xw8DmGIwcEe8PZ06Q.png" /><figcaption>cameraLookAt(orangeBall)</figcaption></figure><h3>Revised all AirSim.plotXXX() methods</h3><p>In previous versions of AirSim-js the last 2 arguments of the AirSim plotXXX() methods were used to separately specify if the object being display was persistent or transient and for transient objects, how many seconds to display the object. This pattern was a little awkward. To improve usability the 2 arguments have been merged into a single union argument type.</p><p>Here’s the new argument list for the plotXXX() methods. Notice the durationOrPersistent union type argument which are now persistent by default.</p><pre>/**<br>* Plots a list of arrows in World NED frame, defined <br>* from points_start[0] to points_end[0], points_start[1] to<br>* points_end[1], ... ,<br>* points_start[n-1] to points_end[n-1]<br>* @param pointsStart - Array of 3D start positions of arrow start<br>*     positions, specified as Vector3 object<br>* @param pointsEnd - Array of 3D end positions of arrow start<br>*     positions, specified as Vector3 objects<br>* @param color - Line color as RGBA tuple of values from 0.0 to 1.0 *     or CSS color name. Default = &#39;red&#39;.<br>* @param thickness - Thickness of line. Default = 5.0.<br>* @param arrowSize - Size of arrow head. Default = 2.0.<br>* @param durationOrPersistent - Duration (seconds) to display arrows<br>*     or True to display indefinetly. Default = True.<br>* @returns A Promise&lt;void&gt; to await on.<br>*/<br>plotArrows(<br>   pointsStart: Array&lt;Vector3&gt;,<br>   pointsEnd: Array&lt;Vector3&gt;,<br>   color: Color = &#39;red&#39;,<br>   thickness = 5.0,<br>   arrowSize = 2.0,<br>   durationOrPersistent: number | true = true): Promise&lt;void&gt;</pre><p>The following methods have been updated to use this durationOrPersistent pattern:</p><pre>plotArrows()<br>plotLineList()<br>plotLineStrip()<br>plotPoints()<br>plotStrings()<br>plotTransforms()<br>plotTransformsWithNames()</pre><p>The new lookat.ts example makes use of the `plotArrows()` method to display a red arrow parallel with the vehicle and a 2nd green arrow pointing to the center of the orange ball from the vehicle’s current location in the Blocks environment.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*z96SLUv40i53lEAhcMkI8g.png" /><figcaption>plotArrows() example</figcaption></figure><h3>Wrapping Up</h3><p>Thanks for checking out what’s new in AirSim-js 0.3.0. If you liked this article please give it a Thumbs Up and a share on twitter. You can reach me on Twitter at <a href="https://twitter.com/ros2jsguy">@ros2jsguy</a> and find code that I’ve developed or working on at my GitHub account: <a href="https://github.com/ros2jsguy">https://github.com/ros2jsguy</a></p><p>Lastly, you can find additional AirSim-js examples in the <a href="https://github.com/ros2jsguy/airsim-js">AirSim-js GitHub repo</a>. Until next time, <strong>Happy Coding!</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e33df151503d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing AirSim-js]]></title>
            <link>https://ros2jsguy.medium.com/introducing-airsim-js-b4d340536908?source=rss-58e0e88c1fc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4d340536908</guid>
            <dc:creator><![CDATA[ROS2JsGuy]]></dc:creator>
            <pubDate>Wed, 20 Jul 2022 04:20:53 GMT</pubDate>
            <atom:updated>2022-07-20T04:44:07.789Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently I released <a href="https://www.npmjs.com/package/airsim-js">AirSim-js</a>, an open-source Nodejs client for <a href="https://www.microsoft.com/en-us/research/project/aerial-informatics-robotics-platform/">AirSim</a> (Aerial Informatics and Robotics Simulation). In this article I’ll introduce you to the cool AirSim environment and how to programmatically drive a car within AirSim using TypeScript and the AirSim-js package.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X2WPe9_GnG6cU7ZIhzCwbQ.png" /><figcaption>AirSimNH (neighborhood) Environment</figcaption></figure><h3>Background</h3><p>If you’re new to AirSim, it’s an open-source 3D simulation platform developed by Microsoft AI Research. Out of the box it includes high resolution models of flying drones and driving cars within worlds such as a simple blocks world, a busy city street environment, a residential neighborhood and even an abandoned amusement park. Within these environments, vehicles, weather, time of day and simulation rate of execution are configurable. Another cool feature of AirSim is it’s support for hardware-in-the-loop. But for developers,<strong> the coolest feature is that AirSim can be programmatically controlled through an RPC interface </strong>based on the <a href="https://msgpack.org/">msgpack-rpc</a> protocol.</p><p>You can see AirSim in action in this <a href="https://youtu.be/-WfTr1-OBGQ">short video</a>.</p><h4>Vehicle Sensors</h4><p>AirSim vehicles can be outfitted with multiple types of sensors. The supported sensors are:</p><ul><li>Barometer for altitude</li><li>Distance meter</li><li>GPS for position</li><li>IMU for acceleration and angular velocity</li><li>3D LIDAR for point mapping</li><li>Magnetometer for heading</li></ul><p>The drone default sensors are: barometer, GPS, IMU and magnetometer. The default car sensors are the lonely GPS sensor. You can easily create a new drone or car with additional sensors such as LIDAR.</p><h4>Cameras and Images</h4><p>In addition to sensors, vehicles are preconfigured with 5 cameras and named by their position, e.g., front_center, back_center, bottom_center or fpv. The specifics of each camera are customizable. Beyond the default cameras, new cameras can added to a vehicle or installed externally anywhere in the sim world. From any camera you can request images in the following formats: RGB, distance, infrared, optical flow or segmentation.</p><h4>ROS Integration</h4><p>AirSim includes an integration with the increasingly popular Robot Operating System (ROS). This is a useful capability being able to tie AirSim into the ROS ecosystem of navigation and control algorithms, e.g. SLAM.</p><h3>Getting Started with AirSim</h3><p>Coding with AirSim-js is simple but first you’ll need to install AirSim and become familiar with it.</p><h4>Install and Launch the AirSim Blocks environment</h4><p>The AirSim project provides prebuilt Linux and Windows binaries for several simulation worlds.</p><ol><li>Begin by <a href="https://github.com/Microsoft/AirSim/#how-to-get-it">downloading</a> the Blocks world for your platform (Linux or Windows).</li></ol><p>2. Unzip the Blocks.zip download to a folder of your choice.</p><p>3. From a terminal, navigate to the Blocks executable and launch it in Car view mode.</p><pre>#Linux<br>&gt; cd install_dir/Blocks/LinuxNoEditor/Blocks/Blocks.sh</pre><pre>#Windows<br>&gt; cd install_dir\Blocks\WindowsNoEditor\Blocks\Binaries\Win64\Blocks.exe</pre><p>On startup, AirSim will present the following view-mode selection dialog. Select <strong>Yes </strong>for Car view-mode<strong>.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/391/1*qQaa08ZSoOkJEGpwzzRDBA.png" /></figure><p>The Blocks world window should appear containing a single car similar to this screenshot.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*lZ7iNmD0R4bdNxwWex8lvA.png" /><figcaption>Blocks World in Car view-mode</figcaption></figure><p>4. Practice driving the car manually using the Arrow keys on your keyboard.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/150/1*MvsoK5BhRFWJ4Wvfiw5amg.png" /></figure><h3>Coding with AirSim-js</h3><h4>Ping the Blocks environment</h4><p>Our 1st coding task is to run an AirSim rpc `ping` command against our running Blocks process. For this you will need to have Nodejs installed on your system and basic knowledge of TypeScript. See the following <a href="http://dddd/">directions </a>if you need assistance with this prerequisite step.</p><h4>Step-1: Node-TypeScript project setup</h4><p>Create and initialize a Nodejs TypeScript package. Begin by entering the following commands from a terminal:</p><pre>mkdir airsim-js-intro<br>cd airsim-js-intro<br>npm init -y<br>npm i airsim-js<br>npm i typescript <a href="http://twitter.com/types/node">@types/node</a> --save-dev<br>npx tsc --init</pre><p><em>Note — the Node-TypeScript project presented are for demonstration purposes only. Please don’t troll me.</em></p><h4>Step-2: Coding ping.ts</h4><p>Create a file named ping.ts and add the following TypeScript code to it. Review the comments for a narration of the code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b06f7a1f6ada80dacd036c1410693f1b/href">https://medium.com/media/b06f7a1f6ada80dacd036c1410693f1b/href</a></iframe><p>A special note about line-7. One of the responsibilities of the AirSim class is to serve as a factory for generic Vehicles, Cars and Multirotors. Therefore a class constructor of one of these vehicle classes is a required parameter. If you provide the constructor of Vehicle subclass such as Car or Multirotor it must match the view-mode of the AirSim world you are connecting. That is don’t run AirSim in Car mode and attempt to use the AirSim-js Multirotor API. Lastly, in the example, the code assumes that ping.ts be will executed on the same machine that is hosting the AirSim world. This is not a hard requriement as the AirSim constructor included parameters for a custom IP and port number.</p><p>For more AirSim class details see <a href="https://ros2jsguy.github.io/airsim-js/api/classes/AirSim.html">AirSim TSDoc</a>.</p><pre>/** <br> * Create an AirSim client.<br> * AirSim serves as a factory for Vehicles, (e.g., Car, Multirotor)<br> * hosted in an AirSim environment. When constructing a new AirSim<br> * client instance you must provide the class of Vehicle hosted by AirSim.<br> * @param vehicleClass — The type of vehicle hosted by the AirSim server<br> * @param port — The AirSim server port number, default = 41451<br> * @param ip — The AirSim server IP address, default = 127.0.0.1<br> */<br>constructor(<br>    private vehicleClass: Constructor&lt;T&gt;,<br>    public port: string | number = 41451,<br>    public readonly ip = &#39;127.0.0.1&#39;<br>)</pre><h4>Step-3: Transpile ping.ts</h4><p>This step converts the ping.ts file to the runnable ping.js javascript file.</p><pre>npx tsc</pre><h4>Step-4: Run ping</h4><p>Run the ping.js file using the Nodejs runtime.</p><pre>node ping.js</pre><p>If everything works correctly the console output should be similar to this:</p><pre>&gt; node ping.js<br>connected: true<br>Calling ping<br>result: true<br>Connected!<br>Client Ver: 1 (Min Req: 1)<br>Server Ver: 1 (Min Req: 1)</pre><h3>Drive the Car in the Blocks environment</h3><p>Next let’s write some code to do something interesting like drive the car. Feel free to skip ahead to the code for driving the Blocks car.</p><p>The idea is to command the car’s steering angle and throttle such that the car turns in a circle. We will do that using a CarControls object. Here’s the definition of CarControls:</p><pre>/**<br> * Car control settings<br> */<br>export type CarControls = {<br>  throttle: number,            // 0.0–1.0<br>  steering: number,            // -1.0 to 1.0, left to right<br>  brake: number,               // 0.0–1.0<br>  handbrake: boolean,          // true = apply handbrake */<br>  is_manual_gear: boolean,     // true implies use manual_gear prop<br>  manual_gear: number,         // -1 to 5, 0 = neutral<br>  gear_immediate: boolean      // shift to manual gear setting now<br>}</pre><p>We can create a CarControls instance from scratch or request the current CarControls from a car instance. Then we modify the subset of properties that represent our intentions as shown.</p><pre>const controls = await car.getControls();<br>controls.throttle = 0.25; // forward at 1/4 speed<br>controls.steering = 1.0;  // full right turn</pre><p><strong>Getting a handle to the Car</strong></p><p>Before we can send commands to a car we need a handle to it. We can do this in 2 ways. The first is to access the car by name, assuming we know the car’s unique name. The second approach shown below is to request all the vehicles and find the target car in the list.</p><pre>const cars = await airsim.getVehicles();<br>const car = cars[0]; // use the 1st car</pre><p><strong>API Control — Enable before use; Disable when not in use</strong></p><p>Before we can send commands to a vehicle we need to enable it’s API. Then upon completion of our use of the vehicle’s api, we should always disable the API.</p><pre>await car.enableApiControl();<br>await car.disableApiControl();</pre><p><strong>Note: When working with a Car instance, failure to disable the API after use may result in keyboard control of the car becoming unresponsive.</strong></p><p>OK, let’s put this all together.</p><h4>Step-1: Create the drive.ts file with car control code</h4><p>Create a file nameddrive.ts file in the root folder of our project and add the following TypeScript code to it.</p><p>Notice the structure and flow of the code as this is a common structure of most AirSim-js programs.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9927c9e99be124aa7bb240e245b18130/href">https://medium.com/media/9927c9e99be124aa7bb240e245b18130/href</a></iframe><p>You may notice the use of the Three.js Math classes, i.e.., Quaternion and Vector3. This is a well proven library that simplifies basic linear algebra mathematics.</p><h4>Step-2: Transpile drive.ts</h4><p>Convert the drive.ts file to the runnable drive.js JavaScript file.</p><pre>npx tsc</pre><h4>Step-3: Run drive.js</h4><p>Launch the Nodejs runtime with the drive.js file and watch the car drive in a circle.</p><pre>node drive.js</pre><p>Use the F1 key to access a menu to adjust your camera views as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*i6u3M8vXpMrZ65mJyIK4Fw.gif" /></figure><h3>Wrapping Up</h3><p>Thanks for checking out this AirSim-js introduction. If you liked this article please give it a Thumbs Up and a share on twitter. You can reach me on Twitter at <a href="https://twitter.com/ros2jsguy">@ros2jsguy</a> and find code that I’ve developed or working on at my GitHub account: <a href="https://github.com/ros2jsguy">https://github.com/ros2jsguy</a></p><p>Lastly, you can find additional AirSim-js examples in the <a href="https://github.com/ros2jsguy/airsim-js">AirSim-js GitHub repo</a>. In the next article we’ll learn how to programmatically fly a drone in the AirSimNH (neighborhood) environment. Until then Happy Coding!</p><h4>References</h4><p><a href="https://www.microsoft.com/en-us/research/project/aerial-informatics-robotics-platform/">Aerial Informatics and Robotics Platform - Microsoft Research</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4d340536908" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introducing The rclnodejs-cli Tools for ROS 2 JavaScript Coders]]></title>
            <link>https://ros2jsguy.medium.com/introducing-the-rclnodejs-cli-tools-for-ros-2-javascript-coders-8889b4e25d38?source=rss-58e0e88c1fc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/8889b4e25d38</guid>
            <dc:creator><![CDATA[ROS2JsGuy]]></dc:creator>
            <pubDate>Fri, 11 Feb 2022 21:14:36 GMT</pubDate>
            <atom:updated>2022-02-11T21:15:49.671Z</atom:updated>
            <content:encoded><![CDATA[<p>For developers interested in implementing <a href="https://ros.org/">ROS 2</a> solutions using JavaScript or TypeScript, the <a href="https://www.npmjs.com/package/rclnodejs">rclnodejs</a> package (<strong>R</strong>OS <strong>c</strong>lient <strong>l</strong>ibrary <strong>nodejs</strong>) provides a complete Nodejs JavaScript binding and TypeScript declarations to the ROS 2 API. A companion Nodejs package <a href="https://www.npmjs.com/package/rclnodejs-cli">rclnodejs-cli</a>, was released last year to provide commandline tools to help when using rclnodejs. Let’s take a look at the rclnodejs-cli tools.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*7apcOGjWmHUHfs6gjIOyeQ.png" /></figure><h4>Prerequisites</h4><p>Before we begin you’ll need to following software installed to run the rclnodejs-cli tools:</p><ul><li>Nodejs version between 10.22–17</li><li>ROS 2 Galactic or Foxy (LTS) releases</li><li>optional: <a href="https://docs.ros.org/en/foxy/Tutorials/Colcon-Tutorial.html">ROS 2 colcon build tool</a> required for the create-packagetool</li></ul><p>If you lack a ROS 2 installation know that it is pretty simple to setup in a Linux environment. A few months ago I setup Linux Ubuntu 20.04 and ROS 2 galactic distros in WSL2 on my Windows 11 machine for a really convenient development environment. See this <a href="https://youtu.be/f8_nvJzuaSU?t=215">youtube demo</a> to see the ROS tools running in WSL. Lastly the screenshots in this article are from this environment using the new Windows Terminal.</p><h4>Running rclnodejs-cli</h4><p>To see tools available from rclnodejs-cli run the following command from a terminal usingnpx . Alternatively you can install rclnodejs-cli as a global package and run it directly without using npx.</p><pre>npx rclnodejs-cli -h</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*ji0FMREE5w7e2bra3C_Yng.png" /></figure><h3>generate-ros-messages Tool</h3><p>The first tool we will look at is the generate-ros-messages tool. <strong>Use this tool when you add new interface packages to your ROS environment for which your Nodejs project uses.</strong></p><p>This tool searches your ROS 2 environment for interface definitions files, e.g., *.msg and *.srv. For each interface file the tool generates a similarly named JavaScript file that rclnodejs uses to serialize and deserialize ROS 2 messages it sends and receives in a ROS graph. You can find all of the generated serialization files in your Nodejs project’s node_modules/rclnodejs/generated folder.</p><h4>Usage</h4><p>Run the generate-ros-messages command in the root directory of your Nodejs package, i.e., the directory containing the package.json file. The Nodejs package must haverclnodejs already installed as a dependent package.</p><pre>cd &lt;your-nodejs-package&gt;<br>npx rclnodejs-cli generate-ros-messages</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/1*YWEPT7KVwVma01IwZHxlRg.png" /></figure><h3>create-package Tool</h3><p><strong>The </strong><strong>create-package tool creates hybrid ROS2-Nodejs packages that can coexist and participate with other ROS2 packages in a ROS2 workspace.</strong> Additionally these packages can be run and orchestrated using the ROS2 <a href="https://docs.ros.org/en/foxy/Tutorials/Launch/Launch-system.html">launch</a> facility. A ROS2-Nodejs package consist of a traditional ROS2 package, specifically an ament-cmake ROS2 package, overlaid with a Nodejs package.</p><p><strong>Key Features</strong></p><ul><li>Creates a ROS2 ament_cmake package and overlays it with a custom Nodejs package.</li><li>--typescript commandline option to configure the package for use with TypeScript.</li><li>Installs the ROS2 JavaScript client library, <a href="https://github.com/RobotWebTools/rclnodejs">rclnodejs</a> as a runtime dependency.</li><li>Creates an example JavaScript/TypeScript ROS2 publisher node and ROS2 launch-description.</li><li>Customized CMakeList.txt install() rules to install key runtime files to the package share/ folder</li></ul><h4>Usage</h4><p>To view the create-package tool arguments and options enter the following command from a terminal:</p><pre>npx rclnodejs-cli create-package -h</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*oOAuZktVuYxWgDav6t332A.png" /></figure><p>Now let’s create a simple ROS2-Nodejs package configured to support TypeScript coding. If you do would rather use JavaScript omit the --typescript flag.</p><pre>npx rclnodejs-cli create-package mypkg --typescript</pre><p><em>Note: Package names should conform to the </em><a href="http://wiki.ros.org/ROS/Patterns/Conventions"><em>ROS2 Patterns and Conventions</em></a><em>, e.g., use </em><em>_ underscores as separators in a package name instead of &#39;-&#39; dashes.</em></p><p>The new package directory content should be similar to this listing:</p><pre>mypkg/<br>  CMakeLists.txt<br>  __init__.py<br>  launch/<br>    mypkg.launch.py<br>  node_modules/<br>  package.json<br>  package.xml<br>  src/<br>    index.ts<br>  tsconfig.json</pre><ol><li>Compile the example TypeScript src/index.ts file, an example ROS node that publishes a String message.</li></ol><pre>npm run build</pre><p>2. Use the <a href="https://docs.ros.org/en/foxy/Tutorials/Colcon-Tutorial.html"><strong>colcon</strong></a><strong> </strong>build utility to install the key JavaScript resources into the ./install/share/ folder.</p><pre>colcon build</pre><p>Your package folder will now include the standard ROS2 package directories: build/, install/ and log/. The install/ directory includes configuration scripts and if you look deep into the install/mypkg/share/mypkg folder you will see the install() rules in the CMakeLists.txt have installed the key JavaScript resources from the src/ and launch/ directories.</p><p><em>Tip — Alway run the </em><em>colcon buildcommand when you are actively developing and using launch files from your project. This will ensure the launch includes your latest code.</em></p><p>3. Add your new ROS2-Nodejs package to your ROS environment.</p><p>From your mypkg root folder run:</p><p>Linux<br>source install/setup.bash</p><p>Windows <br>install\setup.bat</p><p>4. Verify that the ROS2-Nodejs package is part of your ROS2 environment using the ros2 CLI command.</p><pre>ros2 pkg list</pre><p>This command will output a long list of the packages in your ROS2 environment. Scroll through the list and verify it contains the mypkg package.</p><p>5. Launch mypkg.launch.py</p><p>We can now use the ros2 launch command to run the mypkg.launch.py launch-description. This launch file defines how to startup the example app in our ROS2-Nodejs package. The example app creates a ROS2 node and publisher that sends a std_msgs/msg/Stringmessage every second to the topic named foo. See src/index.ts for the TypeScript implementation details.</p><p>Launch example.launch.py as shown below:</p><pre>ros2 launch mypkg example.launch.py</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NYi2OwJq2BSq2ljlKWV9KA.png" /></figure><p>To view the messages being published to the foo topic, open a separate shell configured with your ROS2 environment and enter:</p><pre>ros2 topic echo foo</pre><p>A message should appear every second.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/292/1*GiqWoA6Qvh7eHt3-sDTLyA.png" /></figure><h3>Conclusion</h3><p>I hope this introduction to rclnodejs-cli is helpful and saves you time and hassle with your ROS 2 development. rclnodejs-cli is an open-source project and can be found <a href="https://github.com/RobotWebTools/rclnodejs-cli">here</a> in Github.</p><p><strong><em>Please consider liking this tutorial and following me here and on Twitter </em></strong><a href="https://twitter.com/ros2jsguy"><strong><em>@ros2jsguy</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8889b4e25d38" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Communicate Robot Status using a blink(1) RGB LED]]></title>
            <link>https://ros2jsguy.medium.com/communicate-robot-status-using-a-blink-1-rgb-led-7c70be44b2e7?source=rss-58e0e88c1fc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/7c70be44b2e7</guid>
            <category><![CDATA[robotics]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[led]]></category>
            <category><![CDATA[blink1]]></category>
            <dc:creator><![CDATA[ROS2JsGuy]]></dc:creator>
            <pubDate>Wed, 30 Jun 2021 19:42:05 GMT</pubDate>
            <atom:updated>2021-06-30T19:42:05.779Z</atom:updated>
            <content:encoded><![CDATA[<h3>Visualize Robot Status Using a Programmable blink(1) RGB LED</h3><p><em>This article introduces the programmable blink(1) USB RGB LED and develops a simple cross platform TypeScript/Nodejs program that can be used to visually communicating a robot’s state on a microcontroller such as the Raspberry Pi.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/257/1*FnalIhtWJDn0zHaBWfDLKQ.jpeg" /><figcaption>blink(1) on a Raspberry Pi</figcaption></figure><p>Recently I began developing a small self balancing robot powered by a Raspberry Pi 4. As I have added more features and robustness to the design I found that I needed a way to visually identify various states of the robot’s operation such as power on, initializing, running, error, and obstacle detection. Initially I planned to use several cheap LEDs. But the amount of free space on my breadboard had become pretty tight. While considering my options I remembered the old blink(1) RGB LED that my company gave me a few years ago as part of an internal project. The blink(1) is colorful, very bright and noticeable and easy to control programmatically LED — the perfect solution for my project and I hope your projects as well.</p><h4>blink(1) RGB LED</h4><p>If you’ve never seen a blink(1) it is a cool programmable RGB LED that plugs into a USB port and works on most devices and OSSes. <a href="https://blink1.thingm.com/">ThingM</a>, the company behind the blink(1) device, describes it like this:</p><blockquote>blink(1) packs three dimensions of information (color, brightness and pattern) into a single tiny package that fits into any USB port on nearly every device. It makes it incredibly easy to connect any data source in the cloud or on your computer to a full-color RGB LED so you can know what’s happening…</blockquote><p>The blink(1) is available from ThingM, Amazon and several other regional distributors for approximately $30 USD.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/676/1*38X1Y8LiZZZsz0vHCegNAg.png" /></figure><h3>Controlling a blink(1) LED from TypeScript &amp; Nodejs</h3><p>Let’s look at how easy it is to program a blink(1) LED by developing a small program that uses colored light patterns to communicate the state of a robot system. We will walk through the steps for creating an example program named <strong>blink1-status-led </strong>using TypeScript and Nodejs coding technologies. I’m using these technologies as this is the coding environment in which I have implemented my robot control logic and device drivers. The program will run on Linux, Mac and Windows OSes and most hardware. For example, I evolved this program and deployed on a Raspberry Pi 4 running Ubuntu Linux 20.04 and a blink(1) device.</p><h3>Prerequisites</h3><ul><li>blink(1) LED device</li><li><a href="https://nodejs.org/en/download/releases/">Nodejs version 12</a> or greater</li><li>Computer or microcontroller running Windows, Mac or Linux</li><li>Ensure blink(1) operates correctly.<br>Before starting to code, ensure that your blink(1) LED is functioning properly. The <a href="https://blink1.thingm.com/blink1control/">Blink1Control </a>software utility from ThingM can be helpful in this task. There are versions for both Windows and Mac. Also be sure to close any program that may be accessing your blink(1) before attempting to run our blink1-status-led program.</li><li>Linux only configuration.<br>If you plan to interact with a blink(1) on a Linux system, the system may require USB and HID configuration. installations your OS may need configuration. For more information see Linux Users section <a href="https://github.com/ros2jsguy/node-blink1-async">here</a>.</li></ul><h3>TypeScript/Nodejs Project Setup</h3><p>Our first task is to create a Nodejs project configured with TypeScript tools and JavaScript dependency libraries.</p><p>From a terminal begin by creating a new folder named <strong>blink1-status-led. </strong>This folder will hold all of our project files and source code. The shell commands that follow should work on Mac, Linux and Windows.</p><pre>mkdir blink1-status-led</pre><p>Change the active directory into the new folder.</p><pre>cd blink1-status-led</pre><p>Next let’s create a Nodejs project initialized with defaults and TypeScript tools.</p><pre>npm init -y<br>npm install typescript @types/node @tsconfig/node12 --save-dev</pre><p>Now install the <strong>node-blink1-async</strong> module.</p><pre>npm install @ros2jsguy/node-blink1-async</pre><p>I created the node-blink1-async package to support coding blink(1) LEDs using a modern async JavaScript api and to simplify multi-step display patterns such as blinking the led. If you would rather use a callback style api take a look at the <a href="https://www.npmjs.com/package/node-blink1">node-blink1</a> JS library from which node-blink1-async is based.</p><p>Now let’s setup our project’s TypeScript compiler options. Create a file named <strong>tsconfig.json</strong> and add the following code to it.</p><pre>{<br>  &quot;extends&quot;: &quot;@tsconfig/node12/tsconfig.json&quot;,<br>  &quot;compilerOptions&quot;: {<br>    &quot;outDir&quot;: &quot;./dist&quot;<br>  },<br>  &quot;include&quot;: [<br>    &quot;blink1-status-led.ts&quot;,<br>    &quot;index.ts&quot; <br>  ],<br>  &quot;exclude&quot;: [<br>    &quot;dist/**&quot;<br>  ]<br>}</pre><p>The contents of your blink1-status-led folder should look similar to this:</p><pre>blink1-status-led/<br>  node_modules/<br>  package.json<br>  tsconfig.json</pre><h3>Let’s Code</h3><p>Our program will be divided across 2 small TypeScript files that we will create in this section.</p><h4>blink1-status-led.ts</h4><p>From the blink1-status-led folder open your preferred TypeScript coding tool (e.g. Visual Studio Code, …) and create the file <strong>blink1-status-led.ts</strong>. In this file we will create the TypeScript class, Blink1StatusLedthat will command a blink(1) LED to display a specific light color and pattern for each state such as:</p><ul><li>power on —solid red light</li><li>initializing — medium blink yellow light</li><li>running — solid green light</li><li>error — fast blink red light</li><li>power off — no light</li></ul><p>Our design can control multiple blink(1) devices by identifying the led device to control when creating a Blink1StatusLed instance. If you have a single blink(1) device then it it unnecessary to provide it’s serial-number as a parameter to the Blink1StatusLed constructor as it will be automatically detected and used as the default blink(1) device.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/cec506d376593fb889bb4f5dca722b87/href">https://medium.com/media/cec506d376593fb889bb4f5dca722b87/href</a></iframe><p>Note that the Blink1StatusLed methods are asynchronous and use the node-blink1-async library. You can find documentation for the node-blink1-async <a href="https://ros2jsguy.github.io/node-blink1-async/">here</a>.</p><p>Our design is very simple. When a state is set on a Blink1StatusLed instance, the instance remains in that state with constant visual output until the state is changed externally. We will see how this works when we implement the index.js file next.</p><p>Of special note is the delay(millis: number) method which is provided as a convenience to support synchronous-like execution of multiple async Blink1StatusLed methods. For example if you needed to limit the duration of a blinking pattern to 5 seconds then do something like this:</p><pre>async function shortYellowBlink(){<br>  const blink1StatusLed = new Blink1StatusLed();<br>  await blink1StatusLed.blink(255, 255, 0, BlinkRate.FAST);<br>  await blink1StatusLed.delay(5000); // 5000 milliseconds == 5 secs<br>  await blink1StatusLed.off();<br>} </pre><h4>index.ts</h4><p>Next we will create the <strong>index.ts</strong> file to drive our Blink1StatusLed through it’s various states.</p><p>Create a file named <strong>index.ts</strong> with the following src code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e5de868b6f28a58c0798ba13180fce1f/href">https://medium.com/media/e5de868b6f28a58c0798ba13180fce1f/href</a></iframe><p>This main() function systematically runs the Blink1StatusLed instance through each of its states. As the program executes you should observe your d blink(1) device visually illuminate and transition from state to state as it outputs red, yellow and green color light in solid and blinking patterns.</p><p><strong>Build and Run</strong></p><p>Before we can run our program we need to compile our 2 TypeScript files using the TypeScript compiler, tsc. Run the following command in your terminal:</p><pre>npx tsc</pre><p>The TypeScript compilation process should take only a few seconds to complete. Upon completion you should see a new folder named dist containing JavaScript files with the same name as our TypeScript files. Here’s the full list of our project files:</p><pre>blink1-status-led/<br>  blink1-status-led.ts<br>  index.ts<br>  dist/<br>    blink1-status-led.js<br>    index.js<br>  node_modules/<br>    &lt;...dependency modules...&gt;<br>  package.json<br>  tsconfig.json</pre><p>Now run the program using Nodejs and observe your blink(1) device color and blink pattern display. If you are on Windows use the \ path separator.</p><pre>#linux<br>node dist/index.js</pre><pre>#windows<br>node dist\index.js</pre><p>In addition to the blink(1) visual output here’s the console output from the program.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/417/1*cSnz6qBJTHYdDI_mDfyjrA.png" /></figure><h3>Wrapping Up</h3><p>That’s it! I hope you’re inspired to add more visual state information to your robot and that a blink(1) RGB LED becomes a new option for your projects. There are many more uses for a blink(1) than the small set we have demonstrated in this article. For example, a blink(1) could be used to indicate navigation information with an orange blinking pattern that increases in blink rate and intensity as the robot nears an obstacle or waypoint.</p><p>Lastly if you like this article please give it a Thumbs Up and a share on twitter. You can reach me on Twitter at <a href="https://twitter.com/ros2jsguy">@ros2jsguy</a> and find code that I’ve developed or working on at my GitHub account: <a href="https://github.com/ros2jsguy">https://github.com/ros2jsguy</a> Looking forward I’m planning a part-2 of this article describing how to use a blink(1) with the Robot Operating System (ROS). Until then happy coding!</p><h3>References</h3><ol><li><a href="https://www.npmjs.com/package/@ros2jsguy/node-blink1-async">node-blink1-async npm information</a></li><li><a href="https://github.com/ros2jsguy/node-blink1-async">node-blink1-async GitHub rep</a>ository</li><li><a href="https://ros2jsguy.github.io/node-blink1-async/">node-blink1-async TypeDocs</a></li><li><a href="https://blink1.thingm.com/">ThinkM blink(1) information</a></li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7c70be44b2e7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[5: ROS 2 Version of Conway’s Game of Life in TypeScript]]></title>
            <link>https://ros2jsguy.medium.com/5-ros-2-version-of-conways-game-of-life-in-typescript-9ab1e439022?source=rss-58e0e88c1fc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/9ab1e439022</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ros2]]></category>
            <category><![CDATA[game-of-life]]></category>
            <category><![CDATA[robots]]></category>
            <dc:creator><![CDATA[ROS2JsGuy]]></dc:creator>
            <pubDate>Tue, 23 Jun 2020 10:58:24 GMT</pubDate>
            <atom:updated>2020-06-25T14:48:49.028Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/865/1*S35qKqRAspxVnXagu9oHZw.png" /></figure><p>Implement Conway’s Game of Life using ROS 2 OccupancyMap and rviz2 for visualization.</p><p>As a fun project to help me get familiar with the ROS 2 OccupancyMap message, I coded up Conway’s Game of Life algorithm using an OccupancyMap to model the cellular automaton world. In this article I describe the high-level details of my Game of Life implementation.</p><p>The program is implemented using TypeScript and the Nodejs <a href="https://github.com/RobotWebTools/rclnodejs">rclnodejs</a> package. ROS 2 rviz2 is used to visualize the occupancy-maps published by the program. If you would like to jump straight to building and running my version, the source code is available <a href="https://github.com/ros2jsguy/ros2-js-examples/tree/master/src/example4">here</a>.</p><h3>Game of Life Rules</h3><p>Conway’s Game of Life, a.k.a., Life, is a cellular automaton developed by the mathematician, John Conway in 1970. Life consists of a 2D grid of cells, whith each cell having a state of alive or dead. A cell’s state may change from one generation to the next according to three simple rules.</p><ol><li>Any alive cell with two or three neighbors (adjacent cells) survives to the next generation.</li></ol><p>2. Any dead cell with three neighbors becomes a live cell in the next generation.</p><p>3. All other live cells die in the next generation. Similarly, all other dead cells stay dead.</p><p>See the <strong>Resources</strong> section below for more info about Conway’s Game of Life.</p><h3>OccupancyMap Message</h3><p>I’ve already mentioned that the program uses the ROS 2 OccupancyMap for modeling the cellular world. Let’s take a look at the OccupancyMap definition which is defined as part of the nav_msgs package.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c876266352e4338da30ceb58a0303537/href">https://medium.com/media/c876266352e4338da30ceb58a0303537/href</a></iframe><p>Note the info field of typeMapMetaData. MapMetaData (shown below) defines the grid dimensions on the data field as well as cell orientation and scale.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be68e3fd0383bd894aa0434daf223cd1/href">https://medium.com/media/be68e3fd0383bd894aa0434daf223cd1/href</a></iframe><h3>Project Details</h3><p>The project will consist of the following:</p><ul><li>ROS 2 node, named /ros2_js_examples/game_of_life</li><li>ROS 2 100x100 OccupancyMap will represent the cellular world</li><li>ROS 2 Timer will provide a tick every 500 milliseconds (2 Hz) that initiates the transition of the current world to the next generation</li><li>ROS 2 publisher will broadcast the updated OccupancyMap for each generation, topic = game_of_life</li><li>rviz2 will provide visualization of the cellular world</li><li>This program is implemented as a Nodejs application coded using TypeScript and the ROS 2 rclnodejs JavaScript client library.</li></ul><h3>Code</h3><p>Create the project folder and change directory into it:</p><pre>mkdir -p src/example4<br>cd src/example4</pre><p>The project consists of 2 TypeScript files: index.ts and game-of-life.ts. To minimize redundant code narration I’ve tried to include liberal comments throughout the code as shown below.</p><p>Some key things to notice in the code:</p><ul><li>The occupancy-map cell states are ALIVE = 100, DEAD = 0.</li><li>A ROS2 Timer is used rather than the more common setInterval() JavaScript function. This is because the ROS2 Timer is based on it’s parent node’s clock which can be configured to use simulated time and controlled externally.</li><li>To minimize memory the program uses only 2 data arrays: an array to hold the previous generation of cell states and an array to hold for the current generation of cell states. Also a single occupancy-map instance is created and updated on each new generation with the current generation of cell state data.</li></ul><h4>index.ts</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce2fbacbcd032828f2316871c522411f/href">https://medium.com/media/ce2fbacbcd032828f2316871c522411f/href</a></iframe><h4>game-of-life.ts</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0c24e90e4d92cea17cd429676d0851e1/href">https://medium.com/media/0c24e90e4d92cea17cd429676d0851e1/href</a></iframe><h3>Build</h3><p>From the project root folder run the TypeScript compiler. The output will appear in the dist/example4 folder.</p><pre>tsc</pre><h3>Running game-of-life</h3><p>Our game-of-life program runs in 2 processes that we will start individually.</p><p>First, launch the game-of-life node from a command shell:</p><pre>node dist/example4/index.js</pre><p>Once the program starts you should see messages dribble to stdout with information about the current generation number and number of alive cells.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/659/1*jc7JeTSG5Q-YXDoRJSZw_A.png" /></figure><p>Next run rviz2 to view the occupancy-maps published by the game-of-life node:</p><pre>rviz2 -d src/example4/game-of-life.rviz</pre><p>You should see an rviz2 window appear similar to the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CNgqYlrli-Ar53AA8XZf-Q.png" /></figure><p>If you need to reconfigure the rviz2 display or use ros2 CLI tools you will need the following information:</p><pre>NODE_NAME = ‘game_of_life_node’;<br>NODE_NAMESPACE = ‘ros2_js_examples’;<br>TOPIC = ‘game_of_life’;<br>FRAME_ID = ‘game_of_life_frame’;</pre><h3>Wrap-up</h3><p>I hope you’ve had fun developing your version of Conway’s Game of Life. You may consider additional improvements to your version such as parameterizing the occupancy-map size or using a predefined grid of cells rather than random cell states.</p><h3>References</h3><ol><li><a href="https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life">Wikipedia — Conway’s Game of Life</a></li></ol><p>2. <a href="https://github.com/ros2jsguy/ros2-js-examples/tree/master/src/example4">Source code</a></p><p><strong><em>Please consider liking this tutorial and following me here and on Twitter </em></strong><a href="https://twitter.com/ros2jsguy"><strong><em>@ros2jsguy</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9ab1e439022" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[4: Data Visualization Using ROS 2 rviz2, Pub-Sub Communications and JavaScript/TypeScript]]></title>
            <link>https://ros2jsguy.medium.com/4-data-visualization-using-ros-2-rviz2-pub-sub-communications-and-javascript-typescript-6e43cde75029?source=rss-58e0e88c1fc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e43cde75029</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[rviz2]]></category>
            <category><![CDATA[ros2]]></category>
            <category><![CDATA[robots]]></category>
            <dc:creator><![CDATA[ROS2JsGuy]]></dc:creator>
            <pubDate>Fri, 19 Jun 2020 22:04:22 GMT</pubDate>
            <atom:updated>2022-02-11T20:11:03.188Z</atom:updated>
            <content:encoded><![CDATA[<h3>4: Data Visualization Using ROS 2 rviz2 and Pub-Sub Communications</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*mt31usxzN8860o33M0Y6Tg.png" /></figure><p>Simulate, publish and visualize ROS 2 LIDAR sensor data using TypeScript.</p><p><em>Edited 20220211 — expanded Nodejs version prerequisites to v10.22–17.x</em></p><p>In this tutorial we get closer to a real world scenario as we learn about ROS message interfaces, in particular the LaserScan sensor message, and how to create and publish such messages for other nodes to process. Then we will use the ROS 2 rviz2 visualization tool to render a 3D map created from the sensor data.</p><h3>ROS Interfaces</h3><p>In tutorial #2 we created a node that published hello world String messages to a topic. Then in tutorial #3 we created a node that subscribed to those hello world messages. While those were trivial examples, we gained hands-on experience in how to programmatically publish and subscribe to ROS 2 messages from a JavaScript Nodejs program. We also gleaned a little system design insights as we got an early glimpse into how ROS nodes can operate independently and coordinate between themselves through message interfaces. In addition to message interfaces, ROS supports 2 other interface types: services and actions. We will work with those interface types in future tutorials.</p><blockquote>ROS encourages systems architectures comprised of independent, loosely coupled physical, virtual and computational components that interact through message, service and action interfaces.</blockquote><h4>ROS Common Interfaces</h4><p>ROS includes a number of common interfaces that are organized into packages as shown:</p><ul><li>action_msgs</li><li>builtin_interfaces</li><li>diagnostic_msgs</li><li>geometry_msgs</li><li>nav_msgs</li><li>rcl_interfaces</li><li>rosgraph_msgs</li><li>sensor_msgs</li><li>shape_msgs</li><li>srv_msgs</li><li>stereo_msgs</li><li>trajectory_msgs</li><li>visualization_msgs</li></ul><p>You are encouraged to explore the message interfaces defined in these packages. See the Resources section at the end of this tutorial for a link.</p><h3>LaserScan Message</h3><p>The ROS 2 sensor_msgs package includes the <a href="http://docs.ros.org/melodic/api/sensor_msgs/html/msg/LaserScan.html">LaserScan</a> message type for communicating laser and LIDAR sensor data from a measuring device to other nodes in a ROS graph. Our program will generate and publish messages that adhere to the following LaserScan message definition..</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d007eb85fed3c8ecbf16c1b7f5838997/href">https://medium.com/media/d007eb85fed3c8ecbf16c1b7f5838997/href</a></iframe><h3>Let’s Code</h3><p>Some details about this project. The program will consist of:</p><ul><li>a routine that generates a data set measurements from a planar 360 LIDAR device. Data is generated once per second (1Hz)</li><li>a ROS publisher that broadcast LIDAR sensor data (sensor_msgs/msg/LaserScan) to the topic laser when it is available</li><li>a ROS node that manages sensor data generation and the life-cycle of the publisher</li><li>the program will run indefinitely until the process is manually terminated, e.g., Ctrl-C from shell</li></ul><h3>Prerequisites</h3><p>Getting started you’ll need a dev environment with</p><ul><li>Nodejs v10.22 — v17.x — I’m using Node 16.13.0 (LTS)</li><li>ROS 2 Foxy (LTS) or Galactic release</li></ul><p>If you haven’t setup your ROS 2 JavaScript coding environment see this <a href="https://medium.com/@ros2jsguy/setup-your-ros-2-javascript-robot-coding-environment-1c549e8a48cd">article</a>.</p><p>Lastly if you would like to skip ahead and see the end result, you can find a link to a github project in the <strong>Resources</strong> section found at the end of this article.</p><h3>Step-1: Project Setup</h3><p>Project setup is easy as we will continue developing our code in the Nodejsros2-js-examples project we created in Tutorial #2. From the root folder of our ros2-js-examples project create the src/example2 folder using the following Linux commandline tools.</p><pre>mkdir -p src/example3<br>cd src/example3</pre><h3>Step-2: Creating a Node and Publisher</h3><p>This example will consists of 2 TypeScript files: laserscan-publisher.ts and index.ts.</p><h4>laserscan-publisher.ts</h4><p>Start by creating laserscan-publisher.ts as follows:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3d02647d76e70b72e255166159300094/href">https://medium.com/media/3d02647d76e70b72e255166159300094/href</a></iframe><p>Let’s break down the key lines of code in this file.</p><p>As in all of our tutorials we will be using the JavaScript ROS 2 client library, <strong>rclnodejs</strong>. So our 1st step is to import rclnodejs.</p><pre>import * as rclnodejs from &#39;rclnodejs&#39;;</pre><p>Next we create the LaserScanPublisher class.</p><p>Note how the LaserScanPublisher constructor expects an rclnodejs.Node and an optional topic name to which messages will be published. The constructor creates a publisher instance for the default topic laser_frame.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/686/1*Y_3jbM51xa4N7WCkft45yw.png" /></figure><p>The start() method creates a timer that generates a fake LaserScan message and publishes it every second. The timer runs until either the stop() method is called or the process is killed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*t8GPrDKfYz7f9uwjq94L7Q.png" /></figure><p>The fake sensor data and messages are created by the genLaserScanMsg() method.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*BSjGEhjDInCs1dnODJiFmw.png" /></figure><p>lines 63,64 - Create a LaserScan message object and begin populating it.</p><p>lines 67, 68- Many of the ROS messages require a Header. The header.frame_id is important to note as it refers to the name of a reference frame. We will use the header.frame_id property later in this rviz2 section of this tutorial.</p><h4>index.ts</h4><p>Next create the index.ts file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/65a635b9a727e544669fa923f9fe6174/href">https://medium.com/media/65a635b9a727e544669fa923f9fe6174/href</a></iframe><p>This is the main entry point for running example-3. The main() function does the following:</p><ul><li>initializes the rclnodejs library</li><li>creates a node</li><li>creates a LaserScanPublisher</li><li>starts the publisher timer</li></ul><h3>Step-3: Compile TypeScript</h3><p>Invoke the TypeScript compiler tsc to transcode our *.ts files into JavaScript. The resulting JS files are created in the dist/example3 folder with the same name’s as theirsrc TypeScript files.</p><pre>npm run build</pre><h3>Step-4: Run</h3><p>Using the Nodejs runtime, let’s run our laserscan-publisher program. In your terminal shell enter this command:</p><pre>node dist/example3/index.js</pre><p>You should see messages begin dribbling to stdout as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/609/1*MKEhUvUhE2lt55AInicB-A.png" /></figure><p>Now let’s use the ros2 topic tool to view a published LaserScan message.</p><pre>ros2 topic echo /ros2_js_examples/laser_frame --no-arr </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*V_LtNccbArSKLSYMl2oHbA.png" /></figure><p>Cool! We have LaserScan messages published to the ROS node graph.</p><h3>Using ROS 2 rviz2 Visualization Tool</h3><p>The ROS 2 rviz2 is a data visualization tool that subscribes to topics and displays the data it receives according to the type of message, e.g., our LaserScan message. Now let’s use rviz2 tool to generate a 3D view of our LaserScan message data.</p><p>With our LaserScanPublisher still running and publishing message, launch rviz2 from a terminal shell:</p><pre>rviz2</pre><p>You should see the default rviz2 user interface appear similar to this screenshot from my system.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H4l4i1YReGBqw_Xnzquz1Q.png" /></figure><p>We need to configure rviz2 to subscribe to our LaserScan messages being published to the laser_frame topic.</p><p>Start by adding a LaserScan visualization to the View as shown. Notice steps #2 and #3 in the screenshot are selecting to topic on which our laserscan data is published.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/730/1*KuqJAphnorgPZXbsTBMz8w.png" /></figure><p>Next make the edits shown in red below:</p><p>Fixed Frame: <strong>laser_frame</strong><br>Size: <strong>0.1</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O6rkppcQA2pRKdn_l2M9MA.png" /></figure><p>BINGO! You should see the 180 degree measurements appear. You may need to zoom out to see them. Just for fun I added an Axis visualization to my view.</p><p><em>Note: in this scenario I’ve started example3/index.js before starting rviz2. If rviz2 is running before laserscan data is published rviz2 may not immediately rendering the data. In such cases I’ve found that by changing the LaserScan/Topic/Depth property it will force the topic subscription to reset and laserscan data will then be rendered.</em></p><h4>Optional: Save rviz2 Display Configuration</h4><p>Every time we run this example we don’t want to have to repeat these configuration steps. So our final step is to save the rviz2 display configuration for future use.</p><p>From the rviz2 user interface do the the following:</p><p>Select <strong>File &gt; Save Config</strong>. <br>Name the file laserscan.rviz and save it to src/example3.</p><p>The next time you run rviz2 with example3 use the following command to configure the dispaly using our new laserscan.rviz configuration info:</p><pre>rviz2 -d src/example3/laserscan.rviz</pre><h3>Summary</h3><p>Hopefully you are starting to appreciate the power and convenience of the ROS 2 platform and tools. We will continue to build on top of this experience and put the ROS 2 tools to great use in the next tutorial.</p><h3>Resources</h3><ol><li><a href="https://github.com/ros2jsguy/ros2-js-examples/tree/master/src/example3">Example-3 source code</a></li><li>ROS 2 <a href="https://index.ros.org/doc/ros2/Concepts/About-ROS-Interfaces/">Introduction to Interfaces</a></li><li>ROS 2 <a href="https://github.com/ros2/common_interfaces">Common Interfaces</a></li></ol><p><strong><em>Please consider liking this tutorial and following me here and on Twitter </em></strong><a href="https://twitter.com/ros2jsguy"><strong><em>@ros2jsguy</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e43cde75029" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[3: Creating a ROS 2 Pub-Sub Subscription using TypeScript]]></title>
            <link>https://ros2jsguy.medium.com/3-creating-a-ros-2-pub-sub-subscription-using-typescript-8fd2fdf534db?source=rss-58e0e88c1fc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/8fd2fdf534db</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ros2]]></category>
            <category><![CDATA[pub-sub]]></category>
            <category><![CDATA[robots]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[ROS2JsGuy]]></dc:creator>
            <pubDate>Sun, 14 Jun 2020 10:36:10 GMT</pubDate>
            <atom:updated>2022-02-11T20:06:45.338Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*p3Wdbyf9LqakIzWG" /><figcaption>Photo by <a href="https://unsplash.com/@alinnnaaaa?utm_source=medium&amp;utm_medium=referral">Alina Grubnyak</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this tutorial, we implement a ROS 2 subscription using TypeScript and learn to use the ros2 topic CLI tool for listening in on and testing pub-sub communications.</p><p><em>edited 20220211 — upgraded to use NodeJS 16</em></p><p>In <a href="https://medium.com/@ros2jsguy/2-our-1st-ros-2-typescript-program-4f1703fcaf19">tutorial #2</a> we learned about ROS 2’s publish-subscribe communication mode and how to create a simple ROS 2 node and publisher using the <strong>rclnodejs</strong> library and TypeScript. In this tutorial we introduce how to receive messages using a ROS 2 subscription.</p><h3>ROS Messages</h3><p>In this tutorial and the previous tutorial we are working with the simple ROS String message. ROS 2 includes a rich set of standard messages which we will introduce in up-coming tutorials. <strong>Resources</strong> section below includes a link to the standard ROS messages. ROS messages are formally defined using the Interface Definition Language (IDL). The ROS 2 SDK includes tools for creating programming interfaces from message IDL files.</p><p>Here’s the IDL definition of std_msgs/msg/String that we are using. Note how it only has thedata field:</p><pre>string data</pre><h3>Let’s Code</h3><p>Some details about this project. The program will consist of:</p><ul><li>a ROS Node that manages the life-cycle of a subscription and all of it’s communications</li><li>a ROS Publisher of string messages to the topic msg</li><li>when a message arrives the subscription will print it to stdout</li><li>the program will run indefinitely until the process is manually terminated, e.g., Ctrl-C from shell</li></ul><h4>Prerequisites</h4><p>Getting started you’ll need a dev environment with</p><ul><li>Nodejs 10.22–17.x — I’m using Node 16.13.0 (LTS)</li><li>ROS 2 Foxy (LTS) or Galactic release</li></ul><p>If you haven’t setup your ROS 2 JavaScript coding environment see this <a href="https://medium.com/@ros2jsguy/setup-your-ros-2-javascript-robot-coding-environment-1c549e8a48cd">article</a>.</p><p>Lastly if you would like to skip ahead and see the end result, you can find a link to a github project in the <strong>Resources</strong> section found at the end of this article.</p><h4>Step-1: Project Setup</h4><p>Project setup is easy as we will continue developing our code in the Nodejsros2-js-examples project we created in Tutorial #2. From the root folder of our ros2-js-examples project create the src/example2 folder using the following Linux commandline tools.</p><pre>mkdir -p src/example2<br>cd src/example2</pre><h4>Step-2: Creating a Node and Subscription</h4><p>Create the file node-subscriber.ts file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dc3282a99b58581a62c90ff85b0a75d9/href">https://medium.com/media/dc3282a99b58581a62c90ff85b0a75d9/href</a></iframe><p>Here’s a quick explanation of the key lines of code:</p><p>Line-14: Create a ROS 2 Node with the name node_subscriber in the ros2_js_examples namespace.</p><pre>let node =     rclnodejs.createNode(&#39;node_subscriber&#39;,&#39;ros2_js_example&#39;);</pre><p>Line-15,18: Create a ROS 2 Subscription that listens to the msg topic for a message of type std_msgs/msg/String. The subscription is configured with a callback that simply echo’s the message’s data property to the stdout.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*v3A7Yw-_WMK_Rb_D0UdPJA.png" /></figure><p>Line -23: Inform rclnodejs to begin routing incoming messages to this node.</p><pre>rclnodejs.spin(node);</pre><h4>Step-3: Compile TypeScript</h4><p>Invoke the TypeScript compiler tsc to transcode our node-subsciber.ts file into JavaScript. The resulting JavaScript file is created in the dist/example2 folder with the same name as it’s src TypeScript file.</p><pre>npm run build</pre><p>or for continuous compilation on file changes use:</p><pre>npx tsc -w</pre><h4>Step-4: Run</h4><p>Using the Nodejs runtime, let’s run our node-subscriber program. In your terminal shell enter:</p><pre>node dist/example2/node-subscriber.js</pre><p>Initially not much is happening, as the program is waiting for messages to arrive.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/776/1*dIRbT_g34yUBR-zK5ksggw.png" /></figure><p>Now let’s run node-publisher to generate messages.</p><p>To do this open a new terminal shell and change directory to the ros2-js-examples/ folder. Then run the command:</p><pre>node dist/example1/node-publisher.js</pre><p>Once node-publisher is running and publishing messages, you should see subscription messages begin dribbling to stdout as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UcqXQGr-8vL4FQmdaZ93sQ.png" /></figure><h3>Using The ros2 topic Tool To Test Pub-Sub Messaging</h3><p>In tutorial #2 we got our first look at how the ros2 CLI tools can be used to listen to published messages. Now let’s take a look at how we can use the ros2 topic tool to publish a message to a topic and subscribe to that topic.</p><h4>Publishing to a Topic</h4><p>Open a new terminal shell and enter:</p><pre>ros2 topic pub /ros2_js_examples/msg std_msgs/msg/String ‘{data: hello world}’</pre><p>The topic tool will startup and repeatedly publish a ‘hello world’ message every second until we terminate the process.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*HSqnhf1_XS1tET7huPsegQ.png" /></figure><h4>Subscribing to a Topic</h4><p>Next, open a new terminal shell and enter:</p><pre>ros2 topic echo /ros2_js_examples/msg std_msgs/msg/String</pre><p>The topic tool will listen for published messages on the /ros2_js_examples/msg topic and echo the message to stdout.</p><p><strong>Note that because the node operates in the </strong><strong>/ros2_js_examples namespace we need to prepended the node namespace to the </strong><strong>msg topic name when using the ros2 cli tools.</strong></p><p>Using the ros2 topic tool is a convenient way to test publishing and subscribing to a message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*-ng7ygWH9wxxrXhwbY-6TQ.png" /></figure><h3>Parting Thoughts; Looking Forward</h3><p>Anonymous pub-sub communications is the simplest ROS 2 communications mode to implement and typically the most common form of communications in the node graph. In our next tutorial we introduce the ROS 2 rviz2 visualization tool and put pub-sub communications to work.</p><h3>Resources</h3><ol><li><a href="https://github.com/ros2/common_interfaces">ROS 2 standard interfaces (messages)</a></li></ol><p><strong><em>Please consider liking this tutorial and following me here and on Twitter </em></strong><a href="https://twitter.com/ros2jsguy"><strong><em>@ros2jsguy</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8fd2fdf534db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[2: Our 1st ROS 2 TypeScript Program]]></title>
            <link>https://ros2jsguy.medium.com/2-our-1st-ros-2-typescript-program-4f1703fcaf19?source=rss-58e0e88c1fc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/4f1703fcaf19</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[rclnodejs]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[ros-operating-system]]></category>
            <category><![CDATA[ros2]]></category>
            <dc:creator><![CDATA[ROS2JsGuy]]></dc:creator>
            <pubDate>Thu, 11 Jun 2020 20:14:43 GMT</pubDate>
            <atom:updated>2022-02-11T20:02:08.790Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HUT2umd9DXtNjpUT" /><figcaption>Photo by <a href="https://unsplash.com/@agkdesign?utm_source=medium&amp;utm_medium=referral">Alex Knight</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Join along as we develop a high level introduction of ROS while coding up our first ROS2 JavaScript program, a simple ROS node that sends ‘hello world’ messages using a Twitter style publish-subscribe model.</p><p><em>edited 20220211 — updated to use NodeJS 16, TypeScript 4.5 &amp; rclnodejs-cli</em></p><h3>ROS 2 Conceptual Overview</h3><p>ROS 2 is a cool distributed computing platform. The unit of independent activity is the ROS <strong>node.</strong> ROS enables nodes to discover one another and coordinate their activities and exchange data by passing <strong>messages</strong> through an <strong>anonymous publish-subscribe</strong> mechanism. One or more nodes can reside within an OS process that may reside on the same computer or different computers. The group of nodes within a system and their communications is known as the ROS <strong>graph</strong>.</p><p>The ROS 2 api includes C, C++ and Python programming language bindings known as ROS Client Libraries (RCL). Additional community developed RCLs exists for JavaScript, Java, Rust, etc. Throughout all of the tutorials we will be using the open-source ROS 2 RCL known as <strong>rclnodejs</strong> for JavaScript and TypeScript.</p><p>When designing the interaction and data exchange between nodes we can choose between 3 styles of communications:</p><ul><li>publisher-subscriber — anonymous asynchronous message passing, e.g., Twitter</li><li>client-server — synchronous request-reply communications, e.g., RCP, REST</li><li>actions — long running asynchronous client-server communications, e.g., Jobs</li></ul><p><strong>In this tutorial we use TypeScript and Nodejs to code a ROS 2 node that communicates using publisher-subscriber messaging.</strong></p><h3>Publisher-Subscriber (pub-sub) Communications</h3><p>In a ROS 2 pub-sub communications model, messages are asynchronously broadcast, i.e., published, to the ROS 2 node graph on uniquely named channels. Nodes within the graph that are interested in receiving these messages create a subscription to the channel. ROS handles the network interface and message routing between nodes.</p><p>A ROS node wishing to broadcast a message creates a publisher that is configured with the type of message it will broadcast and the uniquely named topic to which it will broadcast. When ready, the node asks the publisher to publish, i.e., send, the message. Where upon ROS network services dispatch the message. To receive these messages a node creates a subscription that is configured with the type of messages and topic to listen and a handler that will process incoming messages. ROS network services route and deliver messages to awaiting subscriptions. Where upon each subscription’s handler is invoked to process the incoming message.</p><p>The ROS 2 rclnodejs JavaScript library that we will be using provides pub-sub messaging in an interoperable manner with nodes implemented in JavaScript and other languages such as C++ and Python.</p><h3>Let’s Code</h3><p>Some details about this project. It will consist of:</p><ul><li>a ROS Node that manages the life-cycle of a publisher instance and all of it’s communications</li><li>a ROS publisher that broadcasts string messages to the topic msg</li><li>a timer that sends a time-stampedhello world message once every second</li><li>the program will run indefinitely until the process is manually terminated, e.g., Ctrl-C from shell</li></ul><h4>Prerequisites</h4><p>Getting started you’ll need a dev environment with</p><ul><li>Nodejs v10.22–17.x — I’m using Node 16.13.0 (LTS)</li><li>ROS 2 Foxy (LTS) or Galactic release</li></ul><p>If you haven’t setup your ROS 2 JavaScript coding environment see this <a href="https://medium.com/@ros2jsguy/setup-your-ros-2-javascript-robot-coding-environment-1c549e8a48cd">article</a>.</p><p>Lastly if you would like to skip ahead and see the end result, you can find a link to a github project in the <strong>Resources</strong> section found at the end of this article.</p><h4>Step-1: Project Setup</h4><p>Let’s begin setting up a Nodejs project named ros2-js-examples with module dependencies for <a href="https://www.npmjs.com/package/rclnodejs">rclnodejs</a>, the ROS 2 JavaScript client library and TypeScript. See Resources section below for jsdoc documentation.</p><p><em>Note: if you wish to code in JavaScript most of the examples are easily ported from TypeScript to JavaScript (ES6). I’ve chosen to use TypeScript due to it’s rising popularity and I just like using it especially when project complexity and size grows beyond the few examples presented on this site.</em></p><p>We will use rclnodejs-cli to create a working project that we will then evolve. From a command shell enter the following Unix/Linux commands (omit comment lines, e.g., any line starting with #):</p><pre># make project folder structure<br>npx rclnodejs-cli ros2-js-examples --typescript</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*xiAM7yXNMVCIEHjTUjHH0w.png" /></figure><p>The rclnodejs-cli tool generates a few more files and folders than we need for now. So let’s do a bit of quick clean up.</p><pre>cd ros2-js-examples</pre><pre># clean up unused files and folders<br>rm -rf CMakeLists.txt include launch package.xml *.md src</pre><pre># create src/example folder<br>mkdir -p src/example1<br>cd src/example1</pre><p>Note that for all tutorials we will develop example code in the ros2-js-examples project. The code for each tutorial will reside in it’s on folder following this pattern:</p><pre>ros2-js-examples<br>    src/<br>        example1/<br>        example2/<br>        ...<br>        exampleN/</pre><p>Step-2: Code Node and Publisher</p><p>Now let’s code up a ROS 2 node that publishes a Hello World message.</p><ol><li>From the ros2-js-examples/src/example1folder create and open the file node-publisher.ts in your editor.</li><li>Copy-paste the following code into the editor and save.</li></ol><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/876f760a3d724dac32e57476be21b712/href">https://medium.com/media/876f760a3d724dac32e57476be21b712/href</a></iframe><p>Here’s a quick explanation of the code:</p><p>line-5: Import the rclnodejs library</p><pre>import * as rclnodejs from &#39;rclnodejs&#39;;</pre><p>line-10: The rclnodejs library must be initialized and made ready to connecting with other ROS 2 nodes.</p><pre>await rclnodejs.init();</pre><p>line-13: Using rclnodejs, we create a node named node-publisher in the ros2_js_examples namespace.</p><pre>let node = rclnodejs.createNode(&#39;node_publisher&#39;, &#39;ros2_js_examples&#39;);</pre><p>line-14: Next we create a Publisher instance for the topic msg We must include the type of message that will be published. In this case it is a std_msgs String</p><pre>let publisher = node.createPublisher();</pre><p>line-16: Begin asynchronously listening for incoming messages.</p><pre>rclnodejs.spin(node);</pre><p>line-19, 22: Start a timer, i.e., setInterval(), that will publish a message every 1 second.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/405/1*czPnxYjVz7l0UGihyZlqdA.png" /></figure><h4>Step-3: Compile TypeScript</h4><p>Invoke the TypeScript compiler tsc to transcode our node-publisher.ts file into JavaScript. The resulting JS file is created in the dist/ folder with the same name as it’s src TypeScript file.</p><pre>npm run build </pre><h4>Step-4: Run</h4><p>Using the Nodejs runtime, let’s run our example1-publisher program. In your terminal shell enter this command:</p><pre>node dist/example1/node-publisher.js</pre><p>You should see messages begin dribbling to stdout as shown below.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*o5nKxRhnWjykZb5An3ICow.png" /></figure><h4>Step-5: Using ros2 CLI Tools</h4><p>Theros2 commandline interface (CLI) provides tools for launching and running ROS 2 nodes and messages. For example with our example1-publisher program running we can view it’s ROS 2 node as follows:</p><pre>ros2 node list</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*Ium9RdIYBy6hfIfbVzMS7Q.png" /></figure><p>Next let’s view the messages actively being published to the ‘msg’ topic.</p><p>Enter the following command.</p><pre>ros2 topic echo /ros2_js_examples/msg</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*3quNfbZiJmZ-bTy0eopySg.png" /></figure><p>To view other ros2 cli commands enter:</p><pre>ros2 -h</pre><p>Or for help on a specific command enter:</p><pre>ros2 &lt;command&gt; -h</pre><h3>Summary</h3><p>ROS 2 pub-sub communications is very common. This tutorial introduced you to the steps for creating a node and publishing a message to a topic. In the next tutorial we will learn how to subscribe to a topic to receive published messages.</p><h3>Resources</h3><ol><li>Source code for this tutorial can be found <a href="https://github.com/ros2jsguy/ros2-js-examples">here</a>.</li><li><a href="https://index.ros.org/doc/ros2/Concepts/">ROS 2 concepts</a></li><li><a href="http://robotwebtools.org/rclnodejs/docs/0.14.0/index.html">rclnodejs jsdoc</a></li></ol><p><strong><em>Please consider liking this tutorial and following me here and on Twitter </em></strong><a href="https://twitter.com/ros2jsguy"><strong><em>@ros2jsguy</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4f1703fcaf19" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[1: Setup A ROS 2 JavaScript Robot Coding Environment]]></title>
            <link>https://ros2jsguy.medium.com/setup-your-ros-2-javascript-robot-coding-environment-1c549e8a48cd?source=rss-58e0e88c1fc9------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c549e8a48cd</guid>
            <category><![CDATA[robots]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[ros2]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[ROS2JsGuy]]></dc:creator>
            <pubDate>Fri, 05 Jun 2020 20:18:59 GMT</pubDate>
            <atom:updated>2020-06-18T19:54:45.473Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Qx7Zv_NxA_wYhoQQ" /><figcaption>Photo by <a href="https://unsplash.com/@adigold1?utm_source=medium&amp;utm_medium=referral">Adi Goldstein</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>While coding robots can be fun, setting up a robot coding environment can sort of be a pain. In this article we layout the software bits you’ll need. As a convenience to get started quickly, I’m making available a virtual machine that I created with all the software installed and ready to run.</p><p><em>edited 20200618 updated instructions to use ROS2 Foxy Fitzroy version.</em></p><p>Let’s take a look at the software you’ll need for some of the tutorials and projects.</p><ul><li><a href="https://nodejs.org/en/download/">Nodejs</a> (ver. 12) — Nodejs version 12 provides the JavaScript runtime you will need to run code we develop. Don’t be tempted to use the latest greatest version of Nodejs as it is incompatible with some of the JavaScript modules we will be using.</li><li><a href="https://github.com/nvm-sh/nvm#about">NVM</a> (Node Version Manager) — NVM is optional. I recommend using NVM as a much better alternative to installing Nodejs directly. With NVM you can install multiple versions of Nodejs and easily switch between those versions. NVM is super convenient and I install it on all my systems.</li><li>ROS 2 (<a href="https://index.ros.org/doc/ros2/Installation/Foxy/">Foxy Fitzroy release</a>) — Foxy Fitzroy, released in June ’20, is the first long term supported version of ROS 2. This release is available across all platforms (Linux, Mac and Window). Additionally ROS 2 docker images available. See the installation options at the link above.<br><em>Note: If you are installing on Linux be sure to verify that your Linux distro and version support ROS 2. I wasted a lot of time early on trying to install and run ROS 2 on an unsupported Linux distro.</em></li><li><a href="https://git-scm.com/book/en/v2/Getting-Started-Installing-Git">git</a> — an optional tool. Git is a CLI client for managing source code. Our primary use of git will be to download projects from github. Alternatively you can avoid using git and download github hosted projects in zip format directly through your browser.</li><li><a href="https://code.visualstudio.com/download">VS Code</a> or you fav IDE/editor — Your favorite JavaScript or TypeScript coding environment, e.g., VS Code, Eclipse + <a href="https://marketplace.eclipse.org/content/codemix-3">CodeMix</a>, VIM…</li></ul><p>Follow the links for each software product for download and installation instructions.</p><h3>Personal Notes</h3><blockquote>While ROS 2 runs on Linux, Mac and Windows your mileage may vary for getting ROS 2 running on platforms other than Linux.</blockquote><p>After burning a few hours unsuccessfully trying to get ROS 2 setup across my main dev platforms, Mac and Windows, I punted and went with installing it on the recommended Linux. I don’t have a dedicated Linux machine so I resorted to using a free Virtual Box VM. There after the installation was a breeze and worked as documented.</p><h3>ROS 2 JS Developer Environment — Linux Virtual Machine</h3><p>If you want to get started with minimal hassle, the quickest path to coding robots is to download and run my Ros2JSDev Linux Virtual Machine (VM). This VM contains the software listed above with the exception that it installs the newest ROS 2 release name Eloquent Elusor, and runs on Mac, Windows and Linux machines using the free VirtualBox engine.</p><p>Here’s what you need to use the VM:</p><p><a href="https://www.virtualbox.org/wiki/Downloads">VirtualBox</a> — VirtualBox is a general-purpose virtualizer for x86. We will use VirtualBox to import our VM and run it.</p><p><a href="https://drive.google.com/file/d/18TKAnjtUGRulyaDE4id4c0KWs3XYn8Al/view?usp=sharing">Ros2JsDev Virtual Machine</a> — Linux 20.04 (Focal distro) with ROS 2, Nodejs, NVM and VS Code preinstalled. The VM is configured to use 4 Gb RAM and a dynamic 20 Gb file system. I have hosted the VM on my Google Drive for download.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/777/1*yPk3C4ZwI3sFUeNOA8yN7w.png" /></figure><h4>Steps for Downloading and Installing Linux-ROS 2 Virtual Machine</h4><ol><li><a href="https://drive.google.com/file/d/18TKAnjtUGRulyaDE4id4c0KWs3XYn8Al/view?usp=sharing"><strong>DOWNLOAD ros2jsdev VM HERE</strong></a><strong><br></strong>The VM download size is approximately 4 Gb.</li><li>Once downloaded, use the VirtualBox File&gt;Import Appliance… to load the ros2jsdev-foxyfitzroy.ova file. This process took 2–3 minutes on my Macbook Pro.</li><li>After the import process completes, the ros2jsdev VM will be presented in the VirtualBox UI. To launch it, select the VM followed by the Start action. The account details are:</li></ol><p><strong>user id: ros2jsguy<br>password: ros2</strong></p><p>You are encouraged to change the password asap.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*oEib9U6Eh0Bsgnvw3VWZ-w.png" /></figure><h3>Verify your ROS 2 configuration</h3><p>At this point you have all the required software installed. To verify ROS 2 is ready to run, let’s run the ros2 commandline tool.</p><ol><li>Open a terminal</li><li>On the commandline enter:</li></ol><pre>ros2 -h</pre><p>If the ros2 cli tools are installed correctly you should see output similar to this:</p><pre>ros2jsdev:~$ ros2 -h<br>usage: ros2 [-h] Call `ros2 &lt;command&gt; -h` for more detailed usage. …</pre><pre>ros2 is an extensible command-line tool for ROS 2.</pre><pre>optional arguments:<br> -h, — help show this help message and exit</pre><pre>Commands:<br> action Various action related sub-commands<br> component Various component related sub-commands<br> daemon Various daemon related sub-commands<br> doctor Check ROS setup and other potential issues<br> interface Show information about ROS interfaces<br> launch Run a launch file<br> lifecycle Various lifecycle related sub-commands<br> msg Various msg related sub-commands<br> multicast Various multicast related sub-commands<br> node Various node related sub-commands<br> param Various param related sub-commands<br> pkg Various package related sub-commands<br> run Run a package specific executable<br> security Various security related sub-commands<br> service Various service related sub-commands<br> srv Various srv related sub-commands<br> topic Various topic related sub-commands<br> wtf Use `wtf` as alias to `doctor`</pre><pre>Call `ros2 &lt;command&gt; -h` for more detailed usage.</pre><p>We will be making frequent use of the ros2 commandline tools.</p><p>To learn more about a specific action shown above enter ros2 &lt;action&gt; -h, e.g., ros2 pkg -h</p><h3>Next Steps</h3><p>LET’S CODE!!!</p><p><strong><em>Please consider liking this tutorial and following me here and on Twitter </em></strong><a href="https://twitter.com/ros2jsguy"><strong><em>@ros2jsguy</em></strong></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c549e8a48cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>