Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

Enki.h

Go to the documentation of this file.
00001 /*
00002 Teem - an open source evolutionary software framework
00003 http://lis.epfl.ch/resources/Teem
00004 Stephane Magnenat <stephane.magnenat@epfl.ch>,
00005 Antoine Beyeler <antoine.beyeler@epfl.ch>,
00006 and other contributors. See AUTHORS for details
00007 Laboratory of Intelligent Systems, EPFL, Lausanne
00008 
00009 This program is free software; you can redistribute it and/or modify
00010 it under the terms of the GNU General Public License as published by
00011 the Free Software Foundation; either version 2 of the License, or
00012 (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00022 */
00023 
00024 #ifndef __TEEM_ENKI_H
00025 #define __TEEM_ENKI_H
00026 
00027 #include <ishtar/settings.h>
00028 #include <an/Geometry.h>
00029 #include <an/Random.h>
00030 
00031 #include "World.h"
00032 #include "Entity.h"
00033 #include "../enkiviewer/EnkiViewer.h"
00034 #include "../utils/Registrar.h"
00035 
00040 namespace Enki
00041 {
00042     class World;
00043     class Alice;
00044     class PhysicalObject;
00045     class FeedableSbot;
00046     class SbotActiveObject;
00047     class Khepera;
00048 }
00049 
00050 namespace Teem
00051 {
00052     class EnkiSbot;
00053     class EnkiSbotActiveObject;
00054     class EnkiKhepera;
00055     class EnkiAlice;
00056     class EnkiAliceSmallDisk;
00057     class EnkiAliceLargeDisk;
00058     class EnkiRectangularBlock;
00059     class EnkiRealisticConditions;
00060     #ifndef HAVE_VIEWER
00061     class EnkiViewer;
00062     #endif
00063 
00066     class EnkiRealisticConditions
00067     {
00068     public:
00069         double motorInstantNoise(); 
00070         double motorCoeff(); 
00071         double camNoise(); 
00072         bool   camBadPixel(); 
00073 
00074     protected:
00075         friend class EnkiWorld;
00077         EnkiRealisticConditions();
00079         ~EnkiRealisticConditions();
00080 
00081         Ishtar::Variable<double> motorInstantNoiseMean; 
00082         Ishtar::Variable<double> motorInstantNoiseStd; 
00083         Ishtar::Variable<double> motorCoeffRange; 
00084         Ishtar::Variable<double> camNoiseMean; 
00085         Ishtar::Variable<double> camNoiseStd; 
00086         Ishtar::Variable<double> camProbBadPixel; 
00087 
00088         An::UniformRand motorCoeffGenerator; 
00089     };
00090 
00091 
00094     class EnkiWorld : public SquareArenaWorld, public SbotCreator, public SbotActiveObjectCreator, public KheperaCreator, public AliceCreator, public AliceSmallDiskCreator, public AliceLargeDiskCreator, public RectangularBlockCreator
00095     {
00096     protected:
00097         friend class EnkiKhepera;
00098         friend class EnkiAlice;
00099         friend class EnkiAliceSmallDisk;
00100         friend class EnkiAliceLargeDisk;
00101         friend class EnkiSbot;
00102         friend class EnkiSbotActiveObject;
00103         friend class EnkiRectangularBlock;
00104 
00105         Enki::World *world; 
00106         EnkiViewer *viewer; 
00107         Ishtar::VariablesPublisher ishtarPublisher; 
00108         Ishtar::Variable<unsigned, true, 2> dimension; 
00109         Ishtar::Variable<unsigned> useVideo; 
00110         Ishtar::ArrayHelper objectsArrayHelper; 
00111         Ishtar::Variable<bool> realisticMode; 
00112         std::vector<Entity *> autoCreatedEntities; 
00113         EnkiRealisticConditions realisticConditions; 
00114 
00115     public:
00117         EnkiWorld(bool createEnkiViewer = true);
00119         virtual ~EnkiWorld();
00120 
00121         // hack to create viewer
00122         #ifdef HAVE_VIEWER
00123 
00124         template<class ViewerT>
00125         void createViewer() { viewer = new ViewerT(world, useVideo != 0); viewer->startRecordingVideo("enki.avi"); }
00127         template<class ViewerT, class T1>
00128         void createViewer(T1 p1) { viewer = new ViewerT(world, useVideo != 0, p1); viewer->startRecordingVideo("enki.avi"); }
00129         #endif
00130 
00132         virtual Sbot *createSbot();
00134         virtual SbotActiveObject *createSbotActiveObject();
00136         virtual Khepera *createKhepera();
00138         virtual Alice *createAlice();
00140         virtual AliceLargeDisk *createAliceLargeDisk();
00142         virtual AliceSmallDisk *createAliceSmallDisk();
00144         virtual RectangularBlock *createRectangularBlock();
00145 
00146         // implementation of World
00147         virtual void step(double dt);
00148 
00149         // implementation of SquareArenaWorld
00150         virtual An::Point getDimension();
00151         virtual void setWallTextures(const std::valarray<An::Texture> &textures);
00152 
00153         // ! Use new noises conditions.
00154         virtual void useWalls(bool use);
00155 
00157         Enki::World *getEnkiInstance() { return world; }
00158     };
00159 
00162     template<typename T>
00163     class EnkiPositionable : virtual public Positionable
00164     {
00165     public:
00166         T *object; 
00167 
00168     public:
00169         // implementation of Positionable
00170         virtual void setOrientation(double angle) {  object->angle = angle; }
00171         virtual void setPosition(const An::Point &pos) { object->pos = pos; }
00172         virtual const An::Point &getPosition(void) { return object->pos; }
00173         virtual double getOrientation(void) { return object->angle; }
00174 
00176         T *getEnkiInstance(void) { return object; }
00177     };
00178 
00181     class EnkiKhepera : public EnkiPositionable<Enki::Khepera>, public Khepera
00182     {
00183     private:
00184         friend class EnkiWorld;
00185         friend class Registrar<Entity, std::string, EnkiWorld *, std::string>;
00186         EnkiWorld *world; 
00187         Ishtar::VariablesPublisher ishtarPublisher; 
00188 
00190         EnkiKhepera(EnkiWorld *world, const std::string &root);
00191 
00192     public:
00194         virtual ~EnkiKhepera();
00195 
00196         // implementation of DifferentialWheeled
00197         virtual void setSpeed(double left, double right);
00198         virtual void getEncoders(double &left, double &right);
00199 
00200         // implementation of IREquipped
00201         virtual double getIRSensor(unsigned index);
00202 
00203         // implementation of CircularCameraEquipped
00204         virtual An::Color getCameraPixel(unsigned index);
00205         virtual unsigned getCameraSize();
00206 
00207         // reimplementation of EnkiPositionable to reset encoders
00208         virtual void setPosition(const An::Point &pos);
00209     };
00210 
00213     class EnkiAlice : public EnkiPositionable<Enki::Alice>, public Alice
00214     {
00215     private:
00216         friend class EnkiWorld;
00217         friend class Registrar<Entity, std::string, EnkiWorld *, std::string>;
00218         EnkiWorld *world; 
00219         Ishtar::VariablesPublisher ishtarPublisher; 
00220         
00222         EnkiAlice(EnkiWorld *world, const std::string &root);
00223 
00224     public:
00226         virtual ~EnkiAlice();
00227 
00228         // implementation of DifferentialWheeled
00229         virtual void setSpeed(double left, double right);
00230 
00231         // implementation of IRSensorEquipped
00232         virtual double getIRSensor(unsigned index);
00233 
00234         // implementation of Alice
00235         virtual void setTransmitValue(unsigned val);
00236         virtual void setTransmit(bool enabled);
00237         virtual bool wasCommunication(void);
00238         virtual unsigned getSensorId(void);
00239         virtual unsigned getSensorValue(void);
00240         virtual void getSpeed(double &left, double &right);
00241 
00242         // implementation of Camera1DEquipped
00243         virtual An::Color getCameraPixel(unsigned index);
00244         virtual unsigned getCameraSize();
00245     };
00246 
00249     class EnkiAliceSmallDisk : public EnkiPositionable<Enki::PhysicalObject>, public AliceSmallDisk
00250     {
00251     private:
00252         friend class EnkiWorld;
00253         friend class Registrar<Entity, std::string, EnkiWorld *, std::string>;
00254         EnkiWorld *world; 
00255         Ishtar::VariablesPublisher ishtarPublisher; 
00256 
00258         EnkiAliceSmallDisk(EnkiWorld *world, const std::string &root);
00259 
00260     public:
00262         virtual ~EnkiAliceSmallDisk();
00263     };
00264 
00267     class EnkiAliceLargeDisk : public EnkiPositionable<Enki::PhysicalObject>, public AliceLargeDisk
00268     {
00269     private:
00270         friend class EnkiWorld;
00271         friend class Registrar<Entity, std::string, EnkiWorld *, std::string>;
00272         EnkiWorld *world; 
00273         Ishtar::VariablesPublisher ishtarPublisher; 
00274 
00276         EnkiAliceLargeDisk(EnkiWorld *world, const std::string &root);
00277 
00278     public:
00280         virtual ~EnkiAliceLargeDisk();
00281     };
00282 
00283 
00286     class EnkiSbot : public EnkiPositionable<Enki::FeedableSbot>, public Sbot
00287     {
00288     private:
00289         friend class EnkiWorld;
00290         friend class Registrar<Entity, std::string, EnkiWorld *, std::string>;
00291         EnkiWorld *world; 
00292         Ishtar::VariablesPublisher ishtarPublisher; 
00293 
00295         static Ishtar::Variable<bool>* realistic;
00296 
00298         EnkiSbot(EnkiWorld *world, const std::string &root);
00299 
00300     public:
00302         virtual ~EnkiSbot();
00303 
00304         // implementation of DifferentialWheeled
00305         virtual void setSpeed(double left, double right);
00306 
00307         // implementation of Sbot
00308         virtual void getCameraAverage(An::Color meanPixels[8]);
00309         virtual void getCamera(An::Color meanPixels[128]);
00310         virtual void setRingColor(const An::Color &color);
00311         virtual void clearEnergy(void);
00312         virtual void setEnergy(double energy);
00313         virtual double getEnergy(void);
00314         virtual double getDEnergy(void);
00315         virtual void setFrequencies(unsigned frequencies);
00316         virtual unsigned getFrequencies(void);
00318         virtual void randomizeRealisticConditions(void);
00319 
00320     protected:
00321         double motorCoeffL; 
00322         double motorCoeffR; 
00323     };
00324 
00327     class EnkiSbotActiveObject : public EnkiPositionable<Enki::SbotActiveObject>, public SbotActiveObject
00328     {
00329     private:
00330         friend class EnkiWorld;
00331         friend class Registrar<Entity, std::string, EnkiWorld *, std::string>;
00332         EnkiWorld *world; 
00333         Ishtar::VariablesPublisher ishtarPublisher; 
00334 
00335         EnkiSbotActiveObject(EnkiWorld *world, const std::string &root);
00336 
00337     public:
00339         virtual ~EnkiSbotActiveObject();
00340 
00341         // implementation of SbotActiveObject
00342         virtual void setEnergyProperties(double activeDuration, double inactiveDuration, bool consumeEnergy);
00343         virtual void setEnergyTime(double time);
00344         virtual void setEnergyFlow(double activeFlow, double inactiveFlow);
00345         virtual void setEnergy(double energy);
00346         virtual double getEnergy(void);
00347         virtual void setColor(const An::Color &activeColor, const An::Color &inactiveColor);
00348         virtual double getInteractionRange(void);
00349     };
00350 
00353     class EnkiRectangularBlock : public EnkiPositionable<Enki::PhysicalObject>, public RectangularBlock
00354     {
00355     private:
00356         friend class EnkiWorld;
00357         friend class Registrar<Entity, std::string, EnkiWorld *, std::string>;
00358         EnkiWorld *world; 
00359         An::Polygone boundingSurface; 
00360         Ishtar::VariablesPublisher ishtarPublisher; 
00361 
00363         EnkiRectangularBlock(EnkiWorld *world, const std::string &root);
00364 
00365     public:
00367         virtual ~EnkiRectangularBlock();
00368 
00369         // implementation of RectangularBlock
00370         virtual void set(double w, double h, double x, double y, double a);
00371     };
00372 }
00373 
00374 #endif

Generated on Mon Oct 24 17:38:25 2005 for Teem by  doxygen 1.4.2