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