Alvaro Cassinelli
/
skinGames_forktest
just a test
Fork of scoreLight_Advanced by
blobConfig.cpp@27:1ce994629ffc, 2012-06-18 (annotated)
- Committer:
- mbedalvaro
- Date:
- Mon Jun 18 15:09:25 2012 +0000
- Revision:
- 27:1ce994629ffc
- Parent:
- 25:74cb85b85fd2
- Child:
- 28:44b7b6e35548
new weird mode ad hoc, with wrong time delay so it produces blue spots along the contour (for a reason I still don't understand)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedalvaro | 0:345b3bc7a0ea | 1 | |
mbedalvaro | 0:345b3bc7a0ea | 2 | #include "blobConfig.h" |
mbedalvaro | 0:345b3bc7a0ea | 3 | #include "hardwareIO.h" // this is in fact only to get to know the initial position of the spots, as well as the mirror limits to set the bounding box for the blobs |
mbedalvaro | 0:345b3bc7a0ea | 4 | |
mbedalvaro | 0:345b3bc7a0ea | 5 | blobConfig::blobConfig(): numBlobs(0) { |
mbedalvaro | 1:a4050fee11f7 | 6 | //blobArray.clear();// there is no need to do this, the vector does not contains anything here. |
mbedalvaro | 1:a4050fee11f7 | 7 | |
mbedalvaro | 0:345b3bc7a0ea | 8 | } |
mbedalvaro | 0:345b3bc7a0ea | 9 | |
mbedalvaro | 0:345b3bc7a0ea | 10 | blobConfig::~blobConfig() { |
mbedalvaro | 1:a4050fee11f7 | 11 | clearConfig(); |
mbedalvaro | 1:a4050fee11f7 | 12 | |
mbedalvaro | 0:345b3bc7a0ea | 13 | } |
mbedalvaro | 0:345b3bc7a0ea | 14 | |
mbedalvaro | 0:345b3bc7a0ea | 15 | // =========================================== STANDARD CONFIGURATIONS ============================================================================= |
mbedalvaro | 0:345b3bc7a0ea | 16 | |
mbedalvaro | 0:345b3bc7a0ea | 17 | void blobConfig::computeBoundingBox() { |
mbedalvaro | 1:a4050fee11f7 | 18 | for (int i=0; i<blobArray.size(); i++) { |
mbedalvaro | 1:a4050fee11f7 | 19 | blobArray[i]->computeBoundingBox(); |
mbedalvaro | 1:a4050fee11f7 | 20 | } |
mbedalvaro | 0:345b3bc7a0ea | 21 | } |
mbedalvaro | 0:345b3bc7a0ea | 22 | |
mbedalvaro | 0:345b3bc7a0ea | 23 | void blobConfig::clearConfig() { |
mbedalvaro | 1:a4050fee11f7 | 24 | for (int i=0; i<blobArray.size(); i++) delete blobArray[i]; // we must delete the pointer created with new, so the memory for the object is liberated (calls its destructor) |
mbedalvaro | 1:a4050fee11f7 | 25 | blobArray.clear(); |
mbedalvaro | 1:a4050fee11f7 | 26 | numBlobs=0;// this is just equal to blobArray.size() |
mbedalvaro | 0:345b3bc7a0ea | 27 | } |
mbedalvaro | 0:345b3bc7a0ea | 28 | |
mbedalvaro | 1:a4050fee11f7 | 29 | void blobConfig::addOneElasticLoopRelax() { |
mbedalvaro | 1:a4050fee11f7 | 30 | elasticLoop* pBlob= new elasticLoop(); |
mbedalvaro | 12:0de9cd2bced5 | 31 | pBlob->createBlob(blobArray.size(), RELAX, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(0,0)); |
mbedalvaro | 1:a4050fee11f7 | 32 | // add this relaxing loop to the present config: |
mbedalvaro | 1:a4050fee11f7 | 33 | blobArray.push_back(pBlob); |
mbedalvaro | 1:a4050fee11f7 | 34 | |
mbedalvaro | 1:a4050fee11f7 | 35 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 1:a4050fee11f7 | 36 | numBlobs=blobArray.size(); |
mbedalvaro | 1:a4050fee11f7 | 37 | |
mbedalvaro | 0:345b3bc7a0ea | 38 | } |
mbedalvaro | 0:345b3bc7a0ea | 39 | |
mbedalvaro | 0:345b3bc7a0ea | 40 | |
mbedalvaro | 1:a4050fee11f7 | 41 | void blobConfig::addOneElasticLoopContract() { |
mbedalvaro | 1:a4050fee11f7 | 42 | elasticLoop* pBlob= new elasticLoop(); |
mbedalvaro | 12:0de9cd2bced5 | 43 | pBlob->createBlob(blobArray.size(), CONTRACT, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(0,0)); |
mbedalvaro | 1:a4050fee11f7 | 44 | // add this relaxing loop to the present config: |
mbedalvaro | 1:a4050fee11f7 | 45 | blobArray.push_back(pBlob); |
mbedalvaro | 1:a4050fee11f7 | 46 | |
mbedalvaro | 1:a4050fee11f7 | 47 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 1:a4050fee11f7 | 48 | numBlobs=blobArray.size(); |
mbedalvaro | 0:345b3bc7a0ea | 49 | } |
mbedalvaro | 0:345b3bc7a0ea | 50 | |
mbedalvaro | 1:a4050fee11f7 | 51 | void blobConfig::addOneElasticLoopContractCentral() { |
mbedalvaro | 1:a4050fee11f7 | 52 | elasticLoop* pBlob= new elasticLoop(); |
mbedalvaro | 12:0de9cd2bced5 | 53 | pBlob->createBlob(blobArray.size(), CONTRACT_CENTRAL, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(0,0)); |
mbedalvaro | 1:a4050fee11f7 | 54 | // add this relaxing loop to the present config: |
mbedalvaro | 1:a4050fee11f7 | 55 | blobArray.push_back(pBlob); |
mbedalvaro | 1:a4050fee11f7 | 56 | |
mbedalvaro | 1:a4050fee11f7 | 57 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 1:a4050fee11f7 | 58 | numBlobs=blobArray.size(); |
mbedalvaro | 0:345b3bc7a0ea | 59 | } |
mbedalvaro | 0:345b3bc7a0ea | 60 | |
mbedalvaro | 19:228430f1350e | 61 | void blobConfig::addOneElasticLoopContractCentralFast() { |
mbedalvaro | 19:228430f1350e | 62 | elasticLoop* pBlob= new elasticLoop(); |
mbedalvaro | 19:228430f1350e | 63 | pBlob->createBlob(blobArray.size(), CONTRACT_CENTRAL_FAST, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(0,0)); |
mbedalvaro | 19:228430f1350e | 64 | // add this relaxing loop to the present config: |
mbedalvaro | 19:228430f1350e | 65 | blobArray.push_back(pBlob); |
mbedalvaro | 19:228430f1350e | 66 | |
mbedalvaro | 19:228430f1350e | 67 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 19:228430f1350e | 68 | numBlobs=blobArray.size(); |
mbedalvaro | 19:228430f1350e | 69 | } |
mbedalvaro | 19:228430f1350e | 70 | |
mbedalvaro | 1:a4050fee11f7 | 71 | void blobConfig::addOneElasticContourFollowing() { |
mbedalvaro | 1:a4050fee11f7 | 72 | |
mbedalvaro | 1:a4050fee11f7 | 73 | elasticLoop* pBlob= new elasticLoop(); |
mbedalvaro | 12:0de9cd2bced5 | 74 | pBlob->createBlob(blobArray.size(), CONTOUR_FOLLOWING, vector2Df(CENTER_AD_MIRROR_X+100*blobArray.size(), CENTER_AD_MIRROR_Y+100*blobArray.size()), vector2Df(0,0)); |
mbedalvaro | 1:a4050fee11f7 | 75 | // add this relaxing loop to the present config: |
mbedalvaro | 1:a4050fee11f7 | 76 | blobArray.push_back(pBlob); |
mbedalvaro | 1:a4050fee11f7 | 77 | |
mbedalvaro | 1:a4050fee11f7 | 78 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 1:a4050fee11f7 | 79 | numBlobs=blobArray.size(); |
mbedalvaro | 0:345b3bc7a0ea | 80 | } |
mbedalvaro | 0:345b3bc7a0ea | 81 | |
mbedalvaro | 0:345b3bc7a0ea | 82 | |
mbedalvaro | 1:a4050fee11f7 | 83 | void blobConfig:: addOneElasticContourFollowingFAST() { |
mbedalvaro | 1:a4050fee11f7 | 84 | elasticLoop* pBlob= new elasticLoop(); |
mbedalvaro | 12:0de9cd2bced5 | 85 | pBlob->createBlob(blobArray.size(), CONTOUR_FOLLOWING_FAST, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(0,0)); |
mbedalvaro | 0:345b3bc7a0ea | 86 | // add this relaxing loop to the present config: |
mbedalvaro | 1:a4050fee11f7 | 87 | blobArray.push_back(pBlob); |
mbedalvaro | 1:a4050fee11f7 | 88 | |
mbedalvaro | 1:a4050fee11f7 | 89 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 1:a4050fee11f7 | 90 | numBlobs=blobArray.size(); |
mbedalvaro | 1:a4050fee11f7 | 91 | } |
mbedalvaro | 1:a4050fee11f7 | 92 | |
mbedalvaro | 1:a4050fee11f7 | 93 | void blobConfig::addOneElasticBouncing() { |
mbedalvaro | 1:a4050fee11f7 | 94 | elasticLoop* pBlob= new elasticLoop(); |
mbedalvaro | 12:0de9cd2bced5 | 95 | pBlob->createBlob(blobArray.size(), BOUNCING, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(1,1)); |
mbedalvaro | 1:a4050fee11f7 | 96 | // add this relaxing loop to the present config: |
mbedalvaro | 1:a4050fee11f7 | 97 | blobArray.push_back(pBlob); |
mbedalvaro | 1:a4050fee11f7 | 98 | |
mbedalvaro | 1:a4050fee11f7 | 99 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 1:a4050fee11f7 | 100 | numBlobs=blobArray.size(); |
mbedalvaro | 0:345b3bc7a0ea | 101 | } |
mbedalvaro | 0:345b3bc7a0ea | 102 | |
mbedalvaro | 1:a4050fee11f7 | 103 | void blobConfig::addOneRigidLoopBouncing() { |
mbedalvaro | 1:a4050fee11f7 | 104 | rigidLoop* pBlob= new rigidLoop(); |
mbedalvaro | 22:d87317d7ca91 | 105 | pBlob->createBlob(blobArray.size(), SPOT_BOUNCING, vector2Df(CENTER_AD_MIRROR_X+100*blobArray.size(), CENTER_AD_MIRROR_Y+100*blobArray.size()), vector2Df(rand()%3,rand()%3)); |
mbedalvaro | 0:345b3bc7a0ea | 106 | // add this relaxing loop to the present config: |
mbedalvaro | 1:a4050fee11f7 | 107 | blobArray.push_back(pBlob); |
mbedalvaro | 1:a4050fee11f7 | 108 | |
mbedalvaro | 1:a4050fee11f7 | 109 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 1:a4050fee11f7 | 110 | numBlobs=blobArray.size(); |
mbedalvaro | 0:345b3bc7a0ea | 111 | } |
mbedalvaro | 0:345b3bc7a0ea | 112 | |
mbedalvaro | 27:1ce994629ffc | 113 | void blobConfig::addOneRigidLoopFountain() { |
mbedalvaro | 27:1ce994629ffc | 114 | rigidLoop* pBlob= new rigidLoop(); |
mbedalvaro | 27:1ce994629ffc | 115 | pBlob->createBlob(blobArray.size(), SPOT_FOUNTAIN, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(rand()%3,rand()%3)); |
mbedalvaro | 27:1ce994629ffc | 116 | // add this loop to the present config: |
mbedalvaro | 27:1ce994629ffc | 117 | blobArray.push_back(pBlob); |
mbedalvaro | 27:1ce994629ffc | 118 | |
mbedalvaro | 27:1ce994629ffc | 119 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 27:1ce994629ffc | 120 | numBlobs=blobArray.size(); |
mbedalvaro | 27:1ce994629ffc | 121 | } |
mbedalvaro | 27:1ce994629ffc | 122 | |
mbedalvaro | 1:a4050fee11f7 | 123 | void blobConfig::addOneRigidLoopFollowing() { |
mbedalvaro | 1:a4050fee11f7 | 124 | rigidLoop* pBlob= new rigidLoop(); |
mbedalvaro | 14:0fc33a3a7b4b | 125 | pBlob->createBlob(blobArray.size(), SPOT_FOLLOWING, vector2Df(CENTER_AD_MIRROR_X+100*blobArray.size(), CENTER_AD_MIRROR_Y+100*blobArray.size()), vector2Df(0,0)); |
mbedalvaro | 1:a4050fee11f7 | 126 | // add this relaxing loop to the present config: |
mbedalvaro | 1:a4050fee11f7 | 127 | blobArray.push_back(pBlob); |
mbedalvaro | 1:a4050fee11f7 | 128 | |
mbedalvaro | 1:a4050fee11f7 | 129 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 1:a4050fee11f7 | 130 | numBlobs=blobArray.size(); |
mbedalvaro | 1:a4050fee11f7 | 131 | } |
mbedalvaro | 0:345b3bc7a0ea | 132 | |
mbedalvaro | 5:73cd58b58f95 | 133 | void blobConfig::addOneRigidLoopTest() { |
mbedalvaro | 5:73cd58b58f95 | 134 | rigidLoop* pBlob= new rigidLoop(); |
mbedalvaro | 12:0de9cd2bced5 | 135 | pBlob->createBlob(blobArray.size(), SPOT_TEST, vector2Df(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y), vector2Df(0,0)); |
mbedalvaro | 5:73cd58b58f95 | 136 | // add this relaxing loop to the present config: |
mbedalvaro | 5:73cd58b58f95 | 137 | blobArray.push_back(pBlob); |
mbedalvaro | 5:73cd58b58f95 | 138 | |
mbedalvaro | 5:73cd58b58f95 | 139 | // update auxiliary variable numBlobs (just for easy reference): |
mbedalvaro | 5:73cd58b58f95 | 140 | numBlobs=blobArray.size(); |
mbedalvaro | 5:73cd58b58f95 | 141 | } |
mbedalvaro | 5:73cd58b58f95 | 142 | |
mbedalvaro | 0:345b3bc7a0ea | 143 | |
mbedalvaro | 0:345b3bc7a0ea | 144 | // ================================================================================================================================================== |
mbedalvaro | 0:345b3bc7a0ea | 145 | |
mbedalvaro | 0:345b3bc7a0ea | 146 | |
mbedalvaro | 1:a4050fee11f7 | 147 | void blobConfig::allKill() { // this put all the blobs in "dead" mode, meaning that neither rendering nor update is done (but they are not deleted). |
mbedalvaro | 1:a4050fee11f7 | 148 | for (int i=0; i<blobArray.size(); i++) { |
mbedalvaro | 1:a4050fee11f7 | 149 | blobArray[i]->render = false; |
mbedalvaro | 1:a4050fee11f7 | 150 | blobArray[i]->standByMode = false; |
mbedalvaro | 1:a4050fee11f7 | 151 | } |
mbedalvaro | 1:a4050fee11f7 | 152 | } |
mbedalvaro | 0:345b3bc7a0ea | 153 | void blobConfig::allAlive() { |
mbedalvaro | 1:a4050fee11f7 | 154 | for (int i=0; i<blobArray.size(); i++) { |
mbedalvaro | 1:a4050fee11f7 | 155 | blobArray[i]->render = true; |
mbedalvaro | 1:a4050fee11f7 | 156 | blobArray[i]->standByMode = true; |
mbedalvaro | 1:a4050fee11f7 | 157 | } |
mbedalvaro | 1:a4050fee11f7 | 158 | } |
mbedalvaro | 1:a4050fee11f7 | 159 | |
mbedalvaro | 0:345b3bc7a0ea | 160 | void blobConfig::allStandBy() { |
mbedalvaro | 1:a4050fee11f7 | 161 | for (int i=0; i<blobArray.size(); i++) blobArray[i]->standByMode = true; |
mbedalvaro | 0:345b3bc7a0ea | 162 | } |
mbedalvaro | 0:345b3bc7a0ea | 163 | |
mbedalvaro | 0:345b3bc7a0ea | 164 | void blobConfig::allResume() { |
mbedalvaro | 1:a4050fee11f7 | 165 | for (int i=0; i<blobArray.size(); i++) blobArray[i]->standByMode = false; |
mbedalvaro | 0:345b3bc7a0ea | 166 | } |
mbedalvaro | 0:345b3bc7a0ea | 167 | |
mbedalvaro | 1:a4050fee11f7 | 168 | void blobConfig::allVisible() { |
mbedalvaro | 1:a4050fee11f7 | 169 | for (int i=0; i<blobArray.size(); i++) blobArray[i]->render = true; |
mbedalvaro | 0:345b3bc7a0ea | 170 | } |
mbedalvaro | 0:345b3bc7a0ea | 171 | |
mbedalvaro | 0:345b3bc7a0ea | 172 | void blobConfig::allInvisible() { // note that they may continue to evolve |
mbedalvaro | 1:a4050fee11f7 | 173 | for (int i=0; i<blobArray.size(); i++) blobArray[i]->render = false; |
mbedalvaro | 0:345b3bc7a0ea | 174 | } |
mbedalvaro | 0:345b3bc7a0ea | 175 | |
mbedalvaro | 25:74cb85b85fd2 | 176 | void blobConfig::allSetColor(unsigned char c) { |
mbedalvaro | 25:74cb85b85fd2 | 177 | for (int i=0; i<blobArray.size(); i++) blobArray[i]->setColor(c); |
mbedalvaro | 25:74cb85b85fd2 | 178 | } |
mbedalvaro | 25:74cb85b85fd2 | 179 | |
mbedalvaro | 1:a4050fee11f7 | 180 | void blobConfig::update() { // update dynamics of the blob |
mbedalvaro | 1:a4050fee11f7 | 181 | for (int i=0; i<blobArray.size(); i++) { |
mbedalvaro | 3:b44ff6de81bd | 182 | if (blobArray[i]->standByMode==false) blobArray[i]->update(); |
mbedalvaro | 1:a4050fee11f7 | 183 | } |
mbedalvaro | 0:345b3bc7a0ea | 184 | } |
mbedalvaro | 0:345b3bc7a0ea | 185 | |
mbedalvaro | 1:a4050fee11f7 | 186 | void blobConfig::draw() { // draw uses the opengl like renderer (if any), and save projected trajectory in the LaserSensingTrajectory object of each blob |
mbedalvaro | 1:a4050fee11f7 | 187 | for (int i=0; i<blobArray.size(); i++) { |
mbedalvaro | 1:a4050fee11f7 | 188 | if (blobArray[i]->render==true) blobArray[i]->draw(); |
mbedalvaro | 1:a4050fee11f7 | 189 | } |
mbedalvaro | 0:345b3bc7a0ea | 190 | } |
mbedalvaro | 0:345b3bc7a0ea | 191 | |
mbedalvaro | 1:a4050fee11f7 | 192 | void blobConfig::sendConfData() { |
mbedalvaro | 1:a4050fee11f7 | 193 | // For the time being, only "per blob" data sending: |
mbedalvaro | 1:a4050fee11f7 | 194 | // (b) Per-spot sending of data (note: both are NOT exclusive; so if we want just packaged data, we need to make all the spot STOP sending data. |
mbedalvaro | 18:d72935b13858 | 195 | for (int i=0; i<blobArray.size(); i++) { |
mbedalvaro | 1:a4050fee11f7 | 196 | if (blobArray[i]->render==true) blobArray[i]->sendData(); // a blob that is in stand-by mode may send data (good for testing with a fixed loop) |
mbedalvaro | 1:a4050fee11f7 | 197 | } |
mbedalvaro | 0:345b3bc7a0ea | 198 | } |
mbedalvaro | 0:345b3bc7a0ea | 199 | |
mbedalvaro | 0:345b3bc7a0ea | 200 | |
mbedalvaro | 0:345b3bc7a0ea | 201 | |
mbedalvaro | 0:345b3bc7a0ea | 202 |