viernes, 16 de diciembre de 2011

"Robot Dribbler"

Autor: Jorge Henriquez Romero
Competencia: (Nivel 1)
Palabras claves: Robot, Dribbler, Programacion, Proyecto.




Descripción de la actividad
En el siguiente blog les daré a conocer uno de los muchos trabajos realizados en la asignatura “Proyecto de Robot”, en donde se fomentaba el trabajo en equipo y el aprendizaje autono del los alumnos de la carrera.
El trabajo trataba sobre la creación de un robot y un código, para utilizarlos en un juego, en donde el robot debía pasar sobre la mayor cantidad de círculos negros que se encontraban en la pista para obtener puntaje, pero no debía chocar en ningún momento con los obstáculos ni con las paredes de la pista ya que provocaban el termino del juego, el objetivo de este juego es obtener la mayor cantidad de puntaje posible.

Solución



Como solución les mostrare el pseudocódigo con el que trabajamos para luego crear el código, el cual también se los presentare.
Pseudocódigo:
Declarar variables “potencia,vida, puntos, etc.”
Definir Umbral de luz
Definir Umbral de Sonido
(Multitareas)
task avance()
{
While(true) //mientras sea verdad
{
Avanzar motores a la potencia inicial;
Wait(800);
Si(Sensorde luz<Umbral de luz)
{
potencia=potencia+10;
}
task Potencia()
{
While(true){} //mientras sea verdad
}
task Escucha()
{
While(true) //mientras sea verdad
{
Si(Sensorde sonido>Umbral de sonido)
{
Acquire(semaforo); //Adquiere el permiso
Giraen un tiempo random(1500)+800;
Release(semaforo); //Entrega el permiso
}
}
}
task Vida()
{
While(true) //mientras sea verdad
{
Si(sensorde tacto 1 o 2 es tocado)
{
Vida++;
}
Si(vida!=0) //vida no es igual a 0
StopAllTask();
}
}
task Cuenta_Puntos()
{
ClearScreen(); //Limpiar pantalla
tnuevo=currentTick();
while(true) //mientras sea verdad
{
tantiguo=currentTick();
tiempo=tantiguo/1000;
Acquire(semaforo); //Adquiere el permiso
Giraen un tiempo random(1500)+800;
Release(semaforo); //Entrega el permiso
si(tiempo<=10)
puntos=-5*tiempo+50;
si(tiempo>10)
{
puntos=puntos+0;
puntaje[i]=puntos;
Imprimiren pantalla puntaje;
}
}
}
Task Musica()
{
While(true) //mientras sea verdad
Tonomusical;
}
task Comer()
{
While(true) //mientras sea verdad
{
si(Sensorde luz<Umbral de luz)
Tocarun tono;
}
}
Task main()
{
Setearsensor de luz;
Setearsensor de sonido;
Setearsensor de tacto 1;
Setearsensor de tacto 2;
Precedes(Musica, Comer, Avance,Potencia, Escucha, Vida, Cuenta_puntos); //”ordende actividad”
Códigofuente:
//Definiciónde variables
Intvida= 0 ;
int potencia= 
20
 ;
int puntos = 
0
 ;
int puntaje[ 
10
 ];
int i = 
0
 ;
int tiempo = 
0
 ;
int tantiguo= 
0 ,tnuevo= 0
 ;
int e= 
50
 ;
int j= 
50
 ;
mutex semaforo;
#define UMBRAlUZ 40
#define UMBRASON 95
task Avance ()
{
while (true)
{
OnFwd ( OUT_AC
 ,potencia); //Avanzar
Wait ( 800
 );
if ( 
Sensor ( IN_2
 )<UMBRAlUZ)//Aumento de potencia por cada vez q pase por un punto negro.
{
if(potencia< 
101
 )
potencia=potencia+ 
10
 ;
}
}
}

taskEscucha ()
{
while(true)
{
if ( 
Sensor ( IN_3
 ) >UMBRASON) //Si escucha un ruido gira.
{
Acquire
 (semaforo);
OnFwd ( OUT_C , 40
 );//Giro aleatorio
OnRev ( OUT_A 40
 );
Wait ( Random ( 2000 )+ 1200
 );
Release
 (semaforo);
}
}
}
taskVida ()
{
while (true)
{
if ( 
Sensor ( IN_1 ) == 1 || Sensor ( IN_4 ) == 1
 )
{
vida++; //Aumenta la vida finaliza el while
}
if (vida != 
0
 ) //Si vida distinto de cero se acabara elprograma
StopAllTasks
 ();
}
}
taskCuenta_puntos ()
{
ClearScreen
 ();
tnuevo = 
CurrentTick
 ();
while(true)
{
if ( 
Sensor ( IN_2
 ) < UMBRAlUZ)
{
tantiguo = CurrentTick();
tiempo = tantiguo/ 
1000
 ;
Acquire
 (semaforo);
OnFwd ( OUT_A , 40
 );
OnRev ( OUT_C , 40
 );
Wait ( Random ( 1500 )+ 800
 );
Release
 (semaforo);
if (tiempo <= 
10
 )
{puntos = - 
5 *tiempo + 50
 ;}
if (tiempo > 
10
 )
{puntos = puntos + 
0
 ;}
puntaje [i] = puntos;
NumOut
 (e,j, puntaje [i]);
i++;
}
}
}
taskMusica ()
{
while (true)
{
PlayTone ( 440 , 200
 ); //Música que sonara durante eljuego.
Wait ( 200
 );
PlayTone ( 440 , 200
 );
Wait ( 200
 );
PlayTone ( 440 , 200
 );
Wait ( 300
 );
PlayTone ( 349 , 200
 );
Wait ( 200
 );
PlayTone ( 440 , 200
 );
Wait ( 300
 );
PlayTone ( 523 , 200
 );
Wait ( 500
 );
PlayTone ( 262 , 1600
 );
Wait ( 600
 );
PlayTone ( 349 , 400
 ); //repetir
Wait ( 500
 );
PlayTone ( 262 , 400
 );
Wait ( 400
 );
PlayTone ( 196 , 400
 );
Wait ( 500
 );
PlayTone ( 294 , 400
 );
Wait ( 300
 );
PlayTone ( 330 , 400
 );
Wait ( 200
 );
PlayTone ( 294 , 400
 );
Wait ( 200
 );
PlayTone ( 262 , 400
 );
Wait ( 400
 );
PlayTone ( 262 , 800
 );
Wait ( 200
 );
PlayTone ( 349 , 800
 );
Wait ( 300
 );
PlayTone ( 440 , 800
 );
Wait ( 200
 );
PlayTone ( 587 , 800
 );
Wait ( 500
 );
PlayTone ( 466 , 800
 );
Wait ( 200
 );
PlayTone ( 523 , 800
 );
Wait ( 400
 );
PlayTone ( 440 , 800
 );
Wait ( 200
 );
PlayTone ( 349 , 800
 );
Wait ( 200
 );
PlayTone ( 392 , 800
 );
Wait ( 200
 );
PlayTone ( 330 , 800
 );
Wait ( 500
 );
PlayTone ( 349 , 400
 ); //repetir
Wait ( 500
 );
PlayTone ( 262 , 400
 );
Wait ( 400
 );
PlayTone ( 196 , 400
 );
Wait ( 500
 );
PlayTone ( 294 , 400
 );
Wait ( 300
 );
PlayTone ( 330 , 400
 );
Wait ( 200
 );
PlayTone ( 294 , 400
 );
Wait ( 200
 );
PlayTone ( 262 , 400
 );
Wait ( 400
 );
PlayTone ( 262 , 800
 );
Wait ( 200
 );
PlayTone ( 349 , 800
 );
Wait ( 300
 );
PlayTone ( 440 , 800
 );
Wait ( 200
 );
PlayTone ( 587 , 800
 );
Wait ( 500
 );
PlayTone ( 466 , 800
 );
Wait ( 200
 );
PlayTone ( 523 , 800
 );
Wait ( 400
 );
PlayTone ( 440 , 800
 );
Wait ( 200
 );
PlayTone ( 349 , 800
 );
Wait ( 200
 );
PlayTone ( 392 , 800
 );
Wait ( 200
 );
PlayTone ( 330 , 800
 );
Wait 500
 );
}
}
taskComer()
{
while (true)
{
if ( 
Sensor ( IN_2
 ) < UMBRAlUZ)
PlayTone ( 1046 , 100
 ); //Sonido que emite al pasar sobre un punto negro
Wait (50
);
PlayTone ( 1397 , 1600
 );
Wait 800
 );
}
}
}
taskmain ()
{
Precedes
 (Musica, Comer, Avance, Escucha, Vida,Cuenta_puntos);
SetSensorLight ( IN_2
 ); //Encendido desensores
SetSensorTouch IN_1
 );
SetSensorTouch ( IN_4
 );
SetSensorSound IN_3
 );
}
Video de la actividad:



Reflexión
La ayuda de esta actividad me ayudo mucho a fomentar el trabajo en equipo y el aprendizaje autónomo, ya que para crear el código se debía indagar sobre la materia para poder terminarlos y que cumplieran el objetivo de la actividad.
Espero les ayude este blog.

No hay comentarios:

Publicar un comentario