]> git.llucax.com Git - z.facultad/75.68/celdas.git/blobdiff - trunk/src/breve/Celdas.tz
Últimos cambios y documentación.
[z.facultad/75.68/celdas.git] / trunk / src / breve / Celdas.tz
index 6ca2d6c064a89763fda5461dd10c696b5e58f292..481c28cc6b9a0c10609740d56ea0d4834c879e98 100644 (file)
@@ -6,9 +6,9 @@
 @use Drawing.\r
 @use SistemaAutonomo.\r
 \r
 @use Drawing.\r
 @use SistemaAutonomo.\r
 \r
-@define CELDAS_MAX_VELOCITY 30.\r
-@define CELDAS_TURNO 100.\r
-@define CELDAS_SENSOR_THRESHOLD 10.\r
+@define CELDAS_MAX_VELOCITY 5.\r
+@define CELDAS_TURNO 30.\r
+@define CELDAS_SENSOR_THRESHOLD 6.\r
 \r
 PhysicalControl : CeldasControl {\r
        % This class is used for building simple vehicle \r
 \r
 PhysicalControl : CeldasControl {\r
        % This class is used for building simple vehicle \r
@@ -206,19 +206,30 @@ CeldasLightVehicle : CeldasVehicle (aka CeldasVehicles) {
 \r
        + to turn-right:                \r
                tright++.\r
 \r
        + to turn-right:                \r
                tright++.\r
-\r
                self rotate around-axis (0,1,0) by (-1.5709/CELDAS_TURNO)*tright. \r
                self rotate around-axis (0,1,0) by (-1.5709/CELDAS_TURNO)*tright. \r
-                       \r
-               if (tright == CELDAS_TURNO): tright=0.\r
+#!\r
+               if (tright == CELDAS_TURNO):\r
+               {\r
+                 fSensor set-direction to (-1,0,0).\r
+                 bSensor set-direction to (1,0,0).\r
+                 lSensor set-direction to (0,0,-1).\r
+                 rSensor set-direction to (0,0,1).\r
+               }\r
+!#\r
 \r
 \r
        + to turn-left:\r
                tleft++.\r
 \r
 \r
        + to turn-left:\r
                tleft++.\r
-\r
                self rotate around-axis (0,1,0) by (1.5709/CELDAS_TURNO)*tleft. \r
                self rotate around-axis (0,1,0) by (1.5709/CELDAS_TURNO)*tleft. \r
-                       \r
-               if (tleft == CELDAS_TURNO): tleft=0.\r
-\r
+#!\r
+               if (tleft == CELDAS_TURNO):\r
+               {\r
+                 fSensor set-direction to (-1,0,0).\r
+                 bSensor set-direction to (1,0,0).\r
+                 lSensor set-direction to (0,0,-1).\r
+                 rSensor set-direction to (0,0,1).\r
+               }\r
+!#\r
 \r
         + to get-sensor-value:\r
                return (fSensor get-sensor-value).\r
 \r
         + to get-sensor-value:\r
                return (fSensor get-sensor-value).\r
@@ -289,7 +300,7 @@ CeldasLightVehicle : CeldasVehicle (aka CeldasVehicles) {
                teorias{0} set-dato-final name "sensor_l" value ANY.\r
                teorias{0} set-dato-final name "movido" value 1.\r
 \r
                teorias{0} set-dato-final name "sensor_l" value ANY.\r
                teorias{0} set-dato-final name "movido" value 1.\r
 \r
-               teorias{1} init named "Retroceder" with-action "atras".\r
+               teorias{1} init named "Retroceder" with-action "atras".# executed 2.\r
                teorias{1} set-dato-inicial name "sensor_f" value 1.\r
                teorias{1} set-dato-inicial name "sensor_b" value ANY.\r
                teorias{1} set-dato-inicial name "sensor_r" value ANY.\r
                teorias{1} set-dato-inicial name "sensor_f" value 1.\r
                teorias{1} set-dato-inicial name "sensor_b" value ANY.\r
                teorias{1} set-dato-inicial name "sensor_r" value ANY.\r
@@ -313,7 +324,7 @@ CeldasLightVehicle : CeldasVehicle (aka CeldasVehicles) {
                teorias{2} set-dato-final name "sensor_l" value 1.\r
                teorias{2} set-dato-final name "movido" value 0.\r
 \r
                teorias{2} set-dato-final name "sensor_l" value 1.\r
                teorias{2} set-dato-final name "movido" value 0.\r
 \r
-               teorias{3} init named "Rotar a izquierda" with-action "izquierda".\r
+               teorias{3} init named "Rotar a izquierda" with-action "izquierda". # executed 2.\r
                teorias{3} set-dato-inicial name "sensor_f" value 1.\r
                teorias{3} set-dato-inicial name "sensor_b" value ANY.\r
                teorias{3} set-dato-inicial name "sensor_r" value ANY.\r
                teorias{3} set-dato-inicial name "sensor_f" value 1.\r
                teorias{3} set-dato-inicial name "sensor_b" value ANY.\r
                teorias{3} set-dato-inicial name "sensor_r" value ANY.\r
@@ -335,6 +346,31 @@ CeldasLightVehicle : CeldasVehicle (aka CeldasVehicles) {
 \r
         +to iterate:\r
 \r
 \r
         +to iterate:\r
 \r
+               # Movimiento del robot\r
+               if (avanzando):\r
+               {\r
+                       self set-global-velocity to (CELDAS_MAX_VELOCITY).\r
+               }\r
+               if (retrocediendo):\r
+               {\r
+                       self set-global-velocity to (-CELDAS_MAX_VELOCITY).\r
+               }\r
+               if (girando_izq):\r
+               {\r
+                       self set-global-velocity to 0.\r
+                       self turn-left.\r
+                       #if (iterate): self rotate around-axis (0,1,0) by (1.570796/CELDAS_TURNO)*iterate.\r
+                       print "izq: ", (1.570796/CELDAS_TURNO)*iterate.\r
+               }\r
+               if (girando_der):\r
+               {\r
+                       self set-global-velocity to 0.\r
+                       self turn-right.\r
+                       #if (iterate): self rotate around-axis (0,1,0) by (-1.570796/CELDAS_TURNO)*iterate. \r
+                       print "der: ", (-1.570796/CELDAS_TURNO)*iterate.\r
+               }\r
+               #print "vel: ", (bodyLink get-velocity).\r
+\r
                # Actualiza entorno\r
                self update-entorno.\r
 \r
                # Actualiza entorno\r
                self update-entorno.\r
 \r
@@ -399,6 +435,10 @@ CeldasLightVehicle : CeldasVehicle (aka CeldasVehicles) {
                                        girando_der = 1.\r
                                }\r
                        }\r
                                        girando_der = 1.\r
                                }\r
                        }\r
+                       else\r
+                       {\r
+                               plan-finished = 1.\r
+                       }\r
                }\r
 \r
                # Validación de teoría\r
                }\r
 \r
                # Validación de teoría\r
@@ -425,16 +465,6 @@ CeldasLightVehicle : CeldasVehicle (aka CeldasVehicles) {
                        iterate++.\r
                }\r
 \r
                        iterate++.\r
                }\r
 \r
-               # Movimiento del robot\r
-               if (avanzando):\r
-                       self set-global-velocity to (15).\r
-               if (retrocediendo):\r
-                       self set-global-velocity to (-15).\r
-               if (girando_izq):\r
-                       self turn-left.\r
-               if (girando_der):\r
-                       self turn-right.\r
-\r
 }\r
 \r
 Stationary : CeldasObstacle (aka CeldasObstacles) {\r
 }\r
 \r
 Stationary : CeldasObstacle (aka CeldasObstacles) {\r
@@ -602,13 +632,26 @@ Link : CeldasSensor (aka CeldasSensors) {
                        des2=0.\r
                        if(dot(direction,(1,1,1))<0):\r
                        {                        \r
                        des2=0.\r
                        if(dot(direction,(1,1,1))<0):\r
                        {                        \r
-                            if((dot((self get-location),positiveDirection))>(dot(obsLoc,positiveDirection))):\r
-                                       des2=1.      \r
+                            if(dot((body get-location),positiveDirection) > dot((self get-location),positiveDirection)):\r
+                               {\r
+                                       if((dot((self get-location),positiveDirection))>(dot(obsLoc,positiveDirection))):\r
+                                               des2=1.\r
+                               }\r
+                           else\r
+                           if((dot((self get-location),positiveDirection))<(dot(obsLoc,positiveDirection))):\r
+                                       des2=1.         \r
                         }\r
                        else\r
                        {\r
                         }\r
                        else\r
                        {\r
-                            if((dot((self get-location),positiveDirection))<(dot(obsLoc,positiveDirection))):\r
+                            if(dot((body get-location),positiveDirection) < dot((self get-location),positiveDirection)):\r
+                               {\r
+                               if((dot((self get-location),positiveDirection))<(dot(obsLoc,positiveDirection))):\r
                                        des2=1.         \r
                                        des2=1.         \r
+                               }\r
+                          else\r
+                               if((dot((self get-location),positiveDirection))>(dot(obsLoc,positiveDirection))):\r
+                                               des2=1.\r
+                       \r
                        }                       \r
 \r
 \r
                        }                       \r
 \r
 \r