Exemple #1
0
//==============================================================================
int CEyeTrack::ConnectISCAN(  ){
  int iRet;

  if( IsRunning() ) {
    CP_printf("Error in m_InitSerialThread()! Thread is already running.\n");
    return 1;
  }
  iRet = g_SysGrantIO( LPT_BASE );
  if( iRet ) {
    iPortIO_Granted = 0;
    printf("Error: Cannot grant I/O access, error: %d\n", iRet );
    return 1;
  }
 
  iPortIO_Granted = 1;
  PortOutput( LPT_CONTROL, RESET_ON);
  Sleep(1);
  PortOutput( LPT_CONTROL, GATE_OFF);
  Sleep(1);
  PortOutput( LPT_CONTROL, GATE_ON);


  CP_printf("Connecting to %s port\n", x_aszComNames[ m_iComPortIdx-1]);
  iRet = m_Serial.connect(x_aszComNames[ m_iComPortIdx-1], m_iBaudRate, m_iSerialParity);
  if(iRet) {
    CP_printf("Error in m_InitSerialThread, m_Serial.connect() failed\n");
    return 1;
  }

  m_ReadCount = 0;
  m_iMissCount = 0;
  m_nMissedFrames = 0;
  m_iPrevFrame = 0;
  m_iReportSync = 1;  // report next sync
  // Init sliding buffer
  SetBuffer(sizeof(IScanFrameStruct), ISCAN_BUFFER_SIZE);
  ResetBuffer();
  ResetTime();
  m_StartReadingThread( ); 
  if( !IsRunning() ) {
    CP_printf("Error in m_InitSerialThread()! CreateThread() failed.\n");
    PortOutput( LPT_CONTROL, GATE_OFF);
    RemoveBuffer();
    return 1;
  }
  CP_printf("Connected ISCAN\n");
  CP_printf("Expected number of parameters: %d\n", N_DATA_ITEMS);
  return 0;
}
Exemple #2
0
//==============================================================================
int COptoTrack::ConnectOpto(  ){
  BOOL bRes;
  int iErr;
  int iFrameSize;
  int iAttempt, nAttempts;

  CP_printf("Connecting to OptoTrak...\n");
  if( IsRunning() ) {
    CP_printf("  OptoTrak is already connected!\n");
    return 1;
  }

  m_iReadCount = 0;
  m_iOptoFrameIdx = 0;
  m_iPrevFrame = 0;
  m_nMissedTimes = 0;
  m_nMissedFrames = 0;


  // Make several attempts to load system. If OptoTrack was just
  // turned on, first attempt is unsuccessful
  nAttempts = 2;
  iErr = 1;  // we exit the loop when iErr==0
  for( iAttempt = 0; iAttempt < nAttempts && iErr;  iAttempt++ ){
    // Load OptoTrack transputers with system software
    CP_printf("TransputerLoadSystem() Attempt %d of %d\n", iAttempt+1, nAttempts);
    iErr = TransputerLoadSystem( "system" );
    Sleep( 1000 ); // Wait one second to let the system finish loading.
  }
  if( iErr )  {
    CP_printf("Error: %d attempts of TransputerLoadSystem() failed!\n", iAttempt);
    m_PrintOptoError( iErr );
    CP_printf("Make sure that both OptoTrak modules are turned on.\n");
    CP_printf("Giving up on TransputerLoadSystem()\n");
    return 1;
  }
  CP_printf("TransputerLoadSystem(): Ok \n");

  // Initialize the transputer system.
  iErr = TransputerInitializeSystem( 0 );  // 0 == don't create log files
  if( iErr )  {
    CP_printf("Error: TransputerInitializeSystem() failed!\n");
    return 1;
  } 
  CP_printf("TransputerInitializeSystem(): Ok \n");

  // Set optional processing flags (this overrides settings in OPTOTRAK.INI).
  iErr = OptotrakSetProcessingFlags( 
//              OPTO_LIB_POLL_REAL_DATA |  // if this flag is set, CPU clocks are waisted
              OPTO_CONVERT_ON_HOST |     // Convert raw to 3D on PC
              OPTO_RIGID_ON_HOST );      // Convert 3D to rigid on PC
  if( iErr )  {
    CP_printf("Error: OptotrakSetProcessingFlags() failed!\n");
    return 1;
  }
  CP_printf("OptotrakSetProcessingFlags(): Ok \n");
  
  // Load the standard camera parameters.
  iErr = OptotrakLoadCameraParameters( "standard" );
  if( iErr )  {
    CP_printf("Error: OptotrakLoadCameraParameters() failed!\n");
    return 1;
  }
  CP_printf("OptotrakLoadCameraParameters(): Ok \n");


  // create sliding buffer
  iFrameSize = sizeof(tOptoFrame) * m_nSensorsToWrite;
  bRes = SetBuffer( iFrameSize, // Item size
                    int(BUFFER_SIZE_SECONDS * FRAME_RATE_HZ) );   // N items
  if( !bRes ) {
    CP_printf("Error: SetBuffer() failed!\n");
    iErr = 1;
    goto errExit;
  }

//  CP_printf("Raw frame size: %d \n\n", sizeof(tOptoFrame));


  m_iPrevFrame = 0;

  iErr = OptotrakSetStroberPortTable( m_anSensorsPerPort[0],
                                      m_anSensorsPerPort[1],
                                      m_anSensorsPerPort[2],
                                      m_anSensorsPerPort[3] );
  if( iErr )  {
    CP_printf("Error: OptotrakSetStroberPortTable() failed!\n");
    iErr = 1;
    goto errExit;
  }

  // Set up collection 
  // This starts data acquisition
  iErr = OptotrakSetupCollection(
            m_nSensorsToRead,    // Number of markers in the collection. 
            FRAME_RATE_HZ,  // Frequency to collect data frames at. 
            2000.0f,        // Marker frequency for marker maximum on-time. 
            30,             // Dynamic or Static Threshold value to use. 
            160,            // Minimum gain code amplification to use. 
            0,              // Stream mode for the data buffers. 
            0.5f,           // Marker Duty Cycle to use. 
            5.0f,           // Voltage to supply strobers and LEDs 
//            7.5f,           // Voltage to supply strobers and LEDs 
            0.0f,           // Number of seconds of data to collect. 
            0.0f,           // Number of seconds to pre-trigger data by. 
            0 );            // No flags

// Possible flags (not used):
//    OPTOTRAK_GET_NEXT_FRAME_FLAG // Don't receive the same frame twice
//  | OPTOTRAK_BUFFER_RAW_FLAG 
  
  if( iErr )  {
    CP_printf("Error: OptotrakSetupCollection() failed!\n");
    iErr = 1;
    goto errExit;
  }

  // manual warns of errors if we don't wait enough 
  // after calling OptotrakSetupCollection()
  Sleep( 1000 );  
//  TODO: what should be the default state??
//  iErr = OptotrakDeActivateMarkers();

  // Start the thread
  if( m_StartReadingThread( )) {
    CP_printf("Error: m_StartReadingThread() failed!\n");
    iErr = 1;
    goto errExit;
  }

  CP_printf("Connected!\n");
  return 0;

errExit:
    DisconnectOpto();
    return iErr;
}