% at higher speeds.\r
+variables:\r
lSensor, rSensor, fSensor, bSensor (object).\r
- lWheel,rWheel (object).\r
+ lfWheel,rfWheel,lbWheel,rbWheel (object).\r
tleft,tright (int). \r
\r
- \r
+ avanzando,retrocediendo,girando(int). \r
+ \r
+ \r
- to get-density:\r
return 20.0.\r
\r
return 0.8.\r
\r
+ to set-global-velocity to velocity (float):\r
- rWheel set-velocity to velocity.\r
- lWheel set-velocity to velocity.\r
+ rfWheel set-velocity to velocity.\r
+ lfWheel set-velocity to velocity.\r
+ rbWheel set-velocity to velocity.\r
+ lbWheel set-velocity to velocity.\r
\r
+ to get-global-velocity:\r
- return ((rWheel get-velocity) + (lWheel get-velocity)) / 2.\r
+ return ((rfWheel get-velocity) + (lfWheel get-velocity)) / 2.\r
\r
+ to turn-right: \r
tright++.\r
rSensor set-id at 4.\r
rSensor set-body at self.\r
\r
- lWheel = (self add-wheel at (0, 0, -1.5)).\r
- rWheel = (self add-wheel at (0, 0, 1.5)).\r
+ lfWheel = (self add-wheel at (2, 0, -1.5)).\r
+ lbWheel = (self add-wheel at (-2, 0, -1.5)).\r
+ rfWheel = (self add-wheel at (2, 0, 1.5)).\r
+ rbWheel = (self add-wheel at (-2, 0, 1.5)).\r
\r
- tleft=tright=1. #Debe ser inicializado en 0 esta asi para probar!!!!!!!!!!!!!!!!!!!!!!!!\r
- \r
+ tleft=tright=0. #Debe ser inicializado en 0 esta asi para probar!!!!!!!!!!!!!!!!!!!!!!!!\r
+ avanzando=1.\r
+ retrocediendo=0.\r
+ girando=0. \r
+ \r
+to iterate:\r
- #+ to post-iterate:\r
valuef,valueb,valuer,valuel (float).\r
fl, fr(float).\r
\r
valuel=lSensor get-data.\r
valuer=rSensor get-data.\r
\r
- \r
- if(tright>0):\r
- self turn-right.\r
- \r
+ print "senforl: $valuel".\r
\r
+ if(avanzando):\r
+ if(valuef>15):\r
+ self set-global-velocity to (15).\r
+ else \r
+ { \r
+ avanzando=0.\r
+ retrocediendo=1.\r
+ } \r
\r
- #self turn-left with-velocity(20).\r
- #self set-global-velocity to (15).\r
- #if valuef >7: \r
- # self set-global-velocity to (15).\r
- #else if (valuef <=7) && (valuef > 0):\r
- #{ \r
- self set-global-velocity to (0).\r
- #self turn-left with-velocity(2).\r
- #self turn-right with-velocity(2).\r
- #self set-global-velocity to (0).\r
- #}\r
- #print "sensor valuef: $valuef valueb: $valueb".\r
- \r
- #else if value < 0.1: self turn-left with-velocity CELDAS_MAX_TURN_VELOCITY.\r
- #else if value > 10: self set-global-velocity to ((self get-global-velocity) - 1).\r
\r
- #fl = (flWheel get-velocity).\r
- #fr = (frWheel get-velocity).\r
- #print " sensorf: $value sensorb $valueb, fr: $fr, fl: $fl". \r
+ if(retrocediendo):\r
+ if(valueb>15):\r
+ self set-global-velocity to (-15).\r
+ else \r
+ { \r
+ tleft=1.\r
+ retrocediendo=0.\r
+ }\r
+\r
+\r
+ if((tleft) && (valuel>10)): \r
+ {\r
+ #self set-global-velocity to (0).\r
+ self turn-left.\r
+ }\r
+ else\r
+ {\r
+ avanzando=1.\r
+ #tright=1.\r
+ }\r
+\r
+#!\r
+ if((tright) && (valuer>10)): \r
+ {\r
+ #self set-global-velocity to (0).\r
+ self turn-right.\r
+ }\r
+ else\r
+ {\r
+ avanzando=1.\r
+ #tright=1.\r
+ } \r
+!# \r
\r
}\r
\r
des3=0.\r
\r
} \r
-\r
- #aux1=dot((self get-location),(i get-direction)).\r
-\r
- #print "sensor: $id obstaculo: $posObstacle direP: $destiny direS: $direction yo: $yo ".\r
- #print "begin: $wallBegin end: $wallEnd ".\r
- #print "begin: $wallBegin end: $wallEnd".\r
-\r
\r
-\r
- #print "sensor: $id , des1: $des1, des2: $des2, des3: $des3".\r
if ((des2) && (des3)):\r
{ \r
- draw clear. \r
- #print " posObstacle: $posObstacle". \r
- \r
- print "sensor: $id obstaculo: $posObstacle direP: $destiny direS: $direction yo: $yo ".\r
- print "begin: $wallBegin end: $wallEnd ".\r
- \r
+ draw clear. \r
\r
dist=|obsLoc - (self get-location)|.\r
+\r
if( (j==0) || (min>dist) ):\r
{\r
min=dist.\r
obs=obsLoc.\r
+ \r
j++.\r
#print "sensor: $id obstaculo: $posObstacle direP: $destiny direS: $direction yo: $yo ". \r
}\r
#Dibujo el laser\r
draw set-color to (1, 0, 0).\r
draw draw-line from (self get-location) to (obs).\r
- return dist.\r
+ return min.\r
}\r
\r
\r