12.1 Basic
Usamos otro programa como base para el nuestro. En este caso, conectamos nuestro teléfono a la placa Arduino por wifi y también aplicamos un detector de impacto para que Piero retroceda cuando golpee algo.
We used another program as a base for our own one. In this one, we connect our phone to Arduino board by wifi and also apply shock detector for Piero to move back when it hits something.
12.2. Simulink.
Andriod
"Auto_route", "Stop" y "low speed" son botones en la aplicación Arduino. Auto_route es un botón que activa la ruta del Piero. La ruta de esa ruta se guarda en el subsistema "autoroute" y el subsistema "control select" selecciona esta ruta cuando el botón Auto_route está activo.
"Auto_route", "Stop" and "low speed" are buttons on Arduino application. Auto_route is a button which activates the automatic route of the Piero. The path of that route is saved in "autoroute" subsystem and subsystem "control select" selects this path when Auto_route button is active.
"Move_acc"
Este subsistema es el acelerómetro en el teléfono. Moverse en el eje X cambiará la velocidad del robot. Moverse en el eje Y cambiará el ángulo de Piero.
This subsystem is taking the signal from Accelerometer on the phone. Move on X-axis will change the speed of the robot. Move on Y-axis will change the angle for Piero.
"Control"
En este subsistema, estamos comprobando si el botón "Stop" o "low speed" está activado.
Si ninguno de ellos está activo, entonces tenemos la velocidad de speed_in y angle de turn_in.
Si "stop" está activo, entonces tenemos la velocidad 0 y el ángulo 0.
Si "low speed" está activo, entonces tenemos la velocidad de speed_in multiplicada por 1/5 y el ángulo de turn_in.
In this subsystem, we are checking if button "Stop" or "low speed" is on.
If none of them is active then we have the speed from speed_in and angle from turn_in.
If "stop" is active then we have the speed 0 and angle 0.
If "low speed" is active then we have the speed from speed_in multiplied by 1/5 and angle from turn_in.
"Send"
Si se detecta el cambio de velocidad o ángulo, entonces la señal se envía a través del wifi al robot (por el subsistema "Send udp", donde tenemos el UDP send bloque ).
En los subsistemas "num_to_string" y "turn_to_string1" se usa para convertir la entrada en cadena (para poder enviarla por wifi en un mensaje).
If the change of speed or angle is detected, then the signal is sent through wifi to the robot (by subsystem "Send udp", where we have UDP send block).
In subsystems "num_to_string" and "turn_to_string1" is used to convert the input to string (to be able to send it by wifi in one message).
"num_to_string"
La función principal de este bloque es convertir la velocidad dada en una cadena para enviarla.
El masaje contiene:
- Primer cebo - nos dice si la cuerda se referirá a la velocidad lineal "s" o al angular "a".
- Segundo cebo - este se refiere a si es un número positivo o negativo ("-" cuando es negativo)
- Siguiente tres cebos - número entero hasta 999 escrito como una cadena.
- Last cebo - simboliza el final del mensaje "\ n" que es 10 en la tabla ASCI.
La misma regla que usamos en el subsistema "turn_to_string1".
The main function of this block is to convert given velocity to string in order to send it.
Massage contains:
- First bait - is telling us if the string will refer to linear velocity "s" or to angular one "a".
- Second bait - this one refers to whether it is a positive number or a negative ("-" when negative)
- Next three baits - integer number up to 999 written as a string.
- Last bait - symbolize the end of the message "\n" which is 10 in ASCI table.
The same rule we use in "turn_to_string1" subsystem.
Arduino
En este programa, usamos bloques de un proyecto anterior - 10. Dejando la clase. En el marco azul, tenemos los mismos bloques que allí, pero el resto se agregó.
In this program, we used blocks from a previous project - 10.Leaving the class. In the blue frame, we have the same blocks as there, but the rest was added.
Wifi data
El bloque Serial Receive1 es un puerto que conecta Arduino con Android. El estado es "1" cuando los datos son enviados por Android y se supone que Arduino debe reaccionar.
Dentro del subsistema "decode_commands", tenemos el decodificador del mensaje, desde cadena hasta enteros reales.
The Serial Receive1 block is a port that connects Arduino to Android. Status is "1" when data is sent by Android and Arduino supposed to react to it.
Inside of "decode_commands" subsystem, we have decoder of the message - from string to actual integers.
Para decodificar el mensaje primero, necesitamos saber si es una velocidad lineal o un ángulo, debido a que primero buscamos esos gráficos (escritos en la tabla ASCI). El siguiente a buscar es "-" si lo hay en un mensaje, el valor será negativo.
Después de esos signos habrá tres más indicando el valor en sí. Estos pueden estar entre 0-9 en la tabla ASCI.
To decode the message first we need to know if it is linear velocity or an angle - because of that first we are looking for those charts (written in ASCI table). Next one to look for is "-" if there is it in a message the value will be negative.
After those signs will be three more indicating value itself. These ones can be between 0-9 in ASCI table.
El subsistema anterior es "str_to_num" y está cambiando la cadena a un número. Por ejemplo, queremos enviar un número 987. En este caso, el primero irá a 9 y tendremos 9 antes del primer retraso. El segundo será 8 - luego tendremos 9 después del primer retraso y 8 antes. El tercero será 7 - 7 antes del primer retraso, 8 después del primer retraso y 9 después del segundo. Y después de eso aparecerá el último signo - "/ n" que se leerá como 0. Entonces tenemos 9 * 100 + 8 * 10 + 7 = 987
El signo "/ n" tiene pocas funciones:
- terminando un mensaje,
- Restablecer los valores de encontrar "s" o "a" o "-"
- decirle al programa que el mensaje se lee y está listo para enviarlo a otros bloques.
The subsystem above is "str_to_num" and it is changing the string to a number. For example, we want to send a number 987. In this case first one will go 9 and we will have 9 before the first delay. The second one will be 8 - then we will have 9 after first delay and 8 before it. The third will be 7 - 7 before the first delay, 8 after first delay and 9 after second. And after those will the last sign - "/n" which will be read as 0. So then we have 9*100+8*10+7 = 987
Sign "/n" have few function :
- ending a message,
- resetting the values of finding "s" or "a" or"-"
- telling the program that the message is read and ready to send it on other blocks.
Chart
El pin 7 estaba conectado con un detector de impacto situado en el frente de Piero. Si hay una señal en ese pin, el integrador se reinicia.
Como podemos ver si el número de control sería mayor que 0, entonces la velocidad se tomará del Chart. En otro caso, se tomará desde un dispositivo Android.
Pin 7 was connected with shock detector situated on the front of Piero. If there is a signal on that pin the Integrator is reset.
As we can see if the control number would be greater than 0 - then the velocity will be taken from the Chart. In another case, it will be taken from Android device.
El estado inicial es el estado sin colisión - Piero no golpeó nada. Entonces el control es igual a 0.
Cuando un sensor detecta un choque, se envía una señal y el integrador se reinicia. Cuando el integrador alcanza el valor de tres estados cambia a Colisión, en cuyo control = 1, la velocidad lineal es igual a -0.2 y el ángulo es 0. Este estado se mantendrá durante 3 segundos y después de ese tiempo, el usuario de Android podrá volver controlar el robot
The initial state is the state without the collision - Piero didn't hit anything. Then the control is equal to 0.
When a sensor detects a shock - signal is sent and the integrator is reset. When the integrator then hits the value of three status is changed to Collision - in which control = 1, the linear velocity is equal to -0.2 and angle is 0. This state will be held for 3 seconds and after that time Android user can again control the robot.
12.3. Resumen. / 12.3. Summary.
La parte más desafiante de ese proyecto fue comprender el código de la aplicación Android. Antes nunca había usado Simulink para programar ninguna aplicación y ahora sé que es posible y también cómo hacerlo.
The most challenging part of that project was to understand the Android application code. Before I had never used Simulink to program any application and now i know that it is possible and also how to do it.