From: Leandro Lucarella Date: Sat, 16 Dec 2006 21:43:04 +0000 (+0000) Subject: Merge de Celdas-2-6 con Celdas-2-7. No está probado y seguramente no anda nada, pero... X-Git-Tag: entrega-20061218~22 X-Git-Url: https://git.llucax.com/z.facultad/75.68/celdas.git/commitdiff_plain/308d01acaf7100b1bb3123a2d0da52075cc5981a Merge de Celdas-2-6 con Celdas-2-7. No está probado y seguramente no anda nada, pero es una base. --- diff --git a/trunk/src/breve/robot/Celdas-2-7.tz b/trunk/src/breve/robot/Celdas-2-7.tz index 661c068..46d4bfa 100644 --- a/trunk/src/breve/robot/Celdas-2-7.tz +++ b/trunk/src/breve/robot/Celdas-2-7.tz @@ -160,18 +160,16 @@ CeldasLightVehicle : CeldasVehicle (aka CeldasVehicles) { % vehicle is heavier and harder to control, but more stable % at higher speeds. +variables: - lSensor, rSensor, fSensor, bSensor (object). - lWheel,rWheel (object). - tleft,tright (int). + lSensor, rSensor, fSensor, bSensor (object). + lfWheel,rfWheel,lbWheel,rbWheel (object). + tleft,tright (int). iterate(int). - teorias (list). sa (object). teoria (object). entorno (hash). datos-finales (hash). - - + avanzando,retrocediendo,girando(int). - to get-density: return 20.0. @@ -182,12 +180,14 @@ CeldasLightVehicle : CeldasVehicle (aka CeldasVehicles) { - to get-wheel-radius: return 0.8. - + to set-global-velocity to velocity=5 (float): - rWheel set-velocity to velocity. - lWheel set-velocity to velocity. + + to set-global-velocity to velocity (float): + rfWheel set-velocity to velocity. + lfWheel set-velocity to velocity. + rbWheel set-velocity to velocity. + lbWheel set-velocity to velocity. + to get-global-velocity: - return ((rWheel get-velocity) + (lWheel get-velocity)) / 2. + return ((rfWheel get-velocity) + (lfWheel get-velocity)) / 2. + to turn-right: tright++. @@ -208,118 +208,121 @@ CeldasLightVehicle : CeldasVehicle (aka CeldasVehicles) { + to get-sensor-value: return (fSensor get-sensor-value). + +to update-entorno: + entorno{"sensor_f"} = (fSensor get-data). + entorno{"sensor_b"} = (bSensor get-data). + entorno{"sensor_r"} = (rSensor get-data). + entorno{"sensor_l"} = (lSensor get-data). + entorno{"movido"} = 0. # TODO + sa update-entorno entorno entorno. + +to init: sa = new SistemaAutonomo. iterate=0. - fSensor = (self add-sensor at (2.0, .4, 0)). - fSensor set-direction to (1,0,0). - #fSensor set-direction to (0,0,1). - fSensor set-id at 1. - fSensor set-body at self. - bSensor = (self add-sensor at (-2.0, .4, 0)). - bSensor set-direction to (-1,0,0). - #bSensor set-direction to (0,0,1). - bSensor set-id at 2. - bSensor set-body at self. - lSensor = (self add-sensor at (0, .4, 1.5)). - lSensor set-direction to (0,0,1). - #lSensor set-direction to (1,0,0). - lSensor set-id at 3. - lSensor set-body at self. - - - rSensor = (self add-sensor at (0, .4, -1.5)). - rSensor set-direction to (0,0,-1). - #rSensor set-direction to (-1,0,0). - rSensor set-id at 4. - rSensor set-body at self. - - lWheel = (self add-wheel at (0, 0, -1.5)). - rWheel = (self add-wheel at (0, 0, 1.5)). - - tleft=tright=0. #Debe ser inicializado en 0 esta asi para probar!!!!!!!!!!!!!!!!!!!!!!!! - - entorno{"sensor_f"} = 0. - entorno{"sensor_b"} = 0. - entorno{"sensor_r"} = 0. - entorno{"sensor_l"} = 0. - - entorno{"movido"} = 0. - sa update-entorno entorno entorno. - - teorias = 2 new Teorias. - teorias{0} init named "avanzar" with-action "avanza". - (teorias{0}) set-dato-inicial name "sensor_f" value ANY. - (teorias{0}) set-dato-inicial name "sensor_b" value ANY. - (teorias{0}) set-dato-inicial name "sensor_r" value ANY. - (teorias{0}) set-dato-inicial name "sensor_l" value ANY. - (teorias{0}) set-dato-inicial name "movido" value ANY. - (teorias{0}) set-dato-final name "sensor_f" value ANY. - (teorias{0}) set-dato-final name "sensor_b" value ANY. - (teorias{0}) set-dato-final name "sensor_r" value ANY. - (teorias{0}) set-dato-final name "sensor_l" value ANY. - (teorias{0}) set-dato-final name "movido" value ANY. - - teorias{1} init named "avanzar2" with-action "avanza". - (teorias{1}) set-dato-inicial name "sensor_f" value ANY. - (teorias{1}) set-dato-inicial name "sensor_b" value ANY. - (teorias{1}) set-dato-inicial name "sensor_r" value ANY. - (teorias{1}) set-dato-inicial name "sensor_l" value ANY. - (teorias{1}) set-dato-inicial name "movido" value ANY. - (teorias{1}) set-dato-final name "sensor_f" value ANY. - (teorias{1}) set-dato-final name "sensor_b" value ANY. - (teorias{1}) set-dato-final name "sensor_r" value ANY. - (teorias{1}) set-dato-final name "sensor_l" value ANY. - (teorias{1}) set-dato-final name "movido" value ANY. - - - sa add teoria (teorias{0}). - sa add teoria (teorias{1}). + teorias{0} init named "Avanzar" with-action "avanzar". + teorias{0} set-dato-inicial name "sensor_f" value 0. + teorias{0} set-dato-inicial name "sensor_b" value ANY. + teorias{0} set-dato-inicial name "sensor_r" value ANY. + teorias{0} set-dato-inicial name "sensor_l" value ANY. + teorias{0} set-dato-inicial name "movido" value ANY. + teorias{0} set-dato-final name "sensor_f" value ANY. + teorias{0} set-dato-final name "sensor_b" value ANY. + teorias{0} set-dato-final name "sensor_r" value ANY. + teorias{0} set-dato-final name "sensor_l" value ANY. + teorias{0} set-dato-final name "movido" value 1. + + teorias{1} init named "Rotar a derecha" with-action "derecha". + teorias{1} set-dato-inicial name "sensor_f" value 1. + teorias{1} set-dato-inicial name "sensor_b" value ANY. + teorias{1} set-dato-inicial name "sensor_r" value ANY. + teorias{1} set-dato-inicial name "sensor_l" value ANY. + teorias{1} set-dato-inicial name "movido" value ANY. + teorias{1} set-dato-final name "sensor_f" value 0. + teorias{1} set-dato-final name "sensor_b" value ANY. + teorias{1} set-dato-final name "sensor_r" value ANY. + teorias{1} set-dato-final name "sensor_l" value ANY. + teorias{1} set-dato-final name "movido" value 0. + + sa add teoria teorias{0}. + sa add teoria teorias{1}. - datos-finales{"movido"} = 1. - - sa update-datos-finales datos-finales datos-finales. - sa plan. + fSensor = (self add-sensor at (2.0, .4, 0)). + fSensor set-direction to (1,0,0). + #fSensor set-direction to (0,0,1). + fSensor set-id at 1. + fSensor set-body at self. + bSensor = (self add-sensor at (-2.0, .4, 0)). + bSensor set-direction to (-1,0,0). + #bSensor set-direction to (0,0,1). + bSensor set-id at 2. + bSensor set-body at self. + lSensor = (self add-sensor at (0, .4, 1.5)). + lSensor set-direction to (0,0,1). + #lSensor set-direction to (1,0,0). + lSensor set-id at 3. + lSensor set-body at self. + + + rSensor = (self add-sensor at (0, .4, -1.5)). + rSensor set-direction to (0,0,-1). + #rSensor set-direction to (-1,0,0). + rSensor set-id at 4. + rSensor set-body at self. + + + lfWheel = (self add-wheel at (2, 0, -1.5)). + lbWheel = (self add-wheel at (-2, 0, -1.5)). + rfWheel = (self add-wheel at (2, 0, 1.5)). + rbWheel = (self add-wheel at (-2, 0, 1.5)). + + tleft=tright=0. #Debe ser inicializado en 0 esta asi para probar!!!!!!!!!!!!!!!!!!!!!!!! + avanzando=1. + retrocediendo=0. + girando=0. - +to iterate: - #+ to post-iterate: valuef,valueb,valuer,valuel (float). fl, fr(float). + valuef=fSensor get-data. + valueb=bSensor get-data. + valuel=lSensor get-data. + valuer=rSensor get-data. - if(iterate==0): { - print "iteracion 0". - if (sa has-next-theory): - { + datos-finales{"movido"} = 1. + print "senforl: $valuel". - print "hay teoria". - teoria = sa get-next-theory. - if ((teoria get-accion) == "avanza"): { - #entorno{"sensor"} = 1. - #entorno{"movido"} = 1. - self set-global-velocity. - - } - if ((teoria get-accion) == "retrocede"): { - self set-global-velocity to -5. + sa update-datos-finales datos-finales datos-finales. + sa plan. + + if (iterate==0): { + print "iteracion 0". + if (sa has-next-theory): + { + + print "hay teoria". + teoria = sa get-next-theory. + if ((teoria get-accion) == "avanza"): { + #entorno{"sensor"} = 1. + #entorno{"movido"} = 1. + self set-global-velocity. + + } + if ((teoria get-accion) == "retrocede"): { + self set-global-velocity to -5. + + } } } - } - if (iterate==100) && (teoria): + if ((iterate==100) && (teoria)): { - entorno{"sensor_f"} = (fSensor get-data). - entorno{"sensor_b"} = (bSensor get-data). - entorno{"sensor_r"} = (rSensor get-data). - entorno{"sensor_l"} = (lSensor get-data). - - sa update-entorno entorno entorno. + self update-entorno. if (sa validate theory teoria): { print "valida". } @@ -328,11 +331,10 @@ CeldasLightVehicle : CeldasVehicle (aka CeldasVehicles) { } } - - iterate++. - if(iterate==101): - iterate=0. + iterate++. + if(iterate==101): + iterate=0. } Stationary : CeldasObstacle (aka CeldasObstacles) { @@ -529,24 +531,10 @@ Link : CeldasSensor (aka CeldasSensors) { des3=0. } - - #aux1=dot((self get-location),(i get-direction)). - - #print "sensor: $id obstaculo: $posObstacle direP: $destiny direS: $direction yo: $yo ". - #print "begin: $wallBegin end: $wallEnd ". - #print "begin: $wallBegin end: $wallEnd". - - - #print "sensor: $id , des1: $des1, des2: $des2, des3: $des3". if ((des2) && (des3)): { - draw clear. - #print " posObstacle: $posObstacle". - - print "sensor: $id obstaculo: $posObstacle direP: $destiny direS: $direction yo: $yo ". - print "begin: $wallBegin end: $wallEnd ". - + draw clear. dist=|obsLoc - (self get-location)|. if( (j==0) || (min>dist) ): @@ -567,7 +555,7 @@ Link : CeldasSensor (aka CeldasSensors) { #Dibujo el laser draw set-color to (1, 0, 0). draw draw-line from (self get-location) to (obs). - return dist. + return min. } @@ -576,4 +564,4 @@ Link : CeldasSensor (aka CeldasSensors) { } - \ No newline at end of file +