<?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 Pushkal Katara on Medium]]></title>
        <description><![CDATA[Stories by Pushkal Katara on Medium]]></description>
        <link>https://medium.com/@katarapushkal?source=rss-13f24a0f52c9------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*DbuWoyWb2AyDtDsPwupIFQ.jpeg</url>
            <title>Stories by Pushkal Katara on Medium</title>
            <link>https://medium.com/@katarapushkal?source=rss-13f24a0f52c9------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 02:35:28 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@katarapushkal/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[VisualStates: Google Summer Of Code 2018]]></title>
            <link>https://medium.com/@katarapushkal/google-summer-of-code-2018-2c970dcd9647?source=rss-13f24a0f52c9------2</link>
            <guid isPermaLink="false">https://medium.com/p/2c970dcd9647</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[finite-state-machine]]></category>
            <category><![CDATA[robotics]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[Pushkal Katara]]></dc:creator>
            <pubDate>Sat, 30 Jun 2018 20:18:30 GMT</pubDate>
            <atom:updated>2018-07-03T21:53:18.141Z</atom:updated>
            <content:encoded><![CDATA[<p>Much interested in Robotics, I kept searching and trying for robotics related organisations in GSoC, one of which was <a href="http://jderobot.org/">JdeRobot — Universidad Rey Juan Carlos</a>. <em>JdeRobot</em> is an <strong>open source</strong> distributed software framework for developing <em>robotics </em>and <em>computer vision</em> applications. They had a long <a href="https://jderobot.org/GSoC-2018">list</a> of projects which were proposed for GSoC-2018 on their <a href="https://jderobot.org/GSoC-2018">website</a>. In order to submit a proposal, it was mandatory to complete 3 programming challenges and have knowledge of some mentioned prerequisites. I chose to work on the project VisualStates, which required Python and Robotics Operating System as its prerequisites. I submitted the programming assignments before submitting the GSoC proposal. Further there was much discussion about the project with the mentors and I prepared my proposal accordingly. The proposal got selected and I am working on VisualStates this summer as a part of GSoC program. My mentors — José María Cañas Plaza and Okan Aşık are guiding me in the developement of VisualStates tool. I’ll share some theory about VisualStates through this medium post. :D<br><strong><em>JdeRobot</em></strong> also have an open-source <a href="https://jderobot.org/TheRoboticsClub">Robotics Club</a> and a RobotSoftware training <a href="https://jderobot.org/JdeRobot-Academy">Academy</a>. It has some very cool robotic realted projects with simulations of robots like drones, Kobuki incorporating various robotic related algorithms and computer vision algorithms based on deep learning and artificial intelligence.</p><h3>VisualStates: A Robotics Operating System based tool for visual Robot programming using hierarchical automata.</h3><p>VisualStates, a tool based on Hierarchical Finite State Machines to program robot behaviors, each state being a reactive continous controller in itself. A particular<strong> automaton</strong> or a <strong>behavior</strong> or a <strong>group of states </strong>is designed visually with nodes for the states, links for the transitions and specific text source code on them. The tool automatically generates a ROS node as output, in C++ or Python, which connects to configured drivers at runtime and implements the automata. i.e it provides the user a graphical interface to visually program robot behavior according to automata based programming.</p><h3><strong>What are Finite State Machines?</strong></h3><p>First people to define the state machines in an article were Warren McCulloch and Walter Pitts in 1943 and this paper is regarded as inception of field — <strong>Automata theory</strong> applied to modern computation and Artificial Neural Network. In 1967, Marvin Minsky wrote a book on finite and infinite machines which describes computational power of abstract machines(finite machines). The concept emerged when people developed interest in modeling the human thought process into a machine.</p><p>In general, a state machine is any device that stores the status of something at a given time and can operate on input to change the status and/or cause an action or output to take place for any given change. A <strong>computer </strong>is<strong> </strong>basically a state machine and each machine instruction is input that changes one or more states and may cause other actions to take place.</p><p>Remember the movie <strong>The Imitation Game? </strong>an American historical drama based on British mathematician <strong>Alan Turing </strong>who made a prototype of modern computer<strong> </strong>to decrypt Enigma code during World War II.</p><p>The prototype of a Turing Machine generally consists of:</p><ol><li>An infinitely-long <strong>tape</strong> which acts like the memory in a typical computer. The squares on the tape are usually blank at the start and can be written with symbols. The machine can only process the symbols 0 and 1 and “ ”(blank).</li><li>A <strong>head</strong> that can read and write symbols on the tape and move the tape left and right one square at a time.</li><li>A <strong>state register</strong> stores the<strong> </strong>state of Turing machine, one of the finitely many. These states, writes Turing, replace the “state of mind” a person performing computations would ordinarily be in.</li><li>A finite <strong>table </strong>of instructions that, given a state the machine is currently in and the symbol on the square it is reading on the tape, tells the machine to either <strong>erase or write a symbol</strong> or <strong>move the head</strong> or <strong>assume the same or a new state</strong> as stated.</li></ol><p><strong>So whats the use of the state register and the finite table? <br></strong>Consider a simple program with symbols “1 1 0” printed on the tape. The machine is instructed to perform read-write-move sequence —</p><p><strong>Read Symbol 0 -&gt; Write 1 </strong>and move the tape to<strong> Right.<br>Read Symbol 1 -&gt; Write 0 </strong>and move the tape to<strong> Left.<br>Bit-Inversion</strong> process — The machine reads the symbol under the head, say ‘0’, writes 1 and move the tape to right by one square. If ‘1’ is encountered, writes 0 and move the tape to the left by one square . Finally, if a ‘blank’ symbol is read, the machine is halt but in our case we need it to repeat the read-write-move sequence without stopping.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*6KwACGUHzenf3_Dw.jpg" /><figcaption>Symbol under head = 0, write 1 and move the tape right by one square</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*el_ooBx-_MQ6ydA4.jpg" /><figcaption>Symbol under head = 1, write 0 and move the tape right by one square</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*53GaETFC6ASmHrHl.jpg" /><figcaption>Symbol under head = 0, write 1 and move the tape right by one square</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*T7SELtcAvX-mwp0M.jpg" /><figcaption>Finally, a ‘blank’ symbol is read, so the machine does nothing apart from read the blank symbol continously.</figcaption></figure><p>The machine is continously reading blank symbols, but we instructed it to repeat the read-write-move sequence without stopping. This makes our program incomplete.</p><p><strong>How to make the machine repeat the sequence continuously? <br></strong>We’ll use the concept of <strong>Machine State</strong>. We can describe our program with the help of a state table, and completing the state table to develop the finite state machine as follows —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/461/1*NuXvn0kTXp4LxmQXZ31vpg.png" /><figcaption>Machine State Table</figcaption></figure><p>To complete the program, state change during execution must be considered. So we develop states of the machine and under each state we mention the instructions accordingly. After every instruction execution, we also specify a state for the machine to transition to. Hence when a machine encountered a blank symbol, we instruct it to move the tape left before transitioning to State 1 where it reverses the bit inversion process. Thus, while encountering a blank the machine would —</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*0KE5k0oIIcb9fs3O.jpg" /><figcaption>Now when machine encounters a blank sybmol, we instruct it to move the tape left before transitioning to State 1 where it reverses the bit inversion process. Further encountering 0, it inverts the bits and this time moving the tape left instead of right.</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*XmZNfPPQZcz5hZfx.jpg" /><figcaption>Finally again a blank symbol is read, so we move the tape right to get back where it started, and stop the program.</figcaption></figure><p>This solves the issue of machine being halt when a blank space is encountered and tells the machine to stop execution in a particular scenario.</p><p>Wonder how Christopher was designed to break Enigma? Check out this blog with code and simulation — <a href="http://www.cs.miami.edu/home/harald/enigma/">http://www.cs.miami.edu/home/harald/enigma/</a></p><p>Okay but how would I write an automata through code? Here’s how —</p><h3><strong>Automata Based Programming — Programming Model for FSMs</strong></h3><p>A programming paradigm in which the program is thought as a model of finite state machine(FSM). The key indicators for this type of programming inferred from the above details about a state machine are -</p><ol><li>The time period of the program’s execution is clearly separated down to the <em>steps of the automaton</em>. Each of the <em>steps</em> is effectively an execution of a code section.</li><li>Any communication between the steps is only possible explictly via the state conditions. Between any two steps, the program can <strong>not</strong> have implicit components of its state, such as localvariables’ values, return addresses, the current instruction pointer, etc.</li></ol><p>The programmer’s style to code in this technique is very similar to the style of code used to solve mathematical tasks using Turing Machines etc.</p><p>Consider an example to read a text from standard input stream, line by line, and prints the first word of each line.</p><p><strong>A Traditional Program in C:</strong></p><pre>#include &lt;stdio.h&gt;<br>#include <em>&lt;ctype.h&gt;</em><br>int main(void)<br>{<br>    int c;<br>    <strong>do</strong> {<br>        <strong>do</strong> {<br>            c = getchar();<br>        } <strong>while</strong>(c == &#39; &#39;);<br>        <strong>while</strong>(c != EOF &amp;&amp; !isspace(c) &amp;&amp; c != &#39;\n&#39;) {<br>            putchar(c);<br>            c = getchar();<br>        }<br>        putchar(&#39;\n&#39;);<br>        <strong>while</strong>(c != EOF &amp;&amp; c != &#39;\n&#39;)<br>            c = getchar();<br>    } <strong>while</strong>(c != EOF);<br>    <strong>return</strong> 0;<br>}</pre><p><strong>Automata-based style program:</strong></p><p>The same task can be solved thinking in terms of finite state machines. We can divide line parsing into three stages: skipping the leading spaces, printing the word and skipping the trailing characters. Let’s call them <strong>states </strong><strong>before, </strong><strong>inside </strong>and<strong> </strong><strong>after</strong>. The program can be written as:</p><pre>#include <em>&lt;stdio.h&gt;</em><br><strong>enum</strong> states { before, inside, after };<br>void step(<strong>enum</strong> states *state, int c)<br>{<br>    <strong>if</strong>(c == &#39;\n&#39;) {<br>        putchar(&#39;\n&#39;);<br>        *state = before;<br>    } <strong>else</strong><br>    <strong>switch</strong>(*state) {<br>        <strong>case</strong> before:<br>            <strong>if</strong>(c != &#39; &#39;) {<br>                putchar(c);<br>                *state = inside;<br>            }<br>            <strong>break</strong>;<br>        <strong>case</strong> inside:<br>            <strong>if</strong>(c == &#39; &#39;) {<br>                *state = after;<br>            } <strong>else</strong> {<br>                putchar(c);<br>            }<br>            <strong>break</strong>;<br>        <strong>case</strong> after:<br>            <strong>break</strong>;<br>    }<br>} <br>int main(void)<br>{<br>    int c;<br>    <strong>enum</strong> states state = before;<br>    <strong>while</strong>((c = getchar()) != EOF) {<br>        step(&amp;state, c);<br>    }<br>    <strong>if</strong>(state != before)<br>        putchar(&#39;\n&#39;);<br>    <strong>return</strong> 0;<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/448/0*xDn9R4DZkIjhyrHV.png" /><figcaption>The <strong>N </strong>denotes the end of line character, the <strong>S</strong> denotes spaces, and the <strong>A</strong> stands for all the other characters. The automaton follows exactly one arrow on each step with state switches.</figcaption></figure><p>Significant Advantage:</p><ol><li>There’s only one reading(that is, call to the getchar() function) instruction in the program.</li><li>There is only one loop instead of the four the traditional version had.</li><li>The body of the while loop is the <strong>automaton step</strong>, and the loop itself is the cycle of automaton’s work.</li></ol><p>Hence this style of programming is also called switch style programming.</p><p>Some applications of Automata Based Programming are:</p><ol><li>Transformation Systems: Ex — Compilers</li><li>Interactive Systems: Ex — Text Editors, VisualStates ;)</li><li>Reactive System: Ex — Hardware Controllers, VisualStates ;)</li></ol><p>Finite States are also useful in game development to implement Artificial Intelligence. For example, pressing <em>down key </em>while <em>standing,</em> transitions to the <em>ducking</em> state. Pressing <em>down key </em>while jumping transitions to <em>diving</em>.</p><p>Hence, Finite Machines in their pure form, are constructed of States and Transitions. VisualStates can be used to develop these states and transitions and develop an automata or a behavior.</p><p>Thats it for this blog on finite states machines. I’ll further write blogs on how to use VisualStates and develop robotic example with simulations on Gazebo based on robots developed through Robotics Operating System.</p><h4>More where this came from</h4><p>This story is published in <a href="http://blog.usejournal.com/">Noteworthy</a>, where thousands come every day to learn about the people &amp; ideas shaping the products we love.</p><p>Follow our publication to see more product &amp; design stories featured by the <a href="https://usejournal.com/?utm_source=usejournal.com&amp;utm_medium=blog&amp;utm_campaign=guest_post">Journal</a> team.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2c970dcd9647" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>