martes, 11 de octubre de 2011

Robot Dribbler

Robot Dribbler




Alumno: Juan Francisco Mendoza Martínez.
Competencia: Desarrollo de software.
Palabras Claves: Robot, Dribbler, Puntos, Luz, Touch.


Descripción:


   -  Se construyo un robot para que esté funcionara con dos sensores, que serian el de Touch y el sensor de Luz. El sensor de Luz deberá estar ubicado hacia la pista de modo que cuando detecte un circulo negro, esté pueda aumentar su velocidad y puntos (velocidad máxima es igual a 100)... el proceso se repetirá las veces que sea HASTA que el sensor de Touch sea presionado, es aquí donde el juego termina.


Solución:


    -  Hemos alcanzado la solución para llevar a cabo la actividad del Robot Dribbler. Todo esto con un buen y desarrollado trabajo en equipo, no obstante las dificultades que se nos presentaron las pudimos sacar adelante, con ayuda de los profesores en el laboratorio y horas autónomas de estudio. Se aprendió a usar las nuevas líneas de comando que fueron enseñadas en clases como Acquire, Array, Release(Mutex), ExitTo(task).


Pseudocódigo:



definimos enteros vel=20,rdm=0,puntajemostrado=0,i=0,puntaje[]
definimos variable mutual exclusion MUTEX
definimos enteros largos tiempoini,tiempo,tiempo2,tiempodif
Definimos TAREA MELODIA()
{
Ciclo infinito
{
Melodia para busqueda de puntos
}
}
DEFINIMOS TAREA AVANZAR ()
{
tiempoini= tiempo actual
Ciclo infinito
{
Inicializamos el turno MUTEX
tiempoini= tiempo actual
Avanzamos (vel, control de motores)
Liberamos a MUTEX
}
}
DEFINIMOS TAREA GIRAR ()
{
Ciclo infinito
{
SI (el sensor de sonido >90)
{
Inicializamos el turno MUTEX
Retrocedemos ambos motores (45, control de motores)
Por 0,4 seg
Liberamos a MUTEX
}
}
}
DEFINIMOS TAREA GIROPUNTOS ()
{
Ciclo infinito
{
SI (el sensor de luz <40)
{
Inicializamos el turno MUTEX
Apagamos los dos motores
Avanzamos ambos motores (45, control de motores)
Retrocedemos el motor b(45,control de motores)
Por 0,7 seg
Liberamos a MUTEX
}
}
}
DEFINIMOS TAREA PUNTOS ()
{
Ciclo infinito
{
SI (el sensor de luz <40)
{
tiempo= tiempo actual
tiempo2 =(tiempo-tiempoini)
Música de anotación
tiempodif=(tiempo2)/1000
SI(tiempodif<10)
{
puntajeSum=(-5*tiempodif)+50
puntaje[i]=puntajeSum
}
SI (tiempodif>10)
{
puntaje[i]=0
}
i aumentando en una unidad
vel=vel+10
POR 0,4 seg
}
}
}
DEFINIMOS TAREA CHOQUE()
{
CICLO INFINTO
{
SI(SENSOR DE TACTO ES ACTIVADO)
{
Inicializamos el turno MUTEX
Apagamos motores
Ciclo for(desde int i=0;hasta la longitud final de arreglo;con i aumentando en una unidad)
{
puntajemostrado=puntaje[i]+puntajemostrado
}
Mostramos en pantalla(50,50,puntajemostrado)
Por 1 segundo
Limpiar Pantalla
Parar todas las tareas
Liberamos el MUTEX
}
}
}
TAREA PRINCIPAL(){
Iniciamos el sensor de luz
Iniciamos el sensor de sonido
Iniciamos el sensor de tacto
INICIALIZAMOS TODAS LAS TAREAS(AVANZAR,GIRAR,PUNTOS,CHOQUE,MELODIA)
}



Código de fuente en NXC:

int vel=20;
mutex Mutex;
int rdm=0;
int puntaje[];
int puntajeSum;
long tiempo;
long tiempodif;
long tiempoini;
int i=0;
int puntajemostrado=0;
long tiempo2;



task melodia()
{
while(true)
{

PlayTone(262,240);
Wait(160);
PlayTone(262,240);
Wait(160);
PlayTone(294,240);
Wait(160);
PlayTone(294,240);
Wait(160);
PlayTone(330,240);
Wait(160);
PlayTone(330,240);
Wait(160);
PlayTone(294,240);
Wait(160);
PlayTone(294,240);
Wait(160);
PlayTone(262,240);
Wait(160);
}

}

task avanzar(){
tiempoini=CurrentTick();
while(true){
Acquire(Mutex);
OnFwdReg(OUT_AB,vel,OUT_REGMODE_SPEED);
Release(Mutex);
}
}

task girar(){
while(true){
if(Sensor(IN_2)>90){
Acquire(Mutex);
//rdm=Random(650)+100;
OnFwdReg(OUT_A,45,OUT_REGMODE_SPEED);
OnRevReg(OUT_B,45,OUT_REGMODE_SPEED);
Wait(400);
Release(Mutex);


}
}

}
task giropuntos(){
while(true){
if(Sensor(IN_3)<40){
Acquire(Mutex);
Off(OUT_AB);
OnFwdReg(OUT_AB,45,OUT_REGMODE_SPEED);
OnRevReg(OUT_B,45,OUT_REGMODE_SPEED);
Wait(750);
Release(Mutex);
}
}

}
task puntos(){
while(true)
{
if(Sensor(IN_3)<40)
{
tiempo=CurrentTick();
tiempo2=(tiempo-tiempoini);
PlayTone(800,800);
tiempodif=tiempo2/1000;
if(tiempodif < 10)
{

puntajeSum=(-5*tiempodif)+50;
puntaje[i]=puntajeSum;


}

if(tiempodif >10)
{

puntaje[i]=0;

}


i++;
vel=vel+10;
Wait(400);

} //fin del primer if


} //fin del while

} //fin de puntos

task choque(){
while(true){

if(Sensor(IN_1)==1)
{
Acquire(Mutex);
Off(OUT_AB);
for(int i=0;i<ArrayLen(puntaje);i++)
{

puntajemostrado=puntaje[i]+puntajemostrado;


}

NumOut(50,50,puntajemostrado);
Wait(5000);
ClearScreen();




StopAllTasks();
Release(Mutex);
}

}
}



task main(){
SetSensorLight(IN_3);
SetSensorSound(IN_2);
SetSensorTouch(IN_1);
Precedes(avanzar,girar,puntos,choque,melodia);



Vídeo de la actividad:




Reflexión:

  -  Con este trabajo de pudo llegar a buen puerto, cumplimos 100% con el objetivo y el trabajo en equipo fue espectacular. Por mi parte aprendí a usar nuevos comando y la manera de desarrollar estos trabajos cada vez se hacen más fácil.

No hay comentarios:

Publicar un comentario