Changeset 1f1f1b7 in robotics-hold_release


Ignore:
Timestamp:
08/11/13 10:10:50 (8 years ago)
Author:
Steve Castellotti <sc@…>
Branches:
master
Children:
2ff6bfa
Parents:
8cca378
Message:

StimulusTask?.cpp

  • Rollback to initial checkin
  • Updated target to be Virtual Machine host instead of localhost
File:
1 edited

Legend:

Unmodified
Added
Removed
  • wheelchair/bci2000/deploy/BCI2000/src/shared/modules/application/StimulusTask.cpp

    r8cca378 r1f1f1b7  
    11//////////////////////////////////////////////////////////////////////////////// 
    2 // $Id: StimulusTask.cpp 4447 2013-05-22 14:26:10Z mellinger $ 
     2// $Id: StimulusTask.cpp 3866 2012-03-06 16:11:02Z mellinger $ 
    33// Author: juergen.mellinger@uni-tuebingen.de 
    44// Description: A base class for application modules that provide feedback in a 
     
    5858  mPreSequenceDuration( 0 ), 
    5959  mPostSequenceDuration( 0 ), 
    60   mEarlyOffsetPreviousValue( 0.0 ), 
    61   mEarlyOffsetExpression( ), 
    6260  mStimulusDuration( 0 ), 
    6361  mISIMinDuration( 0 ), 
     
    6664  mpMessageField( NULL ), 
    6765  mpAttendedTarget( NULL ), 
    68   mAccumulateEvidence( false ), 
    69   mMinimumEvidence( 0 ), 
    7066  mrDisplay( Window() ) 
    7167{ 
     
    8177   "Application:Sequencing float StimulusDuration= 40ms 40ms 0 % " 
    8278     "// stimulus duration", 
    83    "Application:Sequencing string EarlyOffsetExpression= % % % % " 
    84      "// abort stimulus if this expression becomes true", 
    8579   "Application:Sequencing float ISIMinDuration= 80ms 80ms 0 % " 
    8680     "// minimum duration of inter-stimulus interval", 
     
    9690   "Application:Result%20Processing int DisplayResults= 1 1 0 1 " 
    9791     "// display results of copy/free spelling (boolean)", 
    98  
    99    "Application:Result%20Processing int AccumulateEvidence= 0 0 0 1 " 
    100      "// accumulate evidence until a selection is made (boolean)", 
    101    "Application:Result%20Processing float MinimumEvidence= 0 0 0 % " 
    102      "// do not make a selection unless target evidence exceeds this value. " 
    103      "For a normalized classifier, MinimumEvidence approximates -2.3*log10(Error Probability)", 
    10492  END_PARAMETER_DEFINITIONS 
    10593 
     
    180168  State( "Running" ); 
    181169 
    182   string exprstr = Parameter( "EarlyOffsetExpression" ); 
    183   if( exprstr.size() && !Expression( exprstr ).IsValid() ) 
    184   { 
    185     bcierr << "error in EarlyOffsetExpression parameter: "; 
    186     Expression( exprstr ).Evaluate(); 
    187   } 
    188  
    189170  bcidbg( 2 ) << "Event: Preflight" << endl; 
    190171  OnPreflight( Input ); 
     
    205186  mISIMinDuration = static_cast<int>( Parameter( "ISIMinDuration" ).InSampleBlocks() ); 
    206187  mISIMaxDuration = static_cast<int>( Parameter( "ISIMaxDuration" ).InSampleBlocks() ); 
    207   mEarlyOffsetExpression = Expression( Parameter( "EarlyOffsetExpression" ) ); 
    208188  mStimToClassDuration = 2 * ( mStimulusDuration + mISIMinDuration ); 
    209189  mStimToClassDuration = static_cast<int>( ::ceil( OptionalParameter( "EpochLength", mStimToClassDuration ).InSampleBlocks() ) ); 
    210190 
    211191  mInterpretMode = Parameter( "InterpretMode" ); 
    212   mAccumulateEvidence = ( Parameter( "AccumulateEvidence" ) != 0 ); 
    213   mMinimumEvidence = Parameter( "MinimumEvidence" ); 
    214    
     192 
    215193  bcidbg( 2 ) << "Event: Initialize" << endl; 
    216194  OnInitialize( Input ); 
     
    271249} 
    272250 
    273 bool 
    274 StimulusTask::EarlyOffset(  const GenericSignal& Input, const Association& inAssoc ) 
    275 { 
    276   const Expression& expr = inAssoc.HasEarlyOffsetExpression() ? inAssoc.EarlyOffsetExpression() : mEarlyOffsetExpression; 
    277   bool triggered = false; 
    278   if( mBlocksInPhase == 0 ) 
    279     mEarlyOffsetPreviousValue = expr.Evaluate( &Input, 0 ); 
    280   for( int sample = 0; sample < Statevector->Samples() && !triggered; ++sample ) 
    281   { 
    282     double value = expr.Evaluate( &Input, sample ); 
    283     triggered = value && !mEarlyOffsetPreviousValue; 
    284     mEarlyOffsetPreviousValue = value; 
    285   } 
    286   return triggered; 
    287 } 
    288  
    289251void 
    290252StimulusTask::Process( const GenericSignal& Input, GenericSignal& Output ) 
     
    303265                << endl; 
    304266    mClassResult[ stimulusCodeRes ].push_back( Input ); 
    305  
    306         int maxThresh, minThresh, consecutiveTrialsBeforeSelection, heldTarget, previousClassifierValue, currentStimulusCode; 
     267        //AppLog << "Testing " << stimulusCodeRes << Input << endl;  
     268 
     269        //Ramses Alcaide 07.08.2014 Edits for Hold Begin 
     270        int maxThresh, minThresh, consecutiveTrialsBeforeSelection, heldTarget, previousClassifierValue, previousTarget,currentTarget,currentStimulusCode; 
    307271        double currentClassifierValue; 
    308  
    309272        maxThresh = 40; 
    310         minThresh = 40; // Currently using only one threshold.  
     273        minThresh =10;  
    311274        consecutiveTrialsBeforeSelection = 0; 
    312         previousClassifierValue = 0; 
    313  
    314         // Initialize Target to "Halt". 
    315         heldTarget = 5; 
    316          
     275        heldTarget = -1; 
     276        previousClassifierValue = 0;  
     277        previousTarget = 0; 
     278        currentTarget = 0; 
    317279        currentStimulusCode = 0;  
    318         currentClassifierValue = 0; 
     280        currentClassifierValue =0; 
     281 
    319282        currentStimulusCode = stimulusCodeRes; 
    320283        currentClassifierValue = Input(0,0); 
     284        if (currentStimulusCode == 1 || currentStimulusCode == 7||currentStimulusCode== 6|| currentStimulusCode== 12){ 
     285        if(currentStimulusCode== 1 || currentStimulusCode== 7){ 
     286                currentTarget = 0;       
     287                if (currentClassifierValue >maxThresh) { 
     288                        heldTarget = currentTarget; 
     289 
     290                }else if(currentClassifierValue <minThresh){ 
     291                        heldTarget = 1;  
     292                } 
     293                 
     294        } 
     295        else{ 
     296                currentTarget = 1;  
     297                if (currentClassifierValue >maxThresh) { 
     298                        heldTarget = currentTarget; 
     299 
     300                }else if(currentClassifierValue <minThresh){ 
     301                        heldTarget = 0;  
     302                } 
     303        }                
     304} 
     305 
     306        AppLog <<"Input "<<Input(0,0)<<" " <<"CurrentStimulusCode "<<currentStimulusCode<<" "<<"StimulusCodeRes "<<stimulusCodeRes<<endl; 
     307        AppLog<<"CurrentClassifierValue "<<currentClassifierValue<<" "<<"HeldTarget "<<heldTarget << endl;  
     308 
     309        //Ramses Alcaide 07.08.2014 Edits for Hold End */ 
     310           
     311 
     312        //Ramses Alcaide 07.08.2014 Edits for UDP out Begin 
     313        //const char* address = "localhost:20320"; 
     314        const char* address = "172.16.5.1:20320"; 
    321315         
    322         if ((currentStimulusCode == 1 || currentStimulusCode == 7) && (currentClassifierValue > maxThresh)){ // Forward row/col is intensified and classifier is above the threshold. 
    323                 heldTarget = 1; // Decision is 1 = Forward  
    324         } 
    325          
    326         else if((currentStimulusCode == 5 || currentStimulusCode == 9) && (currentClassifierValue > maxThresh)) { // Backward. 
    327                 heldTarget = 2; 
    328         }                
    329          
    330         else if((currentStimulusCode == 4 || currentStimulusCode == 6) && (currentClassifierValue > maxThresh)) { // Rotate left. 
    331                 heldTarget = 3; 
    332         }                
    333          
    334         else if((currentStimulusCode == 2 || currentStimulusCode == 10) && (currentClassifierValue > maxThresh)) { // Rotate right. 
    335                 heldTarget = 4; 
    336         }                
    337          
    338         else if((currentStimulusCode == 3 || currentStimulusCode == 8) && (currentClassifierValue > maxThresh)) { // Halt. 
    339                 heldTarget = 5; 
    340         } 
    341          
    342         else if (currentClassifierValue < minThresh) { 
    343                                 heldTarget = 0; // Carry on the last decision.   
    344         } 
    345          
    346         AppLog << "Current Classifier Value: " << currentClassifierValue << " - Held Target: " << heldTarget << endl; 
    347  
    348         // Ramses Alcaide 07.08.2014 Edits for UDP out Begin 
    349         const char* address = "172.16.5.1:20320"; 
    350         // const char* address = "localhost:20320"; 
    351         // Read from stdin, write to socket. 
     316        //  write to socket. 
    352317    sending_udpsocket socket( address ); 
    353318    sockstream output( socket ); 
    354     if(!output.is_open()) 
    355       cerr << "Could not open " << address << " for output." << endl; 
    356  
    357     //string line; 
    358         //line = "1"; 
    359     //while( getline( cin, line ) ) 
    360         //AppLog << heldTarget << endl; 
    361         output << heldTarget << endl; 
    362    
    363  
    364  
    365         // Ramses Alcaide 07.08.2014 Edits for UDP out End 
    366  
    367          
    368         bcidbg( 2 ) << "Event: ClassInput" << endl; 
     319    if( !output.is_open() ) 
     320      cerr << "Could not open " << address 
     321           << " for output." << endl; 
     322 
     323    string line; 
     324        line = "1"; 
     325      output << line << endl; 
     326 
     327        //Ramses Alcaide 07.08.2014 Edits for UDP out End*/ 
     328 
     329    bcidbg( 2 ) << "Event: ClassInput" << endl; 
    369330    OnClassInput( stimulusCodeRes, Input ); 
    370331  } 
     
    391352        doProgress = ( mBlocksInPhase >= stimulusDuration ); 
    392353        State( "StimulusBegin" ) = ( mBlocksInPhase == 0 && !doProgress ); 
    393         doProgress |= EarlyOffset( Input, Associations()[ mStimulusCode ] ); 
    394354        DoStimulus( Input, doProgress ); 
    395355      } break; 
     
    403363        if( mInterpretMode != InterpretModes::None 
    404364            && mBlocksSinceStimulus >= mStimToClassDuration 
    405             && !mClassResult.empty() && !mCodesPresented.empty() ) 
     365            && !mClassResult.empty() ) 
    406366        { 
    407367          for( set<int>::const_iterator i = mCodesPresented.begin(); i != mCodesPresented.end(); ++i ) 
     
    414374          if( pTarget != NULL ) 
    415375            pTarget->Select(); 
    416           if( !mAccumulateEvidence || pTarget ) 
    417             mClassResult.clear(); 
     376          mClassResult.clear(); 
    418377          mCodesPresented.clear(); 
    419378        } 
     
    431390 
    432391      default: 
    433         throw std_runtime_error( "Unknown phase value: " << mPhase ); 
     392        throw bciexception( "Unknown phase value: " << mPhase ); 
    434393    } 
    435394    if( doProgress ) 
     
    446405        case preRun: 
    447406          mStimulusCode = OnNextStimulusCode(); 
     407                   
    448408          if( mStimulusCode > 0 ) 
    449409          { // Enter pre sequence phase 
     
    514474 
    515475        default: 
    516           throw std_logic_error( "Unknown phase value: " << mPhase ); 
     476          throw bciexception( "Unknown phase value: " << mPhase ); 
    517477      } 
    518478    } 
     
    539499StimulusTask::OnClassResult( const ClassResult& inResult ) 
    540500{ 
    541   double evidence = 0; 
    542   Target* p = Associations().ClassifyTargets( inResult ).MostLikelyTarget( evidence ); 
    543   bcidbg( 2 ) << "Target evidence: " << evidence << endl; 
    544   if( evidence < mMinimumEvidence ) 
    545     p = 0; 
    546   return p; 
     501  return Associations().ClassifyTargets( inResult ).MostLikelyTarget(); 
    547502} 
    548503 
Note: See TracChangeset for help on using the changeset viewer.