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
blobConfig.cpp
- Committer:
- mbedalvaro
- Date:
- 2012-04-02
- Revision:
- 3:b44ff6de81bd
- Parent:
- 2:34157ebbf56b
- Child:
- 4:f9d364f10335
File content as of revision 3:b44ff6de81bd:
#include "blobConfig.h"
#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
blobConfig::blobConfig(): numBlobs(0) {
//blobArray.clear();// there is no need to do this, the vector does not contains anything here.
}
blobConfig::~blobConfig() {
clearConfig();
}
// =========================================== STANDARD CONFIGURATIONS =============================================================================
void blobConfig::computeBoundingBox() {
for (int i=0; i<blobArray.size(); i++) {
blobArray[i]->computeBoundingBox();
}
}
void blobConfig::clearConfig() {
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)
blobArray.clear();
numBlobs=0;// this is just equal to blobArray.size()
}
void blobConfig::addOneElasticLoopRelax() {
elasticLoop* pBlob= new elasticLoop();
pBlob->createBlob(blobArray.size(), RELAX, vector2D(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y));
// add this relaxing loop to the present config:
blobArray.push_back(pBlob);
// update auxiliary variable numBlobs (just for easy reference):
numBlobs=blobArray.size();
}
void blobConfig::addOneElasticLoopContract() {
elasticLoop* pBlob= new elasticLoop();
pBlob->createBlob(blobArray.size(), CONTRACT, vector2D(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y));
// add this relaxing loop to the present config:
blobArray.push_back(pBlob);
// update auxiliary variable numBlobs (just for easy reference):
numBlobs=blobArray.size();
}
void blobConfig::addOneElasticLoopContractCentral() {
elasticLoop* pBlob= new elasticLoop();
pBlob->createBlob(blobArray.size(), CONTRACT_CENTRAL, vector2D(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y));
// add this relaxing loop to the present config:
blobArray.push_back(pBlob);
// update auxiliary variable numBlobs (just for easy reference):
numBlobs=blobArray.size();
}
void blobConfig::addOneElasticContourFollowing() {
elasticLoop* pBlob= new elasticLoop();
pBlob->createBlob(blobArray.size(), CONTOUR_FOLLOWING, vector2D(CENTER_AD_MIRROR_X+100*blobArray.size(), CENTER_AD_MIRROR_Y+100*blobArray.size()));
// add this relaxing loop to the present config:
blobArray.push_back(pBlob);
// update auxiliary variable numBlobs (just for easy reference):
numBlobs=blobArray.size();
}
void blobConfig:: addOneElasticContourFollowingFAST() {
elasticLoop* pBlob= new elasticLoop();
pBlob->createBlob(blobArray.size(), CONTOUR_FOLLOWING_FAST, vector2D(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y));
// add this relaxing loop to the present config:
blobArray.push_back(pBlob);
// update auxiliary variable numBlobs (just for easy reference):
numBlobs=blobArray.size();
}
void blobConfig::addOneElasticBouncing() {
elasticLoop* pBlob= new elasticLoop();
pBlob->createBlob(blobArray.size(), BOUNCING, vector2D(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y));
// add this relaxing loop to the present config:
blobArray.push_back(pBlob);
// update auxiliary variable numBlobs (just for easy reference):
numBlobs=blobArray.size();
}
void blobConfig::addOneRigidLoopBouncing() {
rigidLoop* pBlob= new rigidLoop();
pBlob->createBlob(blobArray.size(), SPOT_BOUNCING, vector2D(CENTER_AD_MIRROR_X+100*blobArray.size(), CENTER_AD_MIRROR_Y+100*blobArray.size()));
// add this relaxing loop to the present config:
blobArray.push_back(pBlob);
// update auxiliary variable numBlobs (just for easy reference):
numBlobs=blobArray.size();
}
void blobConfig::addOneRigidLoopFollowing() {
rigidLoop* pBlob= new rigidLoop();
pBlob->createBlob(blobArray.size(), SPOT_FOLLOWING, vector2D(CENTER_AD_MIRROR_X, CENTER_AD_MIRROR_Y));
// add this relaxing loop to the present config:
blobArray.push_back(pBlob);
// update auxiliary variable numBlobs (just for easy reference):
numBlobs=blobArray.size();
}
// ==================================================================================================================================================
void blobConfig::allKill() { // this put all the blobs in "dead" mode, meaning that neither rendering nor update is done (but they are not deleted).
for (int i=0; i<blobArray.size(); i++) {
blobArray[i]->render = false;
blobArray[i]->standByMode = false;
}
}
void blobConfig::allAlive() {
for (int i=0; i<blobArray.size(); i++) {
blobArray[i]->render = true;
blobArray[i]->standByMode = true;
}
}
void blobConfig::allStandBy() {
for (int i=0; i<blobArray.size(); i++) blobArray[i]->standByMode = true;
}
void blobConfig::allResume() {
for (int i=0; i<blobArray.size(); i++) blobArray[i]->standByMode = false;
}
void blobConfig::allVisible() {
for (int i=0; i<blobArray.size(); i++) blobArray[i]->render = true;
}
void blobConfig::allInvisible() { // note that they may continue to evolve
for (int i=0; i<blobArray.size(); i++) blobArray[i]->render = false;
}
void blobConfig::update() { // update dynamics of the blob
for (int i=0; i<blobArray.size(); i++) {
if (blobArray[i]->standByMode==false) blobArray[i]->update();
}
}
void blobConfig::draw() { // draw uses the opengl like renderer (if any), and save projected trajectory in the LaserSensingTrajectory object of each blob
for (int i=0; i<blobArray.size(); i++) {
if (blobArray[i]->render==true) blobArray[i]->draw();
}
}
void blobConfig::sendConfData() {
// For the time being, only "per blob" data sending:
// (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.
for (int i=0; i<blobArray.size(); i++) {
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)
}
}
