Está en la página 1de 4

COMPONENTES Y MEDIDAS

ELECTRÓNICAS
UNIDAD 3
PRACTICA 2 PROYECTO:
ROBOT MÓVIL DIFERENCIAL PARA EL FUTBOL DE ROBOTS
PROGRAMACION.
PARTE 2.

Integrante 1 Ruben Moises Ticona Quelca


Integrante 2 Cristian Fidel Yucra Rueda
Integrante 3 Roberto Misael Zurita Valencia
Integrante 4

Insertar el código en texto del ROBOT MÓVIL DIFERENCIAL FUTBOL DE ROBOTS


#include "BluetoothSerial.h"
#include <ESP32Servo.h>

BluetoothSerial ESP_BT;
//Servomotor PD No tocar
Servo derecha, izquierda; //
int ServoDer = 12, ServoIzq = 14;
const int MaxServoDer = 40;
const int MaxServoIzq = 140;
const int MinServoDer = 140;
const int MinServoIzq = 50;
///////////////
unsigned long tiempo = 0;
bool bandera = false;
//////////////////////////////////////
//Control de velocidad
TaskHandle_t Task1;////
const int PWM_x = 17;
const int frecuencia = 20000;
const int Canal = 10;
const int resolucion = 10;
const int Vel_Min = 700;
int velocidad = 1023; //0-1023
const int constante = 50;
//////////////////////////////////////
int motor1A = 27, motor2A = 26, motor1B = 25, motor2B = 33;
//////////////////

void setup() {
/// CONFIGURACION PARA EL PWM
ledcSetup(Canal, frecuencia, resolucion);
ledcAttachPin(PWM_x, Canal);
///Velocidad de los motores robot
ledcWrite(Canal, 1023); /// velocidad de 0 a 1023
////////////////////
// CONFIGURACION PARA NOMBRE DE BLUETOOTH
Serial.begin(115200);

ESP_BT.begin("beto");
////////////////////////////////////
// CONFIGURACION PARA EL SERVOMOTOR
ESP32PWM::allocateTimer(0);
ESP32PWM::allocateTimer(1);
ESP32PWM::allocateTimer(2);
COMPONENTES Y MEDIDAS
ELECTRÓNICAS
UNIDAD 3
ESP32PWM::allocateTimer(3);
derecha.setPeriodHertz(50); // standard 50 hz servo
derecha.attach(ServoDer, 500, 2400); // attaches the servo on pin 18 to the servo object
izquierda.setPeriodHertz(50); // standard 50 hz servo
izquierda.attach(ServoIzq, 500, 2400); // attaches the servo on pin 18 to the servo object
//////////////
pinMode(motor1A, OUTPUT);
pinMode(motor2A, OUTPUT);
pinMode(motor1B, OUTPUT);
pinMode(motor2B, OUTPUT);
//////////////
abrirBrazo();
}

void loop() {
// put your main code here, to run repeatedly:
ledcWrite(Canal, velocidad);
//Serial.println(millis());
preguntar();
if (ESP_BT.available())
{
char letra = ESP_BT.read();
preguntar();
switch (letra)
{
case 'W': avanzar();
break;
case 'S': retroceder();
break;
case 'A': MoverIzquierda();
break;
case 'D': MoverDerecha();
break;
case '1': ControlVelocidad(true);// Incremento de velocidad
break;
case '2': ControlVelocidad(false);// Disminuye la velocidad
break;
case 't': abrirBrazo();
break;
case 'y': cerrarBrazo();
break;
case 'u': detener();
break;

}
}
void avanzar()
{
digitalWrite(motor1A, HIGH);
digitalWrite(motor2A, LOW);
digitalWrite(motor1B, HIGH);
digitalWrite(motor2B, LOW);
}
void retroceder()
{
digitalWrite(motor1A, LOW);
COMPONENTES Y MEDIDAS
ELECTRÓNICAS
UNIDAD 3
digitalWrite(motor2A, HIGH);
digitalWrite(motor1B, LOW);
digitalWrite(motor2B, HIGH);
}
void detener()
{
digitalWrite(motor1A, LOW);
digitalWrite(motor2A, LOW);
digitalWrite(motor1B, LOW);
digitalWrite(motor2B, LOW);
}
void MoverIzquierda()
{
digitalWrite(motor1A, LOW);
digitalWrite(motor2A, HIGH);
digitalWrite(motor1B, HIGH);
digitalWrite(motor2B, LOW);
}
void MoverDerecha()
{
digitalWrite(motor1A, HIGH);
digitalWrite(motor2A, LOW);
digitalWrite(motor1B, LOW);
digitalWrite(motor2B, HIGH);
}
void ControlVelocidad(bool condicion)
{
if (condicion)
{
if (velocidad < 1023)
{
velocidad = velocidad + constante;
}
if (velocidad > 1023)
{
velocidad = 1023;
}
}
else
{
if (velocidad > Vel_Min)
{
velocidad = velocidad - constante;
}
if (velocidad < Vel_Min)
{
velocidad = Vel_Min;
}
}
}
void abrirBrazo()
{
derecha.write(MaxServoDer);
izquierda.write(MaxServoIzq);
}
void cerrarBrazo()
{
derecha.write(MinServoDer);
COMPONENTES Y MEDIDAS
ELECTRÓNICAS
UNIDAD 3
izquierda.write(MinServoIzq);
bandera = true;
tiempo = millis();
}
void preguntar()
{
if (bandera)
{
if ((millis() - tiempo) > 5000)
{
abrirBrazo();
bandera = false;
}
}
}
Insertar capturas de pantalla de la aplicación, mostrando las configuraciones de su control de
la aplicación.

También podría gustarte