{"id":9837,"date":"2015-04-14T22:11:47","date_gmt":"2015-04-14T12:11:47","guid":{"rendered":"http:\/\/legoeng.local\/?p=9837"},"modified":"2019-06-27T12:29:24","modified_gmt":"2019-06-27T02:29:24","slug":"from-sequential-programming-to-state-machines","status":"publish","type":"post","link":"http:\/\/legoeng.local\/from-sequential-programming-to-state-machines\/","title":{"rendered":"From Sequential Programming to State Machines"},"content":{"rendered":"
<\/a>In this unit, we will explore some common algorithms for line following in a very systematic way, starting with well known “sequential” approaches, and then contrasting these with a “state machine” approach.<\/p>\n We will see in detail how a four-step simple line follower with two Light (or Color) sensors works and how to systematize the design of its algorithm. We will analyze the similarity and fundamental difference with the three-step simple line follower typically used with one Light (or Color) sensor.<\/p>\n We will see how to make the robot take decisions sequentially at each line intersection, and how to design data flow diagrams to express graphically the working process of a program.<\/p>\n Finally, we will see how to program a state machine for this line follower and the advantages it brings over sequential programming.<\/p>\n This unit is based on my \u201cTeachers Introduction Course to LEGO\u00ae Mindstorms NXT & EV3<\/a>\u201d at BOGATECH<\/a>\u2019s website. Here the programming examples are based on the LEGO MINDSTORMS EV3 Software, but at BOGATECH\u2019s website you can find the NXT version and the differences between the two platforms, if you are interested.<\/p>\n We can start by asking the students how they think we should conceptually proceed. How should we design the algorithm? Note that the two Light sensors are located on each side of the black line that we want to follow, as shown in the images below.<\/p>\n Note: Although we will refer to Color sensors throughout this article, we are using them as Light sensors. Of course, the approach described in this article applies equally well to an NXT robot with a Light sensor.<\/p>\nExercise 1. A\u00a0four-step simple line follower<\/h2>\n