From c31f28dc627150cda2d49912d408120e7ab8489a Mon Sep 17 00:00:00 2001 From: Leandro Lucarella Date: Fri, 17 Nov 2006 20:09:37 +0000 Subject: [PATCH] Se mejora lectura del sensor y se elimina variable sin demasiada utilidad. --- trunk/src/breve/Celdas.tz | 17 +--- trunk/src/breve/Demo.tz | 14 ++-- trunk/src/breve/Laberinto.tz | 151 +++++++++++++++++++++++++++++++++++ 3 files changed, 160 insertions(+), 22 deletions(-) create mode 100644 trunk/src/breve/Laberinto.tz diff --git a/trunk/src/breve/Celdas.tz b/trunk/src/breve/Celdas.tz index 79b2cc8..b9a63fb 100644 --- a/trunk/src/breve/Celdas.tz +++ b/trunk/src/breve/Celdas.tz @@ -4,8 +4,6 @@ @use Link. @use MultiBody. -@define CELDAS_MAX_VELOCITY 30. - PhysicalControl : CeldasControl { % This class is used for building simple vehicle % simulations. To create a vehicle simulation, @@ -188,10 +186,6 @@ Link : CeldasWheel (aka CeldasWheels) { + variables: joint (object). - velocity (float). - - + to init: - velocity = 0. - to set-joint to j (object): % Used internally. @@ -203,15 +197,12 @@ Link : CeldasWheel (aka CeldasWheels) { + to set-velocity to n (float): % Sets the velocity of this wheel. - if n > CELDAS_MAX_VELOCITY: n = CELDAS_MAX_VELOCITY. - velocity = n. - - joint set-joint-velocity to velocity. + joint set-joint-velocity to n. + to get-velocity: % Gets the velocity of this wheel. - return velocity. + return (joint get-joint-velocity). } @@ -265,9 +256,7 @@ Link : CeldasSensor (aka CeldasSensors) { if angle < sensorAngle: { strength = | (self get-location) - (i get-location) |. - strength = 1.0 / (strength * strength) . - - if strength > 10: strength = 10. + strength = 100.0 / (strength * strength) . if strength > value: value = strength. } diff --git a/trunk/src/breve/Demo.tz b/trunk/src/breve/Demo.tz index 1fe9eb1..7794c3d 100644 --- a/trunk/src/breve/Demo.tz +++ b/trunk/src/breve/Demo.tz @@ -34,14 +34,12 @@ CeldasControl : DemoController { value = sensor get-sensor-value. - if value < 2: { - leftWheel set-velocity to ((leftWheel get-velocity) + 1). - rightWheel set-velocity to ((rightWheel get-velocity) + 1). - } - - if value > 2: { - leftWheel set-velocity to ((leftWheel get-velocity) - 1). - rightWheel set-velocity to ((rightWheel get-velocity) - 1). + if value < 1: { + leftWheel set-velocity to ((leftWheel get-velocity) + 15). + rightWheel set-velocity to ((rightWheel get-velocity) + 15). + } else if value > 10: { + leftWheel set-velocity to ((leftWheel get-velocity) - 15). + rightWheel set-velocity to ((rightWheel get-velocity) - 15). } print value. diff --git a/trunk/src/breve/Laberinto.tz b/trunk/src/breve/Laberinto.tz new file mode 100644 index 0000000..83b5c16 --- /dev/null +++ b/trunk/src/breve/Laberinto.tz @@ -0,0 +1,151 @@ +@use Control. +@use Stationary. +@use Celdas. + +@define altoPared 5. +@define posYPared 25. +@define seccion 20. +@define distanciaTotalX 240. +@define distanciaTotalZ 240. + +Controller myControl. + + +CeldasObstacle : Wall{ + + +to Create to-posX posX = 0 (float) to-posY posY = 2.5 (float) to-posZ posZ = 0 (float) to-widthX widthX = 120(float) to-widthZ widthZ = 5(float): + + self register with-shape (new Cube init-with size (widthX,altoPared,widthZ)) at-location (posX,posY,posZ). + self set-color to (0,1,0). + +} + + +CeldasObstacle : Labyrinth{ + + +to init: + wall (object). + + wall=new Wall. + + #Contorno del laberinto + wall Create to-widthX 11.25*seccion. + wall Create to-posX -5.5*seccion to-widthX 5 to-widthZ 11.25*seccion to-posZ 5.5*seccion . + wall Create to-posX -5.5*seccion to-widthX 5 to-widthZ 11.25*seccion to-posZ 5.5*seccion to-posX 5.5*seccion . + + wall Create to-widthX 5.25*seccion to-posZ 11*seccion to-posX -3*seccion. + wall Create to-widthX 5.25*seccion to-posZ 11*seccion to-posX 3*seccion. + #fin contorno + + #Paredesd verticales (en el diagrama) + wall Create to-widthZ seccion to-widthX 5 to-posZ 10.5*seccion to-posX 0.5*seccion. + wall Create to-widthZ 2*seccion to-widthX 5 to-posZ 10*seccion to-posX -1.5*seccion. + wall Create to-widthZ seccion to-widthX 5 to-posZ 10.5*seccion to-posX -3.5*seccion. + + wall Create to-widthZ 2*seccion to-widthX 5 to-posZ 9*seccion to-posX -0.5*seccion. + wall Create to-widthZ seccion to-widthX 5 to-posZ 9.5*seccion to-posX -4.5*seccion. + wall Create to-widthZ 3*seccion to-widthX 5 to-posZ 8.5*seccion to-posX -2.5*seccion. + wall Create to-widthZ 3*seccion to-widthX 5 to-posZ 8.5*seccion to-posX 3.5*seccion. + + wall Create to-widthZ 5*seccion to-widthX 5 to-posZ 5.5*seccion to-posX -4.5*seccion. + wall Create to-widthZ 6*seccion to-widthX 5 to-posZ 4*seccion to-posX -3.5*seccion. + wall Create to-widthZ 3*seccion to-widthX 5 to-posZ 4.5*seccion to-posX -2.5*seccion. + wall Create to-widthZ 3*seccion to-widthX 5 to-posZ 5.5*seccion to-posX -1.5*seccion. + + wall Create to-widthZ seccion to-widthX 5 to-posZ 2.5*seccion to-posX 0.5*seccion. + wall Create to-widthZ seccion to-widthX 5 to-posZ 1.5*seccion to-posX 1.5*seccion. + wall Create to-widthZ seccion to-widthX 5 to-posZ 4.5*seccion to-posX 1.5*seccion. + wall Create to-widthZ seccion to-widthX 5 to-posZ 6.5*seccion to-posX 1.5*seccion. + + wall Create to-widthZ seccion to-widthX 5 to-posZ 2.5*seccion to-posX -1.5*seccion. + wall Create to-widthZ seccion to-widthX 5 to-posZ 1.5*seccion to-posX -2.5*seccion. + wall Create to-widthZ seccion to-widthX 5 to-posZ 3.5*seccion to-posX -0.5*seccion. + + wall Create to-widthZ seccion to-widthX 5 to-posZ 3.5*seccion to-posX 2.5*seccion. + wall Create to-widthZ 2*seccion to-widthX 5 to-posZ 7*seccion to-posX 2.5*seccion. + wall Create to-widthZ seccion to-widthX 5 to-posZ 4.5*seccion to-posX 3.5*seccion. + + wall Create to-widthZ 6*seccion to-widthX 5 to-posZ 6*seccion to-posX 4.5*seccion. + + #Paredes horizontales (en el diagrama) + wall Create to-widthZ 5 to-widthX 2.25*seccion to-posZ 10*seccion to-posX 1.5*seccion. #1 + wall Create to-widthZ 5 to-widthX 2.25*seccion to-posZ 10*seccion to-posX 4.5*seccion. #2 + + wall Create to-widthZ 5 to-widthX 2.25*seccion to-posZ 9*seccion to-posX -3.5*seccion. #3 + wall Create to-widthZ 5 to-widthX 1.25*seccion to-posZ 8*seccion to-posX -4*seccion. #4 + wall Create to-widthZ 5 to-widthX 5.25*seccion to-posZ 8*seccion to-posX 0. #5 + + wall Create to-widthZ 5 to-widthX 3*seccion to-posZ 9*seccion to-posX 2*seccion. #6 + + wall Create to-widthZ 5 to-widthX 1.25*seccion to-posZ 7*seccion to-posX -3*seccion. #7 + wall Create to-widthZ 5 to-widthX 3.25*seccion to-posZ 7*seccion to-posX 0. #8 + wall Create to-widthZ 5 to-widthX 2.25*seccion to-posZ 6*seccion to-posX 3.5*seccion. #9 + wall Create to-widthZ 5 to-widthX 1.25*seccion to-posZ 6*seccion to-posX -2*seccion. #10 + + wall Create to-widthZ 5 to-widthX 3.25*seccion to-posZ 4*seccion to-posX 0. #11 + wall Create to-widthZ 5 to-widthX 2.25*seccion to-posZ 5*seccion to-posX 2.5*seccion. #12 + + wall Create to-widthZ 5 to-widthX 1.25*seccion to-posZ 3*seccion to-posX -4*seccion. #13 + wall Create to-widthZ 5 to-widthX 1.25*seccion to-posZ 3*seccion to-posX -2*seccion. #14 + wall Create to-widthZ 5 to-widthX 4.25*seccion to-posZ 3*seccion to-posX 2.5*seccion. #15 + #wall Create to-widthZ 5 to-widthX 4*seccion to-posZ 3*seccion to-posX 2.5*seccion. #15 + + wall Create to-widthZ 5 to-widthX seccion to-posZ 2*seccion to-posX -5*seccion. #16 + wall Create to-widthZ 5 to-widthX 2.25*seccion to-posZ 2*seccion to-posX -0.5*seccion. #17 + wall Create to-widthZ 5 to-widthX 4.25*seccion to-posZ 2*seccion to-posX 3.5*seccion. #18 + + wall Create to-widthZ 5 to-widthX 9*seccion to-posZ 1*seccion to-posX 0. #19 + + #push wall onto walls. +} + + +Control: myControl{ ++ variables: + labe(object). + sensor (object). + leftWheel, rightWheel (object). + vehicle (object). + ++ to init: + self point-camera at (0,0,0) from (200,200,200). + new Floor. + + labe = new Labyrinth. + vehicle = new CeldasVehicle. + self watch item vehicle. + + vehicle move to (0, 0, 10). + + leftWheel = (vehicle add-wheel at (-2, 0, -1.5)). + rightWheel = (vehicle add-wheel at (-2, 0, 1.5)). + vehicle add-wheel at (1, 0, 0). + + leftWheel set-velocity to 50.0. + rightWheel set-velocity to 50.0. + + sensor = (vehicle add-sensor at (2.0, .4, 0)). + + ++to iterate: + super iterate. + ++ to post-iterate: + value (float). + + value = sensor get-sensor-value. + + if value < 2: { + leftWheel set-velocity to ((leftWheel get-velocity) + 1). + rightWheel set-velocity to ((rightWheel get-velocity) + 1). + } + + if value > 2: { + leftWheel set-velocity to ((leftWheel get-velocity) - 1). + rightWheel set-velocity to ((rightWheel get-velocity) - 1). + } + + #print value. + +} + -- 2.43.0