]> git.llucax.com Git - z.facultad/75.68/celdas.git/blob - trunk/src/breve/Demo-2wheels.tz
Agrega heurística de generalización hecha por Daniel.
[z.facultad/75.68/celdas.git] / trunk / src / breve / Demo-2wheels.tz
1
2 @use Celdas.
3
4 Controller DemoController.
5
6 CeldasControl : DemoController {
7         + variables:
8                 sensor (object).
9                 blWheel, brWheel (object).
10                 vehicle (object).
11
12                 n (int).
13
14         + to init:
15                 for n=0, n<10, n++:
16                         new CeldasObstacle init at-location (20 * sin(n * 6.28 / 10), 1, 20 * cos(n * 6.28 / 10)).
17
18                 vehicle = new CeldasVehicle.
19                 self watch item vehicle.
20
21                 vehicle move to (10, 0.8, 5).
22
23                 blWheel = (vehicle add-wheel at (0, 0, -1.5)).
24                 brWheel = (vehicle add-wheel at (0, 0, 1.5)).
25
26                 self set-global-velocity to 15.0.
27
28                 sensor = (vehicle add-sensor at (2.0, .4, 0)).
29
30         + to set-global-velocity to velocity (float):
31
32                 brWheel set-velocity to velocity.
33                 blWheel set-velocity to velocity.
34
35         + to get-global-velocity:
36
37                 return ((brWheel get-velocity) 
38                         + (blWheel get-velocity)) / 2.
39
40         + to turn-right with-velocity velocity (float):
41
42                 brWheel set-velocity to velocity.
43                 blWheel set-velocity to -velocity.
44
45         + to turn-left with-velocity velocity (float):
46
47                 blWheel set-velocity to velocity.
48                 brWheel set-velocity to -velocity.
49
50         + to get-sensor-value:
51
52                 return (sensor get-sensor-value).
53
54
55         + to post-iterate:
56                 value (float).
57                 bl, br (float).
58                         
59                 value = self get-sensor-value.
60
61                 if value < 1:       self set-global-velocity to ((self get-global-velocity) + 1).
62                 else if value > 5: self turn-right with-velocity 15.0.
63                 #else if value > 10: self set-global-velocity to ((self get-global-velocity) - 1).
64
65                 bl = (blWheel get-velocity).
66                 br = (brWheel get-velocity).
67                 print "sensor: $value, br: $br, bl: $bl".
68
69 }