Alumno: Juan Francisco Mendoza Martínez
Competencia: Desarrollo de Software
Palabras claves: Robot, pitFinder, sensor, altura.
Descripción de la actividad:
- El robot ha de recorrer una mesa, en donde deberá detectar a través de un sensor de ultrasonido que detectara la altura que hay desde ese punto. Deberemos usar nuestro Robot sobre la pista que se encuentra en laboratorio, para este caso sin paredes. Utilizaremos nuevos comando llamado ARRAY, WriteLnString, ReadLnString, Mutex y los archivos tipo bytes.
Solución:
- Se pudo lograr un buen trabajo en equipo, además lograda con éxito las distintas formas que se implementaron para desarrollar lo solicitado y lo más importante que el robot cumpliera.
Pseudocódigo:
DEFINIMOS ENTERO J=0, i=0, S=0, N=0, t=512, altura [4]
DEFINIMOS PALABRAS pr=”PRECIPICIO”, ln=”=>”,str,scn,ns
DEFINIMOS VARIABLE EXCLUSION MUTUAL mut
DEFINIMOS PUNTEROS arch,byt
DEFINIMOS prox 20
DEFINIMOS SUBRUTINA archivo ()
{
CREAMOS ARCHIVO (“datos1.txt”, t, arch)
ESCRIBIMOS EN EL ARCHIVO (arch,”datos pitfinder”,byt)
ESCRIBIMOS EN EL ARCHIVO (arch,”---------------”,byt)
PARA (CON J=0; HASTA J< LONGITUD de altura; llendo J mas 1)
{
N aumentando en 1
ns= NUMERO COMVERTIDO A PALABRA

str = NUMERO COMVERTIDO A PALABRA (altura[j])
str = pr + ns + ln + str
ESCRIBIMOS EN EL ARCHIVO (arch,str,byt)
}
CERRAR ARCHIVO (arch)
}
DEFINIMOS SUBRUTINA alturag ()
{
Altura[s]= DATOS RECOGIDOS DEL SENSOR 2
MOSTRAMOS NUMEROS EN Pantalla (0,10*s,altura[s])
S aumentando en 1
}
DEFINIMOS TAREA Avanzar ()
{
CICLO HASTA (i<4)
{
AVANZAMOS (MOTOR C, poder: 50)
AVANZAMOS (MOTOR A, poder: 52)
SI (EL SENSOR 2 > prox)
{
I AUMENTANDO EN 1
EMPIEZA (mut)
AVANZAMOS (MOTOR C, PODER: 50)
AVANZAMOS (MOTOR A, PODER: 52)
POR (300 MILISEGUNDOS)
APAGAMOS MOTORES (MOTOR A Y C)
POR (1 SEG)
INVOCAMOS A SUBRUTINA alturag ()
RETROCEDEMOS (MOTOR C, PODER: 50)
RETROCEDEMOS (MOTOR A, PODER: 52)
POR (1SEG)
AVANZAMOS (MOTOR C, PODER: 50)
RETROCEDEMOS (MOTOR A, PODER: 52)
POR (TIEMPO ALEATORIO ENTRE 400 Y 1500 MILISEG)
SOLTAR (mut);
}
}
DEFINIMOS ENTERO pa=50
DEFINIMOS VARIABLE BOOLEANA eof = falso
APAGAMOS MOTORES (MOTOR A Y C)
INVOCAMOS A LA SUBRUTINA archivo ()
LIMPIAMOS PANTALLA
ABRIMOS ARCHIVO PARA LEER("datos1.txt", t, arch)
CICLO HASTA (eof es igual a falso) { si (la línea del achivo(arch,scn) es distinto NO_ERR) eof = verdadero
MOSTRAR NUMEROS EN PANTALLA (PANTALLA_INEA8, pa, scn)
pa= pa-10
POR (500 MILISEG)}
POR (5 SEG)
CIERRO ARCHIVO (arch)
BORRO ARCHIVO ("datos1.txt")
}
TAREA PRINCIPAL ()
{
EJECUTAR TODO A LA VEZ (Avanzar)
SETEAMOS SENSOR DE PROXIMIDAD
}
Código de fuente en NXC:
int j=0;
int i=0;
string pr="Precipicio";
string ln="==>";
int s=0;
int n=0;
int altura[4];
byte arch;
string str;
mutex mut;
string scn;
byte byt;
int t=512;
string ns;
#define prox 20
sub archivo()
{
CreateFile("datos1.txt", t, arch);
WriteLnString(arch, "DATOS PITFINDER", byt);
WriteLnString(arch, "--------------", byt);
for(j=0; j < ArrayLen(altura); j++)
{
n++;
ns= NumToStr
;
str = NumToStr(altura[j]);
str = pr + ns + ln + str;
WriteLnString(arch, str, byt);
}
CloseFile(arch);
}
sub alturag()
{
altura[s]=SensorUS(IN_2);
NumOut(0,10*s,altura[s]);
s++;
}
task Avanzar()
{
while (i<4)
{
OnFwd(OUT_C,50);
OnFwd(OUT_A,52);
if (SensorUS(IN_2)>prox)
{
i++;
Acquire(mut);
OnFwd(OUT_C,50);
OnFwd(OUT_A,52);
Wait(300);
Off(OUT_AC);
Wait(1000);
alturag();
OnRev(OUT_C,50);
OnRev(OUT_A,52);
Wait(1000);
OnFwd(OUT_C,50);
OnRev(OUT_A,52);
Wait(Random(1500)+400);
Release(mut);
}
}
int pa=50;
bool eof = false;
Off(OUT_AC);
archivo();
ClearScreen();
OpenFileRead("datos1.txt", t, arch);
while (eof == false){ // read the text file till the end
if(ReadLnString(arch,scn) != NO_ERR) eof = true;
TextOut(LCD_LINE8,pa,scn);
pa= pa-10;
Wait(500);}
Wait(5000);
CloseFile(arch);
DeleteFile("datos1.txt");
}
task main()
{
Precedes(Avanzar);
SetSensorLowspeed(IN_2);
}
int i=0;
string pr="Precipicio";
string ln="==>";
int s=0;
int n=0;
int altura[4];
byte arch;
string str;
mutex mut;
string scn;
byte byt;
int t=512;
string ns;
#define prox 20
sub archivo()
{
CreateFile("datos1.txt", t, arch);
WriteLnString(arch, "DATOS PITFINDER", byt);
WriteLnString(arch, "--------------", byt);
for(j=0; j < ArrayLen(altura); j++)
{
n++;
ns= NumToStr

str = NumToStr(altura[j]);
str = pr + ns + ln + str;
WriteLnString(arch, str, byt);
}
CloseFile(arch);
}
sub alturag()
{
altura[s]=SensorUS(IN_2);
NumOut(0,10*s,altura[s]);
s++;
}
task Avanzar()
{
while (i<4)
{
OnFwd(OUT_C,50);
OnFwd(OUT_A,52);
if (SensorUS(IN_2)>prox)
{
i++;
Acquire(mut);
OnFwd(OUT_C,50);
OnFwd(OUT_A,52);
Wait(300);
Off(OUT_AC);
Wait(1000);
alturag();
OnRev(OUT_C,50);
OnRev(OUT_A,52);
Wait(1000);
OnFwd(OUT_C,50);
OnRev(OUT_A,52);
Wait(Random(1500)+400);
Release(mut);
}
}
int pa=50;
bool eof = false;
Off(OUT_AC);
archivo();
ClearScreen();
OpenFileRead("datos1.txt", t, arch);
while (eof == false){ // read the text file till the end
if(ReadLnString(arch,scn) != NO_ERR) eof = true;
TextOut(LCD_LINE8,pa,scn);
pa= pa-10;
Wait(500);}
Wait(5000);
CloseFile(arch);
DeleteFile("datos1.txt");
}
task main()
{
Precedes(Avanzar);
SetSensorLowspeed(IN_2);
}
Vídeo del Robot:
Reflexión:
- Actividad complicada al principio, pero no que un buen equipo no pueda desarrollar. Se logró llegar a buen puerto y queda demostrado que uno cada día aprende a nuevas cosas (como nuevos comando etc.).