4 Controller DemoController.
6 CeldasControl : DemoController {
9 flWheel, frWheel, blWheel, brWheel (object).
16 new CeldasObstacle init at-location (20 * sin(n * 6.28 / 10), 1, 20 * cos(n * 6.28 / 10)).
18 vehicle = new CeldasVehicle.
19 self watch item vehicle.
21 vehicle move to (10, 0.8, 5).
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)).
28 self set-global-velocity to 15.0.
30 sensor = (vehicle add-sensor at (2.0, .4, 0)).
32 + to set-global-velocity to velocity (float):
34 brWheel set-velocity to velocity.
35 frWheel set-velocity to velocity.
36 blWheel set-velocity to velocity.
37 flWheel set-velocity to velocity.
39 + to get-global-velocity:
41 return ((brWheel get-velocity) + (frWheel get-velocity)
42 + (blWheel get-velocity) + (flWheel set-velocity)) / 4.
44 + to turn-right with-velocity velocity (float):
46 brWheel set-velocity to velocity.
47 frWheel set-velocity to velocity.
48 blWheel set-velocity to -velocity.
49 flWheel set-velocity to -velocity.
51 + to turn-left with-velocity velocity (float):
53 blWheel set-velocity to velocity.
54 flWheel set-velocity to velocity.
55 brWheel set-velocity to -velocity.
56 frWheel set-velocity to -velocity.
58 + to get-sensor-value:
60 return (sensor get-sensor-value).
65 fl, fr, bl, br (float).
67 value = self get-sensor-value.
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).
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".