]> git.llucax.com Git - z.facultad/75.68/celdas.git/blob - trunk/src/breve/Demo-multi-sensor.tz
CTeoria usa strings en vez de char*.
[z.facultad/75.68/celdas.git] / trunk / src / breve / Demo-multi-sensor.tz
1
2 @use CeldasMultiSensor.
3
4 Controller DemoController.
5
6 CeldasControl : DemoController {
7         + variables:
8                 leftWheel, rightWheel (object).
9                 leftSensor, rightSensor (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, 2, 5).
22
23                 leftWheel = (vehicle add-wheel at (-2, 0, -1.5)).
24                 rightWheel = (vehicle add-wheel at (-2, 0, 1.5)).
25                 vehicle add-wheel at (1, 0, 0).
26
27                 leftWheel set-velocity to 15.0.
28                 rightWheel set-velocity to 15.0.
29
30                 leftSensor = (vehicle add-sensor at (2.0, .4, 0)).
31                 rightSensor = (vehicle add-sensor at (2.0, .4, 0)).
32
33         + to post-iterate:
34                 valueL, valueR (float).
35                         
36                 valueL = leftSensor get-sensor-value.
37                 valueR = rightSensor get-sensor-value.
38
39                 if valueL < 2: leftWheel set-velocity to ((leftWheel get-velocity) + 1).
40                 else:          leftWheel set-velocity to ((leftWheel get-velocity) - 1).
41
42                 if valueL < 2: rightWheel set-velocity to ((rightWheel get-velocity) + 1).
43                 else:          rightWheel set-velocity to ((rightWheel get-velocity) - 1).
44
45                 print "leftSensor = $valueL -- rightSensor = $valueR".
46
47 }