]> git.llucax.com Git - z.facultad/75.68/celdas.git/blob - trunk/src/breve/Celdas.tz
Agrega un modo de salida intentando que sea más fácil generar tablas con la evolución...
[z.facultad/75.68/celdas.git] / trunk / src / breve / Celdas.tz
1 @use PhysicalControl.\r
2 @use Shape.\r
3 @use Stationary.\r
4 @use Link.\r
5 @use MultiBody.\r
6 @use Drawing.\r
7 @use SistemaAutonomo.\r
8 \r
9 @define CELDAS_MAX_VELOCITY 5.\r
10 @define CELDAS_TURNO 30.\r
11 @define CELDAS_SENSOR_THRESHOLD 10.\r
12 \r
13 PhysicalControl : CeldasControl {\r
14         % This class is used for building simple vehicle \r
15         % simulations.  To create a vehicle simulation, \r
16         % subclass CeldasControl and use the init method to \r
17         % create OBJECT(CeldasObstacle) and \r
18         % OBJECT(CeldasVehicle) objects.\r
19 \r
20         + variables:\r
21                 floor (object).\r
22                 floorShape (object).\r
23                 cloudTexture (object).\r
24 \r
25 \r
26         + to init:\r
27                 self enable-lighting.\r
28                 #self enable-smooth-drawing.\r
29 \r
30                 floorShape = new Shape.\r
31                 floorShape init-with-cube size (200, .2, 200).\r
32 \r
33                 floor = new Stationary.\r
34                 floor register with-shape floorShape at-location (0, 0, 0).\r
35                 #floor catch-shadows.\r
36 \r
37                 self point-camera at (0, 0, 0) from (3, 3, 24).\r
38 \r
39                 #self enable-shadows.\r
40                 #self enable-reflections.\r
41 \r
42                 cloudTexture = (new Image load from "images/clouds.png"). \r
43                 self set-background-color to (.4, .6, .9).\r
44                 self set-background-texture-image to cloudTexture.\r
45 \r
46 }\r
47 \r
48 MultiBody : CeldasLightVehicle (aka CeldasLightVehicles) {\r
49         % This object is used in conjunction with OBJECT(CeldasControl) to\r
50         % create simple vehicles.\r
51 \r
52         + variables:\r
53                 bodyShape (object).\r
54                 wheelShape (object).\r
55                 sensorShape (object).\r
56                 bodyLink (object).\r
57 \r
58                 wheels (list).\r
59 \r
60         + to init:\r
61                 bodyShape = new Shape.\r
62                 bodyShape init-with-cube size (4.0, .75, 3.0).  \r
63 \r
64                 wheelShape = new Shape.\r
65                 wheelShape init-with-polygon-disk radius ( self get-wheel-radius ) sides 20 height ( self get-wheel-width ).\r
66                 # 40\r
67 \r
68                 sensorShape = new Shape.\r
69                 sensorShape init-with-polygon-cone radius .2 sides 5 height .5.\r
70                 # 10\r
71 \r
72                 bodyShape set-density to ( self get-density ).\r
73                 bodyLink = new Link.\r
74                 bodyLink set-shape to bodyShape.        \r
75                 bodyLink set-mu to -1.0.\r
76                 bodyLink set-eT to .8.\r
77 \r
78                 self set-root to bodyLink.\r
79 \r
80                 self move to (0, 0.9, 0).\r
81                 self set-texture-scale to 1.5.\r
82 \r
83         - to get-density:\r
84                 return 1.0.\r
85 \r
86         - to get-wheel-width:\r
87                 return 0.1.\r
88 \r
89         - to get-wheel-radius:\r
90                 return 0.6.\r
91 \r
92         + section "Adding Wheels and Sensors to a Vehicle"\r
93 \r
94         + to add-wheel at location (vector):\r
95                 % Adds a wheel at location on the vehicle.  This method returns\r
96                 % the wheel which is created, a OBJECT(CeldasWheel).\r
97 \r
98                 wheel, joint (object).\r
99 \r
100                 wheel = new CeldasWheel.\r
101                 wheel set-shape to wheelShape.\r
102 \r
103                 joint = new RevoluteJoint.\r
104 \r
105                 joint set-relative-rotation around-axis (1, 0, 0) by 1.5708.\r
106                 joint link parent bodyLink to-child wheel with-normal (0, 0, 1)\r
107                                         with-parent-point location with-child-point (0, 0, 0).\r
108 \r
109                 wheel set-eT to .8.\r
110                 wheel set-texture to 0.\r
111                 wheel set-joint to joint.\r
112                 joint set-strength-limit to (joint get-strength-hard-limit) / 2.\r
113                 wheel set-color to (.6, .6, .6).\r
114                 wheel set-mu to 100000.\r
115 \r
116                 self add-dependency on joint.\r
117                 self add-dependency on wheel.\r
118 \r
119                 push wheel onto wheels.\r
120 \r
121                 return wheel.\r
122 \r
123         + to add-sensor at location (vector) with-direction direction = (0,1,0)(vector) :\r
124                 % Adds a sensor at location on the vehicle.  This method returns\r
125                 % the sensor which is created, a OBJECT(CeldasSensor).\r
126 \r
127                 sensor, joint (object).\r
128 \r
129                 sensor = new CeldasSensor.\r
130                 sensor set-direction to direction.\r
131                 \r
132                 sensor set-shape to sensorShape.\r
133 \r
134                 joint = new RevoluteJoint.\r
135 \r
136                 joint set-relative-rotation around-axis (0, 0, 1) by -1.57.\r
137                 joint link parent bodyLink to-child sensor with-normal (1, 0, 0)\r
138                                         with-parent-point location with-child-point (0, 0, 0).\r
139 \r
140                 joint set-double-spring with-strength 300 with-max 0.01 with-min -0.01.\r
141 \r
142                 self add-dependency on joint.\r
143                 self add-dependency on sensor.\r
144 \r
145                 sensor set-color to (0, 0, 0).\r
146 \r
147                 #push sensor onto sensors.\r
148 \r
149                 return sensor.\r
150 \r
151         + to destroy:\r
152                 free sensorShape.\r
153                 free wheelShape.\r
154                 free bodyShape.\r
155 \r
156                 super destroy.\r
157 }\r
158 \r
159 CeldasLightVehicle : CeldasVehicle (aka CeldasVehicles) {\r
160         % A heavy duty version of OBJECT(CeldasLightVehicle), this\r
161         % vehicle is heavier and harder to control, but more stable\r
162         % at higher speeds.\r
163         +variables:\r
164                 lSensor, rSensor, fSensor, bSensor (object).\r
165                 lfWheel,rfWheel,lbWheel,rbWheel (object).\r
166                 tleft,tright (int).         \r
167                 avanzando,retrocediendo,girando_izq,girando_der(int).       \r
168                 iterate(int).\r
169                 teorias (list).\r
170                 sa (object).\r
171                 teoria (object).\r
172                 entorno (hash).\r
173                 datos-finales (hash).\r
174                 plan-finished (int).\r
175                 posicion-inicial (vector).\r
176                 posicion-final (vector).\r
177         \r
178         - to get-density:\r
179                 return 20.0.\r
180 \r
181         - to get-wheel-width:\r
182                 return 0.4.\r
183 \r
184         - to get-wheel-radius:\r
185                 return 0.8.\r
186 \r
187         - to near position thePosition (vector) with-error error (float):\r
188                 vectorAux(vector).\r
189                 vectorAux = (self get-location) - thePosition.\r
190 \r
191                 #print "-----> (pos, other_pos, diff, error): ", (self get-location), thePosition, vectorAux, error.\r
192 \r
193                 if ((|vectorAux::x| < error) && (|vectorAux::z| < error)):\r
194                         return 1.\r
195 \r
196                 return 0.\r
197 \r
198         + to set-global-velocity to velocity (float):\r
199                 rfWheel set-velocity to velocity.\r
200                 lfWheel set-velocity to velocity.\r
201                 rbWheel set-velocity to velocity.\r
202                 lbWheel set-velocity to velocity.\r
203 \r
204         + to get-global-velocity:\r
205                 return ((rfWheel get-velocity) + (lfWheel get-velocity)) / 2.\r
206 \r
207         + to turn-right:                \r
208                 #tright++.\r
209                 #self rotate around-axis (0,1,0) by (-1.5709/CELDAS_TURNO)*tright. \r
210                 #if (tright == CELDAS_TURNO): tright=0.\r
211                 if (tright == 0): self set-global-velocity to 0.\r
212                 self rotate around-axis (0,1,0) by (-1.5709/CELDAS_TURNO)*tright. \r
213                 if (tright == CELDAS_TURNO): tright=0.\r
214                 else tright++.\r
215 \r
216 \r
217         + to turn-left:\r
218                 #tleft++.\r
219                 #self rotate around-axis (0,1,0) by (1.5709/CELDAS_TURNO)*tleft. \r
220                 #if (tleft == CELDAS_TURNO): tleft=0.\r
221                 if (tleft == 0): self set-global-velocity to 0.\r
222                 self rotate around-axis (0,1,0) by (1.5709/CELDAS_TURNO)*tleft.\r
223                 if (tleft == CELDAS_TURNO): tleft=0.\r
224                 else tleft++.\r
225 \r
226 \r
227         + to get-sensor-value:\r
228                 return (fSensor get-sensor-value).\r
229 \r
230 \r
231 \r
232         +to update-entorno:\r
233                 entorno{"sensor_f"} = (fSensor get-sensor-value).\r
234                 entorno{"sensor_b"} = (bSensor get-sensor-value).\r
235                 entorno{"sensor_r"} = (rSensor get-sensor-value).\r
236                 entorno{"sensor_l"} = (lSensor get-sensor-value).\r
237                 sa update-entorno with entorno.            \r
238 \r
239         +to init:\r
240                 # Configuracion de robot\r
241                 fSensor = (self add-sensor at (2.0, .4, 0)).            \r
242                 fSensor set-direction to (1,0,0).\r
243                 #fSensor set-direction to (0,0,1).\r
244                 fSensor set-id at 1.\r
245                 fSensor set-body at self.\r
246                 bSensor = (self add-sensor at (-2.0, .4, 0)).\r
247                 bSensor set-direction to (-1,0,0).\r
248                 #bSensor set-direction to (0,0,1).\r
249                 bSensor set-id at 2.\r
250                 bSensor set-body at self.\r
251                 lSensor = (self add-sensor at (0, .4, 1.5)).\r
252                 lSensor set-direction to (0,0,1).\r
253                 #lSensor set-direction to (1,0,0).\r
254                 lSensor set-id at 3.\r
255                 lSensor set-body at self.\r
256 \r
257                 rSensor = (self add-sensor at (0, .4, -1.5)).\r
258                 rSensor set-direction to (0,0,-1).\r
259                 #rSensor set-direction to (-1,0,0).\r
260                 rSensor set-id at 4.\r
261                 rSensor set-body at self.\r
262 \r
263                 lfWheel = (self add-wheel at (2, 0, -1.5)).\r
264                 lbWheel = (self add-wheel at (-2, 0, -1.5)).\r
265                 rfWheel = (self add-wheel at (2, 0, 1.5)).\r
266                 rbWheel = (self add-wheel at (-2, 0, 1.5)).\r
267 \r
268                 tleft=tright=0.\r
269                 avanzando=0.\r
270                 retrocediendo=0.\r
271                 girando_izq=0.            \r
272                 girando_der=0.            \r
273 \r
274                 posicion-inicial = (self get-location).\r
275                 posicion-final = (0, 0, 0).\r
276 \r
277                 # Configuracion de sistema autonomo\r
278                 sa = new SistemaAutonomo.\r
279                 sa init with-max-pasos 4 with-max-teorias 15.\r
280                 iterate = 0.\r
281                 plan-finished = 1. # así planificamos apenas empezamos\r
282 \r
283                 teorias = 4 new Teorias.\r
284                 teorias{0} init named "Avanzar" with-action "adelante".\r
285                 teorias{0} set-dato-inicial name "sensor_f" value 0.\r
286                 teorias{0} set-dato-inicial name "sensor_b" value ANY.\r
287                 teorias{0} set-dato-inicial name "sensor_r" value ANY.\r
288                 teorias{0} set-dato-inicial name "sensor_l" value ANY.\r
289                 teorias{0} set-dato-inicial name "movido" value ANY.\r
290                 teorias{0} set-dato-final name "sensor_f" value ANY.\r
291                 teorias{0} set-dato-final name "sensor_b" value ANY.\r
292                 teorias{0} set-dato-final name "sensor_r" value ANY.\r
293                 teorias{0} set-dato-final name "sensor_l" value ANY.\r
294                 teorias{0} set-dato-final name "movido" value 1.\r
295 \r
296                 teorias{1} init named "Retroceder" with-action "atras" executed 2.\r
297                 teorias{1} set-dato-inicial name "sensor_f" value 1.\r
298                 teorias{1} set-dato-inicial name "sensor_b" value ANY.\r
299                 teorias{1} set-dato-inicial name "sensor_r" value ANY.\r
300                 teorias{1} set-dato-inicial name "sensor_l" value ANY.\r
301                 teorias{1} set-dato-inicial name "movido" value ANY.\r
302                 teorias{1} set-dato-final name "sensor_f" value 0.\r
303                 teorias{1} set-dato-final name "sensor_b" value ANY.\r
304                 teorias{1} set-dato-final name "sensor_r" value ANY.\r
305                 teorias{1} set-dato-final name "sensor_l" value ANY.\r
306                 teorias{1} set-dato-final name "movido" value 1.\r
307 \r
308                 teorias{2} init named "Rotar a derecha" with-action "derecha".\r
309                 teorias{2} set-dato-inicial name "sensor_f" value 1.\r
310                 teorias{2} set-dato-inicial name "sensor_b" value ANY.\r
311                 teorias{2} set-dato-inicial name "sensor_r" value ANY.\r
312                 teorias{2} set-dato-inicial name "sensor_l" value ANY.\r
313                 teorias{2} set-dato-inicial name "movido" value ANY.\r
314                 teorias{2} set-dato-final name "sensor_f" value 0.\r
315                 teorias{2} set-dato-final name "sensor_b" value ANY.\r
316                 teorias{2} set-dato-final name "sensor_r" value ANY.\r
317                 teorias{2} set-dato-final name "sensor_l" value 1.\r
318                 teorias{2} set-dato-final name "movido" value 0.\r
319 \r
320                 teorias{3} init named "Rotar a izquierda" with-action "izquierda" executed 2.\r
321                 teorias{3} set-dato-inicial name "sensor_f" value 1.\r
322                 teorias{3} set-dato-inicial name "sensor_b" value ANY.\r
323                 teorias{3} set-dato-inicial name "sensor_r" value ANY.\r
324                 teorias{3} set-dato-inicial name "sensor_l" value ANY.\r
325                 teorias{3} set-dato-inicial name "movido" value ANY.\r
326                 teorias{3} set-dato-final name "sensor_f" value 0.\r
327                 teorias{3} set-dato-final name "sensor_b" value ANY.\r
328                 teorias{3} set-dato-final name "sensor_r" value 1.\r
329                 teorias{3} set-dato-final name "sensor_l" value ANY.\r
330                 teorias{3} set-dato-final name "movido" value 0.\r
331 \r
332                 sa add teoria teorias{0}.\r
333                 sa add teoria teorias{1}.\r
334                 sa add teoria teorias{2}.\r
335                 sa add teoria teorias{3}.\r
336 \r
337                 datos-finales{"movido"} = 1.\r
338                 sa update-datos-finales with datos-finales.\r
339 \r
340         +to iterate:\r
341 \r
342                 # Actualiza entorno\r
343                 self update-entorno.\r
344 \r
345                 # Chequeo de objetivo\r
346                 if (self near position posicion-final with-error 5.0):\r
347                 {\r
348                         print "Llegamos al FINAL!!!".\r
349                         self set-global-velocity to 0.\r
350                         return.\r
351                 }\r
352 \r
353                 # Planificación\r
354                 if (plan-finished):\r
355                 {\r
356                         # Actualiza entorno indicando que no se movió para que\r
357                         # el planificador actue\r
358                         sa set-entorno value 0 with-name "movido".\r
359                         sa plan. # Si no tenemos plan, lo hacemos\r
360                         plan-finished = 0.\r
361                         iterate = 0.\r
362                         if (! (sa has-next-theory)):\r
363                         {\r
364                                 plan-finished = 1.\r
365                                 print "El planificador no encuentra PLAN!!!".\r
366                                 return.\r
367                         }\r
368                 }\r
369 \r
370                 # Ejecución de teoría\r
371                 if (iterate == 0):\r
372                 {\r
373                         posicion-inicial = (self get-location).\r
374                         if (sa has-next-theory):\r
375                         {\r
376                                 teoria = sa get-next-theory.\r
377                                 if ((teoria get-accion) == "adelante"):\r
378                                 {\r
379                                         avanzando = 1.\r
380                                         retrocediendo = 0.\r
381                                         girando_izq = 0.\r
382                                         girando_der = 0.\r
383                                 }\r
384                                 if ((teoria get-accion) == "atras"):\r
385                                 {\r
386                                         avanzando = 0.\r
387                                         retrocediendo = 1.\r
388                                         girando_izq = 0.\r
389                                         girando_der = 0.\r
390                                 }\r
391                                 if ((teoria get-accion) == "izquierda"):\r
392                                 {\r
393                                         avanzando = 0.\r
394                                         retrocediendo = 0.\r
395                                         girando_izq = 1.\r
396                                         girando_der = 0.\r
397                                 }\r
398                                 if ((teoria get-accion) == "derecha"):\r
399                                 {\r
400                                         avanzando = 0.\r
401                                         retrocediendo = 0.\r
402                                         girando_izq = 0.\r
403                                         girando_der = 1.\r
404                                 }\r
405                         }\r
406                         else\r
407                         {\r
408                                 plan-finished = 1.\r
409                         }\r
410                 }\r
411 \r
412                 # Validación de teoría\r
413                 if (iterate == CELDAS_TURNO):\r
414                 {\r
415                         # Actualiza entorno segun si se movio o no\r
416                         if (self near position posicion-inicial with-error 2.0):\r
417                         {\r
418                                 sa set-entorno value 0 with-name "movido".\r
419                         }\r
420                         else\r
421                         {\r
422                                 sa set-entorno value 1 with-name "movido".\r
423                         }\r
424                         print iterate.\r
425                         if (!(sa validate theory teoria)):\r
426                         {\r
427                                 plan-finished = 1.\r
428                         }\r
429                         iterate = 0.\r
430                 }\r
431                 else\r
432                 {\r
433                         iterate++.\r
434                 }\r
435 \r
436                 # Movimiento del robot\r
437                 if (avanzando):\r
438                         self set-global-velocity to (CELDAS_MAX_VELOCITY).\r
439                 if (retrocediendo):\r
440                         self set-global-velocity to (-CELDAS_MAX_VELOCITY).\r
441                 if (girando_izq):\r
442                         self turn-left.\r
443                 if (girando_der):\r
444                         self turn-right.\r
445 \r
446 }\r
447 \r
448 Stationary : CeldasObstacle (aka CeldasObstacles) {\r
449         % A CeldasObstacle is used in conjunction with OBJECT(CeldasControl)\r
450         % and OBJECT(CeldasVehicle).  It is what the OBJECT(CeldasSensor)\r
451         % objects on the CeldasVehicle detect.\r
452         % <p>\r
453         % There are no special behaviors associated with the walls--they're \r
454         % basically just plain OBJECT(Stationary) objects.\r
455    \r
456         +variables:\r
457             large (float).\r
458             direction (vector). \r
459 \r
460 \r
461         + to init with-size theSize = (10, 3, .1) (vector) with-color theColor = (1, 0, 0) (vector) at-location theLocation = (0, 0, 0) (vector) with-rotation theRotation = [ ( 0, 0, 1 ), ( 0, 1, 0 ), ( 1, 0, 0 ) ] (matrix):                    \r
462                 self init-with-shape shape (new Shape init-with-cube size theSize) color theColor at-location theLocation with-rotation theRotation.\r
463                 large=20.\r
464 \r
465         + to init-with-shape shape theShape (object) color theColor = (1, 0, 0) (vector) at-location theLocation = (0, 0, 0) (vector) with-rotation theRotation = [ ( 1, 0, 0 ), ( 0, 1, 0 ), ( 0, 0, 1 ) ] (matrix):\r
466                 self register with-shape theShape at-location theLocation with-rotation theRotation.\r
467                 self set-color to theColor.\r
468                 \r
469         + to get-large:\r
470             return large.\r
471 \r
472         + to set-direction at theDirection (vector):\r
473             direction=theDirection.\r
474 \r
475         + to get-direction:\r
476             return direction.\r
477 }\r
478 \r
479 Link : CeldasWheel (aka CeldasWheels) {\r
480         % A CeldasWheel is used in conjunction with OBJECT(CeldasVehicle)\r
481         % to build Celdas vehicles.  This class is typically not instantiated\r
482         % manually, since OBJECT(CeldasVehicle) creates one for you when you\r
483         % add a wheel to the vehicle.\r
484 \r
485         + variables:\r
486                 joint (object).\r
487                 velocity (float).\r
488 \r
489         + to init:\r
490                 velocity = 0.\r
491 \r
492         - to set-joint to j (object):\r
493                 % Used internally.\r
494 \r
495                 joint = j.\r
496 \r
497         + section "Configuring the Wheel's Velocity"\r
498 \r
499         + to set-velocity to n (float):\r
500                 % Sets the velocity of this wheel.\r
501 \r
502                 if n > CELDAS_MAX_VELOCITY: n = CELDAS_MAX_VELOCITY.\r
503                 velocity = n.\r
504 \r
505                 joint set-joint-velocity to velocity.\r
506 \r
507         + to get-velocity:\r
508                 % Gets the velocity of this wheel.\r
509                 \r
510                 return velocity.\r
511 \r
512 }\r
513 \r
514 Link : CeldasSensor (aka CeldasSensors) {\r
515         % A CeldasSensor is used in conjunction with OBJECT(CeldasVehicle)\r
516         % to build Celdas vehicles.  This class is typically not instantiated\r
517         % manually, since OBJECT(CeldasVehicle) creates one for you when you\r
518         % add a sensor to the vehicle.\r
519 \r
520         + variables:\r
521                 direction (vector).\r
522                 positiveDirection(vector).\r
523                 sensorAngle (float).\r
524                 value (float).\r
525                 draw (object).\r
526                 body(object).\r
527                 id(int).\r
528 \r
529         + to init :\r
530                 direction = (1,0,1).\r
531                 positiveDirection= (1,0,1).\r
532                 sensorAngle = 1.6.\r
533                 value = 0.0.\r
534                 draw = new Drawing.\r
535                                 \r
536 \r
537   + section "Configuring the Sensor Values"\r
538         + to set-id at n (int):\r
539             id=n.\r
540 \r
541         + to set-body at robotBody(object):\r
542                 body=robotBody.\r
543                 \r
544         + to set-sensor-angle to n (float):\r
545                 % Sets the angle in which this sensor can detect obstacles.  The default\r
546                 % value of 1.6 means that the sensor can see most of everything in\r
547                 % front of it.  Setting the value to be any higher leads to general\r
548                 % wackiness, so I don't suggest it.\r
549 \r
550                 sensorAngle = n.\r
551 \r
552         + to set-direction to n (vector):\r
553                 direction = n.\r
554                 positiveDirection::x=|n::x|.\r
555                 positiveDirection::y=|n::y|.\r
556                 positiveDirection::z=|n::z|.\r
557 \r
558   + section "Getting the Sensor Values"\r
559 \r
560         + to get-sensor-value:\r
561                 % Gets the sensor value. This should be used from post-iterate,\r
562                 % if not, the sensor reading correspond to the previous\r
563                 % iteration.\r
564                 val (float).\r
565 \r
566                 val = self get-data.\r
567                 if (val > CELDAS_SENSOR_THRESHOLD): return 0.\r
568                 else           return 1.\r
569         \r
570         #+ to iterate:\r
571         \r
572         + to get-data:\r
573                 i (object).\r
574                 min,dist (float).\r
575                 v,obs(vector).\r
576                 j (int).\r
577                 des2,des3(int).\r
578                 wallBegin,wallEnd,wallCenter (float).\r
579                 obsLoc (vector).                \r
580                 posObstacle,destiny,yo(vector).\r
581                                              \r
582                 draw clear.\r
583                 value = 0.0.\r
584                 j=0.\r
585                 min=0.\r
586                 foreach i in (all CeldasObstacles): \r
587                         {\r
588                          posObstacle=i get-location.\r
589                          v = (body get-location) - (self get-location ).\r
590                          obsLoc::y=posObstacle::y.\r
591                          \r
592                          if (dot((i get-direction),(1,0,0))):\r
593                           {\r
594                            obsLoc::x=((self get-location)::x + ((posObstacle::z - (self get-location)::z)*v::x/v::z)).\r
595                            obsLoc::z=posObstacle::z.\r
596                           }                             \r
597                           else\r
598                           {\r
599                            obsLoc::z=((self get-location)::z + ((posObstacle::x - (self get-location)::x)*v::z/v::x)).\r
600                            obsLoc::x=posObstacle::x.\r
601                           } \r
602                                                                 \r
603                         #!\r
604                         if(dot((i get-direction),direction)==0):\r
605                                 des1=1.\r
606                         else\r
607                                 des1=0.\r
608                         !#\r
609 \r
610                         des2=0.\r
611                         if(dot(direction,(1,1,1))<0):\r
612                         {                        \r
613                             if((dot((self get-location),positiveDirection))>(dot(obsLoc,positiveDirection))):\r
614                                         des2=1.      \r
615                         }\r
616                         else\r
617                         {\r
618                             if((dot((self get-location),positiveDirection))<(dot(obsLoc,positiveDirection))):\r
619                                         des2=1.         \r
620                         }                       \r
621 \r
622 \r
623                         #Compruebo que el robot este frente a la pared\r
624                         wallCenter=dot((i get-location),(i get-direction)).\r
625                         wallBegin=wallCenter- (i get-large)/2.\r
626                         wallEnd=wallCenter + (i get-large)/2.           \r
627 \r
628                         \r
629                         yo=self get-location.\r
630                         destiny=i get-direction.\r
631 \r
632                                                                                                                 \r
633 \r
634                         if (dot((self get-location),(i get-direction)) > wallBegin) && (dot((self get-location),(i get-direction)) < wallEnd):\r
635                                 des3=1.\r
636                         else\r
637                         {\r
638                                  des3=0.\r
639                                  \r
640                         }                               \r
641                        \r
642                         if ((des2) && (des3)):\r
643                          {                                    \r
644                                 draw clear.\r
645 \r
646                                 dist=|obsLoc - (self get-location)|.\r
647                                 if( (j==0) || (min>dist) ):\r
648                                  {\r
649                                         min=dist.\r
650                                         obs=obsLoc.\r
651                                         j++.\r
652                                         #print "sensor: $id obstaculo: $posObstacle direP: $destiny direS: $direction yo: $yo ".        \r
653                                  }\r
654 \r
655                          }                                              \r
656 \r
657                         \r
658                 } #end for\r
659 \r
660                 if(j!=0):\r
661                         {\r
662                           #Dibujo el laser\r
663                           draw set-color to (1, 0, 0).\r
664                           draw draw-line from (self get-location) to (obs).\r
665                           return min.\r
666                         }\r
667                 \r
668 \r
669                 value = -1.\r
670                 return value.\r
671 \r
672 \r
673 }\r
674                 \r