11.1 Basic
Esta vez tenemos que salir de la clase evitando obstáculos en el camino. Lo hemos hecho agregando Sensor Flow y algún bloque Switch.
This time we need to get out of the class with avoiding obstacles on the path. We have done it by adding Sensor Flow and some Switch block.
11.2. Simulink.
Como podemos ver, el aspecto general de nuestro proyecto es similar al proyecto 10 - salir de la clase. En el marco azul, tenemos los mismos bloques que allí, pero el resto se agregó.
As we can see the overall look of our project is similar to the project 10 - Leaving the class. In the blue frame, we have the same blocks as there, but the rest was added.
StateFLow
Pin 1 - dando la señal del sensor izquierdo. Podemos considerar que cuando recibimos la señal por encima de 200, hay un obstáculo a la izquierda. En el gráfico, esta señal se llama IRLeft.
Pin 0 - dando la señal desde el sensor derecho. Podemos considerar que cuando recibimos la señal por encima de 200, hay un obstáculo a la derecha. En el gráfico, esta señal se denomina IRRight.
Pin 1 - giving the signal from the left sensor. We can consider that when we receive the signal over 200 - there is an obstacle on the left. In the Chart, this signal is named IRLeft.
Pin 0 - giving the signal from the right sensor. We can consider that when we receive the signal over 200 - there is an obstacle on the right.In the Chart, this signal is named IRRight.
Como podemos ver, el estado inicial es este sin obstáculos y control = 0. Eso significa que la instrucción switch tomará los valores de MATLABFunction.
Cuando el sensor de la izquierda detecte un obstáculo, en el Gráfico iremos a ObstacleLeft. La velocidad lineal se reducirá a 0,2 y Piero girará a la derecha. El control será 1 entonces - eso significa que la instrucción switch tomará los valores de StateFlow. Después de 2 segundos, el estado cambiará al estado inicial.
Cuando el sensor derecho detecte un obstáculo, en el Gráfico iremos a ObstacleRight. La velocidad lineal se reducirá a 0.2 y Piero girará a la izquierda. El control será 1 entonces - eso significa que la instrucción switch tomará los valores de StateFlow. Después de 2 segundos, el estado cambiará al estado inicial.
Cuando ambos sensores detecten un obstáculo, en Chart iremos a ObstacleInFrontOf. La velocidad lineal será 0 y Piero hará 180 grados. El control será 1 entonces - eso significa que la instrucción switch tomará los valores de StateFlow. Después de 2 segundos, el estado cambiará al estado inicial.
As we can see the initial state is this one without obstacles and control = 0. That means the switch statement will take the values from MATLABFunction.
When left sensor will detect an obstacle, then in Chart we will go to ObstacleLeft. Linear velocity will be decreased to 0.2 and Piero will turn right. Control will be 1 then - that means that switch statement will take the values from StateFlow. After 2 seconds state will be changed to the initial state.
When right sensor will detect an obstacle, then in Chart we will go to ObstacleRight. Linear velocity will be decreased to 0.2 and Piero will turn left. Control will be 1 then - that means that switch statement will take the values from StateFlow. After 2 seconds state will be changed to the initial state.
When both sensors will detect an obstacle, then in Chart we will go to ObstacleInFrontOf. Linear velocity will be 0 and Piero will do 180 degrees. Control will be 1 then - that means that switch statement will take the values from StateFlow. After 2 seconds state will be changed to the initial state.
11.3. Resumen. / 11.3. Summary.
Hicimos esta tarea y nuestro Piero pudo salir de la clase incluso con cajas en su camino. La película que lo muestra está en la sección 10. Salir del clase.
A través de este proyecto, hemos aprendido cómo usar StateFlow y ahora sabemos que en el próximo proyecto con gran complejidad y muchas declaraciones de cambio podemos usarlo y simplificar el programa.
We made this task and our Piero was able to go out of the class even with boxes on its path. The film that is showing it is in section 10. Salir del clase.
Through this project, we have learned how to use StateFlow and now we know that in next project with big complexity and lots of switch statements we can use it and simplify the program.