3.1 Basic
Al usar sensores conectados a la parte superior del Piero, podemos evitar colisiones con otros objetos.
Necesitamos considerar ambos casos:
- Cuando tenemos un objeto a la izquierda
- Cuando tenemos un objeto a la derecha
En 1. caso, nuestra solución fue detener el motor de la rueda derecha y al mismo tiempo mover la rueda izquierda hacia delante con la misma velocidad que antes.
En 2. caso, nuestra solución fue detener el motor de la rueda izquierda y al mismo tiempo mover la rueda derecha hacia adelante con la misma velocidad que antes.
En la siguiente subsección, explicaré el bloque Simulink en el ejemplo que el sensor detecta algo a la izquierda.
By using sensors attached to the top of the Piero we are able to avoid collisions with other objects.
We need to consider both cases :
- When we have object on the left
- When we have object on the right
In 1. case our solution was to stop the engine of the right wheel and at the same time move the left wheel forward with the same speed as it was before.
In 2. case, our solution was to stop the engine of the left wheel and at the same time move the right wheel forward with the same speed as it was before.
In next subsection, I will explain the Simulink block on the example that the sensor detects something on the left.
3.1. Simulink Blocks.
1. El primer bloque es el bloque Constant, que usamos en ejercicios anteriores, como una velocidad. El siguiente es un subsistema que contiene sensores: el corazón del programa. El último es un subsistema con motores Piero que ya expliqué en la sección 2.Motores.
1. The first block is Constant block, which we used in previous exercises, as a velocity. Next one is a subsystem which contains sensors – the heart of the program. The last one is a subsystem with Piero’s motors which I already explained in the 2.Motores section.
Subsistema "Sensores"
Subsystem “Sensors”
1. Cuando ingresamos al subsistema Sensores podemos ver dos subsistemas más:
• SensorRight: en la entrada tenemos la velocidad y la salida nos da esa velocidad o 0 (si hay un objeto delante del sensor derecho). Es importante saber que la salida del sensor derecho va al motor izquierdo.
• SensorLeft: funciona de la misma manera que el subsistema SensorRight está exento de comprobar que el sensor izquierdo no es el correcto y que da salida al motor derecho, no al izquierdo.
1. When we enter the subsystem Sensors we can see two more subsystems:
- SensorRight – on the input we have the velocity and the output gives us that velocity or 0 (if there is an object in front of the right sensor). It is important to know that the output of the right sensor goes to the left engine.
- SensorLeft –works the same as the subsystem SensorRight exempt checking the left sensor not the right one and giving the output to right motor, not the left one.
2. Aquí podemos ver la primera parte de SensorLeft En esta sección utilizamos
- Analog Input Block para verificar el sensor. Arduino que usamos tiene la entrada analógica máxima de 5 V. El bloque de entrada analógica proporciona una salida máxima de 1023. Eso significa que 280 (como en una imagen) es igual a 1,37 V.
- Data Type Conversion – necesitamos este bloque para convertir la entrada en doble y usarla en los próximos pasos.
2. Here we can see the first part of the SensorLeft In this section we used
- Analog Input block for checking the sensor. Arduino which we used has the max analog input of 5 V. The analog input block provides a maximum output of 1023. That means 280 (as in a picture) is equal to 1,37 V.
- Data Type Conversion – we need this block to convert the input into double and use it in next steps.
3.En esta sección, usamos el bloque fcn con una función en él.
Lo usamos para convertir el valor de la salida del sensor a la distancia entre el sensor y el objeto (en cm).
La tabla de la Hoja de datos del sensor nos da la relación entre la distancia y el voltaje. Como podemos ver en la tabla, para valores muy cercanos del objeto se pueden dar valores muy altos para que podamos estimar la distancia como un mínimo de 10 cm y un máximo de 50 cm. Usamos la ecuación dada por el fabricante del sensor, donde A y B son valores de un sistema de ecuaciones, a través de una calibración de un valor mínimo y máximo X1 = 350 para l1 = 10 cm y X2 = 129 para L2 = 50 cm y x es el valor del sensor. De esa manera es:
Después de transformar la salida, agregamos un bloque de Saturación para limitar la entrada de 0 cm a 50 cm (rango que especificamos).
3.In this section, we use fcn block with a function in it.
We use it to convert the value from the output of the sensor to the distance between the sensor and the object (in cm).
The table from the sensor's Datasheet giving us the relationship between distance and the voltage. As we can see in the table for very close values of the object can be given very high values so we can estimate the distance as a minimum 10 cm and the maximum 50 cm. We used the equation given by the sensor manufacturer, where A and B are values of a system of equations, through a calibration of a minimum value and maximum X1 = 350 for l1 = 10cm and X2 = 129 for L2 = 50cm and x is the value from the sensor. That way it is:
After transforming the output we add a Saturation block to limit input from 0 cm to 50 cm(range that we specified).
4. Switch block decide la velocidad: si la entrada es inferior a 20 cm, la velocidad será 0 y, por lo tanto, la rueda derecha se detendrá. De lo contrario, la velocidad será igual a esta en un Sensores.
El subsistema SensorRight se ve casi igual. Las diferencias son:
- el puerto del sensor (derecha)
- la salida va a la rueda izquierda
4. Switch block decides the velocity – if the input is less than 20 cm then the velocity will be 0 and therefore right wheel will stop. Otherwise, the velocity will be equal to this one in a Sensors
The subsystem SensorRight looks almost the same. The differences are :
- the port of the sensor (right one)
- the output goes to the left wheel
Ficha de datos / DataSheet
El diagrama para el sensor.
The diagram for the sensor.
Fuente: https://engineering.purdue.edu/ME588/SpecSheets/sharp_gp2d12.pdf
Source: https://engineering.purdue.edu/ME588/SpecSheets/sharp_gp2d12.pdf
3.2. Resumen. / 3.2. Summary.
Nuestro Piero responde al objeto que tiene enfrente. Ahora sé cómo convertir la salida de la placa Arduino a distancia real y también saber un poco más sobre los sensores en sí. Además, hay otra posibilidad de hacer esto:
- Objeto a la izquierda - la rueda izquierda se detiene, la rueda derecha retrocede
- Objeto en la derecha - la rueda derecha se detiene, la rueda izquierda retrocede
Our Piero responds to the object in front of him. Now I know how to convert the output from the Arduino board to real distance and also know a little more about the sensors itself. Also, there is another possibility to do this :
- Object on the left – left wheel stops, right wheel goes backward
- Object on the right – right wheel stops, left wheel goes backward