{"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":"
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>\n We can help the students by making a small drawing on the board and asking them:<\/p>\n Tip<\/strong>: If the\u00a0path has very tight angles the robot might detect them as intersections. This might even happen in right angles, depending on the width of the line or the distance between both sensors. For the purpose of this exercise, create a gentle and smooth path. In further units we will address more advanced challenges like how to make the robot negotiate tight angles without losing the line…\u00a0<\/span><\/p>\n Another more systematic, but less graphic, way to find all the combinations of the two Color sensors\u2019 readings is to build a table of values.<\/p>\n<\/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
Exercise 1. A\u00a0four-step simple line follower<\/h2>\n
<\/a>
\n