Alvaro Cassinelli
/
skinGames_forktest
just a test
Fork of scoreLight_Advanced by
Diff: main.cpp
- Revision:
- 44:46e25fa1669b
- Parent:
- 42:c4e9c1116af4
- Child:
- 46:90516893793a
--- a/main.cpp Fri Mar 28 10:25:06 2014 +0000 +++ b/main.cpp Mon Mar 31 10:57:35 2014 +0000 @@ -60,6 +60,12 @@ // Timers: Timer measureLoopPeriod; + +Timer measureReadPeriod; // timer for reading hardare or communication data (I will read in ms) +#define periodReadingData 30 + + int renderFraction=1;// when 1, the blob needs to be rendered completely before update; 2 means half of it, etc. 0 means render all the time. + //Timer measureUpdatePeriod; @@ -73,13 +79,14 @@ // ------------------------------- // Set the Ethernet port: - printf("Setting up...\r\n"); + // pc.printf("Setting up...\r\n"); + //printf("Setting up...\r\n"); EthernetErr ethErr = eth.setup(); if (ethErr) { - printf("Error %d in setup.\r\n", ethErr); - return -1; + // pc.printf("Error %d in setup.\r\n", ethErr); + // return -1; } - printf("Setup OK\r\n"); + // pc.printf("Setup OK\r\n"); //(1) Sending message: // Set IP and Port: @@ -104,10 +111,13 @@ // initialize with the desired blob configuration: + blobconf.initConfig(ONE_ELASTIC_FOLLOWING); + // Tested modes: - blobconf.clearConfig(); + // blobconf.clearConfig(); // blobconf.addOneElasticLoopContractCentral(); - blobconf.addOneElasticContourFollowing(); + + // blobconf.addOneElasticContourFollowing(); // blobconf.addOneRigidLoopBouncing(); // blobconf.addOneRigidLoopBouncing(); @@ -119,8 +129,9 @@ // START WITH TWO FOLLOWING SPOTS (exhibition Tokyo Design Week): // blobconf.initConfig(FOLLOWING_SPOTS, 2); // value is the nb of spots instantiated // Make them of different color: -// blobconf.blobArray[0]->setBlueColor(1); -// blobconf.blobArray[1]->setGreenColor(1); + //blobconf.blobArray[0]->setBlueColor(1); + //blobconf.blobArray[1]->setGreenColor(1); + // start in no stand by mode: blobconf.allResume(); @@ -148,10 +159,15 @@ #endif //measureUpdatePeriod.start(); + + measureReadPeriod.start(); while (true) { - if (lsr.endedFullDisplay()) { + // Process sensing buffer and compute light forces (for all blobs here, or in the update function for each one) + blobconf.processSensedData(); + + if (lsr.endedFractionDisplay(renderFraction)) {// (lsr.endedFullDisplay()) { // measureUpdatePeriod.stop(); // measureUpdatePeriod.reset(); @@ -180,11 +196,19 @@ // measureUpdatePeriod.start(); - } + } else { + + // do a delay to equilibrate the timings? + //wait_us(6700); + } - // COMMUNICATION: + // COMMUNICATION and HARDWARE CONTROL: + // (a) Reading commands: + if (measureReadPeriod.read_ms()>periodReadingData) { + measureReadPeriod.stop(); + // Ethernet: Net::poll(); // this will take care of calling processOSC(UDPSocketEvent e) when a new packet arrives. @@ -212,11 +236,22 @@ // for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setFixedThreshold(IO.potValue); // pc.printf("Got :%d\n", IO.potValue); // } - if (rotaryEncoder1.CheckNew()) for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setFixedThreshold(rotaryEncoder1.Get()); + if (rotaryEncoder1.CheckNew()) { + for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setFixedThreshold(rotaryEncoder1.Get()); + pc.printf("Fixed Threshold :%d\n", rotaryEncoder1.Get()); + } // (3) Change additional mirror delay from rotary encoder: - if (rotaryEncoder2.CheckNew()) for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setDelayMirrors(rotaryEncoder2.Get()); + if (rotaryEncoder2.CheckNew()) { + for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.setDelayMirrors(rotaryEncoder2.Get()); + pc.printf("Mirror delay :%d\n", rotaryEncoder2.Get()); + } + + // Restart the timer: + measureLoopPeriod.reset(); + measureReadPeriod.start(); + } // text: /* @@ -230,15 +265,15 @@ #ifdef LOOPTIMECOMPUTE if (timeCounterNum>50) myled = 0; // if (timeCounterNum%10==0) blobconf.sendConfData(); - if (timeCounterNum>100) { + if (timeCounterNum>1000) { myled = 1; measureLoopPeriod.stop(); sendMes.setTopAddress("/timeloop"); sendMes.setSubAddress("/"); - // long x=(long)(int(measureLoopPeriod.read_us()/100.0)); + long x=(long)(int(measureLoopPeriod.read_us()/1000.0)); // long x=(long)(blobconf.blobArray[0]->displaySensingBuffer.lsdTrajectory.size()); // long x=(long)(blobconf.blobArray[0]->normRecenteringVector); - long x=(long)(1000*blobconf.blobArray[0]->displaySensingBuffer.lsdTrajectory[0].intensity); + //long x=(long)(1000*blobconf.blobArray[0]->displaySensingBuffer.lsdTrajectory[0].intensity); sendMes.setArgs( "i", &x); osc.sendOsc( &sendMes ); timeCounterNum=0; @@ -389,7 +424,9 @@ timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL); // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL); - } else if (!strcmp(address[0], "elastic_mouth")) { // + } + + else if (!strcmp(address[0], "elastic_mouth")) { // timerForRendering.detach(); blobconf.initConfig(ONE_ELASTIC_MOUTH); @@ -471,6 +508,12 @@ lsr.setConfigToRender(&blobconf); timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThread, RENDER_INTERVAL); // timerForRendering.attach(&lsr, &simpleLaserSensingRenderer::laserRenderThreadONEBLOBONLY, RENDER_INTERVAL); + + if ( blobconf.numBlobs>1) + for (int i=0; i< blobconf.numBlobs; i++) { + blobconf.blobArray[i]->displaySensingBuffer.setDelayMirrors(2); + blobconf.blobArray[i]->angleCorrectionForceLoop=-8;// in degrees + } } } @@ -592,23 +635,53 @@ // ADJUST MIRROR ANGLE CORRECTION: else if (!strcmp( address[0], "adjustPlusAngle" ) ) { int value=data[0]; // this is not a factor, but an additive quantity to the current delay - if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data) - for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.addDelayMirrors(value); - } + if (value!=-1) // otherwise do nothing, this is a reception error (there was no data) + for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->addAngleCorrection(value); } else if (!strcmp( address[0], "adjustMinusAngle" ) ) { int value=data[0]; // this is not a factor, but an substractive quantity to the current delay - if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data) - for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.addDelayMirrors(-value); - } + if (value!=-1) // otherwise do nothing, this is a reception error (there was no data) + for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->addAngleCorrection(-value); } - else if (!strcmp( address[0], "adjustPlusAngle" ) ) { + // ADJUST MIRROR DELAY (angle or mirror delay are equivalent in case of circular blobs): + else if (!strcmp( address[0], "adjustPlusDelay" ) ) { int value=data[0]; // value 100 means no change of speed. 200 is twice as fast, 50 is half as fast. if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data) for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.addDelayMirrors(value); } } + else if (!strcmp( address[0], "adjustMinusDelay" ) ) { + int value=data[0]; // value 100 means no change of speed. 200 is twice as fast, 50 is half as fast. + if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data) + for (int i=0; i< blobconf.numBlobs; i++) blobconf.blobArray[i]->displaySensingBuffer.addDelayMirrors(-value); + } + } + + else if (!strcmp( address[0], "adjustRenderFraction" ) ) { + int value=data[0]; // value 100 means no change of speed. 200 is twice as fast, 50 is half as fast. + if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data) + renderFraction=value; + if (renderFraction>lsr.configTotalPoints) renderFraction=0;// update ALL the time (per-point) + if (renderFraction<1) renderFraction=1; + } + } + + else if (!strcmp( address[0], "adjustPlusRenderFraction" ) ) { + int value=data[0]; // value 100 means no change of speed. 200 is twice as fast, 50 is half as fast. + if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data) + renderFraction+=value; + if (renderFraction>lsr.configTotalPoints) renderFraction=0;// meaning: update ALL the time (per-point) + } + } + + else if (!strcmp( address[0], "adjustMinusRenderFraction" ) ) { + int value=data[0]; // value 100 means no change of speed. 200 is twice as fast, 50 is half as fast. + if (value!=-1) { // otherwise do nothing, this is a reception error (there was no data) + renderFraction=((renderFraction-value)>=1? renderFraction-value : 1); + } + } + // THRESHOLD MODE, and PARAMETERS: