just a test

Dependencies:   mbed

Fork of scoreLight_Advanced by Alvaro Cassinelli

Committer:
mbedalvaro
Date:
Sat Apr 28 12:35:21 2012 +0000
Revision:
18:d72935b13858
Parent:
17:356ca5690a59
Child:
19:228430f1350e
this works pretty nicely. I will change some parameters on the elastic loop, as well as compute the KINETIC ENERGY

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedalvaro 0:345b3bc7a0ea 1 #ifndef SOUNDSPOT_H
mbedalvaro 0:345b3bc7a0ea 2 #define SOUNDSPOT_H
mbedalvaro 0:345b3bc7a0ea 3
mbedalvaro 0:345b3bc7a0ea 4 //#define SEND_AS_BLOB // for test (sending positions in a single OSC blob chunk)
mbedalvaro 0:345b3bc7a0ea 5 //#define SEND_AS_STRING
mbedalvaro 0:345b3bc7a0ea 6 #define SEND_AS_POINTS
mbedalvaro 0:345b3bc7a0ea 7
mbedalvaro 0:345b3bc7a0ea 8 // The global object OSC for sending/receiving messages:
mbedalvaro 0:345b3bc7a0ea 9 #include "mbedOSC.h"
mbedalvaro 0:345b3bc7a0ea 10 extern OSCMessage recMes;
mbedalvaro 0:345b3bc7a0ea 11 extern OSCMessage sendMes;
mbedalvaro 0:345b3bc7a0ea 12 extern OSCClass osc;
mbedalvaro 0:345b3bc7a0ea 13
mbedalvaro 0:345b3bc7a0ea 14 extern DigitalOut myled2; // for tests...
mbedalvaro 0:345b3bc7a0ea 15
mbedalvaro 0:345b3bc7a0ea 16 #include "classLaserSensingTrajectory.h"
mbedalvaro 0:345b3bc7a0ea 17 #include "classRigidScafold.h"
mbedalvaro 0:345b3bc7a0ea 18
mbedalvaro 1:a4050fee11f7 19
mbedalvaro 1:a4050fee11f7 20 #define min(a, b) (((a) < (b)) ? (a) : (b))
mbedalvaro 1:a4050fee11f7 21 #define max(a, b) (((a) > (b)) ? (a) : (b))
mbedalvaro 1:a4050fee11f7 22
mbedalvaro 0:345b3bc7a0ea 23 // This is a polymorphic class, and elasticLoop, livingSpot are derived classes that
mbedalvaro 5:73cd58b58f95 24 // instantiate particular methods (update, etc).
mbedalvaro 0:345b3bc7a0ea 25 class soundSpot {
mbedalvaro 5:73cd58b58f95 26 protected: // (note: protected means that the child classes will have access to these variables/methods; private means that only this class members have access)
mbedalvaro 5:73cd58b58f95 27
mbedalvaro 5:73cd58b58f95 28 // number of points of this blob:
mbedalvaro 5:73cd58b58f95 29 int numPoints; // this in fact is equal to sensingTrajectory.size() for instance.
mbedalvaro 18:d72935b13858 30 Timer measureSendPeriod;
mbedalvaro 18:d72935b13858 31
mbedalvaro 5:73cd58b58f95 32 public:
mbedalvaro 5:73cd58b58f95 33
mbedalvaro 5:73cd58b58f95 34 // CONSTRUCTOR AND DESTRUCTOR --------------------------------------------------------------------------------------------------------------
mbedalvaro 5:73cd58b58f95 35 soundSpot();
mbedalvaro 5:73cd58b58f95 36 // Destructor (virtual, because one can only delete an object of a derived type
mbedalvaro 5:73cd58b58f95 37 // through a pointer to one of its base classes IF the base class has a virtual destructor)
mbedalvaro 5:73cd58b58f95 38 virtual ~soundSpot();// { cout<<"Destroying Base";}
mbedalvaro 5:73cd58b58f95 39
mbedalvaro 5:73cd58b58f95 40 // METHODS -------------------------------------------------------------------------------------------------------------
mbedalvaro 5:73cd58b58f95 41 // COMMON methods to all the kind of blobs:
mbedalvaro 5:73cd58b58f95 42 // (1) properties of the visible loop:
mbedalvaro 12:0de9cd2bced5 43 void setColor(unsigned char c);
mbedalvaro 5:73cd58b58f95 44 // (2) Sending modes:
mbedalvaro 5:73cd58b58f95 45 void stopAllSending(void);
mbedalvaro 5:73cd58b58f95 46 void resetAllSendingModes(void);
mbedalvaro 5:73cd58b58f95 47 void initCommonVariables();
mbedalvaro 5:73cd58b58f95 48 void sendData(void); // send data common to all kind of blobs
mbedalvaro 0:345b3bc7a0ea 49
mbedalvaro 5:73cd58b58f95 50 // VIRTUAL METHODS (common to all blobs, but each type of blob will implement it differently):
mbedalvaro 5:73cd58b58f95 51 // Blob creation:
mbedalvaro 12:0de9cd2bced5 52 virtual void setRegionMotion(float mmix, float mmiy, float mmax, float mmay)=0;
mbedalvaro 5:73cd58b58f95 53 // virtual void createBlob()=0; // note: the number of masses in the blob will be given from the scafold.
mbedalvaro 5:73cd58b58f95 54 // virtual void createBlob(int _id, ElasticLoopMode _elasticBlobMode, vector2D _initPos)=0;
mbedalvaro 5:73cd58b58f95 55 // Update:
mbedalvaro 5:73cd58b58f95 56 virtual void update(void)=0;
mbedalvaro 5:73cd58b58f95 57 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.
mbedalvaro 5:73cd58b58f95 58 // Draw (on lsdTrajectory):
mbedalvaro 5:73cd58b58f95 59 virtual void draw(void)=0; // NOTE: this method actually "renders" the trajectory using the laser renderer (not yet done)
mbedalvaro 5:73cd58b58f95 60 // Send data through OSC:
mbedalvaro 5:73cd58b58f95 61 virtual void sendDataSpecific(void)=0; // send data specific to each blob
mbedalvaro 5:73cd58b58f95 62
mbedalvaro 5:73cd58b58f95 63 // DATA --------------------------------------------------------------------------------------------------------------
mbedalvaro 5:73cd58b58f95 64 int identifier; //0, 1, 2...
mbedalvaro 5:73cd58b58f95 65 char spotName[20]; //spot, elastic,...
mbedalvaro 17:356ca5690a59 66 unsigned char blobColor;
mbedalvaro 5:73cd58b58f95 67
mbedalvaro 5:73cd58b58f95 68 // initial position and speed of the blob:
mbedalvaro 12:0de9cd2bced5 69 vector2Df startCenter;
mbedalvaro 12:0de9cd2bced5 70 vector2Df startSpeed;
mbedalvaro 5:73cd58b58f95 71
mbedalvaro 5:73cd58b58f95 72 // SCAFOLD (rigid structure of points, with a center and methods to create it):
mbedalvaro 5:73cd58b58f95 73 RigidScafold bluePrint;
mbedalvaro 5:73cd58b58f95 74
mbedalvaro 5:73cd58b58f95 75 // LASER DISPLAY/SENSING-TRAJECTORY with DATA BUFFER:
mbedalvaro 5:73cd58b58f95 76 LaserSensingTrajectory displaySensingBuffer;
mbedalvaro 5:73cd58b58f95 77
mbedalvaro 5:73cd58b58f95 78 // the following are common to all kind of blobs, but the way these quantities are calculated (in the update() method) differs greatly:
mbedalvaro 12:0de9cd2bced5 79 vector2Df totalLightForce;
mbedalvaro 12:0de9cd2bced5 80 vector2Df recenteringVectorLoop;
mbedalvaro 5:73cd58b58f95 81 float angleCorrectionForceLoop;
mbedalvaro 5:73cd58b58f95 82 float angleRecenteringVector; // auxiliary variables for sending data (for the recenteringVectorLoop)
mbedalvaro 5:73cd58b58f95 83 float normRecenteringVector;
mbedalvaro 5:73cd58b58f95 84
mbedalvaro 5:73cd58b58f95 85 // Statistics of the loop (area and enclosing box):
mbedalvaro 5:73cd58b58f95 86 float cx, cy, w, h;
mbedalvaro 5:73cd58b58f95 87 float area, approxArea;
mbedalvaro 5:73cd58b58f95 88
mbedalvaro 0:345b3bc7a0ea 89 bool render; // when false, the blob is NOT RENDERED
mbedalvaro 0:345b3bc7a0ea 90 bool standByMode; // when true, the blob is NOT UPDATED
mbedalvaro 0:345b3bc7a0ea 91
mbedalvaro 5:73cd58b58f95 92 // something touched the blob:
mbedalvaro 0:345b3bc7a0ea 93 bool searchActive;
mbedalvaro 0:345b3bc7a0ea 94 bool firstTimeNoTouch;
mbedalvaro 0:345b3bc7a0ea 95 //bool lightTouched; // belongs to the lsdTrajectory
mbedalvaro 0:345b3bc7a0ea 96 int noTouchedCounter;
mbedalvaro 12:0de9cd2bced5 97 vector2Df randomForce;
mbedalvaro 0:345b3bc7a0ea 98
mbedalvaro 0:345b3bc7a0ea 99 // the blob touched the wall limits (these variables are updated in the "update" method, and implemented differently for each blob)
mbedalvaro 0:345b3bc7a0ea 100 bool blobWallCollision;
mbedalvaro 0:345b3bc7a0ea 101 int wallCounter;
mbedalvaro 5:73cd58b58f95 102
mbedalvaro 5:73cd58b58f95 103 // HARDWARE SENDING MODE (can be changed by serial or osc commands):
mbedalvaro 18:d72935b13858 104 unsigned short periodSendingData; // max data rate for sending data (in ms)
mbedalvaro 5:73cd58b58f95 105 bool sendSerial;
mbedalvaro 5:73cd58b58f95 106 bool sendOSC;
mbedalvaro 18:d72935b13858 107 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
mbedalvaro 18:d72935b13858 108 // will be limited to periodSendingData.
mbedalvaro 5:73cd58b58f95 109 // SENDING modes for things COMMON TO ALL THE KIND OF BLOBS:
mbedalvaro 5:73cd58b58f95 110 // (d) Light sensing statistics:
mbedalvaro 5:73cd58b58f95 111 bool sendingBlobMaxMin; // max and min intensities are calculated directly from the lsdTrajectory
mbedalvaro 5:73cd58b58f95 112 bool sendingTouched; // when someone touches the blob (can be calculated directly from the lsdTrajectory)
mbedalvaro 5:73cd58b58f95 113 bool sendingLightForce; // the total light force (note: this CANNOT be calculated on the lsdTrajectory, but on the update method, particular to each loop).
mbedalvaro 5:73cd58b58f95 114 // (e) Recentering vector: (note: redundant with sendingLightForce, IF the correction angle is known).
mbedalvaro 5:73cd58b58f95 115 bool sendingRecenteringVector;
mbedalvaro 5:73cd58b58f95 116 bool sendingRecenteringAngle;
mbedalvaro 5:73cd58b58f95 117 bool sendingRecenteringNorm;
mbedalvaro 0:345b3bc7a0ea 118
mbedalvaro 5:73cd58b58f95 119 // SPECIFIC TO EACH BLOB (move this from here, use virtual methods to set their values):
mbedalvaro 5:73cd58b58f95 120 // (a) anchor mass data:
mbedalvaro 5:73cd58b58f95 121 bool sendingAnchorPosition;
mbedalvaro 5:73cd58b58f95 122 bool sendingAnchorForce; // this is the total force on the anchor mass, not just the recentering force
mbedalvaro 5:73cd58b58f95 123 bool sendingAnchorTouchWall;
mbedalvaro 5:73cd58b58f95 124 // (b) data from blob points:
mbedalvaro 5:73cd58b58f95 125 bool sendingLoopPositions;
mbedalvaro 5:73cd58b58f95 126 bool sendingLoopForces;// this is not just the forces from light, but all the forces in each particle
mbedalvaro 5:73cd58b58f95 127 bool sendingLoopForcesLight;
mbedalvaro 5:73cd58b58f95 128 bool sendingLoopRegions; // from this we can detect "hits"
mbedalvaro 5:73cd58b58f95 129 bool sendingLoopTouchWall;
mbedalvaro 5:73cd58b58f95 130 // (c) Blob geometry:
mbedalvaro 5:73cd58b58f95 131 bool sendingBlobArea;
mbedalvaro 5:73cd58b58f95 132 bool sendingBlobNormals;
mbedalvaro 5:73cd58b58f95 133 bool sendingBlobAngles; // redundant with sendingBlobNormals, but simplified (only angle of normal)
mbedalvaro 0:345b3bc7a0ea 134 };
mbedalvaro 0:345b3bc7a0ea 135
mbedalvaro 0:345b3bc7a0ea 136 #endif