From: Leandro Lucarella Date: Fri, 24 Nov 2006 05:18:45 +0000 (+0000) Subject: Distintos modelos de robots con los que estuve jugando. El Ășnico que parece X-Git-Tag: entrega-20061218~57 X-Git-Url: https://git.llucax.com/z.facultad/75.68/celdas.git/commitdiff_plain/2b4efb3e1f71dee7a3854f5a76e17d8edaf2316d?ds=sidebyside Distintos modelos de robots con los que estuve jugando. El Ășnico que parece andar respetablemente bien es el Demo-4wheels.tz. --- diff --git a/trunk/src/breve/Demo-2wheels.tz b/trunk/src/breve/Demo-2wheels.tz new file mode 100644 index 0000000..4c4c45b --- /dev/null +++ b/trunk/src/breve/Demo-2wheels.tz @@ -0,0 +1,69 @@ + +@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". + +} diff --git a/trunk/src/breve/Demo-4wheels.tz b/trunk/src/breve/Demo-4wheels.tz new file mode 100644 index 0000000..943de3b --- /dev/null +++ b/trunk/src/breve/Demo-4wheels.tz @@ -0,0 +1,79 @@ + +@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". + +} diff --git a/trunk/src/breve/Demo-myvehicle-4wheels.tz b/trunk/src/breve/Demo-myvehicle-4wheels.tz new file mode 100644 index 0000000..865681b --- /dev/null +++ b/trunk/src/breve/Demo-myvehicle-4wheels.tz @@ -0,0 +1,81 @@ + +@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. + +}