1 @use PhysicalControl.
\r
8 @define CELDAS_MAX_VELOCITY 30.
\r
10 PhysicalControl : CeldasControl {
\r
11 % This class is used for building simple vehicle
\r
12 % simulations. To create a vehicle simulation,
\r
13 % subclass CeldasControl and use the init method to
\r
14 % create OBJECT(CeldasObstacle) and
\r
15 % OBJECT(CeldasVehicle) objects.
\r
19 floorShape (object).
\r
20 cloudTexture (object).
\r
24 self enable-lighting.
\r
25 #self enable-smooth-drawing.
\r
27 floorShape = new Shape.
\r
28 floorShape init-with-cube size (200, .2, 200).
\r
30 floor = new Stationary.
\r
31 floor register with-shape floorShape at-location (0, 0, 0).
\r
32 #floor catch-shadows.
\r
34 self point-camera at (0, 0, 0) from (3, 3, 24).
\r
36 #self enable-shadows.
\r
37 #self enable-reflections.
\r
39 cloudTexture = (new Image load from "images/clouds.png").
\r
40 self set-background-color to (.4, .6, .9).
\r
41 self set-background-texture-image to cloudTexture.
\r
45 MultiBody : CeldasLightVehicle (aka CeldasLightVehicles) {
\r
46 % This object is used in conjunction with OBJECT(CeldasControl) to
\r
47 % create simple vehicles.
\r
51 wheelShape (object).
\r
52 sensorShape (object).
\r
59 bodyShape = new Shape.
\r
60 bodyShape init-with-cube size (4.0, .75, 3.0).
\r
62 wheelShape = new Shape.
\r
63 wheelShape init-with-polygon-disk radius ( self get-wheel-radius ) sides 20 height ( self get-wheel-width ).
\r
66 sensorShape = new Shape.
\r
67 sensorShape init-with-polygon-cone radius .2 sides 5 height .5.
\r
70 bodyShape set-density to ( self get-density ).
\r
71 bodyLink = new Link.
\r
72 bodyLink set-shape to bodyShape.
\r
73 bodyLink set-mu to -1.0.
\r
74 bodyLink set-eT to .8.
\r
76 self set-root to bodyLink.
\r
78 self move to (0, 0.9, 0).
\r
79 self set-texture-scale to 1.5.
\r
84 - to get-wheel-width:
\r
87 - to get-wheel-radius:
\r
90 + section "Adding Wheels and Sensors to a Vehicle"
\r
92 + to add-wheel at location (vector):
\r
93 % Adds a wheel at location on the vehicle. This method returns
\r
94 % the wheel which is created, a OBJECT(CeldasWheel).
\r
96 wheel, joint (object).
\r
98 wheel = new CeldasWheel.
\r
99 wheel set-shape to wheelShape.
\r
101 joint = new RevoluteJoint.
\r
103 joint set-relative-rotation around-axis (1, 0, 0) by 1.5708.
\r
104 joint link parent bodyLink to-child wheel with-normal (0, 0, 1)
\r
105 with-parent-point location with-child-point (0, 0, 0).
\r
107 wheel set-eT to .8.
\r
108 wheel set-texture to 0.
\r
109 wheel set-joint to joint.
\r
110 joint set-strength-limit to (joint get-strength-hard-limit) / 2.
\r
111 wheel set-color to (.6, .6, .6).
\r
112 wheel set-mu to 100000.
\r
114 self add-dependency on joint.
\r
115 self add-dependency on wheel.
\r
117 push wheel onto wheels.
\r
121 + to add-sensor at location (vector) with-direction direction = (0,1,0)(vector) :
\r
122 % Adds a sensor at location on the vehicle. This method returns
\r
123 % the sensor which is created, a OBJECT(CeldasSensor).
\r
125 sensor, joint (object).
\r
127 sensor = new CeldasSensor.
\r
128 sensor set-direction to direction.
\r
130 sensor set-shape to sensorShape.
\r
132 joint = new RevoluteJoint.
\r
134 joint set-relative-rotation around-axis (0, 0, 1) by -1.57.
\r
135 joint link parent bodyLink to-child sensor with-normal (1, 0, 0)
\r
136 with-parent-point location with-child-point (0, 0, 0).
\r
138 joint set-double-spring with-strength 300 with-max 0.01 with-min -0.01.
\r
140 self add-dependency on joint.
\r
141 self add-dependency on sensor.
\r
143 sensor set-color to (0, 0, 0).
\r
145 #push sensor onto sensors.
\r
157 CeldasLightVehicle : CeldasVehicle (aka CeldasVehicles) {
\r
158 % A heavy duty version of OBJECT(CeldasLightVehicle), this
\r
159 % vehicle is heavier and harder to control, but more stable
\r
160 % at higher speeds.
\r
162 lSensor, rSensor, fSensor, bSensor (object).
\r
163 lfWheel,rfWheel,lbWheel,rbWheel (object).
\r
164 tleft,tright (int).
\r
166 avanzando,retrocediendo,girando(int).
\r
172 - to get-wheel-width:
\r
175 - to get-wheel-radius:
\r
178 + to set-global-velocity to velocity (float):
\r
179 rfWheel set-velocity to velocity.
\r
180 lfWheel set-velocity to velocity.
\r
181 rbWheel set-velocity to velocity.
\r
182 lbWheel set-velocity to velocity.
\r
184 + to get-global-velocity:
\r
185 return ((rfWheel get-velocity) + (lfWheel get-velocity)) / 2.
\r
190 self rotate around-axis (0,1,0) by (-1.5709/10)*tright.
\r
192 if(tright==10): tright=0.
\r
198 self rotate around-axis (0,1,0) by (1.5709/10)*tleft.
\r
200 if(tleft==10): tleft=0.
\r
203 + to get-sensor-value:
\r
204 return (fSensor get-sensor-value).
\r
207 fSensor = (self add-sensor at (2.0, .4, 0)).
\r
208 fSensor set-direction to (1,0,0).
\r
209 #fSensor set-direction to (0,0,1).
\r
210 fSensor set-id at 1.
\r
211 fSensor set-body at self.
\r
212 bSensor = (self add-sensor at (-2.0, .4, 0)).
\r
213 bSensor set-direction to (-1,0,0).
\r
214 #bSensor set-direction to (0,0,1).
\r
215 bSensor set-id at 2.
\r
216 bSensor set-body at self.
\r
217 lSensor = (self add-sensor at (0, .4, 1.5)).
\r
218 lSensor set-direction to (0,0,1).
\r
219 #lSensor set-direction to (1,0,0).
\r
220 lSensor set-id at 3.
\r
221 lSensor set-body at self.
\r
224 rSensor = (self add-sensor at (0, .4, -1.5)).
\r
225 rSensor set-direction to (0,0,-1).
\r
226 #rSensor set-direction to (-1,0,0).
\r
227 rSensor set-id at 4.
\r
228 rSensor set-body at self.
\r
230 lfWheel = (self add-wheel at (2, 0, -1.5)).
\r
231 lbWheel = (self add-wheel at (-2, 0, -1.5)).
\r
232 rfWheel = (self add-wheel at (2, 0, 1.5)).
\r
233 rbWheel = (self add-wheel at (-2, 0, 1.5)).
\r
235 tleft=tright=0. #Debe ser inicializado en 0 esta asi para probar!!!!!!!!!!!!!!!!!!!!!!!!
\r
241 valuef,valueb,valuer,valuel (float).
\r
244 valuef=fSensor get-data.
\r
245 valueb=bSensor get-data.
\r
246 valuel=lSensor get-data.
\r
247 valuer=rSensor get-data.
\r
249 print "senforl: $valuel".
\r
253 self set-global-velocity to (15).
\r
263 self set-global-velocity to (-15).
\r
271 if((tleft) && (valuel>10)):
\r
273 #self set-global-velocity to (0).
\r
283 if((tright) && (valuer>10)):
\r
285 #self set-global-velocity to (0).
\r
297 Stationary : CeldasObstacle (aka CeldasObstacles) {
\r
298 % A CeldasObstacle is used in conjunction with OBJECT(CeldasControl)
\r
299 % and OBJECT(CeldasVehicle). It is what the OBJECT(CeldasSensor)
\r
300 % objects on the CeldasVehicle detect.
\r
302 % There are no special behaviors associated with the walls--they're
\r
303 % basically just plain OBJECT(Stationary) objects.
\r
307 direction (vector).
\r
310 + 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
311 self init-with-shape shape (new Shape init-with-cube size theSize) color theColor at-location theLocation with-rotation theRotation.
\r
314 + 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
315 self register with-shape theShape at-location theLocation with-rotation theRotation.
\r
316 self set-color to theColor.
\r
321 + to set-direction at theDirection (vector):
\r
322 direction=theDirection.
\r
324 + to get-direction:
\r
328 Link : CeldasWheel (aka CeldasWheels) {
\r
329 % A CeldasWheel is used in conjunction with OBJECT(CeldasVehicle)
\r
330 % to build Celdas vehicles. This class is typically not instantiated
\r
331 % manually, since OBJECT(CeldasVehicle) creates one for you when you
\r
332 % add a wheel to the vehicle.
\r
341 - to set-joint to j (object):
\r
346 + section "Configuring the Wheel's Velocity"
\r
348 + to set-velocity to n (float):
\r
349 % Sets the velocity of this wheel.
\r
351 if n > CELDAS_MAX_VELOCITY: n = CELDAS_MAX_VELOCITY.
\r
354 joint set-joint-velocity to velocity.
\r
357 % Gets the velocity of this wheel.
\r
363 Link : CeldasSensor (aka CeldasSensors) {
\r
364 % A CeldasSensor is used in conjunction with OBJECT(CeldasVehicle)
\r
365 % to build Celdas vehicles. This class is typically not instantiated
\r
366 % manually, since OBJECT(CeldasVehicle) creates one for you when you
\r
367 % add a sensor to the vehicle.
\r
370 direction (vector).
\r
371 positiveDirection(vector).
\r
372 sensorAngle (float).
\r
379 direction = (1,0,1).
\r
380 positiveDirection= (1,0,1).
\r
383 draw = new Drawing.
\r
386 + section "Configuring the Sensor Values"
\r
387 + to set-id at n (int):
\r
390 + to set-body at robotBody(object):
\r
393 + to set-sensor-angle to n (float):
\r
394 % Sets the angle in which this sensor can detect obstacles. The default
\r
395 % value of 1.6 means that the sensor can see most of everything in
\r
396 % front of it. Setting the value to be any higher leads to general
\r
397 % wackiness, so I don't suggest it.
\r
401 + to set-direction to n (vector):
\r
403 positiveDirection::x=|n::x|.
\r
404 positiveDirection::y=|n::y|.
\r
405 positiveDirection::z=|n::z|.
\r
407 + section "Getting the Sensor Values"
\r
409 + to get-sensor-value:
\r
410 % Gets the sensor value. This should be used from post-iterate,
\r
411 % if not, the sensor reading correspond to the previous
\r
423 wallBegin,wallEnd,wallCenter (float).
\r
425 toObstacle(vector).
\r
430 posObstacle,destiny,yo(vector).
\r
436 foreach i in (all CeldasObstacles):
\r
438 posObstacle=i get-location.
\r
439 v = (body get-location) - (self get-location ).
\r
440 obsLoc::y=posObstacle::y.
\r
442 if (dot((i get-direction),(1,0,0))):
\r
444 obsLoc::x=((self get-location)::x + ((posObstacle::z - (self get-location)::z)*v::x/v::z)).
\r
445 obsLoc::z=posObstacle::z.
\r
449 obsLoc::z=((self get-location)::z + ((posObstacle::x - (self get-location)::x)*v::z/v::x)).
\r
450 obsLoc::x=posObstacle::x.
\r
454 if(dot((i get-direction),direction)==0):
\r
461 if(dot(direction,(1,1,1))<0):
\r
463 if((dot((self get-location),positiveDirection))>(dot(obsLoc,positiveDirection))):
\r
468 if((dot((self get-location),positiveDirection))<(dot(obsLoc,positiveDirection))):
\r
473 #Compruebo que el robot este frente a la pared
\r
474 wallCenter=dot((i get-location),(i get-direction)).
\r
475 wallBegin=wallCenter- (i get-large)/2.
\r
476 wallEnd=wallCenter + (i get-large)/2.
\r
479 yo=self get-location.
\r
480 destiny=i get-direction.
\r
484 if (dot((self get-location),(i get-direction)) > wallBegin) && (dot((self get-location),(i get-direction)) < wallEnd):
\r
492 if ((des2) && (des3)):
\r
496 dist=|obsLoc - (self get-location)|.
\r
498 if( (j==0) || (min>dist) ):
\r
504 #print "sensor: $id obstaculo: $posObstacle direP: $destiny direS: $direction yo: $yo ".
\r
515 draw set-color to (1, 0, 0).
\r
516 draw draw-line from (self get-location) to (obs).
\r