Alvaro Cassinelli / Mbed 2 deprecated skinGames_forktest

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers soundSpot.h Source File

soundSpot.h

00001 #ifndef SOUNDSPOT_H
00002 #define SOUNDSPOT_H
00003 
00004 //#define SEND_AS_BLOB // for test (sending positions in a single OSC blob chunk)
00005 //#define SEND_AS_STRING
00006 #define SEND_AS_POINTS
00007 
00008 // The global object OSC for sending/receiving messages:
00009 #include "mbedOSC.h"
00010 extern OSCMessage recMes;
00011 extern OSCMessage sendMes;
00012 extern OSCClass osc;
00013 
00014 extern DigitalOut myled2; // for tests...
00015 
00016 #include "classLaserSensingTrajectory.h"
00017 #include "classRigidScafold.h"
00018 
00019 
00020 #define min(a, b) (((a) < (b)) ? (a) : (b))
00021 #define max(a, b) (((a) > (b)) ? (a) : (b))
00022 
00023 // This is a polymorphic class, and elasticLoop, livingSpot are derived classes that
00024 // instantiate particular methods (update, etc).
00025 class soundSpot {
00026 protected: // (note: protected means that the child classes will have access to these variables/methods; private means that only this class members have access)
00027 
00028     // number of points of this blob:
00029     int numPoints; // this in fact is equal to sensingTrajectory.size() for instance.
00030     Timer measureSendPeriod;
00031     
00032 public:
00033 
00034     // CONSTRUCTOR AND DESTRUCTOR --------------------------------------------------------------------------------------------------------------
00035     soundSpot();
00036     // Destructor (virtual, because one can only delete an object of a derived type
00037     // through a pointer to one of its base classes IF the base class has a virtual destructor)
00038     virtual ~soundSpot();// { cout<<"Destroying Base";}
00039 
00040     // METHODS -------------------------------------------------------------------------------------------------------------
00041     // COMMON methods to all the kind of blobs:
00042     // (1) properties of the visible loop:
00043     void setColor(unsigned char c);
00044     void setGreenColor(unsigned char c);
00045     void setBlueColor(unsigned char c);
00046     
00047     // (2) Sending modes:
00048     void stopAllSending(void);
00049     void resetAllSendingModes(void);
00050     void initCommonVariables();
00051     void sendData(void); // send data common to all kind of blobs
00052     
00053     // VIRTUAL METHODS (common to all blobs, but each type of blob will implement it differently):
00054     // Blob creation:
00055     virtual void setRegionMotion(float mmix, float mmiy, float mmax, float mmay)=0;
00056 // virtual void createBlob()=0; // note: the number of masses in the blob will be given from the scafold.
00057 //  virtual void createBlob(int _id, ElasticLoopMode _elasticBlobMode, vector2D _initPos)=0;
00058     // Update:
00059     virtual void update(vector2Df referencePos=vector2Df(0,0))=0;
00060     virtual void computeBoundingBox(void)=0; // this is virtual because the displayed blob may be the scafold itself (in case of laser spot), or the elastic loop.
00061     // Draw (on lsdTrajectory):
00062     virtual void draw(void)=0; // NOTE: this method actually "renders" the trajectory using the laser renderer (not yet done)
00063 // Send data through OSC:
00064     virtual void sendDataSpecific(void)=0; // send data specific to each blob
00065 
00066 // Some parameters (very different treatement for each type of blob):
00067     virtual void setSpeed(float speed=7.0)=0;
00068     virtual void setSize(float size=20.0)=0;
00069     virtual void speedFactor(float speedfactor=100.0)=0;
00070     virtual void sizeFactor(float sizeFactor=100.0)=0;
00071     
00072     void addAngleCorrection(float _moreAngleCorrection);
00073     void setAngleCorrection(float _angleCorrection);
00074 
00075    virtual void explosion()=0; // not very nice programming style, it should be a MODE instead or something like that. 
00076    virtual vector2Df getCenter()=0;
00077    virtual void resetPositionSpeed()=0; 
00078    virtual void setPositionSpeed(vector2Df _pos, vector2Df _spe)=0;
00079    
00080    virtual void showChildParameters()=0; 
00081    void printParameters(); // first show common parameters, then call the virtual method:
00082     
00083     // DATA --------------------------------------------------------------------------------------------------------------
00084     int identifier; //0, 1, 2...
00085     char spotName[20]; //spot, elastic,... (this may be useful to set particular variables by forcing type cast (bad, but couldn't find a more elegant solution for the moment)
00086     unsigned char blobColor, transientBlobColor; // transient blob color is the color of the blob when touching something for instance. 
00087     bool blueTouch; // this is equivalent to "debugDelayMirrors" #define, but per-blob (ie. blue active in dark zones). Good for elastic loops...
00088     
00089     // initial position and speed of the blob:
00090     vector2Df startCenter;
00091     vector2Df startSpeed;
00092     
00093     // Special fields:
00094     vector2Df gravity;
00095 
00096     // SCAFOLD (rigid structure of points, with a center and methods to create it):
00097     RigidScafold bluePrint;
00098 
00099     // LASER DISPLAY/SENSING-TRAJECTORY with DATA BUFFER for each blob:
00100     LaserSensingTrajectory displaySensingBuffer;
00101 
00102 // the following are common to all kind of blobs, but the way these quantities are calculated (in the update() method) differs greatly:
00103     vector2Df totalLightForce;
00104     vector2Df recenteringVectorLoop;
00105     float angleCorrectionForceLoop;
00106     float angleRecenteringVector; // auxiliary variables for sending data (for the recenteringVectorLoop)
00107     float normRecenteringVector;
00108 
00109     // Geometry/kinematics of the loop:
00110     float cx, cy, w, h;
00111     float area, approxArea;
00112     float totalKineticEnergy;
00113 
00114     bool render; // when false, the blob is NOT RENDERED
00115     bool standByMode; // when true, the blob is NOT UPDATED
00116 
00117     // something touched the blob:
00118     bool searchActive;
00119     bool firstTimeNoTouch;
00120     //bool lightTouched; // belongs to the lsdTrajectory
00121     int noTouchedCounter;
00122     vector2Df randomForce;
00123 
00124     // the blob touched the wall limits (these variables are updated in the "update" method, and implemented differently for each blob)
00125     bool blobWallCollision;
00126     int wallCounter;
00127 
00128     // HARDWARE SENDING MODE (can be changed by serial or osc commands):
00129     unsigned short periodSendingData; // max data rate for sending data (in ms)
00130     bool sendSerial;
00131     bool sendOSC;
00132     bool sendingOnlyWhenTouch; // when this is "true", data will be send ONLY when something touches the blob (border or light touch). Note that the max speed of sending
00133                                // will be limited to periodSendingData. 
00134     // SENDING modes for things COMMON TO ALL THE KIND OF BLOBS:
00135     // (d) Light sensing statistics:
00136     bool sendingBlobMaxMin; // max and min intensities are calculated directly from the lsdTrajectory
00137     bool sendingTouched; // when someone touches the blob (can be calculated directly from the lsdTrajectory)
00138     bool sendingLightForce; // the total light force (note: this CANNOT be calculated on the lsdTrajectory, but on the update method, particular to each loop).
00139     // (e) Recentering vector: (note: redundant with sendingLightForce, IF the correction angle is known).
00140     bool sendingRecenteringVector;
00141     bool sendingRecenteringAngle;
00142     bool sendingRecenteringNorm;
00143 
00144     // SPECIFIC TO EACH BLOB (move this from here, use virtual methods to set their values):
00145     // (a) anchor mass data:
00146     bool sendingAnchorPosition;
00147     bool sendingAnchorForce; // this is the total force on the anchor mass, not just the recentering force
00148     bool sendingAnchorTouchWall;
00149     // (b) data from blob points:
00150     bool sendingLoopPositions;
00151     bool sendingLoopForces;// this is not just the forces from light, but all the forces in each particle
00152     bool sendingLoopForcesLight;
00153     bool sendingLoopRegions; // from this we can detect "hits"
00154     bool sendingLoopTouchWall;
00155     // (c) Blob geometry/kinematics:
00156     bool sendingBlobArea;
00157     bool sendingKineticEnergy;
00158     bool sendingBlobNormals;
00159     bool sendingBlobAngles; // redundant with sendingBlobNormals, but simplified (only angle of normal)
00160 };
00161 
00162 #endif