4 Controller DemoController.
6 CeldasVehicle : MyVehicle {
10 flWheel, frWheel, blWheel, brWheel (object).
12 + to init at location = (0, 0, 0) (vector):
14 self move to location.
16 blWheel = (self add-wheel at (2, 0, -1.5)).
17 brWheel = (self add-wheel at (2, 0, 1.5)).
18 blWheel = (self add-wheel at (-2, 0, -1.5)).
19 brWheel = (self add-wheel at (-2, 0, 1.5)).
21 #blWheel set-velocity to 15.0.
22 #brWheel set-velocity to 15.0.
24 sensor = (self add-sensor at (2.0, .4, 0)).
26 + to set-global-velocity to velocity (float):
28 brWheel set-velocity to velocity.
29 frWheel set-velocity to velocity.
30 blWheel set-velocity to velocity.
31 flWheel set-velocity to velocity.
33 + to get-global-velocity:
35 return ((brWheel get-velocity) + (frWheel get-velocity)
36 + (blWheel get-velocity) + (flWheel set-velocity)) / 4.
38 + to turn-right with-velocity velocity (float):
40 brWheel set-velocity to velocity.
41 frWheel set-velocity to velocity.
42 blWheel set-velocity to -velocity.
43 flWheel set-velocity to -velocity.
45 + to turn-left with-velocity velocity (float):
47 blWheel set-velocity to velocity.
48 flWheel set-velocity to velocity.
49 brWheel set-velocity to -velocity.
50 frWheel set-velocity to -velocity.
52 + to get-sensor-value:
54 return (sensor get-sensor-value).
58 CeldasControl : DemoController {
66 new CeldasObstacle init at-location (20 * sin(n * 6.28 / 10), 1, 20 * cos(n * 6.28 / 10)).
68 vehicle = new MyVehicle.
69 self watch item vehicle.
74 value = vehicle get-sensor-value.
76 if value < 1: vehicle set-global-velocity to ((vehicle get-global-velocity) + 1).
77 else if value > 10: vehicle set-global-velocity to ((vehicle get-global-velocity) - 1).