andar respetablemente bien es el Demo-4wheels.tz.
--- /dev/null
+
+@use Celdas.
+
+Controller DemoController.
+
+CeldasControl : DemoController {
+ + variables:
+ sensor (object).
+ blWheel, brWheel (object).
+ vehicle (object).
+
+ n (int).
+
+ + to init:
+ for n=0, n<10, n++:
+ new CeldasObstacle init at-location (20 * sin(n * 6.28 / 10), 1, 20 * cos(n * 6.28 / 10)).
+
+ vehicle = new CeldasVehicle.
+ self watch item vehicle.
+
+ vehicle move to (10, 0.8, 5).
+
+ blWheel = (vehicle add-wheel at (0, 0, -1.5)).
+ brWheel = (vehicle add-wheel at (0, 0, 1.5)).
+
+ self set-global-velocity to 15.0.
+
+ sensor = (vehicle add-sensor at (2.0, .4, 0)).
+
+ + to set-global-velocity to velocity (float):
+
+ brWheel set-velocity to velocity.
+ blWheel set-velocity to velocity.
+
+ + to get-global-velocity:
+
+ return ((brWheel get-velocity)
+ + (blWheel get-velocity)) / 2.
+
+ + to turn-right with-velocity velocity (float):
+
+ brWheel set-velocity to velocity.
+ blWheel set-velocity to -velocity.
+
+ + to turn-left with-velocity velocity (float):
+
+ blWheel set-velocity to velocity.
+ brWheel set-velocity to -velocity.
+
+ + to get-sensor-value:
+
+ return (sensor get-sensor-value).
+
+
+ + to post-iterate:
+ value (float).
+ bl, br (float).
+
+ value = self get-sensor-value.
+
+ if value < 1: self set-global-velocity to ((self get-global-velocity) + 1).
+ else if value > 5: self turn-right with-velocity 15.0.
+ #else if value > 10: self set-global-velocity to ((self get-global-velocity) - 1).
+
+ bl = (blWheel get-velocity).
+ br = (brWheel get-velocity).
+ print "sensor: $value, br: $br, bl: $bl".
+
+}
--- /dev/null
+
+@use Celdas.
+
+Controller DemoController.
+
+CeldasControl : DemoController {
+ + variables:
+ sensor (object).
+ flWheel, frWheel, blWheel, brWheel (object).
+ vehicle (object).
+
+ n (int).
+
+ + to init:
+ for n=0, n<10, n++:
+ new CeldasObstacle init at-location (20 * sin(n * 6.28 / 10), 1, 20 * cos(n * 6.28 / 10)).
+
+ vehicle = new CeldasVehicle.
+ self watch item vehicle.
+
+ vehicle move to (10, 0.8, 5).
+
+ flWheel = (vehicle add-wheel at (2, 0, -1.5)).
+ frWheel = (vehicle add-wheel at (2, 0, 1.5)).
+ blWheel = (vehicle add-wheel at (-2, 0, -1.5)).
+ brWheel = (vehicle add-wheel at (-2, 0, 1.5)).
+
+ self set-global-velocity to 15.0.
+
+ sensor = (vehicle add-sensor at (2.0, .4, 0)).
+
+ + to set-global-velocity to velocity (float):
+
+ brWheel set-velocity to velocity.
+ frWheel set-velocity to velocity.
+ blWheel set-velocity to velocity.
+ flWheel set-velocity to velocity.
+
+ + to get-global-velocity:
+
+ return ((brWheel get-velocity) + (frWheel get-velocity)
+ + (blWheel get-velocity) + (flWheel set-velocity)) / 4.
+
+ + to turn-right with-velocity velocity (float):
+
+ brWheel set-velocity to velocity.
+ frWheel set-velocity to velocity.
+ blWheel set-velocity to -velocity.
+ flWheel set-velocity to -velocity.
+
+ + to turn-left with-velocity velocity (float):
+
+ blWheel set-velocity to velocity.
+ flWheel set-velocity to velocity.
+ brWheel set-velocity to -velocity.
+ frWheel set-velocity to -velocity.
+
+ + to get-sensor-value:
+
+ return (sensor get-sensor-value).
+
+
+ + to post-iterate:
+ value (float).
+ fl, fr, bl, br (float).
+
+ value = self get-sensor-value.
+
+ if value < 1: self set-global-velocity to ((self get-global-velocity) + 1).
+ else if value > 5: self turn-right with-velocity 15.0.
+ #else if value > 10: self set-global-velocity to ((self get-global-velocity) - 1).
+
+ fl = (flWheel get-velocity).
+ bl = (blWheel get-velocity).
+ fr = (frWheel get-velocity).
+ br = (brWheel get-velocity).
+ print "sensor: $value, fr: $fr, fl: $fl, br: $br, bl: $bl".
+
+}
--- /dev/null
+
+@use Celdas.
+
+Controller DemoController.
+
+CeldasVehicle : MyVehicle {
+
+ + variables:
+ sensor (object).
+ flWheel, frWheel, blWheel, brWheel (object).
+
+ + to init at location = (0, 0, 0) (vector):
+
+ self move to location.
+
+ blWheel = (self add-wheel at (2, 0, -1.5)).
+ brWheel = (self add-wheel at (2, 0, 1.5)).
+ blWheel = (self add-wheel at (-2, 0, -1.5)).
+ brWheel = (self add-wheel at (-2, 0, 1.5)).
+
+ #blWheel set-velocity to 15.0.
+ #brWheel set-velocity to 15.0.
+
+ sensor = (self add-sensor at (2.0, .4, 0)).
+
+ + to set-global-velocity to velocity (float):
+
+ brWheel set-velocity to velocity.
+ frWheel set-velocity to velocity.
+ blWheel set-velocity to velocity.
+ flWheel set-velocity to velocity.
+
+ + to get-global-velocity:
+
+ return ((brWheel get-velocity) + (frWheel get-velocity)
+ + (blWheel get-velocity) + (flWheel set-velocity)) / 4.
+
+ + to turn-right with-velocity velocity (float):
+
+ brWheel set-velocity to velocity.
+ frWheel set-velocity to velocity.
+ blWheel set-velocity to -velocity.
+ flWheel set-velocity to -velocity.
+
+ + to turn-left with-velocity velocity (float):
+
+ blWheel set-velocity to velocity.
+ flWheel set-velocity to velocity.
+ brWheel set-velocity to -velocity.
+ frWheel set-velocity to -velocity.
+
+ + to get-sensor-value:
+
+ return (sensor get-sensor-value).
+
+}
+
+CeldasControl : DemoController {
+ + variables:
+ vehicle (object).
+
+ n (int).
+
+ + to init:
+ for n=0, n<10, n++:
+ new CeldasObstacle init at-location (20 * sin(n * 6.28 / 10), 1, 20 * cos(n * 6.28 / 10)).
+
+ vehicle = new MyVehicle.
+ self watch item vehicle.
+
+ + to post-iterate:
+ value (float).
+
+ value = vehicle get-sensor-value.
+
+ if value < 1: vehicle set-global-velocity to ((vehicle get-global-velocity) + 1).
+ else if value > 10: vehicle set-global-velocity to ((vehicle get-global-velocity) - 1).
+
+ print value.
+
+}