{"id":20136,"date":"2024-02-07T12:32:49","date_gmt":"2024-02-07T11:32:49","guid":{"rendered":"https:\/\/complex-systems-ai.com\/?page_id=20136"},"modified":"2024-02-11T13:52:42","modified_gmt":"2024-02-11T12:52:42","slug":"exercices-lego-mindstorms","status":"publish","type":"page","link":"https:\/\/complex-systems-ai.com\/en\/algorithmic\/exercises-correct-lego-mindstorms\/","title":{"rendered":"9 Lego Mindstorms Corrected Exercises"},"content":{"rendered":"<div data-elementor-type=\"wp-page\" data-elementor-id=\"20136\" class=\"elementor elementor-20136\">\n\t\t\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-b6ee20d elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"b6ee20d\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-33 elementor-top-column elementor-element elementor-element-b661b77\" data-id=\"b661b77\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-c365847 elementor-align-justify elementor-widget elementor-widget-button\" data-id=\"c365847\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"button.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-button-wrapper\">\n\t\t\t\t\t<a class=\"elementor-button elementor-button-link elementor-size-sm\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/\">\n\t\t\t\t\t\t<span class=\"elementor-button-content-wrapper\">\n\t\t\t\t\t\t\t\t\t<span class=\"elementor-button-text\">Algorithmic<\/span>\n\t\t\t\t\t<\/span>\n\t\t\t\t\t<\/a>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-33 elementor-top-column elementor-element elementor-element-dfab6f8\" data-id=\"dfab6f8\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-0d3ce4d elementor-align-justify elementor-widget elementor-widget-button\" data-id=\"0d3ce4d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"button.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-button-wrapper\">\n\t\t\t\t\t<a class=\"elementor-button elementor-button-link elementor-size-sm\" href=\"https:\/\/complex-systems-ai.com\/en\/\">\n\t\t\t\t\t\t<span class=\"elementor-button-content-wrapper\">\n\t\t\t\t\t\t\t\t\t<span class=\"elementor-button-text\">Home page<\/span>\n\t\t\t\t\t<\/span>\n\t\t\t\t\t<\/a>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t<div class=\"elementor-column elementor-col-33 elementor-top-column elementor-element elementor-element-6eccacd\" data-id=\"6eccacd\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-4b4821a elementor-align-justify elementor-widget elementor-widget-button\" data-id=\"4b4821a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"button.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<div class=\"elementor-button-wrapper\">\n\t\t\t\t\t<a class=\"elementor-button elementor-button-link elementor-size-sm\" href=\"https:\/\/fr.wikipedia.org\/wiki\/Algorithme\" target=\"_blank\" rel=\"noopener\">\n\t\t\t\t\t\t<span class=\"elementor-button-content-wrapper\">\n\t\t\t\t\t\t\t\t\t<span class=\"elementor-button-text\">Wiki<\/span>\n\t\t\t\t\t<\/span>\n\t\t\t\t\t<\/a>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-ca4cfe9 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"ca4cfe9\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-a581bd4\" data-id=\"a581bd4\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-657a521 elementor-widget elementor-widget-heading\" data-id=\"657a521\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewbox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewbox=\"0 0 24 24\" version=\"1.2\" baseprofile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/exercises-correct-lego-mindstorms\/#Exercices-corriges-sur-le-logiciel-de-robotique-Lego-Mindstorms\" >Corrected exercises on the Lego Mindstorms robotics software<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/exercises-correct-lego-mindstorms\/#Exercice-1\" >Exercise 1<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/exercises-correct-lego-mindstorms\/#Exercice-2\" >Exercise 2<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/exercises-correct-lego-mindstorms\/#Exercice-3\" >Exercise 3<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/exercises-correct-lego-mindstorms\/#Exercice-4\" >Exercise 4<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/exercises-correct-lego-mindstorms\/#Exercice-5\" >Exercise 5<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/exercises-correct-lego-mindstorms\/#Exercice-6\" >Exercise 6<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/exercises-correct-lego-mindstorms\/#Exercice-7\" >Exercise 7<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/exercises-correct-lego-mindstorms\/#Exercice-8\" >Exercise 8<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/exercises-correct-lego-mindstorms\/#Exercice-9\" >Exercise 9<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercices-corriges-sur-le-logiciel-de-robotique-Lego-Mindstorms\"><\/span>Corrected exercises on the Lego Mindstorms robotics software<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-9777eb1 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"9777eb1\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-d7df3a7\" data-id=\"d7df3a7\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-311e916 elementor-widget elementor-widget-text-editor\" data-id=\"311e916\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>This series of corrected exercises on Lego Mindstorms allows you to become familiar with programming and robotics software.<\/p><p><img decoding=\"async\" class=\"aligncenter wp-image-11096 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2020\/09\/cropped-Capture.png\" alt=\"Lego Mindstorms\" width=\"97\" height=\"97\" title=\"\"><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-cf3db34 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"cf3db34\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-0afd2bf\" data-id=\"0afd2bf\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-4cd2bc0 elementor-widget elementor-widget-heading\" data-id=\"4cd2bc0\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-1\"><\/span>Exercise 1<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-2e20959 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"2e20959\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-a89e8c8\" data-id=\"a89e8c8\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-0a3877b elementor-widget elementor-widget-text-editor\" data-id=\"0a3877b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>In this exercise, you will learn how to program the robot to perform simple movements. Understanding how to make your robot perform its movements is essential because it will constantly need to perform them in the following exercises.<\/p><p>Using the programming guide provided to you, please program your robot<br \/>so that it performs the following actions:<\/p><p>move forward for a period of 3 seconds,<\/p><p>go back for a period of 3 seconds,<\/p><p>turn to the left then to the right.<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-03baab2 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"03baab2\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-d66a6f8\" data-id=\"d66a6f8\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-a18bd2d elementor-widget elementor-widget-toggle\" data-id=\"a18bd2d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-1691\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-1691\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-1691\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-1691\"><p>This exercise aims to simply explain how to program the robot using LEGO software. There are two ways to approach these problems:<\/p><p>either by using the Move block (which allows you to control both motors at once), or by using two Motor blocks (one for each motor, which allows you to control each motor independently).<\/p><p>The second way uses loops so it is best to approach it if students are comfortable with this notion (which will be seen in the second exercise).<\/p><p>\u2013 move forward for a duration of 3 seconds, Place a Move block, check motors B and C and enter 3 seconds as the duration.<\/p><p>\u2013 go backwards for a duration of 3 seconds, Same as for the previous exercise except that you must select the \u201cBackward\u201d direction.<\/p><p>\u2013 turn on angles to the left then to the right. Place the \u201cDirect\u201d cursor either all the way to the right or all the way to the left.<\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-047e0a9 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"047e0a9\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-8296e4e\" data-id=\"8296e4e\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-5227d33 elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"5227d33\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-eea5d57 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"eea5d57\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-494c274\" data-id=\"494c274\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-4bf71a6 elementor-widget elementor-widget-heading\" data-id=\"4bf71a6\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-2\"><\/span>Exercise 2<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-54ad29f elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"54ad29f\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-b60d157\" data-id=\"b60d157\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-bf24b5d elementor-widget elementor-widget-text-editor\" data-id=\"bf24b5d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>and in programming, a loop is a control structure that allows a series of instructions to be repeated as long as a condition is true or is not met (depending on the type of loop used). There are several types such as for example While (condition) do. A loop can also be infinite, that is to say that its instruction block will be repeated indefinitely (more concretely: until stopped <em>manual \u00a0<\/em>from the program).<\/p><p>The robot is equipped with a number of sensors (a more precise description of each is given in the guide provided). These sensors make it possible to measure different parameters of the environment in which the robot operates. It is possible to use these measurements as a condition for stopping the loops and this is what will interest us later.<\/p><p><span style=\"color: var( --e-global-color-text ); font-family: var( --e-global-typography-text-font-family ), Sans-serif; font-size: 1.125rem; font-weight: var( --e-global-typography-text-font-weight );\">An infinite loop therefore allows us to have the robot perform an action (or a sequence of actions) without any particular stopping condition.<\/span><\/p><ol><li>Make your robot perform an unlimited circle-shaped trajectory<\/li><li>Move forward and backward (only a short distance) unlimitedly<\/li><li>Loop with stop condition<\/li><\/ol><p>A loop is most generally used with a stopping condition, that is to say that all of the instructions in the loop body will only be executed as long as the specified condition is true (from a point of logical view). In pseudo-code, a loop is written as follows:<\/p><p>As long as (<em>condition<\/em>) TO DO<\/p><p><em>\u00a0 \u00a0 \u00a0instructions<\/em><\/p><p>End While<\/p><p>You will then be asked to think about the algorithms of your programs and write them in the form of pseudo-code. The pseudocode is a <em>language \u00a0<\/em>close to natural, that is, when writing the algorithm you do not need to think about the implementation (how to translate it into the programming language).<\/p><p>In the case of our robot, we can put logical operations, a counter or sensors as conditions and this is what we will see here. For example, let&#039;s admit that our robot has a noise detection sensor (this is not the case in reality) and that we want it to move forward until it detects a noise, a pseudo-algorithm. code would be: <a href=\"https:\/\/complex-systems-ai.com\/en\/algorithmic\/\">algorithm<\/a> in pseudo-code would be:<\/p><p>As long as (undetected noise)<\/p><p>\u00a0 \u00a0 \u00a0 Move forward()<\/p><p>End While<\/p><p>When it detects the noise, it will stop repeating its block of instructions.<\/p><p>For each of the following actions and using a separate sensor, write a small algorithm in pseudo-code then program it:<\/p><ol><li>Move the robot forward then stop 20 cm from an obstacle,<\/li><li>Make the robot move forward then stop when it comes into contact with an obstacle,<\/li><li>Make the robot move forward then stop when it sees a color on the ground.<\/li><\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-71a4082 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"71a4082\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-513187f\" data-id=\"513187f\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-fd8f9f8 elementor-widget elementor-widget-toggle\" data-id=\"fd8f9f8\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-2651\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-2651\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-2651\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-2651\"><p>Infinite loop<\/p><ol><li>Make your robot perform an unlimited circle-shaped trajectory\u00a0<\/li><\/ol><p>To do this, you must use two blocks <em>Engines \u00a0<\/em>and place them in an \u201cunlimited\u201d loop. To make the trajectory in a circle, one motor must rotate faster than the other (play on the \u201cPower\u201d parameter) such as B at 75 and C at 40.<\/p><ol start=\"2\"><li>Move forward and backward (only a short distance) unlimitedly<\/li><\/ol><p>You must put two motor units to move forward (same power, same direction, same duration) in an infinite loop, then put two motor units back to move backward (the direction must be reversed in relation to the action of moving forward).<\/p><p>Please note, for the two motors to be active in parallel, the duration must be in degrees (for example 500) or rotations and the first of the two motor blocks (for each action), must have the \u201cWait for end\u201d option unchecked.<\/p><p><img decoding=\"async\" class=\"alignnone wp-image-20142 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego1.png\" alt=\"lego mindstorms\" width=\"375\" height=\"95\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego1.png 375w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego1-300x76.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego1-18x5.png 18w\" sizes=\"(max-width: 375px) 100vw, 375px\" \/><\/p><p>Loops with stopping conditions<\/p><ol><li>Move the robot forward then stop 5 cm from an obstacle,<\/li><\/ol><p>While (distance() <em>\u2265 <\/em>5)<\/p><p>\u00a0 \u00a0 \u00a0move forward()<\/p><p>End While<\/p><p>The loops used by the LEGO programming software are not While, that is, the condition of the loop is the condition of <u>exit<\/u> loop and not the validity condition.<\/p><p>Here, the loop must therefore have the ultrasonic sensor as a \u201cControl\u201d parameter and as a \u201cUntil\u201d condition. <em>&lt; <\/em>5 cm\u201d. This loop must contain two blocks <em>Engines <\/em>for motors B and C with the same power and the same direction and whose duration is \u201cunlimited\u201d.<\/p><p><img decoding=\"async\" class=\"alignnone wp-image-20143 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego2.jpg\" alt=\"lego mindstorms\" width=\"228\" height=\"74\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego2.jpg 228w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego2-18x6.jpg 18w\" sizes=\"(max-width: 228px) 100vw, 228px\" \/><\/p><ol start=\"2\"><li>Make the robot move forward then stop when it comes into contact with an obstacle,<\/li><\/ol><p>While (TouchSensor not pressed) do<\/p><p>\u00a0 \u00a0 \u00a0Move forward()<\/p><p>End While<\/p><p>The loop must contain two blocks <em>Engines \u00a0<\/em>for motors B and C (same power, same direction, unlimited duration) and have one of the touch sensors as control with the condition \u201cAction: pressed\u201d.<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20144 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego3.jpg\" alt=\"lego mindstorms\" width=\"227\" height=\"76\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego3.jpg 227w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego3-18x6.jpg 18w\" sizes=\"(max-width: 227px) 100vw, 227px\" \/><\/p><p>Please note: this version is simple but the robot only stops when it comes into contact with a single sensor. It is nevertheless possible to use a logical equation to bring the two sensors into play (the robot stops with the contact of one of the two sensors). To do this, you must use two \u201cTouch Sensor\u201d blocks and construct the following logic equation (which you enter as a condition in a loop with \u201cLogic\u201d as a control):<\/p><p><em>E <\/em>= 1 + 2<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20145 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego4.jpg\" alt=\"lego mindstorms\" width=\"299\" height=\"99\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego4.jpg 299w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego4-18x6.jpg 18w\" sizes=\"(max-width: 299px) 100vw, 299px\" \/><\/p><ol start=\"3\"><li>Make the robot move forward then stop when it sees a color on the ground.<\/li><\/ol><p>The color chosen doesn&#039;t really matter, but black is a practical choice because it can be measured with the color or brightness sensor.<\/p><p>While (color() <em>\/<\/em>= black) do<\/p><p>\u00a0 \u00a0 \u00a0Move forward()<\/p><p>End While<\/p><p>The loop must contain two blocks <em>Engines \u00a0<\/em>for motors B and C (same power, same direction, unlimited duration) and have as control the color sensor in \u201cColor\u201d mode with the condition \u201cUp to the range\u201d and the cursors framing black.<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20146 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego5.jpg\" alt=\"lego mindstorms\" width=\"229\" height=\"75\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego5.jpg 229w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego5-18x6.jpg 18w\" sizes=\"(max-width: 229px) 100vw, 229px\" \/><\/p><p>The color sensor can be used in \u201cPhotosensitive\u201d mode for this exercise if the stopping color is black. To do this, in the \u201cPhotosensitive\u201d mode set the condition \u201cUntil <em>&lt;<\/em> <em>X<\/em>&quot; Or \u00a0<em>X<\/em> is an upper limit of black to be determined by measurement on the support used as a test track.<\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-7b66add elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"7b66add\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-3d3746f\" data-id=\"3d3746f\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-1d67134 elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"1d67134\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-962ebcc elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"962ebcc\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-840901f\" data-id=\"840901f\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-19c8502 elementor-widget elementor-widget-heading\" data-id=\"19c8502\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-3\"><\/span>Exercise 3<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-3aac12e elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"3aac12e\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-b96da5a\" data-id=\"b96da5a\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-0a311d8 elementor-widget elementor-widget-text-editor\" data-id=\"0a311d8\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>You will have to program your robot so that it counts the colors. He must be able to advance along an area comprising a succession of colored areas, although the end of this area is marked by a black band. He must therefore count the number of times a colored strip appears while moving his screen forward. At the end of the course, it will display the number of color zones on the screen.<\/p><ol><li>Write an algorithm corresponding to this problem in pseudo-code<\/li><li>Implement your algorithm in your robot<\/li><\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-3105b33 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"3105b33\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-f940d8d\" data-id=\"f940d8d\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-1d548ed elementor-widget elementor-widget-toggle\" data-id=\"1d548ed\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-3071\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-3071\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-3071\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-3071\"><p>The goal of this exercise is to reuse what has been seen so far (loops, sensor) while introducing the notion of variable (from an algorithmic point of view and at the level of the robot programming software).<\/p><ol><li>Write an algorithm corresponding to this problem in pseudo-code<\/li><\/ol><p>ColorPrevious <em>\u2190 <\/em>color() NbRed <em>\u2190 <\/em>0<\/p><p>NbYellow <em>\u2190 <\/em>0<\/p><p>NbBlue <em>\u2190 <\/em>0<\/p><p>While (ReadColor() =<em>\/<\/em><em>\u00a0\u00a0\u00a0 <\/em>BLACK) do<\/p><p>\u00a0 \u00a0 \u00a0While (color() = PreviousColor)<\/p><p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 Move forward()<\/p><p>\u00a0 \u00a0 \u00a0End While<\/p><p>\u00a0 \u00a0 \u00a0If (color() = RED) then NbRed = NbRed + 1<\/p><p>\u00a0 \u00a0 \u00a0If (color() = YELLOW) then NbYellow = NbYellow + 1<\/p><p>\u00a0 \u00a0 \u00a0If (color() = BLUE) then NbBlue = NbBlue + 1<\/p><p>\u00a0 \u00a0 \u00a0End if<\/p><p>\u00a0 \u00a0 \u00a0ColorPrevious <em>\u2190 <\/em>color()<\/p><p>End While<\/p><p>color() is a function that returns the numerical value of the color read by the color sensor.<\/p><p>This algorithm works as follows: the robot advances as long as it is still in the same color zone then as soon as it has changed zone, it then increments the variable associated with this color. It ends up updating the PreviousColor variable to detect the change of zone on the next loop. The whole thing is in a black detection loop which will stop the robot as soon as it reads black.<\/p><ol start=\"2\"><li>Implement your algorithm in your robot<\/li><\/ol><p>To program it, we must first create the variables that will be used later (Previous Color, Red, Blue, Yellow); they are of digital type and initialized from the start of the program.<\/p><p>Then we place a main loop with the control \u201cColor sensor\u201d and the action \u201cUp to the black range\u201d. Within this loop we put back a loop containing two motor blocks to move the robot forward (duration set to \u201cUnlimited\u201d). The control of this loop must be placed on \u201cLogic\u201d with as input a comparison operation between the \u201cPrevious Color\u201d variable and the color sensor:<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20147 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/robor7.png\" alt=\"lego mindstorm\" width=\"546\" height=\"276\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/robor7.png 546w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/robor7-300x152.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/robor7-18x9.png 18w\" sizes=\"(max-width: 546px) 100vw, 546px\" \/><\/p><p>After this loop, we place three switch blocks (one for each color) in which we execute the operation of incrementing the associated color variable. Here for example is the red one:<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20148 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/robot8.png\" alt=\"lego mindstorms\" width=\"456\" height=\"320\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/robot8.png 456w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/robot8-300x211.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/robot8-18x12.png 18w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/robot8-120x85.png 120w\" sizes=\"(max-width: 456px) 100vw, 456px\" \/><\/p><p>Then, after these three switches, we do not forget to update the \u201cPrevious Color\u201d variable with the color sensor (as during initialization).<\/p><p>After the loop \u00a0<em>main<\/em>, we display the content of the color variables on the screen or with sounds.<\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-56b8ce7 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"56b8ce7\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-8b00675\" data-id=\"8b00675\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-8b73a07 elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"8b73a07\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-324f960 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"324f960\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-0fd5190\" data-id=\"0fd5190\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-f6c8135 elementor-widget elementor-widget-heading\" data-id=\"f6c8135\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-4\"><\/span>Exercise 4<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-7e8a01c elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"7e8a01c\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-b266374\" data-id=\"b266374\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-0f6fd41 elementor-widget elementor-widget-text-editor\" data-id=\"0f6fd41\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>The robot must follow a black path on the ground, the ground being white.<\/p><ol><li>Write an algorithm corresponding to this problem in pseudo-code<\/li><li>Implement your algorithm in your robot.<\/li><\/ol><p>Bonus question: can your program follow all types of routes?<\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-a408719 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"a408719\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-02ac338\" data-id=\"02ac338\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-cdfba9b elementor-widget elementor-widget-toggle\" data-id=\"cdfba9b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-2151\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-2151\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-2151\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-2151\"><ol><li>Write in pseudo-code an algorithm corresponding to this problem<\/li><\/ol><p>As long as (true) do<\/p><p>\u00a0 \u00a0 \u00a0While (color() = BLACK) do<\/p><p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 ShiftLeft()<\/p><p>\u00a0 \u00a0 \u00a0End While<\/p><p>\u00a0 \u00a0 \u00a0While (color() = WHITE) do<\/p><p>\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 DeviateRight()<\/p><p>\u00a0 \u00a0 \u00a0End While<\/p><p>End While\u00a0\u00a0 \u00a0<\/p><p>color() is a function that returns the numerical value of the color read by the color sensor.<\/p><p>DeviateLeft() and DeviateRight() are functions that move the robot forward by deviating to the left or to the right.<\/p><p>A line follower actually follows not the line but the edge of the line (the boundary between white and black). The algorithm presented here is very simple. Within an infinite loop, we place two loops: one for black and one for white. The black loop deviates the robot to the left as long as it reads black, and the white loop deviates the robot to the right as long as it reads white. Thus, the robot alternates movements to the left and to the right.<\/p><p>Note: this algorithm corresponds to a \u201cleft follower\u201d, that is to say in the case where white is to the left of black. We can make a \u201cright follower\u201d by reversing the direction of deviation.<\/p><ol start=\"2\"><li>Implement your algorithm in your robot<\/li><\/ol><p>To implement it in the robot, we first place a \u201cloop\u201d block with \u201cForever\u201d as a control.<\/p><p>In this block, we then place another loop but this time with the control \u201cColor sensor\u201d in \u201cPhotosensitive\u201d mode and with the action \u201cUntil <em>&lt;<\/em> 35\u201d (35 is a value of the upper limit of black brightness, this value must be determined by measurement during the session because it can vary depending on the lighting or the test track used).<\/p><p>Inside this loop, place two \u201cMotor\u201d blocks for each of the two motors, one of which has a lower power than the other (to deviate to the left, motor C must go slower than B ). Make a similar loop for the white with this time action positioned on \u201cUntil \u00a0<em>&gt;<\/em> 35\u201d and the motor powers reversed.<\/p><p>The difference between the respective powers of the motors will affect both the overall speed of the robot (the time it will take to make a complete turn) and its ability to follow a path more or less <em>twisted<\/em>. To do this, do not hesitate to do several tests with different values to find a good compromise (correct values are for example 75 and 10).<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20149 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/robot9.png\" alt=\"lego mindstorms\" width=\"636\" height=\"136\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/robot9.png 636w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/robot9-300x64.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/robot9-18x4.png 18w\" sizes=\"(max-width: 636px) 100vw, 636px\" \/><\/p><p>Bonus question: can your program follow all types of routes?<\/p><p>Normally this program does not allow you to follow all types of tracks. Indeed, as soon as the route becomes too complex, the robot should no longer be able to follow (unless one of the two motors is almost stopped, which will then make it very slow). It cannot follow an inside or too tight turn, nor a right angle turn. To be convinced, don&#039;t hesitate to perform it on the bonus circuits.<\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-5fbc3e9 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"5fbc3e9\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-92f5fbf\" data-id=\"92f5fbf\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-b52aef7 elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"b52aef7\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-6f553ae elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"6f553ae\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-307669e\" data-id=\"307669e\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-9f82f41 elementor-widget elementor-widget-heading\" data-id=\"9f82f41\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-5\"><\/span>Exercise 5<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-9d3e13a elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"9d3e13a\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-fe22616\" data-id=\"fe22616\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-aafff9b elementor-widget elementor-widget-text-editor\" data-id=\"aafff9b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>When carrying out certain tasks, your robot often has to repeat standard actions several times, such as turning 90\u00b0 to the right or moving forward 10 cm. For&#039;<em>alleviate \u00a0<\/em>your program, it is possible to create personalized blocks which are subsequently used like the default blocks (in this way, instead of having several times the different blocks which manage the angle calculations and the activation of the motors, we only use one several times). This principle is similar to functions (or procedures) in algorithmics.<\/p><p>As a reminder, in algorithmics, a function is a sequence of instructions relatively independent of the main program and which is repeated several times. This sequence of instructions is then grouped into a single instruction block which is the function.<\/p><p>Using the programming guide (and more particularly the block creation section) as well as the appendix on distance and rotation calculations, create the following personalized blocks:<\/p><ul><li>Move forward: moves the robot forward according to the distance given as input (this distance will be in centimeters),<\/li><li>Back up: moves the robot back according to the distance given in input (this distance will be in centimeters),<\/li><li>TurnRight: turns the robot at a given input angle to the right,<\/li><li>TurnLeft: turns the robot at a given input angle to the left,<\/li><li>RotateRight: rotates the robot at a given input angle to the right,<\/li><li>RotateLeft: rotates the robot at a given input angle to the left<\/li><\/ul><p>Now, using the blocks you just created, please create a program that allows your robot to perform this trajectory:<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20153 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/robot10.png\" alt=\"lego mindstorms\" width=\"388\" height=\"277\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/robot10.png 388w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/robot10-300x214.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/robot10-18x12.png 18w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/robot10-120x85.png 120w\" sizes=\"(max-width: 388px) 100vw, 388px\" \/><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-889c982 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"889c982\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-23bf2dd\" data-id=\"23bf2dd\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-7732127 elementor-widget elementor-widget-toggle\" data-id=\"7732127\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-1241\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-1241\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-1241\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-1241\"><p>You must therefore use the programming guide as well as the appendix on distances and rotations to create the blocks and implement the formulas using the operation blocks.<\/p><p>\u2013 Move forward: moves the robot forward according to the distance given as input (this distance will be in centimeters),<\/p><p>It is therefore necessary to code the formula distance*360\/13.5 using constants for 360 and 13.5 and a variable in reading mode for the distance; then give the result as the input value of a block <em>Move <\/em>set to a duration in \u201cDegrees\u201d. To create the block, simply select all these blocks except the variable block for the distance, then go to <em>To modify <\/em><em>\u2192 Create new block My block <\/em>:<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20154 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego6.jpg\" alt=\"lego mindstorms\" width=\"431\" height=\"237\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego6.jpg 431w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego6-300x165.jpg 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego6-18x10.jpg 18w\" sizes=\"(max-width: 431px) 100vw, 431px\" \/><\/p><ul><li>Back up: moves the robot back according to the distance given in input (this distance will be in centimeters),<\/li><\/ul><p>You must code the same formula as for the block <em>Move forward <\/em>but this time the block <em>Move <\/em>must be set to rotate the motors in the other direction.<\/p><ul><li>TurnRight: turns the robot at a given input angle to the right,<\/li><\/ul><p>This time, it&#039;s the formula angle*2pi*15.5\/13.5 and put the result at the input of motor C (motor B must be deactivated).<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20155 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego7.png\" alt=\"lego mindstorms\" width=\"673\" height=\"279\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego7.png 673w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego7-300x124.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego7-18x7.png 18w\" sizes=\"(max-width: 673px) 100vw, 673px\" \/><\/p><ul><li>TurnLeft: turns the robot at a given input angle to the left,<\/li><\/ul><p>The formula remains the same as before but this time it is motor B which is activated and motor C which is deactivated.<\/p><ul><li>RotateRight: rotates the robot at a given input angle to the right,<\/li><\/ul><p>The formula is almost the same as before except that we remove the coefficient 2 (the circle described being half as large). Furthermore, the result of the calculation is given as input to engines B and C this time; the C motor going forward and the B motor going backwards.<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20157 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego8.png\" alt=\"lego mindstorms\" width=\"626\" height=\"302\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego8.png 626w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego8-300x145.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego8-18x9.png 18w\" sizes=\"(max-width: 626px) 100vw, 626px\" \/><\/p><ul><li>RotateLeft: rotates the robot at a given input angle to the left. Same formula as for the previous block except that the directions of the motors are reversed<\/li><\/ul><p>The files are to be placed in the Blocks\/My blocks folder of the profile folder: Forward.rbt, Backward.rbt, RotateLeft.rbt, RotateRight.rbt, PivoterLeft.rbt, PivoterDroite.rbt<\/p><p>The trajectory to then be made by the robot is rather simple with the blocks. It is therefore necessary to place the blocks successively <em>Move forward<\/em>, <em>RotateRight<\/em>, <em>Move forward<\/em>, <em>RotateLeft<\/em>, <em>Move forward<\/em>, <em>RotateRight<\/em>, <em>Move forward<\/em>, <em>Swing<\/em><em>RIGHT<\/em>, <em>Move forward<\/em>, <em>RotateRight <\/em>with associated distances and angles. Be careful, however, to take the correct angle value for the pivots (you must take the value of the additional angle).<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20158 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego9.png\" alt=\"lego mindstorms\" width=\"713\" height=\"137\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego9.png 713w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego9-300x58.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego9-18x3.png 18w\" sizes=\"(max-width: 713px) 100vw, 713px\" \/><\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-8052361 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"8052361\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-b270f24\" data-id=\"b270f24\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-3b78f57 elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"3b78f57\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-c4406a9 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"c4406a9\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-db427b5\" data-id=\"db427b5\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-4c1f364 elementor-widget elementor-widget-heading\" data-id=\"4c1f364\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-6\"><\/span>Exercise 6<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-13b1fbb elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"13b1fbb\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-77af73c\" data-id=\"77af73c\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-770393d elementor-widget elementor-widget-text-editor\" data-id=\"770393d\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Using a state graph (finite state automaton), give the program the following actions.<\/p><ol><li>Stop at the right place<\/li><\/ol><p>The initial state considers the robot in white, this allows you to start the robot from anywhere (i.e. white or black). Each time it changes color (black or white), it will move to the next state. Each state has the associated action of moving forward except the state following the third transition <em>black <\/em>(which therefore corresponds to the third time that the robot encounters a black zone) where the robot stops.<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20159 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego10.png\" alt=\"lego mindstorms\" width=\"648\" height=\"139\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego10.png 648w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego10-300x64.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego10-18x4.png 18w\" sizes=\"(max-width: 648px) 100vw, 648px\" \/><\/p><p>\u00a02. Obstacle detection, the robot moves straight forward then reverses if it hits an obstacle<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20161 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego12.png\" alt=\"lego mindstorms\" width=\"373\" height=\"125\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego12.png 373w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego12-300x101.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego12-18x6.png 18w\" sizes=\"(max-width: 373px) 100vw, 373px\" \/><\/p><p>3. The robot goes straight ahead then turns right (resp. left) if it encounters an obstacle on the left (resp. right) or turns around if the obstacle is in front of it.<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20166 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego14.jpg\" alt=\"lego mindstorms\" width=\"367\" height=\"332\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego14.jpg 367w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego14-300x271.jpg 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego14-13x12.jpg 13w\" sizes=\"(max-width: 367px) 100vw, 367px\" \/><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-09ca9ac elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"09ca9ac\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-d7e9a96\" data-id=\"d7e9a96\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-20a006b elementor-widget elementor-widget-toggle\" data-id=\"20a006b\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-3421\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-3421\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-3421\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-3421\"><p>1.<\/p><p>To program this state graph, you must first create a numeric type variable <em>state <\/em>which will contain the current state. It will be initialized to 0 at the start of the program. We add within a loop so the condition is <em>until state = 5<\/em>, a first switch on the value of the variable <em>state <\/em>which will allow the value of the current state to be changed according to the actions detected (reading white or black) followed by a second switch also on the value of the variable <em>state <\/em>which will determine the actions to be performed in each state:<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20160 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego11.png\" alt=\"lego mindstorms\" width=\"741\" height=\"263\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego11.png 741w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego11-300x106.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego11-18x6.png 18w\" sizes=\"(max-width: 741px) 100vw, 741px\" \/><\/p><p>2.<\/p><p>You must proceed in the same way as for the previous program: two switches; one for transitions and one for actions. However, in the file provided as a correction we grouped these two switches into one to show that this was also possible. Changing the variable <em>state <\/em>is therefore done at the end of the action loop. This way is more compact but a little less clear and organized but remains possible and functional.<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20165 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego13.png\" alt=\"lego mindstorms\" width=\"619\" height=\"271\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego13.png 619w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego13-300x131.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego13-18x8.png 18w\" sizes=\"(max-width: 619px) 100vw, 619px\" \/><\/p><p>3.<\/p><p>We therefore use the same program structure as before but this time clearly differentiating the contact on the left or on the right.<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20167 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego15.png\" alt=\"lego mindstorms\" width=\"784\" height=\"322\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego15.png 784w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego15-300x123.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego15-768x315.png 768w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego15-18x7.png 18w\" sizes=\"(max-width: 784px) 100vw, 784px\" \/><\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-98f030c elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"98f030c\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-f67542f\" data-id=\"f67542f\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-28ec7c6 elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"28ec7c6\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-5ac6a89 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"5ac6a89\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-ddeaad7\" data-id=\"ddeaad7\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-6bab334 elementor-widget elementor-widget-heading\" data-id=\"6bab334\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-7\"><\/span>Exercise 7<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-3b9b74e elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"3b9b74e\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-502cb49\" data-id=\"502cb49\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-1053fa8 elementor-widget elementor-widget-text-editor\" data-id=\"1053fa8\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>We will try to program the robot so that it searches for an object in a space delimited by a black line and takes it out of this space. Your program must therefore include two distinct phases: a first of searching for the object and a second of removing the object from this space (it will remove the object by pushing it outwards).<\/p><p>\u00a0Your program must be \u00a0<em>clever \u00a0<\/em>: you do not have to program the robot so that it goes directly to the object (the latter can be located anywhere in space). In addition, the robot will have to start in a very distinct position. Here is an example of object placement:<\/p><ol><li>Describe a simple algorithm to perform this task,<\/li><li>Create a program that performs these actions based on the algorithm.<\/li><\/ol><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-20168\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego16.jpg\" alt=\"lego mindstorms\" width=\"193\" height=\"152\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego16.jpg 193w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego16-15x12.jpg 15w\" sizes=\"(max-width: 193px) 100vw, 193px\" \/><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-d541ad5 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"d541ad5\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-b1643e1\" data-id=\"b1643e1\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-0d9e7dc elementor-widget elementor-widget-toggle\" data-id=\"0d9e7dc\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-1421\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-1421\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-1421\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-1421\"><p>1.<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20169 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego16.png\" alt=\"lego mindstorms\" width=\"351\" height=\"270\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego16.png 351w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego16-300x231.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego16-16x12.png 16w\" sizes=\"(max-width: 351px) 100vw, 351px\" \/><\/p><p>First, the robot advances until it either encounters darkness or touches an object. If it encounters black, it backs up and then rotates at a random angle (between 0 and 180 degrees) then leaves again. If it comes into contact with an object, it then continues to advance until it encounters black; he will then have taken the object out of the frame.<\/p><p>2.<\/p><p>To program this, we start by placing a loop with the logical condition that one of the tactile sensors is pressed (so use the blocks for these sensors with a logic block <em>OR <\/em>). We then place inside this loop a loop with the logical condition <em>Black OR (Touch1 OR Touch2)<\/em>, we stop the motors at the exit of this loop so that the robot does not leave the frame if the loop stopped because it saw black:<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20170 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego17.png\" alt=\"lego mindstorms\" width=\"660\" height=\"279\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego17.png 660w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego17-300x127.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego17-18x8.png 18w\" sizes=\"(max-width: 660px) 100vw, 660px\" \/><\/p><p>We then place a switch to see if the loop was interrupted because the robot saw black. In this case, we place a block <em>To move back <\/em>\u2013 created in the previous exercise \u2013 followed by a block <em>Random <\/em>which takes a number between 0 and 180 and gives it as input to a block <em>RotateLeft<\/em>.<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20171 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego18.jpg\" alt=\"lego mindstorms\" width=\"675\" height=\"309\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego18.jpg 675w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego18-300x137.jpg 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego18-18x8.jpg 18w\" sizes=\"(max-width: 675px) 100vw, 675px\" \/><\/p><p>After the main loop, we place a loop making the robot move forward until it sees black.<\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-f23f2fb elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"f23f2fb\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-57bf4de\" data-id=\"57bf4de\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-cf2e73a elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"cf2e73a\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-4641015 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"4641015\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-6ae3228\" data-id=\"6ae3228\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-9f506c8 elementor-widget elementor-widget-heading\" data-id=\"9f506c8\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-8\"><\/span>Exercise 8<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-719b97e elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"719b97e\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-210b029\" data-id=\"210b029\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-9064b0e elementor-widget elementor-widget-text-editor\" data-id=\"9064b0e\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>As in the previous exercise, we will program our robot so that it searches for an object in a space. Except that in this version we will use the ultrasonic sensor. It is therefore a question of programming the robot so that it first searches in which direction the object is located, then it moves towards it and stops 5 cm away.<\/p><ol><li>Write an algorithm corresponding to this problem in pseudo-code<\/li><li>Implement your algorithm in your robot<\/li><\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-69adfae elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"69adfae\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-d169496\" data-id=\"d169496\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-e7875da elementor-widget elementor-widget-toggle\" data-id=\"e7875da\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-2421\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-2421\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-2421\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-2421\"><p>1.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20173 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego19.png\" alt=\"lego mindstorms\" width=\"599\" height=\"380\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego19.png 599w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego19-300x190.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego19-18x12.png 18w\" sizes=\"(max-width: 599px) 100vw, 599px\" \/><\/p>\n<p>Here, rather than blindly searching for the object, the robot will search in which direction it is located. To do this, the sensor will scan the entire space in front of the robot (the sensor will rotate through an angle of 180\u02da) and look for the shortest distance to an obstacle (on the same principle as a minimum search algorithm in a painting) ; it will memorize the angle to deduce the direction in which the robot will go.<\/p>\n<p>2.<\/p>\n<p>First, we rotate motor A 90\u02da to the left to orient the ultrasonic sensor, then we place a sensor block just after <em>Rotation <\/em>to reset the value returned by the latter. We then store in a variable <em>distanceMin <\/em>the value returned by the ultrasound sensor and we initialize another variable <em>corner<\/em> to 0. And finally, we start a slow rotation of A towards the right:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20174 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego20.jpg\" alt=\"lego mindstorms\" width=\"529\" height=\"262\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego20.jpg 529w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego20-300x149.jpg 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego20-18x9.jpg 18w\" sizes=\"(max-width: 529px) 100vw, 529px\" \/><\/p>\n<p>We now place a loop in which we will carry out the comparisons to find the angle of the minimum distance. This loop controls the rotation sensor of motor A and as a condition <em>until <\/em><em>&gt;<\/em><em> 180\u02da<\/em>. At the start of the loop, we store in <em>Number 1 <\/em>the distance measured by the ultrasonic sensor and in <em>corner <\/em>the value returned by the rotation sensor of A. Comparisons and possible assignments are then made with these variables.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20175 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego21.png\" alt=\"lego mindstorms\" width=\"776\" height=\"283\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego21.png 776w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego21-300x109.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego21-768x280.png 768w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego21-18x7.png 18w\" sizes=\"(max-width: 776px) 100vw, 776px\" \/><\/p>\n<p>Finally, after the loop, motor A is stopped and then rotated 90\u02datowards the left to refocus the ultrasonic sensor. We then rotate the robot according to the value of <em>corner <\/em>then we advance it up to 5 cm from the object:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20176 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego22.jpg\" alt=\"lego mindstorms\" width=\"760\" height=\"277\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego22.jpg 760w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego22-300x109.jpg 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego22-18x7.jpg 18w\" sizes=\"(max-width: 760px) 100vw, 760px\" \/><\/p>\n<p>ANOTHER APPROACH:<\/p>\n<p>We slowly rotate the ultrasonic sensor until there is an obstacle and at this moment we make the robot move towards it. This approach therefore assumes that the space in front of the robot (therefore over a given distance, for example 40 cm) only contains the desired object, it therefore remains less good than the previous one but simpler to understand, which is why it is presented here:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20177 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego23.png\" alt=\"lego mindstorms\" width=\"407\" height=\"274\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego23.png 407w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego23-300x202.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego23-18x12.png 18w\" sizes=\"(max-width: 407px) 100vw, 407px\" \/><\/p>\n<p>The program therefore closely resembles the initial version, except that the rotation of motor A stops as soon as it detects an object.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20178 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego24.jpg\" alt=\"lego mindstorms\" width=\"780\" height=\"347\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego24.jpg 780w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego24-300x133.jpg 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego24-768x342.jpg 768w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego24-18x8.jpg 18w\" sizes=\"(max-width: 780px) 100vw, 780px\" \/><\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-bd5b316 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"bd5b316\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-17fc14e\" data-id=\"17fc14e\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-5ed97cb elementor-widget-divider--view-line elementor-widget elementor-widget-divider\" data-id=\"5ed97cb\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"divider.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-divider\">\n\t\t\t<span class=\"elementor-divider-separator\">\n\t\t\t\t\t\t<\/span>\n\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-2eb3f88 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"2eb3f88\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-e178ca2\" data-id=\"e178ca2\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-fc52c4f elementor-widget elementor-widget-heading\" data-id=\"fc52c4f\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"heading.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t<h2 class=\"elementor-heading-title elementor-size-default\"><span class=\"ez-toc-section\" id=\"Exercice-9\"><\/span>Exercise 9<span class=\"ez-toc-section-end\"><\/span><\/h2>\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-9209b97 elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"9209b97\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-b2d7c5e\" data-id=\"b2d7c5e\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-55afb86 elementor-widget elementor-widget-text-editor\" data-id=\"55afb86\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>We will now program the robot so that it is able to escape from a maze <em>simple<\/em>. Be careful, finding a path to cross a maze is a difficult problem from a computer point of view (we speak of a problem <em>NP-Complete <\/em>), this is why all the proposed mazes are simple because you are not asked for an efficient algorithm for all the mazes.<\/p><p>A- Basic maze<\/p><p>The first type of maze is made up only of high walls (25 cm). Here is his plan:<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-20183\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego25.jpg\" alt=\"lego mindstorms\" width=\"136\" height=\"134\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego25.jpg 136w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego25-12x12.jpg 12w\" sizes=\"(max-width: 136px) 100vw, 136px\" \/><\/p><p>You will therefore have to program your robot so that it crosses it. To do this, you will need to use the ultrasonic sensor to determine which way to go at each intersection.<\/p><ol><li>Write in pseudo-code a naive algorithm allowing the robot to traverse such a maze<\/li><li>Implement your algorithm in your robot<\/li><\/ol><p>B- Advanced maze<\/p><p>We now modify the maze by replacing a high wall with a low obstacle (10 cm).<\/p><p>How can I make the robot always go through the maze?<\/p><ol><li>Modify the previous algorithm to take this change into account<\/li><li>Implement your modified algorithm into your robot<\/li><\/ol><p>C- Impasse<\/p><p>We will now take this labyrinth layout:<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-20184\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego26.jpg\" alt=\"lego mindstorms\" width=\"101\" height=\"137\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego26.jpg 101w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego26-9x12.jpg 9w\" sizes=\"(max-width: 101px) 100vw, 101px\" \/><\/p><p>As you can see, this maze has a dead end. What to do if your robot ends up in it?<\/p><ol><li>Modify the previous algorithm to take into account deadlocks<\/li><li>Implement your modified algorithm into your robot<\/li><li>Bonus question: can he get through all the mazes?<\/li><\/ol>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<section class=\"elementor-section elementor-top-section elementor-element elementor-element-dcc711b elementor-section-boxed elementor-section-height-default elementor-section-height-default\" data-id=\"dcc711b\" data-element_type=\"section\" data-e-type=\"section\">\n\t\t\t\t\t\t<div class=\"elementor-container elementor-column-gap-default\">\n\t\t\t\t\t<div class=\"elementor-column elementor-col-100 elementor-top-column elementor-element elementor-element-057373d\" data-id=\"057373d\" data-element_type=\"column\" data-e-type=\"column\">\n\t\t\t<div class=\"elementor-widget-wrap elementor-element-populated\">\n\t\t\t\t\t\t<div class=\"elementor-element elementor-element-e5ee6b2 elementor-widget elementor-widget-toggle\" data-id=\"e5ee6b2\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"toggle.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle\">\n\t\t\t\t\t\t\t<div class=\"elementor-toggle-item\">\n\t\t\t\t\t<div id=\"elementor-tab-title-2411\" class=\"elementor-tab-title\" data-tab=\"1\" role=\"button\" aria-controls=\"elementor-tab-content-2411\" aria-expanded=\"false\">\n\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon elementor-toggle-icon-left\" aria-hidden=\"true\">\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-closed\"><i class=\"fas fa-caret-right\"><\/i><\/span>\n\t\t\t\t\t\t\t\t<span class=\"elementor-toggle-icon-opened\"><i class=\"elementor-toggle-icon-opened fas fa-caret-up\"><\/i><\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t\t<\/span>\n\t\t\t\t\t\t\t\t\t\t\t\t<a class=\"elementor-toggle-title\" tabindex=\"0\">Solution<\/a>\n\t\t\t\t\t<\/div>\n\n\t\t\t\t\t<div id=\"elementor-tab-content-2411\" class=\"elementor-tab-content elementor-clearfix\" data-tab=\"1\" role=\"region\" aria-labelledby=\"elementor-tab-title-2411\"><p>HAS-<\/p><p>This first type of maze only has one path that leads directly to the exit. The goal is to understand the behavior of the robot within this maze; that is to say, advance up to a wall then look for which way to turn.\u00a0<\/p><p>To know which way to turn, you can have several approaches, such as looking arbitrarily to the left to see if there is an obstacle and, if necessary, turning left if not right. In the following algorithm (and therefore the proposed program), at each intersection the robot turns to the side where the obstacle is furthest away. Here is the algorithm:<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20185 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego27.png\" alt=\"lego mindstorms\" width=\"379\" height=\"320\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego27.png 379w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego27-300x253.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego27-14x12.png 14w\" sizes=\"(max-width: 379px) 100vw, 379px\" \/><\/p><p>The robot advances up to 15 cm from the wall then stops. He then measures the distance separating him from the wall on the left then from the wall on the right. it then turns to the side where this distance is greatest and then begins to move forward again. He stops as soon as he sees red.<\/p><p>We start by placing blocks <em>Variable <\/em>in fashion <em>To write <\/em>to initialize variables <em>distanceLeft <\/em>and <em>distanceRight <\/em>to 0. Then, we place a loop with the color sensor as control and the stopping condition <em>All the way to the red beach <\/em>(this loop will end the program when the robot is at the end of the maze).<\/p><p>We then place a loop to move the robot forward to an obstacle. It must therefore contain two blocks <em>Engine <\/em>for B and C with a as duration <em>Unlimited<\/em>.\u00a0<\/p><p>. Be careful, the robot must stop (and therefore exit this loop) either 15 cm from an obstacle, or when it sees red; the control must therefore not be the ultrasonic sensor but a logical equation constructed with two sensor blocks (ultrasonic sensor set to <em>distance <\/em><em>less than 15 cm <\/em>and color sensor set to <em>in the red beach<\/em>) :<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20186 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego28.jpg\" alt=\"lego mindstorms\" width=\"651\" height=\"378\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego28.jpg 651w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego28-300x174.jpg 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego28-18x10.jpg 18w\" sizes=\"(max-width: 651px) 100vw, 651px\" \/><\/p><p>The rest of the program is the set of instructions corresponding to choosing which way the robot will turn. This part takes place within a switch with the color sensor as control and set to <em>Out of the red beach <\/em>; in fact, this allows you not to search for obstacles if the robot has stopped.\u00a0<\/p><p>The first step therefore consists of rotating the motor A to the left then recording the value returned by the ultrasonic sensor in <em>distanceLeft<\/em>, then turn motor A to the right and record the value returned by the ultrasonic sensor in <em>distanceRight<\/em>. We then compare the two variables and in a switch <em>logic <\/em>which takes as input the result of the comparison, we use the blocks <em>RotateRight <\/em>Where <em>RotateLeft <\/em>created in a previous exercise (with 90 as input angle value) to turn to the correct side:<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20187 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego29.png\" alt=\"lego mindstorms\" width=\"782\" height=\"309\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego29.png 782w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego29-300x119.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego29-768x303.png 768w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego29-18x7.png 18w\" sizes=\"(max-width: 782px) 100vw, 782px\" \/><\/p><p>B-<\/p><p>We now modify the maze by replacing a high wall with a low obstacle (10 cm).<\/p><p>To take this change into account, the use of the touch sensor must be added. We will therefore make the robot stop if it hits an obstacle that it could not have seen with the ultrasonic sensor.<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20188 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego30.png\" alt=\"lego mindstorms\" width=\"537\" height=\"370\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego30.png 537w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego30-300x207.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego30-18x12.png 18w\" sizes=\"(max-width: 537px) 100vw, 537px\" \/><\/p><p>The algorithm is almost the same as for the previous question. Only the condition of the loop to move the robot forward has changed: the robot stops moving forward if it is 15 cm from an obstacle OR if it touches an obstacle. After this loop, we add a condition to check if it is the second case (tactile sensors) which made the robot stop, and if this is the case, we make it move back 15 cm. The rest of the algorithm is unchanged.<\/p><p>So all you have to do is take the previous program and make a few modifications and additions. It is necessary to modify the<em>logical equation <\/em>loop control that moves the robot towards an obstacle. The robot must now stop if it is 15 cm from an obstacle or if it sees red or if it comes into contact with an obstacle. We must therefore add the blocks corresponding to touch sensors 1 and 2 with a logic block (type <em>OR <\/em>) :<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20189 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego31.png\" alt=\"lego mindstorms\" width=\"716\" height=\"330\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego31.png 716w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego31-300x138.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego31-18x8.png 18w\" sizes=\"(max-width: 716px) 100vw, 716px\" \/><\/p><p>After this loop, we place a switch to check if we have left the loop because of the tactile sensors and move the robot back 15 cm if necessary (for this, we can use the block created to move back):<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20190 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego32.jpg\" alt=\"lego mindstorms\" width=\"395\" height=\"224\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego32.jpg 395w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego32-300x170.jpg 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego32-18x10.jpg 18w\" sizes=\"(max-width: 395px) 100vw, 395px\" \/><\/p><p>VS-<\/p><p>The robot is in an impasse if, when it is stopped (therefore blocked by a wall facing it), the walls on the left and right are too close to it (the distance measured on the left is less than a certain distance \u2013 here we chose 20 cm \u2013, the same for the distance measured on the right). We must therefore modify the condition to decide which side to turn:<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20191 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego33.png\" alt=\"lego mindstorms\" width=\"541\" height=\"446\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego33.png 541w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego33-300x247.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego33-15x12.png 15w\" sizes=\"(max-width: 541px) 100vw, 541px\" \/><\/p><p>The algorithm is therefore very similar to the previous one. We added the condition <em>If (distanceLeft <\/em><em>&lt; 20 AND distanceRight <\/em><em>&lt;<\/em><em> 20) <\/em>which makes it possible to detect a dead end and therefore makes the robot turn around if this is the case. Otherwise the decision on which side to turn remains the same.<\/p><p>To detect dead ends, we take the advanced maze program and place the blocks used to determine which way the robot will turn in a switch having a logical value as control: the value will be the result of the equation <em>distanceLeft <\/em><em>&lt;<\/em> 20 <em>AND distanceRight<\/em> <em>&lt;<\/em>20 :<\/p><p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-20192 size-full\" src=\"http:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego34.png\" alt=\"lego mindstorms\" width=\"767\" height=\"301\" title=\"\" srcset=\"https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego34.png 767w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego34-300x118.png 300w, https:\/\/complex-systems-ai.com\/wp-content\/uploads\/2024\/02\/lego34-18x7.png 18w\" sizes=\"(max-width: 767px) 100vw, 767px\" \/><\/p><\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t<\/section>\n\t\t\t\t<\/div>","protected":false},"excerpt":{"rendered":"<p>Algorithmic Home page Wiki Corrected exercises on the Lego Mindstorms robotics software This series of corrected exercises on Lego Mindstorms allows you to familiarize yourself with\u2026 <\/p>","protected":false},"author":1,"featured_media":0,"parent":1062,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-20136","page","type-page","status-publish","hentry"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/complex-systems-ai.com\/en\/wp-json\/wp\/v2\/pages\/20136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/complex-systems-ai.com\/en\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/complex-systems-ai.com\/en\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/complex-systems-ai.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/complex-systems-ai.com\/en\/wp-json\/wp\/v2\/comments?post=20136"}],"version-history":[{"count":19,"href":"https:\/\/complex-systems-ai.com\/en\/wp-json\/wp\/v2\/pages\/20136\/revisions"}],"predecessor-version":[{"id":20219,"href":"https:\/\/complex-systems-ai.com\/en\/wp-json\/wp\/v2\/pages\/20136\/revisions\/20219"}],"up":[{"embeddable":true,"href":"https:\/\/complex-systems-ai.com\/en\/wp-json\/wp\/v2\/pages\/1062"}],"wp:attachment":[{"href":"https:\/\/complex-systems-ai.com\/en\/wp-json\/wp\/v2\/media?parent=20136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}