New

Dependencies:   SparkfunAnalogJoystick

Revision:
4:60e3365da280
Parent:
3:3d54fd4109c0
Child:
5:9f30f0a6dc76
--- a/main.cpp	Wed Jul 21 19:16:11 2021 +0000
+++ b/main.cpp	Thu Jul 22 01:56:42 2021 +0000
@@ -1,536 +1,524 @@
+// Librerías para abstraer funciones de MBed para manejar el microprocesador y los sensores.
 #include "mbed.h"
 #include "platform/mbed_thread.h"
 #include "SparkfunAnalogJoystick.h"
 
-#define M_PI 3.14159265358979323846
+// Constantes de programación para procesos y funciones.
+// Valor en frecuencia de las notas reproducidas por el Buzzer que da avisos al usuario de la silla.
+#define Nota_C4 262
+#define Nota_A4 440
+#define Nota_E4 659
+
+// Hilos para ejecutar tareas concurrentes.
+Thread Thread1; // Primer hilo para sensor de proximidad.
+Thread Thread2; // Segundo hilo para sensor de proximidad.
+Thread Thread3; // Tercer hilo para sensor de proximidad.
+Thread Thread4; // Cuarto hilo para sensor de proximidad.
+Thread Thread5; // Hilo para manejar el joystick.
+Thread Thread6; // Hilo para manejar los comandos de voz recibidos por la Raspberry PI.
+Thread Thread7; // Hilo para manejar la selección de modo de la silla.
 
-Thread thread1;
-Thread thread2;
-Thread thread3;
-Thread thread4;
-Thread thread5;
-Thread thread6;
-Thread thread7;
+// Variables globales de distancias en el entorno de la silla de ruedas.
+int Distance1 = 0; // Distancia adelante de la silla.
+int Distance2 = 0; // Distancia atrás de la silla.
+int Distance3 = 0; // Distancia a la izquierda de la silla.
+int Distance4 = 0; // Distancia a la derecha de la silla.
+int DistanceLimit = 15; // Distancia límite de acercamiento a un Obstaculo permitida por la silla.
 
-int distance1 = 0; //distancia  adelante.  
-int distance2 = 0; //distancia atras.
-int distance3 = 0; // distancia izquierda.
-int distance4 = 0; // distancia derecha. 
+// Entradas digitales para selección de modos de la silla.
+DigitalIn Modo1(D8); // Modo manual.
+DigitalIn Modo2(D9); // Modo por comandos del joystick.
+DigitalIn Modo3(D10); // Modo por comandos de voz.
+DigitalIn Modo4(D11); // Modo por rutas autónomas
 
-int distanceLimit = 15;
+// Interfaz serial para comunicación con la Raspberry PI.
+Serial PC(USBTX,USBRX); // Por aquí se reciben caracteres que el miprocesador interpreta para ejecutar una acción, como los comandos de voz o alguna alerta.
 
-DigitalIn modo1(D8);  //Modo manual
-DigitalIn modo2(D9);  //Modo comandos joystick
-DigitalIn modo3(D10); //Modo comandos de voz
-DigitalIn modo4(D11); //Modo rutas autonomas
+// Salidas digitales y PWM para controlar el driver de los motores.
+DigitalOut Direccion1(PC_6); // Dirección del motor 1.
+PwmOut PWM_Velocidad1(PB_15); // Velocidad del motor 1.
+DigitalOut Direccion2(D14); // Dirección del motor 2.
+PwmOut PWM_Velocidad2(D15); // Velocidad del motor 2.
 
-Serial pc(USBTX, USBRX); //Para recibir los comandos de voz.
-
+// Salida para manejar la señal del buzzer de alertas.
+PwmOut Buzzer(D3);
 
-//motor driver
-DigitalOut direccion1(PC_6);
-PwmOut PWM_velocidad1(PB_15);
+// Función para reproducir un sonido del buzzer cuando se detecta proximidad a un obstáculo.
+void Reproducir_Buzzer_Proximidad(void)
+{
+   Timer BuzzTime;
+   BuzzTime.reset();
+   BuzzTime.start();
+   while(BuzzTime.read_us() < 3000000) // Ejecutar sonido del buzzer por 3 segundos.
+   {
+        Buzzer.period(1.0/Nota_C4); // Configurando el período, que es equivalente a frecuencia (veces que se reproducirá el tono por segundo).
+        Buzzer.write(0.5);
+        thread_sleep_for(200);
+        
+        Buzzer.period(1.0/Nota_A4); // Configurando el período, que es equivalente a frecuencia (veces que se reproducirá el tono por segundo).
+        Buzzer.write(0.5);
+        thread_sleep_for(200);
+        
+        Buzzer.period(1.0/Nota_E4); // Configurando el período, que es equivalente a frecuencia (veces que se reproducirá el tono por segundo).
+        Buzzer.write(0.5);
+        thread_sleep_for(200);
+   }
+   BuzzTime.stop();
+}
 
-DigitalOut direccion2(D14);
-PwmOut PWM_velocidad2(D15);
-
-
-void flushSerialBuffer(void)
+// Función para limpiar caracteres presentes en el buffer de la interfaz serial.
+void LimpiarSerialBuffer(void)
 {
     char char1 = 0;
-    while (pc.readable())
+    while(PC.readable())
     {
-        char1 = pc.getc();
+        char1 = PC.getc();
     }
     return;
 }
 
+// Función para moder la silla hacia adelante.
+void Mover_Hacia_Adelante(int Tiempo)
+{
+    Direccion1 = 0; // En dirección de las manecillas del reloj.
+    Direccion2 = 0; // En dirección de las manecillas del reloj.
 
-void mover_hacia_adelante(int tiempo){
-    direccion1 = 0; // En direccion de las manecillas del reloj.
-    direccion2 = 0; // En direccion de las manecillas del reloj.
-    
-    
-    PWM_velocidad1.period(0.0001f); //Declaramos el periodo
-    PWM_velocidad1.write(0.15f); //%25
-    
-    PWM_velocidad2.period(0.0001f); //Declaramos el periodo
-    PWM_velocidad2.write(0.15f); //25%
-    
-    
-    thread_sleep_for(tiempo); 
-    
-    PWM_velocidad1.write(0.0f);
-    PWM_velocidad2.write(0.0f);
+    PWM_Velocidad1.period(0.0001f); // Declaramos el período.
+    PWM_Velocidad1.write(0.15f); // %25 del duty cicle.
+
+    PWM_Velocidad2.period(0.0001f); // Declaramos el período.
+    PWM_Velocidad2.write(0.15f); // %25 del duty cicle.
+
+    thread_sleep_for(Tiempo);
+
+    PWM_Velocidad1.write(0.0f);
+    PWM_Velocidad2.write(0.0f);
 }
 
-void mover_hacia_atras(int tiempo){
-    direccion1 = 1; // En direccion de las manecillas del reloj.
-    direccion2 = 1; // En direccion de las manecillas del reloj.
-    
-    
-    PWM_velocidad1.period(0.0001f); //Declaramos el periodo
-    PWM_velocidad1.write(0.15f); //%25
+// Función para moder la silla hacia atrás.
+void Mover_Hacia_Atras(int Tiempo)
+{
+    Direccion1 = 1; // En dirección contraria a las manecillas del reloj.
+    Direccion2 = 1; // En dirección contraria a las manecillas del reloj.
+
+    PWM_Velocidad1.period(0.0001f); // Declaramos el período.
+    PWM_Velocidad1.write(0.15f); // %25 del duty cicle.
     
-    PWM_velocidad2.period(0.0001f); //Declaramos el periodo
-    PWM_velocidad2.write(0.15f); //25%
-    
-    
-    thread_sleep_for(tiempo); 
-    
-    PWM_velocidad1.write(0.0f);
-    PWM_velocidad2.write(0.0f);
+    PWM_Velocidad2.period(0.0001f); // Declaramos el período.
+    PWM_Velocidad2.write(0.15f); // %25 del duty cicle.
+
+    thread_sleep_for(Tiempo); 
+
+    PWM_Velocidad1.write(0.0f);
+    PWM_Velocidad2.write(0.0f);
 }
 
+// Función para moder la silla hacia la izquierda.
+void Mover_Hacia_Izquierda(int Tiempo)
+{
+    Direccion1 = 1; // En dirección contraria a las manecillas del reloj.
+    Direccion2 = 0; // En dirección de las manecillas del reloj.
 
-void mover_hacia_izquierda(int tiempo){
-    direccion1 = 1; // En direccion de las manecillas del reloj.
-    direccion2 = 0; // En direccion de las manecillas del reloj.
-    
-    
-    PWM_velocidad1.period(0.0001f); //Declaramos el periodo
-    PWM_velocidad1.write(0.15f); //%25
-    
-    PWM_velocidad2.period(0.0001f); //Declaramos el periodo
-    PWM_velocidad2.write(0.15f); //25%
-    
-    
-    thread_sleep_for(tiempo); 
-    
-    PWM_velocidad1.write(0.0f);
-    PWM_velocidad2.write(0.0f);
+    PWM_Velocidad1.period(0.0001f); // Declaramos el período.
+    PWM_Velocidad1.write(0.15f); // %25 del duty cicle.
+
+    PWM_Velocidad2.period(0.0001f); // Declaramos el período.
+    PWM_Velocidad2.write(0.15f); // %25 del duty cicle.
+
+    thread_sleep_for(Tiempo); 
+
+    PWM_Velocidad1.write(0.0f);
+    PWM_Velocidad2.write(0.0f);
 }
 
+// Función para moder la silla hacia la derecha.
+void Mover_Hacia_Derecha(int Tiempo)
+{
+    Direccion1 = 0; // En dirección de las manecillas del reloj.
+    Direccion2 = 1; // En dirección contraria a las manecillas del reloj.
 
-void mover_hacia_derecha(int tiempo){
-    direccion1 = 0; // En direccion de las manecillas del reloj.
-    direccion2 = 1; // En direccion de las manecillas del reloj.
-    
-    
-    PWM_velocidad1.period(0.0001f); //Declaramos el periodo
-    PWM_velocidad1.write(0.15f); //%25
-    
-    PWM_velocidad2.period(0.0001f); //Declaramos el periodo
-    PWM_velocidad2.write(0.15f); //25%
-    
-    
-    thread_sleep_for(tiempo); 
-    
-    PWM_velocidad1.write(0.0f);
-    PWM_velocidad2.write(0.0f);
+    PWM_Velocidad1.period(0.0001f); // Declaramos el período.
+    PWM_Velocidad1.write(0.15f); // %25 del duty cicle.
+
+    PWM_Velocidad2.period(0.0001f); // Declaramos el período.
+    PWM_Velocidad2.write(0.15f); // %25 del duty cicle.
+
+    thread_sleep_for(Tiempo); 
+
+    PWM_Velocidad1.write(0.0f);
+    PWM_Velocidad2.write(0.0f);
 }
 
-
-
-void thread1_HCSR04()
+// Función para leer el sensor de proximidad 1.
+void Thread1_HCSR04()
 {
-    DigitalOut trigger(D0);
-    DigitalIn  echo(D1);
-    Timer sonar;
-    int correction = 0;
-    sonar.reset();
-    // measure actual software polling timer delays
-    // delay used later in time correction
-    // start timer
-    sonar.start();
-    // min software polling delay to read echo pin
-    while (echo==2)
+    DigitalOut Trigger(D0);
+    DigitalIn Echo(D1);
+    Timer Sonar;
+    int Correccion = 0;
+    Sonar.reset();
+    Sonar.start();
+    while(Echo == 2)
     {
         
     };
-    // stop timer
-    sonar.stop();
-    // read timer
-    correction = sonar.read_us();
-    printf("Sensor proximidad 1: Approximate software overhead timer delay is %d uS\n\r",correction);
-    //Loop to read Sonar distance values, scale, and print
+    Sonar.stop();
+    Correccion = Sonar.read_us();
+    printf("Sensor de proximidad 1: El retardo aproximado del temporizador de sobrecarga del software es %d uS\n\r",Correccion);
     while(1)
     {
-        //trigger sonar to send a ping
-        trigger = 1;
-        sonar.reset();
+        Trigger = 1;
+        Sonar.reset();
         wait_us(10.0);
-        trigger = 0;
-        //wait for echo high
-        while (echo==0)
+        Trigger = 0;
+        while(Echo == 0)
         {
             
         };
-        //echo high, so start timer
-        sonar.start();
-        //wait for echo low
-        while (echo==1) {};
-        //stop timer and read value
-        sonar.stop();
-        //subtract software overhead timer delay and scale to cm
-        distance1 = (sonar.read_us()-correction)/58.0;
-        //printf("Sensor proximidad 1: %d cm \n\r",distance1);
-        //wait so that any echo(s) return before sending another ping
+        Sonar.start();
+        while(Echo == 1)
+        {
+            
+        };
+        Sonar.stop();
+        Distance1 = (Sonar.read_us()-Correccion)/58.0;
+        //printf("Sensor de proximidad 1: %d cm \n\r",Distance1);
         thread_sleep_for(1000);
     }
 }
 
-void thread2_HCSR04()
+// Función para leer el sensor de proximidad 2.
+void Thread2_HCSR04()
 {
-    DigitalOut trigger(D2);
-    DigitalIn  echo(D3);
-    Timer sonar;
-    int correction = 0;
-    sonar.reset();
-    // measure actual software polling timer delays
-    // delay used later in time correction
-    // start timer
-    sonar.start();
-    // min software polling delay to read echo pin
-    while (echo==2)
+    DigitalOut Trigger(D2);
+    DigitalIn  Echo(D3);
+    Timer Sonar;
+    int Correccion = 0;
+    Sonar.reset();
+    Sonar.start();
+    while(Echo == 2)
     {
         
     };
-    // stop timer
-    sonar.stop();
-    // read timer
-    correction = sonar.read_us();
-    printf("Sensor proximidad 2: Approximate software overhead timer delay is %d uS\n\r",correction);
-    //Loop to read Sonar distance values, scale, and print
+    Sonar.stop();
+    Correccion = Sonar.read_us();
+    printf("Sensor de proximidad 2: El retardo aproximado del temporizador de sobrecarga del software es %d uS\n\r",Correccion);
     while(1)
     {
-        // trigger sonar to send a ping
-        trigger = 1;
-        sonar.reset();
+        Trigger = 1;
+        Sonar.reset();
         wait_us(10.0);
-        trigger = 0;
-        //wait for echo high
-        while (echo==0)
+        Trigger = 0;
+        while(Echo == 0)
         {
             
         };
-        //echo high, so start timer
-        sonar.start();
-        //wait for echo low
-        while (echo==1)
+        Sonar.start();
+        while(Echo == 1)
         {
             
         };
-        //stop timer and read value
-        sonar.stop();
-        //subtract software overhead timer delay and scale to cm
-        distance2 = (sonar.read_us()-correction)/58.0;
-        //printf("Sensor proximidad 2: %d cm \n\r",distance2);
-        //wait so that any echo(s) return before sending another ping
+        Sonar.stop();
+        Distance2 = (Sonar.read_us()-Correccion)/58.0;
+        //printf("Sensor de proximidad 2: %d cm \n\r",Distance2);
         thread_sleep_for(1000);
     }
 }
 
-void thread3_HCSR04()
+// Función para leer el sensor de proximidad 3.
+void Thread3_HCSR04()
 {
-    DigitalOut trigger(D4);
-    DigitalIn  echo(D5);
-    Timer sonar;
-    int correction = 0;
-    sonar.reset();
-    // measure actual software polling timer delays
-    // delay used later in time correction
-    // start timer
-    sonar.start();
-    // min software polling delay to read echo pin
-    while (echo==2)
+    DigitalOut Trigger(D4);
+    DigitalIn  Echo(D5);
+    Timer Sonar;
+    int Correccion = 0;
+    Sonar.reset();
+    Sonar.start();
+    while(Echo == 2)
     {
         
     };
-    // stop timer
-    sonar.stop();
-    // read timer
-    correction = sonar.read_us();
-    printf("Sensor proximidad 3: Approximate software overhead timer delay is %d uS\n\r",correction);
-    //Loop to read Sonar distance values, scale, and print
+    Sonar.stop();
+    Correccion = Sonar.read_us();
+    printf("Sensor de proximidad 3: El retardo aproximado del temporizador de sobrecarga del software es %d uS\n\r",Correccion);
     while(1)
     {
-        // trigger sonar to send a ping
-        trigger = 1;
-        sonar.reset();
+        Trigger = 1;
+        Sonar.reset();
         wait_us(10.0);
-        trigger = 0;
-        //wait for echo high
-        while (echo==0)
+        Trigger = 0;
+        while(Echo == 0)
         {
             
         };
-        //echo high, so start timer
-        sonar.start();
-        //wait for echo low
-        while (echo==1)
+        Sonar.start();
+        while(Echo == 1)
         {
             
         };
-        //stop timer and read value
-        sonar.stop();
-        //subtract software overhead timer delay and scale to cm
-        distance3 = (sonar.read_us()-correction)/58.0;
-        //printf("Sensor proximidad 3: %d cm \n\r",distance3);
-        //wait so that any echo(s) return before sending another ping
+        Sonar.stop();
+        Distance3 = (Sonar.read_us()-Correccion)/58.0;
+        //printf("Sensor de proximidad 3: %d cm \n\r",Distance3);
         thread_sleep_for(1000);
     }
 }
 
-void thread4_HCSR04()
+// Función para leer el sensor de proximidad 4.
+void Thread4_HCSR04()
 {
-    DigitalOut trigger(D6);
-    DigitalIn  echo(D7);
-    Timer sonar;
-    int correction = 0;
-    sonar.reset();
-    // measure actual software polling timer delays
-    // delay used later in time correction
-    // start timer
-    sonar.start();
-    // min software polling delay to read echo pin
-    while (echo==2)
+    DigitalOut Trigger(D6);
+    DigitalIn  Echo(D7);
+    Timer Sonar;
+    int Correccion = 0;
+    Sonar.reset();
+    Sonar.start();
+    while(Echo == 2)
     {
         
     };
-    // stop timer
-    sonar.stop();
-    // read timer
-    correction = sonar.read_us();
-    printf("Sensor proximidad 4: Approximate software overhead timer delay is %d uS\n\r",correction);
-    //Loop to read Sonar distance values, scale, and print
+    Sonar.stop();
+    Correccion = Sonar.read_us();
+    printf("Sensor de proximidad 4: El retardo aproximado del temporizador de sobrecarga del software es %d uS\n\r",Correccion);
     while(1)
     {
-        // trigger sonar to send a ping
-        trigger = 1;
-        sonar.reset();
+        Trigger = 1;
+        Sonar.reset();
         wait_us(10.0);
-        trigger = 0;
-        //wait for echo high
-        while (echo==0)
+        Trigger = 0;
+        while(Echo == 0)
         {
             
         };
-        //echo high, so start timer
-        sonar.start();
-        //wait for echo low
-        while (echo==1)
+        Sonar.start();
+        while(Echo == 1)
         {
             
         };
-        //stop timer and read value
-        sonar.stop();
-        //subtract software overhead timer delay and scale to cm
-        distance4 = (sonar.read_us()-correction)/58.0;
-        //printf("Sensor proximidad 4: %d cm \n\r",distance4);
-        //wait so that any echo(s) return before sending another ping
+        Sonar.stop();
+        Distance4 = (Sonar.read_us()-Correccion)/58.0;
+        //printf("Sensor de proximidad 4: %d cm \n\r",Distance4);
         thread_sleep_for(1000);
     }
 }
 
-void thread5_Joystick()
+// Función para leer valores del joystick y ejecutar sus comandos.
+void Thread5_Joystick()
 {
-    SparkfunAnalogJoystick JoyStick(A1, A0, D12);
+    SparkfunAnalogJoystick JoyStick(A1,A0,D12);
     float X;
     float Y;
     while(1)
     {
-        if(!modo1 && modo2 && !modo3 && !modo4)
+        if(!Modo1 && Modo2 && !Modo3 && !Modo4)
         {
             X = JoyStick.xAxis();
             Y = JoyStick.yAxis();
             /*
-            printf("X-Axis: %f\n\r", X);
-            printf("Y-Axis: %f\n\r", Y);
+            printf("X-Axis: %f\n\r",X);
+            printf("Y-Axis: %f\n\r",Y);
             printf(" \n\r");
             */
-            if(X >= -0.60f && X  <= 0.60f && Y >= 0.90f && Y <= 1.00f )
+            if(X >= -0.60f && X <= 0.60f && Y >= 0.90f && Y <= 1.00f)
             {        
-                if(distance1 > distanceLimit)
+                if(Distance1 > DistanceLimit)
                 {
-                    printf("Comandos joystick: Hacia adelante \r \n"); 
-                    mover_hacia_adelante(1000); // un segundo 
+                    printf("Comandos del joystick: Hacia adelante. \r \n");
+                    Mover_Hacia_Adelante(1000); // Mover por un segundo.
                 }
                 else
                 {
-                    printf("Comandos joystick: Obstaculo adelante \r \n"); 
+                    printf("Comandos del joystick: Obstaculo hacia adelante. \r \n");
+                    Reproducir_Buzzer_Proximidad();
                 }
-                thread_sleep_for(500);   
+                thread_sleep_for(500);
             }
-            if(X >= -0.60f && X  <= 0.60f && Y <= -0.90f && Y >= -1.00f)
+            if(X >= -0.60f && X <= 0.60f && Y <= -0.90f && Y >= -1.00f)
             {
-                if(distance2 > distanceLimit)
+                if(Distance2 > DistanceLimit)
                 {
-                    printf("Comandos joystick: Hacia atras \r \n"); 
-                    mover_hacia_atras(1000); // un segundo
+                    printf("Comandos del joystick: Hacia atras. \r \n");
+                    Mover_Hacia_Atras(1000); // Mover por un segundo.
                 }
                 else
                 {
-                    printf("Comandos joystick: Obstaculo atras \r \n"); 
-                } 
-                thread_sleep_for(500); 
+                    printf("Comandos del joystick: Obstaculo hacia atras. \r \n");
+                    Reproducir_Buzzer_Proximidad();
+                }
+                thread_sleep_for(500);
             }
             if(Y >= -0.60f && Y  <= 0.60f && X <= -0.90f && X >= -1.00f)
             {
-                if(distance3 > distanceLimit)
+                if(Distance3 > DistanceLimit)
                 {
-                    printf("Comandos joystick: Hacia izquierda \r \n"); 
-                    mover_hacia_izquierda(1000); //un segundo
+                    printf("Comandos del joystick: Hacia la izquierda. \r \n");
+                    Mover_Hacia_Izquierda(1000); // Mover por un segundo.
                 }
                 else
                 {
-                    printf("Comandos joystick: Obstaculo izquierda \r \n"); 
+                    printf("Comandos del joystick: Obstaculo hacia la izquierda. \r \n");
+                    Reproducir_Buzzer_Proximidad();
                 }
-                thread_sleep_for(500);    
+                thread_sleep_for(500);
             }
-            if(Y >= -0.60f && Y  <= 0.60f && X >= 0.90f && X <= 1.00f)
+            if(Y >= -0.60f && Y <= 0.60f && X >= 0.90f && X <= 1.00f)
             {
-                if(distance4 > distanceLimit)
+                if(Distance4 > DistanceLimit)
                 {
-                    printf("Comandos joystick: Hacia derecha \r \n"); 
-                    mover_hacia_derecha(1000); // segundo
+                    printf("Comandos del joystick: Hacia la derecha. \r \n");
+                    Mover_Hacia_Derecha(1000); // Mover por un segundo.
                 }
                 else
                 {
-                    printf("Comandos joystick: Obstaculo derecha \r \n"); 
+                    printf("Comandos del joystick: Obstaculo hacia la derecha. \r \n");
+                    Reproducir_Buzzer_Proximidad();
                 }
                 thread_sleep_for(500);
             }
-            thread_sleep_for(5); 
+            thread_sleep_for(5);
         }
     }
 }
 
-void thread6_ComandosVoz()
+// Función para leer datos del serial con caracteres de comandos de voz y ejecutar instrucciones.
+void Thread6_ComandosVoz()
 {
     while(1)
     {
-        if(!modo1 && !modo2 && modo3 && !modo4)
+        if(!Modo1 && !Modo2 && Modo3 && !Modo4)
         {
-            flushSerialBuffer();
-            char c = pc.getc();
-            
-            thread_sleep_for(5); //timer necesario para que el compilar se de cuenta el orden correcto de ejecucion
-            
-            int m = modo3.read();
-            printf("estado modo 3 (comandos de voz): %d \r \n",m);
-        
-            if(m == 1){     
+            LimpiarSerialBuffer();
+            char c = PC.getc();
+            thread_sleep_for(5); // Retraso necesario para que el compilador se dé cuenta del orden correcto de ejecución.
+            int m = Modo3.read();
+            printf("Estado del modo 3 (Comandos de Voz): %d \r \n",m);
+            if(m == 1)
+            {
                 if(c == 'w')
                 {
-                    //printf("Distance1 - %d \r \n",distance1);
-                    if(distance1 > distanceLimit)
+                    //printf("Distance1 - %d \r \n",Distance1);
+                    if(Distance1 > DistanceLimit)
                     {
-                        pc.printf(" Comandos de voz: Hacia adelante \r \n");
-                        mover_hacia_adelante(3000);
+                        PC.printf("Comandos de voz: Hacia adelante. \r \n");
+                        Mover_Hacia_Adelante(3000);
                     }
                     else
                     {
-                        printf(" Comandos de voz: Obstaculo! No se puede ir hacia adelante. \r \n");      
+                        printf("Comandos de voz: Obstaculo! No se puede ir hacia adelante. \r \n");
+                        Reproducir_Buzzer_Proximidad();
                     }
                     thread_sleep_for(1000);
                 }
                 if(c == 's')
                 {
-                    //printf("Distance2 - %d \r \n",distance2);
-                    if(distance2 > distanceLimit)
+                    //printf("Distance2 - %d \r \n",Distance2);
+                    if(Distance2 > DistanceLimit)
                     {
-                        pc.printf(" Comandos de voz: Hacia atras \r \n");
-                        mover_hacia_atras(3000); 
+                        PC.printf("Comandos de voz: Hacia atras. \r \n");
+                        Mover_Hacia_Atras(3000);
                     }
                     else
                     {
-                        printf(" Comandos de voz: Obstaculo! No se puede ir hacia atras. \r \n");      
+                        printf("Comandos de voz: Obstaculo! No se puede ir hacia atras. \r \n");
+                        Reproducir_Buzzer_Proximidad();
                     }
                     thread_sleep_for(1000);
-                }                           
+                }
                 if(c == 'a')
                 {
-                    //printf("Distance3 - %d \r \n",distance3);
-                    if(distance3 > distanceLimit)
+                    //printf("Distance3 - %d \r \n",Distance3);
+                    if(Distance3 > DistanceLimit)
                     {
-                        pc.printf(" Comandos de voz: Hacia la izquierda  \r \n");
-                        mover_hacia_izquierda(3000);
+                        PC.printf("Comandos de voz: Hacia la izquierda. \r \n");
+                        Mover_Hacia_Izquierda(3000);
                     }
                     else
                     {
-                        printf(" Comandos de voz:  Obstaculo! No se puede ir hacia la izquierda. \r \n");      
+                        printf("Comandos de voz: Obstaculo! No se puede ir hacia la izquierda. \r \n");
+                        Reproducir_Buzzer_Proximidad();
                     }
                     thread_sleep_for(1000);
                 }
                 if(c == 'd')
-                { 
-                    //printf("Distance4 - %d \r \n",distance4);
-                    if(distance4 > distanceLimit)
+                {
+                    //printf("Distance4 - %d \r \n",Distance4);
+                    if(Distance4 > DistanceLimit)
                     {
-                        pc.printf(" Comandos de voz: Hacia la derecha \r \n");
-                        mover_hacia_derecha(3000);
-                    } 
+                        PC.printf("Comandos de voz: Hacia la derecha. \r \n");
+                        Mover_Hacia_Derecha(3000);
+                    }
                     else
                     {
-                        printf(" Comandos de voz:  Obstaculo! No se puede ir hacia la derecha. \r \n");      
+                        printf("Comandos de voz: Obstaculo! No se puede ir hacia la derecha. \r \n");
+                        Reproducir_Buzzer_Proximidad();
                     }
                     thread_sleep_for(1000);
                 }
             }
             c = ' ';
-            thread_sleep_for(5); 
+            thread_sleep_for(5);
         }
     }
 }
 
-void thread7_IndicarModo()
+// Función para seleccionar el modo de operación de la silla.
+void Thread7_IndicarModo()
 {
-    bool estadomodo1 = false;
-    bool estadomodo2 = false;
-    bool estadomodo3 = false;
-    bool estadomodo4 = false;
-    while (true)
+    bool EstadoModo1 = false;
+    bool EstadoModo2 = false;
+    bool EstadoModo3 = false;
+    bool EstadoModo4 = false;
+    while(true)
     {
-        if(modo1 && !modo2 && !modo3 && !modo4 && !estadomodo1)
+        if(Modo1 && !Modo2 && !Modo3 && !Modo4 && !EstadoModo1)
         {
-            printf("Modo manual  \r \n");
-            estadomodo1 = true;
-            estadomodo2 = false;
-            estadomodo3 = false;
-            estadomodo4 = false;
+            printf("Operando: Modo manual. \r \n");
+            EstadoModo1 = true;
+            EstadoModo2 = false;
+            EstadoModo3 = false;
+            EstadoModo4 = false;
         }
-        if(!modo1 && modo2 && !modo3 && !modo4 && !estadomodo2)
+        if(!Modo1 && Modo2 && !Modo3 && !Modo4 && !EstadoModo2)
         {
-            printf("Modo comandos joystick  \r \n");
-            estadomodo1 = false;
-            estadomodo2 = true;
-            estadomodo3 = false;
-            estadomodo4 = false;
-        }   
-        if(!modo1 && !modo2 && modo3 && !modo4 && !estadomodo3)
+            printf("Operando: Modo de comandos de joystick. \r \n");
+            EstadoModo1 = false;
+            EstadoModo2 = true;
+            EstadoModo3 = false;
+            EstadoModo4 = false;
+        }
+        if(!Modo1 && !Modo2 && Modo3 && !Modo4 && !EstadoModo3)
         {
-            printf("Modo comandos de voz  \r \n");
-            estadomodo1 = false;
-            estadomodo2 = false;
-            estadomodo3 = true;
-            estadomodo4 = false;
-        }   
-        if(!modo1 && !modo2 && !modo3 && modo4 && !estadomodo4)
+            printf("Operando: Modo de comandos de voz. \r \n");
+            EstadoModo1 = false;
+            EstadoModo2 = false;
+            EstadoModo3 = true;
+            EstadoModo4 = false;
+        }
+        if(!Modo1 && !Modo2 && !Modo3 && Modo4 && !EstadoModo4)
         {
-            printf("Modo rutas autonomas \r \n");
-            estadomodo1 = false;
-            estadomodo2 = false;
-            estadomodo3 = false;
-            estadomodo4 = true;
-        }       
+            printf("Operando: Modo de rutas autonomas. \r \n");
+            EstadoModo1 = false;
+            EstadoModo2 = false;
+            EstadoModo3 = false;
+            EstadoModo4 = true;
+        }
     }
 }
 
+// Proceso principal de todo el software ejecutado por el microprocesador.
 int main()
 {
-    thread1.start(thread1_HCSR04);
+    Thread1.start(Thread1_HCSR04);
     thread_sleep_for(200);
-    thread2.start(thread2_HCSR04);
+    Thread2.start(Thread2_HCSR04);
     thread_sleep_for(200);
-    thread3.start(thread3_HCSR04);
+    Thread3.start(Thread3_HCSR04);
     thread_sleep_for(200);
-    thread4.start(thread4_HCSR04);
+    Thread4.start(Thread4_HCSR04);
     thread_sleep_for(200);
-    thread5.start(thread5_Joystick);
+    Thread5.start(Thread5_Joystick);
     thread_sleep_for(200);
-    thread6.start(thread6_ComandosVoz);
+    Thread6.start(Thread6_ComandosVoz);
     thread_sleep_for(200);
-    thread7.start(thread7_IndicarModo);
+    Thread7.start(Thread7_IndicarModo);
     thread_sleep_for(200);
-}
\ No newline at end of file
+}