]> git.llucax.com Git - z.facultad/75.68/celdas.git/blob - trunk/src/breve/Demo-4wheels.tz
(no commit message)
[z.facultad/75.68/celdas.git] / trunk / src / breve / Demo-4wheels.tz
1
2 @use Celdas.
3
4 Controller DemoController.
5
6 CeldasControl : DemoController {
7         + variables:
8                 sensor (object).
9                 flWheel, frWheel, 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                 flWheel = (vehicle add-wheel at (2, 0, -1.5)).
24                 frWheel = (vehicle add-wheel at (2, 0, 1.5)).
25                 blWheel = (vehicle add-wheel at (-2, 0, -1.5)).
26                 brWheel = (vehicle add-wheel at (-2, 0, 1.5)).
27
28                 self set-global-velocity to 15.0.
29
30                 sensor = (vehicle add-sensor at (2.0, .4, 0)).
31
32         + to set-global-velocity to velocity (float):
33
34                 brWheel set-velocity to velocity.
35                 frWheel set-velocity to velocity.
36                 blWheel set-velocity to velocity.
37                 flWheel set-velocity to velocity.
38
39         + to get-global-velocity:
40
41                 return ((brWheel get-velocity) + (frWheel get-velocity)
42                         + (blWheel get-velocity) + (flWheel set-velocity)) / 4.
43
44         + to turn-right with-velocity velocity (float):
45
46                 brWheel set-velocity to velocity.
47                 frWheel set-velocity to velocity.
48                 blWheel set-velocity to -velocity.
49                 flWheel set-velocity to -velocity.
50
51         + to turn-left with-velocity velocity (float):
52
53                 blWheel set-velocity to velocity.
54                 flWheel set-velocity to velocity.
55                 brWheel set-velocity to -velocity.
56                 frWheel set-velocity to -velocity.
57
58         + to get-sensor-value:
59
60                 return (sensor get-sensor-value).
61
62
63         + to post-iterate:
64                 value (float).
65                 fl, fr, bl, br (float).
66                         
67                 value = self get-sensor-value.
68
69                 if value < 1:       self set-global-velocity to ((self get-global-velocity) + 1).
70                 else if value > 5: self turn-right with-velocity 15.0.
71                 #else if value > 10: self set-global-velocity to ((self get-global-velocity) - 1).
72
73                 fl = (flWheel get-velocity).
74                 bl = (blWheel get-velocity).
75                 fr = (frWheel get-velocity).
76                 br = (brWheel get-velocity).
77                 print "sensor: $value, fr: $fr, fl: $fl, br: $br, bl: $bl".
78
79 }