Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of scoreLight_Advanced by
soundSpot.cpp
00001 #include "soundSpot.h" 00002 00003 // SHOULD NOT BE HERE: (only because I am using serial princ pc object) 00004 #include "hardwareIO.h" 00005 00006 // Constructor: 00007 soundSpot::soundSpot() { // by default, the child constructor call the parameterless default constructor (we could force another by doing: soundSpot::soundSpot : LivingSpot (params...) { ..} 00008 00009 // DEFAULT sending mode will be all off: 00010 stopAllSending(); 00011 resetAllSendingModes(); 00012 00013 initCommonVariables(); 00014 00015 // initialize timer for sending OSC data: 00016 periodSendingData=25;// by default, we send the data every 25 ms. Note: the "data" to send will of course depend on the kind of blob. That will be therefore re-set when 00017 // instantiating the kind of blob. 00018 measureSendPeriod.start(); 00019 } 00020 00021 // IMPORTANT: the destructor of the base class is virtual, but it won't be implemented with the same name in the child class; therefore, it 00022 // must be implemented in the base class (and it will be called when using delete of the child, first the delete child, then delete base) 00023 soundSpot::~soundSpot() { 00024 } 00025 00026 void soundSpot::printParameters() { 00027 // first show common parameters, then call the virtual method: 00028 pc.printf("Mirror delay :%d\n", displaySensingBuffer.delayMirrorSamples); 00029 pc.printf("Angle correction force :%f\n", angleCorrectionForceLoop); 00030 pc.printf("Thresholding mode :%d\n", displaySensingBuffer.modeThreshold); 00031 pc.printf("Min Contrast Ratio :%f / Current Contrast: %f\n", displaySensingBuffer.min_contrast_ratio, 1.0*displaySensingBuffer.maxI/displaySensingBuffer.minI); 00032 pc.printf("Threshold Factor: %f\n", displaySensingBuffer.threshold_factor); 00033 pc.printf("Min Acceptable Intensity :%f\n", displaySensingBuffer.min_acceptable_intensity); 00034 pc.printf("Current Max / Min Intensity: %d / %d\n", displaySensingBuffer.maxI, displaySensingBuffer.minI, displaySensingBuffer.maxI/displaySensingBuffer.minI); 00035 this->showChildParameters(); 00036 } 00037 00038 void soundSpot::setColor(unsigned char c) { 00039 blobColor=0x07&c; // we will use the first three bits to set the RGB colors. 00040 } 00041 00042 void soundSpot::setGreenColor(unsigned char c) { 00043 // this set/reset the green bit only: 00044 if (c>0) blobColor=blobColor|0x2; //meaning second bit to 1 00045 else blobColor=blobColor&0x5; // meaning second bit to 0 00046 } 00047 00048 void soundSpot::setBlueColor(unsigned char c) { 00049 // this set/reset the green bit only: 00050 if (c>0) blobColor=blobColor|0x1; //meaning first bit to 1 00051 else blobColor=blobColor&0x6; // meaning first bit to 0 00052 } 00053 00054 void soundSpot::addAngleCorrection(float _moreAngleCorrection) { 00055 angleCorrectionForceLoop+=_moreAngleCorrection; 00056 } 00057 void soundSpot::setAngleCorrection(float _angleCorrection) { 00058 angleCorrectionForceLoop=_angleCorrection; 00059 } 00060 00061 void soundSpot::initCommonVariables() { 00062 firstTimeNoTouch=true; 00063 // randomForce.set(1,0);// first time there won't be any force, or random force 00064 // randomForce=randomForce.getRotatedDeg(1.0*(rand()%360)); 00065 // randomForce.normalize(); 00066 00067 noTouchedCounter=0; 00068 wallCounter=0; 00069 blobWallCollision=false; 00070 //slidingDirection=true; // (will change when touching wall) 00071 00072 gravity.set(0,0); 00073 00074 render=true; 00075 standByMode=true; // ALWAYS START IN STANDBY MODE 00076 } 00077 00078 void soundSpot::resetAllSendingModes() { 00079 // RESET SENDING DATA: 00080 sendingOnlyWhenTouch=false; 00081 // (a) anchor mass data: 00082 sendingAnchorPosition=false; 00083 sendingAnchorForce=false; // this is the total force on the anchor mass, not just the recentering force 00084 sendingAnchorTouchWall=false; 00085 // (b) data from blob points: 00086 sendingLoopPositions=false; 00087 sendingLoopForces=false;// this is not just the forces from light, but all the forces in each particle 00088 sendingLoopForcesLight=false;// forces only from light 00089 sendingLoopRegions=false; // from this we can detect "hits" 00090 sendingLoopTouchWall=false; 00091 // (c) Blob geometry: 00092 sendingBlobArea=false; 00093 sendingBlobNormals=false; 00094 sendingBlobAngles=false; // redundant with sendingBlobNormals, but simplified (only angle of normal) 00095 sendingKineticEnergy=false; 00096 // (d) Light sensing statistics: 00097 sendingBlobMaxMin=false; 00098 sendingLightForce=false; // the total light force 00099 sendingTouched=false; 00100 // (e) Recentering vector: (note: redundant with sendingLightForce, IF the correction angle is known). 00101 sendingRecenteringVector=false; 00102 sendingRecenteringAngle=false; 00103 sendingRecenteringNorm=false; 00104 } 00105 00106 void soundSpot::stopAllSending() { 00107 // STOP HARDWARE SENDING MODE (per spot): 00108 sendSerial=false; 00109 sendOSC=true; 00110 } 00111 00112 void soundSpot::sendData(void) { // send data common to all kind of blobs 00113 // send common things, such as testing if it is the right time to send data: 00114 00115 if (measureSendPeriod.read_ms()>periodSendingData) { 00116 measureSendPeriod.stop(); 00117 measureSendPeriod.reset(); 00118 00119 // Send data specific to the derived class: 00120 if ((sendingOnlyWhenTouch==false)||(blobWallCollision==true)||(displaySensingBuffer.lightTouched==true)) 00121 sendDataSpecific(); // this will depend on the kind of blob 00122 00123 measureSendPeriod.start(); 00124 } 00125 00126 } 00127
Generated on Tue Jul 12 2022 18:50:27 by
1.7.2
