viernes, 3 de diciembre de 2010

PROYECTO MINIAPOLIS

ESTE ES UNTRABAJO HECHO POR LOS ESTUDIANTES DEL TEC DE MONTERREY CAMPUS SANTA FE.

EL OBJETIVO PRIMORDIAL ES HACER UN DIRIGIBLE AUTONOMO, CON UN MICROCONTROLADOR ATMEGA 328, MONTADO SOBRE UN KIT ARDUINO DUEMILANOVE.

EL MATERIAL USADO PARA ESTE PROYECTO ES:

- UN KIT DE ARDUINO
- 3 SENSORES ULTRASONICOS (PING PARALLAX)
- 3 MOTORES DC
- 3 PROPELLERS
- 1 SERVO MOTOR
- GLOBOS DE HELIO EQUIVALENTES A 0.5 m3
- 4 PILAS 9 V
- REGULADORES DE VOLTAJE 7805
- 2 PUENTES H L293B
- PLACA FENOLICA
- CABLES

DESARROLLO

PENSAMOS EN HACER UN DIRIGIBLE QUE TUVIERA TRES MOTORES CON LOS CUALES DOS IMPULSARIAN HACIA EL FRENTE Y OTRO MANTENDRIA LA ALTURA ESTABLE.

PASOS DE LA FABRICACIÓN DEL DIRIGIBLE:



LA RETROALIMENTACIÓN DE LOS MOTORES ESTA DADA POR LA ALTURA MEDIDA CON LOS SENSORES ULTRASONICOS. TODAS LAS VELOCIDADES DE LOS MOTORES ESTAN CONTROLADAS POR UN CICLO DE TRABAJO.

EL PROGRAMA DE NUESTRO PROYECTO CONSISTE:


#include <Servo.h>

Servo servo;

int pos = 0;

int PWM1=3;
int PWM2=5;
int PWM3=6;

const int pingPinx = 2;
const int pingPiny = 4;
const int pingPinz = 11;
const int PUENTEH1 = 7;
const int PUENTEH2 = 8;
const int PUENTEH3 = 9;
const int PUENTEH4 = 10;


void setup() {
   // initialize serial communication:
   Serial.begin(9600);
     servo.attach(13);
}

void loop()
{

   long durationx, cmx, durationy, cmy, durationz, cmz;;

   pinMode(pingPinx, OUTPUT);
   digitalWrite(pingPinx, LOW);
   delayMicroseconds(2);
   digitalWrite(pingPinx, HIGH);
   delayMicroseconds(5);
   digitalWrite(pingPinx, LOW);
   pinMode(pingPinx, INPUT);
   durationx = pulseIn(pingPinx, HIGH);
   cmx = microsecondsToCentimeters(durationx) ;

   pinMode(pingPiny, OUTPUT);
   digitalWrite(pingPiny, LOW);
   delayMicroseconds(2);
   digitalWrite(pingPiny, HIGH);
   delayMicroseconds(5);
   digitalWrite(pingPiny, LOW);
   pinMode(pingPiny, INPUT);
   durationy = pulseIn(pingPiny, HIGH);
   cmy = microsecondsToCentimeters1(durationy);

   pinMode(pingPinz, OUTPUT);
   digitalWrite(pingPinz, LOW);
   delayMicroseconds(2);
   digitalWrite(pingPinz, HIGH);
   delayMicroseconds(5);
   digitalWrite(pingPinz, LOW);
   pinMode(pingPinz, INPUT);
   durationz = pulseIn(pingPinz, HIGH);
   cmz = microsecondsToCentimeters2(durationz);
  
   int XPWM = ((325 - cmx) - 70);
   int YPWM = ((325 - cmy) - 70);
 //  int ZPWM = ((325 - cmy) - 70);

   if (cmx < 40 && cmy > 40){
   int XPWM = cmx + 30 + 180;
   int YPWM = 50;
   analogWrite(PWM1, XPWM);
   analogWrite(PWM2, YPWM);
   digitalWrite(PUENTEH1, LOW);
   digitalWrite(PUENTEH2, HIGH);
   digitalWrite(PUENTEH3, LOW);
   digitalWrite(PUENTEH4, HIGH);
   servo.attach(13);
   servo.write(50);              // tell servo to go to position in variable 'pos'
   delay(180);                   // waits 15ms for the servo to reach the position
   //Serial.print("Izquierda");
   //Serial.print(cmx);
   //Serial.print("cm   ");
   //Serial.print(cmy);
   //Serial.print("cm   ");
   //Serial.print(XPWM   );
   //Serial.print("     ");
   //Serial.print(   YPWM);
   //Serial.println();
   //delay(100);
   }
   if (cmx > 40 && cmy < 40){
   int YPWM = cmy + 30 + 180;
   int XPWM = 50;
   analogWrite(PWM1, XPWM);
   analogWrite(PWM2, YPWM);
   digitalWrite(PUENTEH1, LOW);
   digitalWrite(PUENTEH2, HIGH);
   digitalWrite(PUENTEH3, LOW);
   digitalWrite(PUENTEH4, HIGH);
   servo.attach(13);
   servo.write(125);              // tell servo to go to position in variable 'pos'
   delay(180);                   // waits 15ms for the servo to reach the position
   //Serial.println("Derecha");
   //Serial.print(cmx);
   //Serial.print("cm   ");
   //Serial.print(cmy);
   //Serial.print("cm   ");
   //Serial.print(XPWM   );
   //Serial.print("     ");
   //Serial.print(   YPWM);
   //Serial.println();
   //delay(100);
   }
   if (cmx >= 60 && cmy >= 60){
   int XPWM = 124;
   int YPWM = 124;
   analogWrite(PWM1, XPWM);
   analogWrite(PWM2, YPWM);
   digitalWrite(PUENTEH1, LOW);
   digitalWrite(PUENTEH2, HIGH);
   digitalWrite(PUENTEH3, LOW);
   digitalWrite(PUENTEH4, HIGH);
   servo.attach(13);
   servo.write(90);              // tell servo to go to position in variable 'pos'
   delay(180);                   // waits 15ms for the servo to reach the position
   //Serial.print("Centro");
   //Serial.print(cmx);
   //Serial.print("cm   ");
   //Serial.print(cmy);
   //Serial.print("cm   ");
   //Serial.print(XPWM   );
   //Serial.print("     ");
   //Serial.print(   YPWM);
   //Serial.println();
   //delay(100);
   }
   if (cmz <= 100){
   int ZPWM = 255;
   analogWrite(PWM3, ZPWM);
   }
   if (cmz >= 150){
   int ZPWM = 124;
   analogWrite(PWM3, ZPWM);
   }
}

long microsecondsToCentimeters(long microseconds)
{
   // The speed of sound is 340 m/s or 29 microseconds per centimeter.
   // The ping travels out and back, so to find the distance of the
   // object we take half of the distance travelled.
   return microseconds / 29 / 2;
}

long microsecondsToCentimeters1(long microseconds)
{
   // The speed of sound is 340 m/s or 29 microseconds per centimeter.
   // The ping travels out and back, so to find the distance of the
   // object we take half of the distance travelled.
   return microseconds / 29 / 2;
}

long microsecondsToCentimeters2(long microseconds)
{
   // The speed of sound is 340 m/s or 29 microseconds per centimeter.
   // The ping travels out and back, so to find the distance of the
   // object we take half of the distance travelled.
   return microseconds / 29 / 2;
}


SE HACE UNA MEDICION DE LOS SONARES, SI SE DETECTA UNA SEÑAL MENOR A 40 CM COMENZARA A MODIFICARSE EL CICLO DE TRABAJO DEL MOTOR Y GIRARA LA DIRECCION CONTROLADA POR UN SERVO.

EJEMPLO:

SI EL SENSOR X DETECTA UNA DISTANCIA MENOR A 40 CM, EL SERVO GIRA A SU DERECHA 45 GRADOS, EL MOTOR CORRESPONDIENTE AUMENTA SU PWM A 255 Y EL OTRO MOTOR BAJA SU POTENCIA A 50. UNA VEZ LIBRADO EL OBSTACULO LOS DOS MOTORES REGRESAN A UN PWM DE 124 Y EL SERVO AL ORIGEN. EN CASO DE QUE EL SENSOR Y DETECTE LO MENCIONADO AL INICIO PASA LO MISMO SOLO QUE LOS MOTORES INVIERTEN SU FUNCION Y EL SERVO GIRA 45 GRADOS EN DIRECCION A LA IZQUIERDA.

RECOMENDACIONES:

NOSOTROS NOS ENCONTRAMOS CON CIERTOS PROBLEMAS AL CONECTAR LOS MOTORES, ESTOS NO SE PODIAN QUEDAR SIN POTENCIA POR QUE LA CORRIENTE QUE RECIBIAN DESDE UN INICIO NO ERA LA MISMA QUE AL YA ESTAR EN MARCHA TODO EL SISTEMA. ESTO DERIVADO DE LOS PICOS DE CORRIENTE EN LOS MOTORES DE DC. TAMBIÉN DEBERAN SER MUY CUIDADOSOS EN EL ANGULO QUE LE MANDAN AL SERVO Y CHECAR LA VELOCIDAD CON QUE LO REALIZA. UTILIZAR FUENTES INDEPENDIENTES ES LO MEJOR Y EVITAR EL MAYOR PESO POSIBLE.