@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,
+ variables:
joint (object).
- velocity (float).
-
- + to init:
- velocity = 0.
- to set-joint to j (object):
% Used internally.
+ 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).
}
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.
}
--- /dev/null
+@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.
+
+}
+