4.1 Basic
Al utilizar sensores conectados en la parte superior del Piero, podemos evitar colisiones con otros objetos y también sacar a Piero de la esquina.
Para hacerlo modificamos un pequeño programa anterior "3.Sensor".
En la sección Simulink Block asumiremos que Piero está en una esquina.
By using sensors attached to the top of the Piero we are able to avoid collisions with other objects and also get Piero out of the corner.
In order to do it, we modified a little previous program “3.Sensors”.
In Simulink Block section we will presume that Piero is in a corner.
4.1. Simulink Blocks.
Aquí tenemos el aspecto general del programa.
Here we have the overall look of the program.
Subsistema “IfCollisionLeft”
Subsystem “IfCollisionLeft”
1. En el subsistema IfCollisionLeft usamos otro subsistema llamado "Sensor left distance". Dentro de este, tenemos los mismos bloques que en "3.Sensors" para proporcionar distancia desde el sensor izquierdo. Después de eso, hay un bloque Switch para ver si la distancia es mayor o menor que 20 - si el resultado es False, el sensor que queda detecta la colisión. Lo mismo ocurre con IfCollisionRight.
1. In subsystem IfCollisionLeft we used another subsystem called “Sensor left distance”. Inside this one, we have the same blocks as in “3.Sensors” to provide distance from the left sensor. After that, there is a Switch block to see if the distance is more or less than 20 – if the result is False then sensor left to detect the collision. The same is with IfCollisionRight.
Subsistema “Velocity not corner”
Subsystem “Velocity not corner”
2. Esta subsección está hecha para Piero si tiene otra colisión en esa esquina (solo en un sensor) o no hay colisión. Sensor izquierdo y Sensor derecho son salidas de IfCollisionLeft y IfCollisionRight. Switch bock es comprobar qué sensor es la colisión y cuál no. Si hay una colisión, el motor en el lado opuesto se detendrá y de lo contrario irá con Velocity1 o Velocity2 (son iguales).
2. This subsection is made for Piero if he has other collision that corner (just on one sensor) or there is no collision. Sensor left and Sensor right are outputs of IfCollisionLeft and IfCollisionRight. Switch bock is to check on which sensor is the collision and on which one not. If there is a collision – the motor on opposite side will stop and otherwise it will go with Velocity1 or Velocity2 (they are equal).
Subsistema “Velocity corner”
Subsystem “Velocity corner”
3. Este subsistema simplemente da la velocidad para la rueda izquierda y derecha en caso de una esquina
3. This subsystem simply giving the velocity for left and right wheel in case of a corner
4. Ahora volveremos al bloque Logic Operator y Bloque Switch en el programa principal. El operador lógico da 1 como salida SÓLO si ambas entradas son ceros, lo que significa que ambos sensores al mismo tiempo necesitan detectar una colisión. La salida va al Switch como una declaración:
- 1 – ambos sensores detectan una colisión y la velocidad será proporcionada por el subsistema Velocity Corner
- 0 – ninguno de los sensores o solo uno detectan una colisión y luego la velocidad es proporcionada por Velocity not corner.
4. Now we will go back to Logical Operator block and Switch block in the main program. Logical Operator gives 1 as an output ONLY if both inputs are zeros – that means that both sensors at the same time need to detect a collision. The output goes to the Switch as a statement :
- 1 – both sensors detect a collision and the velocity will be provided by Velocity Corner subsystem
- 0 – none of the sensors or just one detect collision and then the velocity is provided by Velocity not corner
4.2. Resumen. / 4.2. Summary.
Completamos la tarea y ahora nuestro Piero sabe qué hacer en un rincón. La parte más desafiante fue un uso correcto de la declaración de cambio y para simplificar el programa tanto como sea posible.
We completed the task and now our Piero knows what to do in a corner. The most challenging part was a correct use of the switch statement and to simplify the program as much as it is possible.