{"id":168,"date":"2016-01-14T07:58:53","date_gmt":"2016-01-14T07:58:53","guid":{"rendered":"http:\/\/iict-space.heig-vd.ch\/ape\/?page_id=168"},"modified":"2016-01-14T10:23:55","modified_gmt":"2016-01-14T10:23:55","slug":"fsm_read_bits_from_ground","status":"publish","type":"page","link":"http:\/\/iict-space.heig-vd.ch\/ape\/teaching\/aro1\/fsm_read_bits_from_ground\/","title":{"rendered":"FSM_read_bits_from_ground"},"content":{"rendered":"<p>Ce fichier doit s\u2019appeler par exemple: <strong>FSM_read_bits_from_ground.aesl<\/strong><\/p>\n<p>Ce code utilise des subroutines pour \u00eatre mieux structur\u00e9 et la machine d&#8217;\u00e9tats est r\u00e9alis\u00e9e \u00e0 l&#8217;aide de deux subroutines: update_state o\u00f9 l&#8217;on\u00a0d\u00e9termine les transitions d&#8217;\u00e9tat et update_output qui d\u00e9termine les sorties pour chaque \u00e9tat de la machine. Lorsque vous pressez sur le bouton du centre, il d\u00e9marre et avance \u00e0 une vitesse de 50. &#8220;onevent prox&#8221; permet de &#8220;lire&#8221;\u00a0le signal d&#8217;horloge (capteur gauche) et lorsque l&#8217;on d\u00e9tecte le flanc montant de l&#8217;horloge, la subroutine read_data va lire la donn\u00e9e (data) \u00e0 l&#8217;aide du capteur droit. Votre travail consiste \u00e0 modiifer les subroutines update_state et update_output.<\/p>\n<pre class=\"\">var data\r\nvar state\r\nvar clock_value\r\nvar ground_reading\r\nclock_value = 0\r\ndata = 0\r\nstate = 0\r\n\r\nmotor.left.target = 0\r\nmotor.right.target = 0\r\n\r\n#------------------------------------------------\r\nsub update_state # update the states\r\nif state == 0 then\r\n  if data == 0 then\r\n   state = 0\r\n  else\r\n   state = 1\r\n  end\r\nelseif state == 1 then\r\n  if data == 0 then\r\n   state = 0\r\n  else\r\n   state = 1\r\n  end\r\nelse\r\n  motor.left.target = 0 # error condition\r\n  motor.right.target = 0\r\n  call leds.top(32,0,0) # signal error condition\r\nend\r\n\r\n#------------------------------------------------\r\nsub update_output # update the outputs\r\nif state == 0 then\r\n  call leds.circle(1,0,0,0,0,0,0,0) # show current state for debugging\r\nelseif state == 1 then\r\n  call leds.circle(0,1,0,0,0,0,0,0) # show current state for debugging\r\n\r\n  call leds.top(0,32,0) # signal goal\r\nend\r\n\r\n#------------------------------------------------\r\nsub read_data # read the right ground sensor\r\nif prox.ground.delta[1] &lt; 350 then # black line (data)\r\n  call leds.bottom.right(0,0,32) # show the data value\r\n  data = 1 # update the data value\r\nelse\r\n  call leds.bottom.right(0,0,0) # show the data value\r\n  data = 0 # update the data value\r\nend\r\n\r\n#------------------------------------------------\r\nsub update_all\r\ncallsub read_data # read the data\r\ncallsub update_state # update the states\r\ncallsub update_output # update the output\r\n\r\n#------------------------------------------------\r\nonevent prox\r\nground_reading = prox.ground.delta[0] # read the left ground sensor (clock)\r\n\r\nif clock_value == 0 then\r\n  if ground_reading &lt; 340 then # black line \r\n    clock_value = 1 # update the clock value \r\n    call leds.bottom.left(0,0,32) # show the clock value    \r\n    callsub update_all # rising clock ! =&gt;    |read right sensor\r\n                                            # |update states\r\n                                            # |update outputs\r\nend\r\nelse\r\n if ground_reading &gt; 360 then # white line\r\n   clock_value = 0 # update the clock value\r\n   call leds.bottom.left(0,0,0) # show the clock value\r\n end\r\nend\r\n\r\n#------------------------------------------------\r\nonevent button.center\r\nif button.center == 1 then\r\n  if motor.left.target == 0 then # start moving\r\n   state = 0\r\n   call leds.top(0,0,0)\r\n   motor.left.target = 50\r\n   motor.right.target = 50\r\n  else # stop moving\r\n   motor.left.target = 0\r\n   motor.right.target = 0\r\n  end\r\nend\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Ce fichier doit s\u2019appeler par exemple: FSM_read_bits_from_ground.aesl Ce code utilise des subroutines pour \u00eatre mieux structur\u00e9 et la machine d&#8217;\u00e9tats est r\u00e9alis\u00e9e \u00e0 l&#8217;aide de deux subroutines: update_state o\u00f9 l&#8217;on\u00a0d\u00e9termine les transitions d&#8217;\u00e9tat et update_output qui d\u00e9termine les sorties pour <a class=\"more-link\" href=\"http:\/\/iict-space.heig-vd.ch\/ape\/teaching\/aro1\/fsm_read_bits_from_ground\/\">Continue reading <span class=\"screen-reader-text\">  FSM_read_bits_from_ground<\/span><span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":10,"featured_media":0,"parent":140,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"_links":{"self":[{"href":"http:\/\/iict-space.heig-vd.ch\/ape\/wp-json\/wp\/v2\/pages\/168"}],"collection":[{"href":"http:\/\/iict-space.heig-vd.ch\/ape\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/iict-space.heig-vd.ch\/ape\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/iict-space.heig-vd.ch\/ape\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"http:\/\/iict-space.heig-vd.ch\/ape\/wp-json\/wp\/v2\/comments?post=168"}],"version-history":[{"count":6,"href":"http:\/\/iict-space.heig-vd.ch\/ape\/wp-json\/wp\/v2\/pages\/168\/revisions"}],"predecessor-version":[{"id":187,"href":"http:\/\/iict-space.heig-vd.ch\/ape\/wp-json\/wp\/v2\/pages\/168\/revisions\/187"}],"up":[{"embeddable":true,"href":"http:\/\/iict-space.heig-vd.ch\/ape\/wp-json\/wp\/v2\/pages\/140"}],"wp:attachment":[{"href":"http:\/\/iict-space.heig-vd.ch\/ape\/wp-json\/wp\/v2\/media?parent=168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}