Example #1
0
void main( int argc, unsigned char *argv[] )
{
	OptotrakSettings
		dtSettings;
    int
		nCurDevice,
		nCurMarker,
		nDevices,
		nMarkersToActivate;
	ApplicationDeviceInformation
		*pdtDevices;
    DeviceHandle
        *pdtDeviceHandles;
    DeviceHandleInfo
        *pdtDeviceHandlesInfo;
	unsigned int
		uFlags,
		uElements,
        uChannelCnt,
		uFrameNumber;
    Position3d
        *p3dData;
    static int
        puOdauData[ SAMPLE_NUM_CHANNELS + 1];
    char
        szNDErrorString[MAX_ERROR_STRING_LENGTH + 1];


    /*
     * initialization
	 * intialize variables
     */
	pdtDevices = NULL;
	pdtDeviceHandles = NULL;
	pdtDeviceHandlesInfo = NULL;
	p3dData = NULL;
	dtSettings.nMarkers = 0;
	dtSettings.fFrameFrequency = SAMPLE_FRAMEFREQ;
	dtSettings.fMarkerFrequency = SAMPLE_MARKERFREQ;
	dtSettings.nThreshold = 30;
	dtSettings.nMinimumGain = 160;
	dtSettings.nStreamData = SAMPLE_STREAMDATA;
	dtSettings.fDutyCycle = SAMPLE_DUTYCYCLE;
	dtSettings.fVoltage = SAMPLE_VOLTAGE;
	dtSettings.fCollectionTime = 1.0;
	dtSettings.fPreTriggerTime = 0.0;
	nDevices = 0;
	nMarkersToActivate = 0;

	/*
	 * Announce that the program has started
	 */
	fprintf( stdout, "\nOptotrak Certus sample program #19\n\n" );

	/*
	 * look for the -nodld parameter that indicates 'no download'
	 */
	if( ( argc < 2 ) || ( strncmp( argv[1], "-nodld", 6 ) != 0 ) )
	{
		/*
		 * Load the system of processors.
		 */
		fprintf( stdout, "...TransputerLoadSystem\n" );
		if( TransputerLoadSystem( "system" ) != OPTO_NO_ERROR_CODE )
		{
			goto ERROR_EXIT;
		} /* if */

		sleep( 1 );
	} /* if */

    /*
     * Communication Initialization
     * Once the system processors have been loaded, the application
     * prepares for communication by initializing the system processors.
     */
	fprintf( stdout, "...TransputerInitializeSystem\n" );
    if( TransputerInitializeSystem( OPTO_LOG_ERRORS_FLAG | OPTO_LOG_MESSAGES_FLAG ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */

	/*
	 * Determine if this sample will run with the system attached.
	 * This sample is intended for Optotrak Certus systems.
	 */
	fprintf( stdout, "...DetermineSystem\n" );
	if( uDetermineSystem( ) != OPTOTRAK_CERTUS_FLAG )
	{
		goto ERROR_EXIT;
	} /* if */

    /*
     * Strober Initialization
     * Once communication has been initialized, the application must
     * determine the strober configuration.
     * The application retrieves device handles and all strober
     * properties from the system.
     */
	fprintf( stdout, "...DetermineStroberConfiguration\n" );
	if( DetermineStroberConfiguration( &pdtDeviceHandles, &pdtDeviceHandlesInfo, &nDevices ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */

	/*
	 * check if any devices have been detected by the system
	 */
	if( nDevices == 0 )
	{
		fprintf( stdout, ".........no devices detected.  Quitting program...\n" );
		goto PROGRAM_COMPLETE;
	} /* if */

    /*
     * Now that all the device handles have been completely set up,
     * the application can store all the device handle information in
     * an internal data structure.  This will facilitate lookups when
     * a property setting needs to be checked.
     */
    ApplicationStoreDeviceProperties( &pdtDevices, pdtDeviceHandlesInfo, nDevices );

	/*
	 * Change the number of markers to fire for all devices
	 */
	for( nCurDevice = 0; nCurDevice < nDevices; nCurDevice++ )
	{
		nMarkersToActivate = pdtDevices[nCurDevice].b3020Capability?
							   CERTUS_SAMPLE_3020_STROBER_MARKERSTOFIRE : CERTUS_SAMPLE_STROBER_MARKERSTOFIRE;

		SetMarkersToActivateForDevice( &(pdtDevices[nCurDevice]), pdtDeviceHandlesInfo[nCurDevice].pdtHandle->nID, nMarkersToActivate );
	} /* if */
	fprintf( stdout, "\n" );

	/*
	 * Determine the collection settings based on the device properties
	 */
	ApplicationDetermineCollectionParameters( nDevices, pdtDevices, &dtSettings );


    /*
     * Set optional processing flags (this overides the settings in Optotrak.INI).
     */
	fprintf( stdout, "...OptotrakSetProcessingFlags\n" );
    if( OptotrakSetProcessingFlags( OPTO_LIB_POLL_REAL_DATA |
                                    OPTO_CONVERT_ON_HOST |
                                    OPTO_RIGID_ON_HOST ) )
    {
        goto ERROR_EXIT;
    } /* if */

    /*
	 * Load camera parameters.
     */
	fprintf( stdout, "...OptotrakLoadCameraParameters\n" );
    if( OptotrakLoadCameraParameters( "standard" ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */

	/*
	 * Ensure that we are firing some markers
	 */
	if( dtSettings.nMarkers == 0 )
	{
		fprintf( stdout, "Error: There are no markers to be activated.\n" );
		goto ERROR_EXIT;
	} /* if */

	/*
	 * allocate memory for 3d data
	 */
	p3dData = (Position3d*)malloc( dtSettings.nMarkers * sizeof( Position3d ) );

    /*
     * Configure ODAU Collection.
     */
	fprintf( stdout, "...OdauSetupCollection\n" );
    if( OdauSetupCollection( ODAU1,
							 SAMPLE_NUM_CHANNELS,		/* Number of analog channels to collect. */
							 SAMPLE_ODAU_GAIN,			/* Gain to use for the analog channels.*/
							 ODAU_DIGITAL_INPB_INPA,	/* Mode for the Digital I/O port.*/
							 (float)100.0,				/* Frequency to collect data frames at. */
							 (float)90000.0,			/* Frequency to scan channels at. */
							 SAMPLE_STREAMDATA,			/* Stream mode for the data buffers. */
							 (float)1.0,				/* Number of seconds of data to collect. */
							 0.0,						/* Number of seconds to pre-trigger data by. */
							 0 ) )						/* Flags. */
    {
        goto ERROR_EXIT;
    } /* if */

    /*
     * Configure Optotrak Collection
     * Once the system strobers have been enabled, and all settings are
     * loaded, the application can set up the Optotrak collection
     */
	fprintf( stdout, "...OptotrakSetupCollection\n" );
	fprintf( stdout, ".....%d, %.2f, %.0f, %d, %d, %d, %.2f, %.2f, %.0f, %.0f\n",
								 dtSettings.nMarkers,
			                     dtSettings.fFrameFrequency,
				                 dtSettings.fMarkerFrequency,
					             dtSettings.nThreshold,
						         dtSettings.nMinimumGain,
							     dtSettings.nStreamData,
								 dtSettings.fDutyCycle,
								 dtSettings.fVoltage,
								 dtSettings.fCollectionTime,
								 dtSettings.fPreTriggerTime );
    if( OptotrakSetupCollection( dtSettings.nMarkers,
			                     dtSettings.fFrameFrequency,
				                 dtSettings.fMarkerFrequency,
					             dtSettings.nThreshold,
						         dtSettings.nMinimumGain,
							     dtSettings.nStreamData,
								 dtSettings.fDutyCycle,
								 dtSettings.fVoltage,
								 dtSettings.fCollectionTime,
								 dtSettings.fPreTriggerTime,
								 OPTOTRAK_NO_FIRE_MARKERS_FLAG | OPTOTRAK_BUFFER_RAW_FLAG | OPTOTRAK_SWITCH_AND_CONFIG_FLAG ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */

    /*
     * Wait one second to let the camera adjust.
     */
    sleep( 1 );

	/*
	 * Activate markers.
	 */
	fprintf( stdout, "...OptotrakActivateMarkers\n" );
	if( OptotrakActivateMarkers( ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */
	sleep( 1 );

	/*
	 * loop around until a device is plugged or unplugged
	 */
	while( 1 )
	{
		fprintf( stdout, "\nCHANGE THE STROBER CONFIGURATION OR PRESS SWITCH TO END THIS TEST\n\n" );
		sleep( 1 );

		if( DataGetLatest3D( &uFrameNumber, &uElements, &uFlags, p3dData ) != OPTO_NO_ERROR_CODE )
		{
			goto ERROR_EXIT;
		} /* if */

        fprintf( stdout, "\nFrame Number: %8u\n", uFrameNumber );

		/*
		 * display the 3d data
		 */
		fprintf( stdout, "3D Data Display (%d Markers)\n", dtSettings.nMarkers );
		for( nCurMarker = 0; nCurMarker < dtSettings.nMarkers; nCurMarker++ )
		{
			DisplayMarker( nCurMarker + 1, p3dData[nCurMarker] );
		} /* for */

		/*
		 * check if the tool configuration has changed
		 */
		if( uFlags & OPTO_TOOL_CONFIG_CHANGED_FLAG )
		{
			/*
			 * exit the program loop
			 */
			fprintf( stdout, "\n\n\n...Tool Configuration Changed\n" );
			break;
		} /* if */

		if( uFlags & OPTO_SWITCH_DATA_CHANGED_FLAG )
		{
			/*
			 * exit the program loop
			 */
			fprintf( stdout, "\n\n\n...Switch Data Changed\n" );
			break;
		} /* if */

        /*
         * Get a frame of ODAU raw data.
         */
        fprintf( stdout, "\n" );
        if( DataGetLatestOdauRaw( ODAU1, &uFrameNumber, &uElements, &uFlags, puOdauData ) )
        {
            goto ERROR_EXIT;
        } /* if */

        /*
         * Print out the data.
         */
        for( uChannelCnt = 0; uChannelCnt < SAMPLE_NUM_CHANNELS; ++uChannelCnt )
        {
            fprintf( stdout, "Channel %u  Raw 0x%08x  Voltage %f\n",
                     uChannelCnt + 1,
                     puOdauData[ uChannelCnt],
                     (float)( (int)( puOdauData[uChannelCnt])) * 0.000305175/(float)SAMPLE_ODAU_GAIN );
            /*
             * if you have an ODAUI unit, instead of an ODAUII unit,
             * replace the above fprintf statement with:
             * fprintf( stdout, "Channel %u  Raw 0x%08x  Voltage %f\n",
             *          uChannelCnt + 1,
             *          puOdauData[ uChannelCnt ],
             *          (float)( (int)( puOdauData[ uChannelCnt] & 0x0FFF ) - 2048) *
             *                          (10.0/2048.0)/(float)SAMPLE_ODAU_GAIN );
             */
        } /* for */
        fprintf( stdout, "Digital 0x%04x\n", puOdauData[SAMPLE_NUM_CHANNELS] );

	} /* while */

	sleep( 1 );


PROGRAM_COMPLETE:
    /*
     * CLEANUP
     */
	fprintf( stdout, "\n" );
	fprintf( stdout, "...TransputerShutdownSystem\n" );
    OptotrakDeActivateMarkers( );
    TransputerShutdownSystem( );

	/*
	 * free all memory
	 */
	if( pdtDeviceHandlesInfo )
	{
		for( nCurDevice = 0; nCurDevice < nDevices; nCurDevice++ )
		{
			AllocateMemoryDeviceHandleProperties( &(pdtDeviceHandlesInfo[nCurDevice].grProperties), 0 );
		} /* for */
	} /* if */
	AllocateMemoryDeviceHandles( &pdtDeviceHandles, 0 );
	AllocateMemoryDeviceHandlesInfo( &pdtDeviceHandlesInfo, pdtDeviceHandles, 0 );

	exit( 0 );


ERROR_EXIT:
	/*
	 * Indicate that an error has occurred
	 */
	fprintf( stdout, "\nAn error has occurred during execution of the program.\n" );
    if( OptotrakGetErrorString( szNDErrorString, MAX_ERROR_STRING_LENGTH + 1 ) == 0 )
    {
        fprintf( stdout, szNDErrorString );
    } /* if */

	fprintf( stdout, "\n\n...TransputerShutdownSystem\n" );
	OptotrakDeActivateMarkers( );
	TransputerShutdownSystem( );

	/*
	 * free all memory
	 */
	if( pdtDeviceHandlesInfo )
	{
		for( nCurDevice = 0; nCurDevice < nDevices; nCurDevice++ )
		{
			AllocateMemoryDeviceHandleProperties( &(pdtDeviceHandlesInfo[nCurDevice].grProperties), 0 );
		} /* for */
	} /* if */
	AllocateMemoryDeviceHandles( &pdtDeviceHandles, 0 );
	AllocateMemoryDeviceHandlesInfo( &pdtDeviceHandlesInfo, pdtDeviceHandles, 0 );

    exit( 1 );

} /* main */
Example #2
0
void main( int argc, unsigned char *argv[] )
{
    OptotrakSettings
    dtSettings;
    char
    szNDErrorString[MAX_ERROR_STRING_LENGTH + 1],
                    szProperty[32];
    int
    i,
    nCurDevice,
    nCurProperty,
    nCurFrame,
    nCurMarker,
    nMarkersToActivate,
    nDevices,
    nDeviceMarkers;
    ApplicationDeviceInformation
    *pdtDevices;
    DeviceHandle
    *pdtDeviceHandles;
    DeviceHandleInfo
    *pdtDeviceHandlesInfo;
    unsigned int
    uFlags,
    uElements,
    uFrameNumber;
    Position3d
    *p3dData;
    char
    *pChar,
    szInput[10];


    /*
     * initialization
     * intialize variables
     */
    pdtDevices = NULL;
    pdtDeviceHandles = NULL;
    pdtDeviceHandlesInfo = NULL;
    p3dData = NULL;
    nMarkersToActivate = 0;
    nDevices = 0;
    nDeviceMarkers = 0;
    dtSettings.nMarkers = 0;
    dtSettings.fFrameFrequency = SAMPLE_FRAMEFREQ;
    dtSettings.fMarkerFrequency = SAMPLE_MARKERFREQ;
    dtSettings.nThreshold = 30;
    dtSettings.nMinimumGain = 160;
    dtSettings.nStreamData = SAMPLE_STREAMDATA;
    dtSettings.fDutyCycle = SAMPLE_DUTYCYCLE;
    dtSettings.fVoltage = SAMPLE_VOLTAGE;
    dtSettings.fCollectionTime = 1.0;
    dtSettings.fPreTriggerTime = 0.0;

    /*
     * Announce that the program has started
     */
    fprintf( stdout, "\nOptotrak Certus sample program\n\n" );

    /*
     * look for the -nodld parameter that indicates 'no download'
     */
    if( ( argc < 2 ) || ( strncmp( argv[1], "-nodld", 6 ) != 0 ) )
    {
        /*
         * Load the system of processors.
         */
        fprintf( stdout, "...TransputerLoadSystem\n" );
        if( TransputerLoadSystem( "system" ) != OPTO_NO_ERROR_CODE )
        {
            goto ERROR_EXIT;
        } /* if */

        sleep( 1 );
    } /* if */

    /*
     * Communication Initialization
     * Once the system processors have been loaded, the application
     * prepares for communication by initializing the system processors.
     */
    fprintf( stdout, "...TransputerInitializeSystem\n" );
    if( TransputerInitializeSystem( OPTO_LOG_ERRORS_FLAG | OPTO_LOG_MESSAGES_FLAG ) != OPTO_NO_ERROR_CODE )
    {
        goto ERROR_EXIT;
    } /* if */

    /*
     * Determine if this sample will run with the system attached.
     * This sample is intended for Optotrak Certus systems.
     */
    fprintf( stdout, "...DetermineSystem\n" );
    if( uDetermineSystem( ) != OPTOTRAK_CERTUS_FLAG )
    {
        goto PROGRAM_COMPLETE;
    } /* if */


EXECUTION_START:
    /*
     * Strober Initialization
     * Once communication has been initialized, the application must
     * determine the strober configuration.
     * The application retrieves device handles and all strober
     * properties from the system.
     */
    fprintf( stdout, "...DetermineStroberConfiguration\n" );
    if( DetermineStroberConfiguration( &pdtDeviceHandles, &pdtDeviceHandlesInfo, &nDevices ) != OPTO_NO_ERROR_CODE )
    {
        goto ERROR_EXIT;
    } /* if */

    /*
     * Now that all the device handles have been completely set up,
     * the application can store all the device handle information in
     * an internal data structure.  This will facilitate lookups when
     * a property setting needs to be checked.
     */
    ApplicationStoreDeviceProperties( &pdtDevices, pdtDeviceHandlesInfo, nDevices );

    /*
     * Change the number of markers to fire for all devices
     */
    for( nCurDevice = 0; nCurDevice < nDevices; nCurDevice++ )
    {
        nMarkersToActivate = pdtDevices[nCurDevice].b3020Capability?
                             CERTUS_SAMPLE_3020_STROBER_MARKERSTOFIRE : CERTUS_SAMPLE_STROBER_MARKERSTOFIRE;

        SetMarkersToActivateForDevice( &(pdtDevices[nCurDevice]), pdtDeviceHandlesInfo[nCurDevice].pdtHandle->nID, nMarkersToActivate );
    } /* if */
    fprintf( stdout, "\n" );

    /*
     * Retrieve the device properties again to verify that the changes took effect.
     */
    for( nCurDevice = 0; nCurDevice < nDevices; nCurDevice++ )
    {
        if( GetDevicePropertiesFromSystem( &(pdtDeviceHandlesInfo[nCurDevice]) ) != OPTO_NO_ERROR_CODE )
        {
            goto ERROR_EXIT;
        } /* if */
    } /* for */

    if( ApplicationStoreDeviceProperties( &pdtDevices, pdtDeviceHandlesInfo, nDevices ) != OPTO_NO_ERROR_CODE )
    {
        goto ERROR_EXIT;
    } /* if */

    /*
     * Display all the property values
     */
    for( nCurDevice = 0; nCurDevice < nDevices; nCurDevice++ )
    {
        fprintf( stdout, "...Device %d properties:\n", nCurDevice );
        for( nCurProperty = 0; nCurProperty < pdtDeviceHandlesInfo[nCurDevice].nProperties; nCurProperty++ )
        {
            /*
             * Determine the property
             */
            switch( pdtDeviceHandlesInfo[nCurDevice].grProperties[nCurProperty].uPropertyID )
            {
            case DH_PROPERTY_NAME:
                sprintf( szProperty, "Device Name          " );
                break;

            case DH_PROPERTY_MARKERSTOFIRE:
                sprintf( szProperty, "Markers To Activate  " );
                /*
                 * add to the number of total markers being fired
                 */
                dtSettings.nMarkers += pdtDeviceHandlesInfo[nCurDevice].grProperties[nCurProperty].dtData.nData;
                break;

            case DH_PROPERTY_MAXMARKERS:
                sprintf( szProperty, "MaxDeviceMarkers     " );
                break;

            case DH_PROPERTY_STARTMARKERPERIOD:
                sprintf( szProperty, "Start Marker Period  " );
                break;

            case DH_PROPERTY_SWITCHES:
                sprintf( szProperty, "Device Switches      " );
                break;

            case DH_PROPERTY_VLEDS:
                sprintf( szProperty, "Device VLEDs         " );
                break;

            case DH_PROPERTY_PORT:
                sprintf( szProperty, "Strober Port         " );
                break;

            case DH_PROPERTY_ORDER:
                sprintf( szProperty, "Strober Port Order   " );
                break;

            case DH_PROPERTY_SUBPORT:
                sprintf( szProperty, "Strober SubPort      " );
                break;

            case DH_PROPERTY_FIRINGSEQUENCE:
                sprintf( szProperty, "Activation Sequence  " );
                break;

            case DH_PROPERTY_HAS_ROM:
                sprintf( szProperty, "Has Rom?             " );
                break;

            case DH_PROPERTY_TOOLPORTS:
                sprintf( szProperty, "Num ToolPorts        " );
                break;

            case DH_PROPERTY_3020_CAPABILITY:
                sprintf( szProperty, "3020 Capability      " );
                break;

            case DH_PROPERTY_3020_MARKERSTOFIRE:
                sprintf( szProperty, "3020 MrkrsToActivate " );
                /*
                 * add to the number of total markers being fired
                 */
                dtSettings.nMarkers += pdtDeviceHandlesInfo[nCurDevice].grProperties[nCurProperty].dtData.nData;
                break;

            case DH_PROPERTY_3020_STARTMARKERPERIOD:
                sprintf( szProperty, "3020 StartMarkerPrd  " );
                break;

            case DH_PROPERTY_STATUS:
                sprintf( szProperty, "Status               " );
                break;

            case DH_PROPERTY_UNKNOWN:
            default:
                sprintf( szProperty, "Unknown Property %d ", pdtDeviceHandlesInfo[nCurDevice].grProperties[nCurProperty].uPropertyID );
                break;

            } /* switch */

            /*
             * Determine the property's data type before displaying it
             */
            switch( pdtDeviceHandlesInfo[nCurDevice].grProperties[nCurProperty].dtPropertyType )
            {
            case DH_PROPERTY_TYPE_INT:
                fprintf( stdout, "......Property_%.2d - %s = %d\n", nCurProperty, szProperty, pdtDeviceHandlesInfo[nCurDevice].grProperties[nCurProperty].dtData.nData );
                break;
            case DH_PROPERTY_TYPE_FLOAT:
                fprintf( stdout, "......Property_%.2d - %s = %f\n", nCurProperty, szProperty, pdtDeviceHandlesInfo[nCurDevice].grProperties[nCurProperty].dtData.fData );
                break;
            case DH_PROPERTY_TYPE_DOUBLE:
                fprintf( stdout, "......Property_%.2d - %s = %f\n", nCurProperty, szProperty, pdtDeviceHandlesInfo[nCurDevice].grProperties[nCurProperty].dtData.dData );
                break;
            case DH_PROPERTY_TYPE_CHAR:
                fprintf( stdout, "......Property_%.2d - %s = %s\n", nCurProperty, szProperty, pdtDeviceHandlesInfo[nCurDevice].grProperties[nCurProperty].dtData.cData );
                break;
            case DH_PROPERTY_TYPE_STRING:
                if( pdtDeviceHandlesInfo[nCurDevice].grProperties[nCurProperty].uPropertyID == DH_PROPERTY_FIRINGSEQUENCE )
                {
                    fprintf( stdout, "......Property_%.2d - %s = ", nCurProperty, szProperty );
                    for( pChar = pdtDeviceHandlesInfo[nCurDevice].grProperties[nCurProperty].dtData.szData; ( pChar != '\0' ) && ( *pChar != 0 ); pChar++ )
                    {
                        fprintf( stdout, "%.3d, ", *pChar );
                    } /* for */
                    fprintf( stdout, "\n" );
                }
                else
                {
                    fprintf( stdout, "......Property_%.2d - %s = %s\n", nCurProperty, szProperty, pdtDeviceHandlesInfo[nCurDevice].grProperties[nCurProperty].dtData.szData );
                } /* if */
                break;
            default:
                fprintf( stdout, "......Property_%.2d = UNKNOWN PROPERTY TYPE\n", nCurDevice );
                break;
            } /* switch */

        } /* for */

        fprintf( stdout, "\n" );
    } /* for */


    fprintf( stdout, "Continue?  or determine strober configuration Again? [c|a] : " );
    gets( szInput );
    if( szInput[0] == 'a' )
    {
        goto EXECUTION_START;
    } /* if */

    /*
     * Retrieve Optotrak Data
     */

    fprintf( stdout, "\n" );

    /*
     * check if any devices have been detected by the system
     */
    if( nDevices == 0 )
    {
        fprintf( stdout, ".........no devices detected.\n" );
        fprintf( stdout, "Quit program? [y|n] : " );
        gets( szInput );
        if( szInput[0] == 'y' )
        {
            goto PROGRAM_COMPLETE;
        } /* if */

        fprintf( stdout, "...restarting program execution\n\n" );
        goto EXECUTION_START;
    } /* if */

    /*
     * Determine the collection settings based on the device properties
     */
    ApplicationDetermineCollectionParameters( nDevices, pdtDevices, &dtSettings );


    /*
     * Set optional processing flags (this overides the settings in Optotrak.INI).
     */
    fprintf( stdout, "...OptotrakSetProcessingFlags\n" );
    if( OptotrakSetProcessingFlags( OPTO_LIB_POLL_REAL_DATA |
                                    OPTO_CONVERT_ON_HOST |
                                    OPTO_RIGID_ON_HOST ) )
    {
        goto ERROR_EXIT;
    } /* if */

    /*
     * Load camera parameters.
     */
    fprintf( stdout, "...OptotrakLoadCameraParameters\n" );
    if( OptotrakLoadCameraParameters( "standard" ) != OPTO_NO_ERROR_CODE )
    {
        goto ERROR_EXIT;
    } /* if */

    /*
     * Ensure that we are firing some markers
     */
    if( dtSettings.nMarkers == 0 )
    {
        fprintf( stdout, "Error: There are no markers to be activated.\n" );
        goto ERROR_EXIT;
    } /* if */

    /*
     * allocate memory for 3d data
     */
    p3dData = (Position3d*)malloc( dtSettings.nMarkers * sizeof( Position3d ) );

    /*
     * Configure Optotrak Collection
     * Once the system strobers have been enabled, and all settings are
     * loaded, the application can set up the Optotrak collection
     */
    fprintf( stdout, "...OptotrakSetupCollection\n" );
    fprintf( stdout, ".....%d, %.2f, %.0f, %d, %d, %d, %.2f, %.2f, %.0f, %.0f\n",
             dtSettings.nMarkers,
             dtSettings.fFrameFrequency,
             dtSettings.fMarkerFrequency,
             dtSettings.nThreshold,
             dtSettings.nMinimumGain,
             dtSettings.nStreamData,
             dtSettings.fDutyCycle,
             dtSettings.fVoltage,
             dtSettings.fCollectionTime,
             dtSettings.fPreTriggerTime );
    if( OptotrakSetupCollection( dtSettings.nMarkers,
                                 dtSettings.fFrameFrequency,
                                 dtSettings.fMarkerFrequency,
                                 dtSettings.nThreshold,
                                 dtSettings.nMinimumGain,
                                 dtSettings.nStreamData,
                                 dtSettings.fDutyCycle,
                                 dtSettings.fVoltage,
                                 dtSettings.fCollectionTime,
                                 dtSettings.fPreTriggerTime,
                                 OPTOTRAK_NO_FIRE_MARKERS_FLAG | OPTOTRAK_BUFFER_RAW_FLAG | OPTOTRAK_SWITCH_AND_CONFIG_FLAG ) != OPTO_NO_ERROR_CODE )
    {
        goto ERROR_EXIT;
    } /* if */

    /*
     * Wait one second to let the camera adjust.
     */
    sleep( 1 );

    /*
     * Prepare for realtime data retrieval.
     * Activate markers. Turn on the markers prior to data retrieval.
     */
    fprintf( stdout, "...OptotrakActivateMarkers\n" );
    if( OptotrakActivateMarkers( ) != OPTO_NO_ERROR_CODE )
    {
        goto ERROR_EXIT;
    } /* if */
    sleep( 1 );

    /*
     * Get and display five frames of 3D data.
     */
    fprintf( stdout, "\n\nSample Program Results:\n\n" );
    fprintf( stdout, "\n\n3D Data Display\n" );
    for( nCurFrame = 0; nCurFrame < 5; nCurFrame++ )
    {
        /*
         * Get a frame of data.
         */
        fprintf( stdout, "\n" );
        if( DataGetLatest3D( &uFrameNumber, &uElements, &uFlags, p3dData ) )
        {
            goto ERROR_EXIT;
        } /* if */

        /*
         * Print out the data.
         */
        fprintf( stdout, "Frame Number: %8u\n", uFrameNumber );
        fprintf( stdout, "Elements    : %8u\n", uElements );
        fprintf( stdout, "Flags       : 0x%04x\n", uFlags );
        for( nCurMarker = 0; nCurMarker < dtSettings.nMarkers; nCurMarker++ )
        {
            DisplayMarker( nCurMarker + 1, p3dData[nCurMarker] );
        } /* for */

    } /* for */
    fprintf( stdout, "\n" );

    /*
     * De-activate the markers.
     */
    fprintf( stdout, "...OptotrakDeActivateMarkers\n" );
    if( OptotrakDeActivateMarkers() )
    {
        goto ERROR_EXIT;
    } /* if */

    /*
     * Stop the collection.
     */
    fprintf( stdout, "...OptotrakStopCollection\n" );
    if( OptotrakStopCollection( ) != OPTO_NO_ERROR_CODE )
    {
        goto ERROR_EXIT;
    } /* if */

    fprintf( stdout, "Run again? [y|n] : " );
    gets( szInput );
    if( szInput[0] == 'y' )
    {
        goto EXECUTION_START;
    } /* if */

PROGRAM_COMPLETE:
    /*
     * CLEANUP
     */
    fprintf( stdout, "\n" );
    fprintf( stdout, "...TransputerShutdownSystem\n" );
    TransputerShutdownSystem( );

    /*
     * free all memory
     */
    if( pdtDeviceHandlesInfo )
    {
        for( i = 0; i < nDevices; i++ )
        {
            AllocateMemoryDeviceHandleProperties( &(pdtDeviceHandlesInfo[i].grProperties), 0 );
        } /* for */
    } /* if */
    AllocateMemoryDeviceHandles( &pdtDeviceHandles, 0 );
    AllocateMemoryDeviceHandlesInfo( &pdtDeviceHandlesInfo, pdtDeviceHandles, 0 );
    free( p3dData );

    exit( 0 );


ERROR_EXIT:
    /*
     * Indicate that an error has occurred
     */
    fprintf( stdout, "\nAn error has occurred during execution of the program.\n" );
    if( OptotrakGetErrorString( szNDErrorString, MAX_ERROR_STRING_LENGTH + 1 ) == 0 )
    {
        fprintf( stdout, szNDErrorString );
    } /* if */

    fprintf( stdout, "\n\n...TransputerShutdownSystem\n" );
    OptotrakDeActivateMarkers( );
    TransputerShutdownSystem( );

    /*
     * free all memory
     */
    if( pdtDeviceHandlesInfo )
    {
        for( i = 0; i < nDevices; i++ )
        {
            AllocateMemoryDeviceHandleProperties( &(pdtDeviceHandlesInfo[i].grProperties), 0 );
        } /* for */
    } /* if */
    AllocateMemoryDeviceHandles( &pdtDeviceHandles, 0 );
    AllocateMemoryDeviceHandlesInfo( &pdtDeviceHandlesInfo, pdtDeviceHandles, 0 );
    free( p3dData );

    exit( 1 );

} /* main */
Example #3
0
void main( int argc, unsigned char *argv[] )
{
	OptotrakSettings
		dtSettings;
    int
		i,
		nIterations,
		nCurDevice,
		nCurMarker,
		nDevices,
		nMarkersToActivate;
	ApplicationDeviceInformation
		*pdtDevices;
    DeviceHandle
        *pdtDeviceHandles;
    DeviceHandleInfo
        *pdtDeviceHandlesInfo;
	unsigned int
		uFlags,
		uElements,
		uFrameNumber;
    Position3d
        *p3dData;
    char
        szNDErrorString[MAX_ERROR_STRING_LENGTH + 1];


    /*
     * initialization
	 * intialize variables
     */
	pdtDevices = NULL;
	pdtDeviceHandles = NULL;
	pdtDeviceHandlesInfo = NULL;
	p3dData = NULL;
	dtSettings.nMarkers = 0;
	dtSettings.fFrameFrequency = SAMPLE_FRAMEFREQ;
	dtSettings.fMarkerFrequency = SAMPLE_MARKERFREQ;
	dtSettings.nThreshold = 30;
	dtSettings.nMinimumGain = 160;
	dtSettings.nStreamData = SAMPLE_STREAMDATA;
	dtSettings.fDutyCycle = SAMPLE_DUTYCYCLE;
	dtSettings.fVoltage = SAMPLE_VOLTAGE;
	dtSettings.fCollectionTime = 1.0;
	dtSettings.fPreTriggerTime = 0.0;
	nDevices = 0;
	nMarkersToActivate = 0;

	/*
	 * Announce that the program has started
	 */
	fprintf( stdout, "\nOptotrak Certus sample program #2\n\n" );

	/*
	 * look for the -nodld parameter that indicates 'no download'
	 */
	if( ( argc < 2 ) || ( strncmp( argv[1], "-nodld", 6 ) != 0 ) )
	{
		/*
		 * Load the system of processors.
		 */
		fprintf( stdout, "...TransputerLoadSystem\n" );
		if( TransputerLoadSystem( "system" ) != OPTO_NO_ERROR_CODE )
		{
			goto ERROR_EXIT;
		} /* if */

		sleep( 1 );
	} /* if */

    /*
     * Communication Initialization
     * Once the system processors have been loaded, the application
     * prepares for communication by initializing the system processors.
     */
	fprintf( stdout, "...TransputerInitializeSystem\n" );
    if( TransputerInitializeSystem( OPTO_LOG_ERRORS_FLAG | OPTO_LOG_MESSAGES_FLAG ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */

	/*
	 * Determine if this sample will run with the system attached.
	 * This sample is intended for Optotrak Certus systems.
	 */
	fprintf( stdout, "...DetermineSystem\n" );
	if( uDetermineSystem( ) != OPTOTRAK_CERTUS_FLAG )
	{
		goto ERROR_EXIT;
	} /* if */

	nIterations = 2;
	for( i = 0; i < nIterations; i++ )
	{
		/*
		 * Strober Initialization
		 * Once communication has been initialized, the application must
		 * determine the strober configuration.
		 * The application retrieves device handles and all strober
		 * properties from the system.
		 */
		fprintf( stdout, "...DetermineStroberConfiguration\n" );
		if( DetermineStroberConfiguration( &pdtDeviceHandles, &pdtDeviceHandlesInfo, &nDevices ) != OPTO_NO_ERROR_CODE )
		{
			goto ERROR_EXIT;
		} /* if */

		/*
		 * check if any devices have been detected by the system
		 */
		if( nDevices == 0 )
		{
			fprintf( stdout, ".........no devices detected.  Quitting program...\n" );
			goto PROGRAM_COMPLETE;
		} /* if */

		/*
		 * Now that all the device handles have been completely set up,
		 * the application can store all the device handle information in
		 * an internal data structure.  This will facilitate lookups when
		 * a property setting needs to be checked.
		 */
		ApplicationStoreDeviceProperties( &pdtDevices, pdtDeviceHandlesInfo, nDevices );

		/*
		 * Change the number of markers to fire for all devices
		 */
		for( nCurDevice = 0; nCurDevice < nDevices; nCurDevice++ )
		{
			nMarkersToActivate = pdtDevices[nCurDevice].b3020Capability?
								   CERTUS_SAMPLE_3020_STROBER_MARKERSTOFIRE : CERTUS_SAMPLE_STROBER_MARKERSTOFIRE;

			SetMarkersToActivateForDevice( &(pdtDevices[nCurDevice]), pdtDeviceHandlesInfo[nCurDevice].pdtHandle->nID, nMarkersToActivate );
		} /* for */
		fprintf( stdout, "\n" );

		/*
		 * If there are strobers with tool capabilities, but no tools,
		 * then set up the strobers to fire some markers
		 */
		for( nCurDevice = 0; nCurDevice < nDevices; nCurDevice++ )
		{
			if( pdtDevices[nCurDevice].nToolPorts > 0 )
			{
				/*
				 * set the markers to activate for this device
				 * this will be 0 if there are tools plugged into the
				 * device, or CERTUS_SAMPLE_STROBER_MARKERSTOFIRE if there
				 * are no tools plugged in
				 */
				nMarkersToActivate = CERTUS_SAMPLE_STROBER_MARKERSTOFIRE;
				SetMarkersToActivateForToolDevice( &(pdtDevices[nCurDevice]), pdtDeviceHandlesInfo[nCurDevice].pdtHandle->nID, nMarkersToActivate, pdtDevices, nDevices );
			} /* if */
		} /* for */

		/*
		 * Determine the collection settings based on the device properties
		 */
		ApplicationDetermineCollectionParameters( nDevices, pdtDevices, &dtSettings );


		/*
		 * Set optional processing flags (this overides the settings in Optotrak.INI).
		 */
		fprintf( stdout, "...OptotrakSetProcessingFlags\n" );
		if( OptotrakSetProcessingFlags( OPTO_LIB_POLL_REAL_DATA |
										OPTO_CONVERT_ON_HOST |
										OPTO_RIGID_ON_HOST ) )
		{
			goto ERROR_EXIT;
		} /* if */

		/*
		 * Load camera parameters.
		 */
		fprintf( stdout, "...OptotrakLoadCameraParameters\n" );
		if( OptotrakLoadCameraParameters( "standard" ) != OPTO_NO_ERROR_CODE )
		{
			goto ERROR_EXIT;
		} /* if */

		/*
		 * Ensure that we are firing some markers
		 */
		if( dtSettings.nMarkers == 0 )
		{
			fprintf( stdout, "Error: There are no markers to be activated.\n" );
			goto ERROR_EXIT;
		} /* if */

		/*
		 * allocate memory for 3d data
		 */
		p3dData = (Position3d*)malloc( dtSettings.nMarkers * sizeof( Position3d ) );

		/*
		 * Configure Optotrak Collection
		 * Once the system strobers have been enabled, and all settings are
		 * loaded, the application can set up the Optotrak collection
		 */
		fprintf( stdout, "...OptotrakSetupCollection\n" );
		fprintf( stdout, ".....%d, %.2f, %.0f, %d, %d, %d, %.2f, %.2f, %.0f, %.0f\n",
									 dtSettings.nMarkers,
									 dtSettings.fFrameFrequency,
									 dtSettings.fMarkerFrequency,
									 dtSettings.nThreshold,
									 dtSettings.nMinimumGain,
									 dtSettings.nStreamData,
									 dtSettings.fDutyCycle,
									 dtSettings.fVoltage,
									 dtSettings.fCollectionTime,
									 dtSettings.fPreTriggerTime );
		if( OptotrakSetupCollection( dtSettings.nMarkers,
									 dtSettings.fFrameFrequency,
									 dtSettings.fMarkerFrequency,
									 dtSettings.nThreshold,
									 dtSettings.nMinimumGain,
									 dtSettings.nStreamData,
									 dtSettings.fDutyCycle,
									 dtSettings.fVoltage,
									 dtSettings.fCollectionTime,
									 dtSettings.fPreTriggerTime,
									 OPTOTRAK_NO_FIRE_MARKERS_FLAG | OPTOTRAK_BUFFER_RAW_FLAG | OPTOTRAK_SWITCH_AND_CONFIG_FLAG ) != OPTO_NO_ERROR_CODE )
		{
			goto ERROR_EXIT;
		} /* if */

		/*
		 * Wait one second to let the camera adjust.
		 */
		sleep( 1 );

		/*
		 * Prepare for realtime data retrieval.
		 * Activate markers. Turn on the markers prior to data retrieval.
		 */
		fprintf( stdout, "...OptotrakActivateMarkers\n" );
		if( OptotrakActivateMarkers( ) != OPTO_NO_ERROR_CODE )
		{
			goto ERROR_EXIT;
		} /* if */
		sleep( 1 );

		/*
		 * loop around until a device is plugged or unplugged
		 */
		while( 1 )
		{
			fprintf( stdout, "\nCHANGE THE STROBER CONFIGURATION TO END THIS TEST\n\n" );
			sleep( 1 );

			if( DataGetLatest3D( &uFrameNumber, &uElements, &uFlags, p3dData ) != OPTO_NO_ERROR_CODE )
			{
				goto ERROR_EXIT;
			} /* if */

			/*
			 * display the 3d data
			 */
			fprintf( stdout, "3D Data Display (%d Markers)\n", dtSettings.nMarkers );
			/*
			 * Print out the data.
			 */
			fprintf( stdout, "Frame Number: %8u\n", uFrameNumber );
			fprintf( stdout, "Elements    : %8u\n", uElements );
			fprintf( stdout, "Flags       : 0x%04x\n", uFlags );
			for( nCurMarker = 0; nCurMarker < dtSettings.nMarkers; nCurMarker++ )
			{
				DisplayMarker( nCurMarker + 1, p3dData[nCurMarker] );
			} /* for */

			/*
			 * check if the tool configuration has changed
			 */
			if( uFlags & OPTO_TOOL_CONFIG_CHANGED_FLAG )
			{
				fprintf( stdout, "\n\n\n...Tool Configuration Changed\n" );
				sleep( 3 );
				break;
			} /* if */
		} /* while */

		sleep( 1 );

		/*
		 * stop the collection since we are finished at this point
		 */
		fprintf( stdout, "...OptotrakStopCollection\n\n\n" );
		if( OptotrakStopCollection( ) != OPTO_NO_ERROR_CODE )
		{
			goto ERROR_EXIT;
		} /* if */

	} /* for */

	/*
	 * Exiting the loop above means that the tool configuration has changed
	 */
	fprintf( stdout, "...DetermineStroberConfiguration\n" );
	if( DetermineStroberConfiguration( &pdtDeviceHandles, &pdtDeviceHandlesInfo, &nDevices ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */


PROGRAM_COMPLETE:
    /*
     * CLEANUP
     */
	fprintf( stdout, "\n" );
	fprintf( stdout, "...TransputerShutdownSystem\n" );
    OptotrakDeActivateMarkers( );
    TransputerShutdownSystem( );

	/*
	 * free all memory
	 */
	if( pdtDeviceHandlesInfo )
	{
		for( nCurDevice = 0; nCurDevice < nDevices; nCurDevice++ )
		{
			AllocateMemoryDeviceHandleProperties( &(pdtDeviceHandlesInfo[nCurDevice].grProperties), 0 );
		} /* for */
	} /* if */
	AllocateMemoryDeviceHandles( &pdtDeviceHandles, 0 );
	AllocateMemoryDeviceHandlesInfo( &pdtDeviceHandlesInfo, pdtDeviceHandles, 0 );

	exit( 0 );


ERROR_EXIT:
	/*
	 * Indicate that an error has occurred
	 */
	fprintf( stdout, "\nAn error has occurred during execution of the program.\n" );
    if( OptotrakGetErrorString( szNDErrorString, MAX_ERROR_STRING_LENGTH + 1 ) == 0 )
    {
        fprintf( stdout, szNDErrorString );
    } /* if */

	fprintf( stdout, "\n\n...TransputerShutdownSystem\n" );
	OptotrakDeActivateMarkers( );
	TransputerShutdownSystem( );

	/*
	 * free all memory
	 */
	if( pdtDeviceHandlesInfo )
	{
		for( nCurDevice = 0; nCurDevice < nDevices; nCurDevice++ )
		{
			AllocateMemoryDeviceHandleProperties( &(pdtDeviceHandlesInfo[nCurDevice].grProperties), 0 );
		} /* for */
	} /* if */
	AllocateMemoryDeviceHandles( &pdtDeviceHandles, 0 );
	AllocateMemoryDeviceHandlesInfo( &pdtDeviceHandlesInfo, pdtDeviceHandles, 0 );

    exit( 1 );

} /* main */
Example #4
0
void main( int argc, unsigned char *argv[] )
{
	OptotrakSettings
		dtSettings;
    char
        szNDErrorString[MAX_ERROR_STRING_LENGTH + 1];
    int
		i,
		nVLED,
		nMarkersToActivate,
		nCurDevice,
		nDevices;
	ApplicationDeviceInformation
		*pdtDevices;
    DeviceHandle
        *pdtDeviceHandles;
    DeviceHandleInfo
        *pdtDeviceHandlesInfo;


    /*
     * initialization
	 * intialize variables
     */
	pdtDevices = NULL;
	pdtDeviceHandles = NULL;
	pdtDeviceHandlesInfo = NULL;
	nDevices = 0;
	dtSettings.nMarkers = 0;
	dtSettings.fFrameFrequency = SAMPLE_FRAMEFREQ;
	dtSettings.fMarkerFrequency = SAMPLE_MARKERFREQ;
	dtSettings.nThreshold = 30;
	dtSettings.nMinimumGain = 160;
	dtSettings.nStreamData = SAMPLE_STREAMDATA;
	dtSettings.fDutyCycle = SAMPLE_DUTYCYCLE;
	dtSettings.fVoltage = SAMPLE_VOLTAGE;
	dtSettings.fCollectionTime = 1.0;
	dtSettings.fPreTriggerTime = 0.0;

	/*
	 * Announce that the program has started
	 */
	fprintf( stdout, "\nOptotrak Certus sample program #11\n\n" );

	/*
	 * look for the -nodld parameter that indicates 'no download'
	 */
	if( ( argc < 2 ) || ( strncmp( argv[1], "-nodld", 6 ) != 0 ) )
	{
		/*
		 * Load the system of processors.
		 */
		fprintf( stdout, "...TransputerLoadSystem\n" );
		if( TransputerLoadSystem( "system" ) != OPTO_NO_ERROR_CODE )
		{
			goto ERROR_EXIT;
		} /* if */

		sleep( 1 );
	} /* if */

    /*
     * Communication Initialization
     * Once the system processors have been loaded, the application
     * prepares for communication by initializing the system processors.
     */
	fprintf( stdout, "...TransputerInitializeSystem\n" );
    if( TransputerInitializeSystem( OPTO_LOG_ERRORS_FLAG | OPTO_LOG_MESSAGES_FLAG ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */

	/*
	 * Determine if this sample will run with the system attached.
	 * This sample is intended for Optotrak Certus systems.
	 */
	fprintf( stdout, "...DetermineSystem\n" );
	if( uDetermineSystem( ) != OPTOTRAK_CERTUS_FLAG )
	{
		goto PROGRAM_COMPLETE;
	} /* if */

    /*
     * Strober Initialization
     * Once communication has been initialized, the application must
     * determine the strober configuration.
     * The application retrieves device handles and all strober
     * properties from the system.
     */
	fprintf( stdout, "...DetermineStroberConfiguration\n" );
	if( DetermineStroberConfiguration( &pdtDeviceHandles, &pdtDeviceHandlesInfo, &nDevices ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */

	/*
	 * check if any devices have been detected by the system
	 */
	if( nDevices == 0 )
	{
		fprintf( stdout, ".........no devices detected.  Quitting program...\n" );
		goto PROGRAM_COMPLETE;
	} /* if */

    /*
     * Now that all the device handles have been completely set up,
     * the application can store all the device handle information in
     * an internal data structure.  This will facilitate lookups when
     * a property setting needs to be checked.
     */
    ApplicationStoreDeviceProperties( &pdtDevices, pdtDeviceHandlesInfo, nDevices );

	/*
	 * Change the number of markers to fire for all devices
	 */
	for( nCurDevice = 0; nCurDevice < nDevices; nCurDevice++ )
	{
		nMarkersToActivate = pdtDevices[nCurDevice].b3020Capability?
							   CERTUS_SAMPLE_3020_STROBER_MARKERSTOFIRE : CERTUS_SAMPLE_STROBER_MARKERSTOFIRE;

		SetMarkersToActivateForDevice( &(pdtDevices[nCurDevice]), pdtDeviceHandlesInfo[nCurDevice].pdtHandle->nID, nMarkersToActivate );
	} /* if */
	fprintf( stdout, "\n" );

	/*
	 * Determine the collection settings based on the device properties
	 */
	ApplicationDetermineCollectionParameters( nDevices, pdtDevices, &dtSettings );

    /*
     * Set optional processing flags (this overides the settings in Optotrak.INI).
     */
	fprintf( stdout, "...OptotrakSetProcessingFlags\n" );
    if( OptotrakSetProcessingFlags( OPTO_LIB_POLL_REAL_DATA |
                                    OPTO_CONVERT_ON_HOST |
                                    OPTO_RIGID_ON_HOST ) )
    {
        goto ERROR_EXIT;
    } /* if */

    /*
	 * Load camera parameters.
     */
	fprintf( stdout, "...OptotrakLoadCameraParameters\n" );
    if( OptotrakLoadCameraParameters( "standard" ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */

    /*
     * Configure Optotrak Collection
     * Once the system strobers have been enabled, and all settings are
     * loaded, the application can set up the Optotrak collection
     */
	fprintf( stdout, "...OptotrakSetupCollection\n" );
	fprintf( stdout, ".....%d, %.2f, %.0f, %d, %d, %d, %.2f, %.2f, %.0f, %.0f\n",
								 dtSettings.nMarkers,
			                     dtSettings.fFrameFrequency,
				                 dtSettings.fMarkerFrequency,
					             dtSettings.nThreshold,
						         dtSettings.nMinimumGain,
							     dtSettings.nStreamData,
								 dtSettings.fDutyCycle,
								 dtSettings.fVoltage,
								 dtSettings.fCollectionTime,
								 dtSettings.fPreTriggerTime );
    if( OptotrakSetupCollection( dtSettings.nMarkers,
			                     dtSettings.fFrameFrequency,
				                 dtSettings.fMarkerFrequency,
					             dtSettings.nThreshold,
						         dtSettings.nMinimumGain,
							     dtSettings.nStreamData,
								 dtSettings.fDutyCycle,
								 dtSettings.fVoltage,
								 dtSettings.fCollectionTime,
								 dtSettings.fPreTriggerTime,
								 OPTOTRAK_NO_FIRE_MARKERS_FLAG | OPTOTRAK_BUFFER_RAW_FLAG | OPTOTRAK_SWITCH_AND_CONFIG_FLAG ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */

    /*
     * Wait one second to let the camera adjust.
     */
    sleep( 1 );

    /*
     * Prepare for realtime data retrieval.
     * Activate markers. Turn on the markers prior to data retrieval.
     */
	fprintf( stdout, "...OptotrakActivateMarkers\n" );
    if( OptotrakActivateMarkers( ) != OPTO_NO_ERROR_CODE )
    {
        goto ERROR_EXIT;
    } /* if */
	sleep( 1 );

	fprintf( stdout, "...waiting for 2 seconds\n" );
	sleep( 2 );

	/*
	 * Look through all devices to find visible LEDs
	 */
	fprintf( stdout, "\nProgram Results:\n" );
	for( i = 0; i < nDevices; i++ )
	{
		if( pdtDevices[i].nVLEDs == 0 )
		{
			fprintf( stdout, "...Device %d has no LEDs.  skipping...\n", i + 1 );
			continue;
		} /* if */

		/*
		 * Turn every visible LED in the device on, except for the first VLED
		 * NOTE: The first VLED is reserved by the strober so we do not try to set it.
		 */
		if( pdtDevices[i].nVLEDs == 1 )
		{
			fprintf( stdout, "...Device %d has only 1 LED.  skipping...\n", i + 1 );
			continue;
		} /* if */

		for( nVLED = 2; nVLED <= pdtDevices[i].nVLEDs; nVLED++ )
		{
			fprintf( stdout, "...OptotrakDeviceHandleSetVisibleLED (Device %d, LED %d)\n", i + 1, nVLED );
			if( OptotrakDeviceHandleSetVisibleLED( pdtDeviceHandlesInfo[i].pdtHandle->nID,
												   nVLED, VLEDST_ON ) != OPTO_NO_ERROR_CODE )
			{
				goto ERROR_EXIT;
			} /* if */
		} /* for */
	} /* for */

	fprintf( stdout, "...waiting for 5 seconds.  LEDs should be ON\n\n" );
	sleep( 5 );

	/*
	 * now make all the LEDs blink
	 */
	for( i = 0; i < nDevices; i++ )
	{
		if( pdtDevices[i].nVLEDs == 0 )
		{
			continue;
		} /* if */

		/*
		 * Make every visible LED in the device blink, except for the first VLED
		 * NOTE: The first VLED is reserved by the strober so we do not try to set it.
		 */
		if( pdtDevices[i].nVLEDs == 1 )
		{
			continue;
		} /* if */

		for( nVLED = 2; nVLED <= pdtDevices[i].nVLEDs; nVLED++ )
		{
			fprintf( stdout, "...OptotrakDeviceHandleSetVisibleLED (Device %d, LED %d)\n", i + 1, nVLED );
			if( OptotrakDeviceHandleSetVisibleLED( pdtDeviceHandlesInfo[i].pdtHandle->nID,
												   nVLED, VLEDST_BLINK ) != OPTO_NO_ERROR_CODE )
			{
				goto ERROR_EXIT;
			} /* if */
		} /* for */
	} /* for */

	fprintf( stdout, "...waiting for 5 seconds.  LEDs should be BLINKING\n\n" );
	sleep( 5 );

	/*
	 * finally, turn all LEDs off
	 */
	for( i = 0; i < nDevices; i++ )
	{
		if( pdtDevices[i].nVLEDs == 0 )
		{
			continue;
		} /* if */

		/*
		 * Turn every visible LED in the device off, except for the first VLED
		 * NOTE: The first VLED is reserved by the strober so we do not try to set it.
		 */
		if( pdtDevices[i].nVLEDs == 1 )
		{
			continue;
		} /* if */

		for( nVLED = 2; nVLED <= pdtDevices[i].nVLEDs; nVLED++ )
		{
			fprintf( stdout, "...OptotrakDeviceHandleSetVisibleLED (Device %d, LED %d)\n", i + 1, nVLED );
			if( OptotrakDeviceHandleSetVisibleLED( pdtDeviceHandlesInfo[i].pdtHandle->nID,
												   nVLED, VLEDST_OFF ) != OPTO_NO_ERROR_CODE )
			{
				goto ERROR_EXIT;
			} /* if */
		} /* for */
	} /* for */

	fprintf( stdout, "...waiting for 5 seconds.  LEDs should be OFF\n\n" );
	sleep( 5 );

    /*
     * De-activate the markers.
     */
	fprintf( stdout, "...OptotrakDeActivateMarkers\n" );
    if( OptotrakDeActivateMarkers() )
    {
        goto ERROR_EXIT;
    } /* if */

PROGRAM_COMPLETE:
    /*
     * CLEANUP
     */
	fprintf( stdout, "\n" );
	fprintf( stdout, "...TransputerShutdownSystem\n" );
    OptotrakDeActivateMarkers( );
    TransputerShutdownSystem( );
	exit( 0 );


ERROR_EXIT:
	/*
	 * Indicate that an error has occurred
	 */
	fprintf( stdout, "\nAn error has occurred during execution of the program.\n" );
    if( OptotrakGetErrorString( szNDErrorString, MAX_ERROR_STRING_LENGTH + 1 ) == 0 )
    {
        fprintf( stdout, szNDErrorString );
    } /* if */

	fprintf( stdout, "\n\n...TransputerShutdownSystem\n" );
	OptotrakDeActivateMarkers( );
	TransputerShutdownSystem( );

    exit( 1 );

} /* main */
Example #5
0
void main( int argc, unsigned char *argv[] )
{
	OptotrakSettings
		dtSettings;
    char
        szNDErrorString[MAX_ERROR_STRING_LENGTH + 1];
    int
		i,
		nCurDevice,
		nCurMarker,
		nMarkersToActivate,
		nDevices,
		nDeviceMarkers,
		nNumSensors,
		nCurSensor;
	ApplicationDeviceInformation
		*pdtDevices;
    DeviceHandle
        *pdtDeviceHandles;
    DeviceHandleInfo
        *pdtDeviceHandlesInfo;
	unsigned int
		uFlags,
		uElements,
		uFrameNumber;
    Position3d
        *p3dData;
	float
		*pfCurSensor,
		*pCentroidData;

    /*
     * initialization
	 * intialize variables
     */
	pdtDevices = NULL;
	pdtDeviceHandles = NULL;
	pdtDeviceHandlesInfo = NULL;
	p3dData = NULL;
	nMarkersToActivate = 0;
	nDevices = 0;
	nDeviceMarkers = 0;
	dtSettings.nMarkers = 0;
	dtSettings.fFrameFrequency = SAMPLE_FRAMEFREQ;
	dtSettings.fMarkerFrequency = SAMPLE_MARKERFREQ;
	dtSettings.nThreshold = 30;
	dtSettings.nMinimumGain = 160;
	dtSettings.nStreamData = SAMPLE_STREAMDATA;
	dtSettings.fDutyCycle = SAMPLE_DUTYCYCLE;
	dtSettings.fVoltage = SAMPLE_VOLTAGE;
	dtSettings.fCollectionTime = 1.0;
	dtSettings.fPreTriggerTime = 0.0;

	/*
	 * Announce that the program has started
	 */
	fprintf( stdout, "\nOptotrak Certus sample program #16\n\n" );

	/*
	 * look for the -nodld parameter that indicates 'no download'
	 */
	if( ( argc < 2 ) || ( strncmp( argv[1], "-nodld", 6 ) != 0 ) )
	{
		/*
		 * Load the system of processors.
		 */
		fprintf( stdout, "...TransputerLoadSystem\n" );
		if( TransputerLoadSystem( "system" ) != OPTO_NO_ERROR_CODE )
		{
			goto ERROR_EXIT;
		} /* if */

		sleep( 1 );
	} /* if */

    /*
     * Communication Initialization
     * Once the system processors have been loaded, the application
     * prepares for communication by initializing the system processors.
     */
	fprintf( stdout, "...TransputerInitializeSystem\n" );
    if( TransputerInitializeSystem( OPTO_LOG_ERRORS_FLAG | OPTO_LOG_MESSAGES_FLAG ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */

	/*
	 * Determine if this sample will run with the system attached.
	 * This sample is intended for Certus systems.
	 */
	fprintf( stdout, "...DetermineSystem\n" );
	if( uDetermineSystem( ) != OPTOTRAK_CERTUS_FLAG )
	{
		goto PROGRAM_COMPLETE;
	} /* if */

    /*
     * Strober Initialization
     * Once communication has been initialized, the application must
     * determine the strober configuration.
     * The application retrieves device handles and all strober
     * properties from the system.
     */
	fprintf( stdout, "...DetermineStroberConfiguration\n" );
	if( DetermineStroberConfiguration( &pdtDeviceHandles, &pdtDeviceHandlesInfo, &nDevices ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */

	/*
	 * check if any devices have been detected by the system
	 */
	if( nDevices == 0 )
	{
		fprintf( stdout, ".........no devices detected.  Quitting program...\n" );
		goto PROGRAM_COMPLETE;
	} /* if */

    /*
     * Now that all the device handles have been completely set up,
     * the application can store all the device handle information in
     * an internal data structure.  This will facilitate lookups when
     * a property setting needs to be checked.
     */
    ApplicationStoreDeviceProperties( &pdtDevices, pdtDeviceHandlesInfo, nDevices );

	/*
	 * Change the number of markers to fire for all devices
	 */
	for( nCurDevice = 0; nCurDevice < nDevices; nCurDevice++ )
	{
		nMarkersToActivate = pdtDevices[nCurDevice].b3020Capability?
							   CERTUS_SAMPLE_3020_STROBER_MARKERSTOFIRE : CERTUS_SAMPLE_STROBER_MARKERSTOFIRE;

		SetMarkersToActivateForDevice( &(pdtDevices[nCurDevice]), pdtDeviceHandlesInfo[nCurDevice].pdtHandle->nID, nMarkersToActivate );
	} /* if */
	fprintf( stdout, "\n" );

	/*
	 * Determine the collection settings based on the device properties
	 */
	ApplicationDetermineCollectionParameters( nDevices, pdtDevices, &dtSettings );


    /*
     * Set optional processing flags (this overides the settings in Optotrak.INI).
     */
	fprintf( stdout, "...OptotrakSetProcessingFlags\n" );
    if( OptotrakSetProcessingFlags( OPTO_LIB_POLL_REAL_DATA |
                                    OPTO_CONVERT_ON_HOST |
                                    OPTO_RIGID_ON_HOST ) )
    {
        goto ERROR_EXIT;
    } /* if */

    /*
	 * Load camera parameters.
     */
	fprintf( stdout, "...OptotrakLoadCameraParameters\n" );
    if( OptotrakLoadCameraParameters( "standard" ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */

	/*
	 * allocate memory for all data
	 */
	if( OptotrakGetStatus( &nNumSensors, NULL, NULL, NULL,
							NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */

	/*
	 * Ensure that we are firing some markers
	 */
	if( dtSettings.nMarkers == 0 )
	{
		fprintf( stdout, "Error: There are no markers to be activated.\n" );
		goto ERROR_EXIT;
	} /* if */

	p3dData = (Position3d*)malloc( dtSettings.nMarkers * sizeof( Position3d ) );
	pCentroidData = (float*)malloc( dtSettings.nMarkers * nNumSensors * sizeof( float ) );

    /*
     * Configure Optotrak Collection
     * Once the system strobers have been enabled, and all settings are
     * loaded, the application can set up the Optotrak collection
     */
	fprintf( stdout, "...OptotrakSetupCollection\n" );
	fprintf( stdout, ".....%d, %.2f, %.0f, %d, %d, %d, %.2f, %.2f, %.0f, %.0f\n",
								 dtSettings.nMarkers,
			                     dtSettings.fFrameFrequency,
				                 dtSettings.fMarkerFrequency,
					             dtSettings.nThreshold,
						         dtSettings.nMinimumGain,
							     dtSettings.nStreamData,
								 dtSettings.fDutyCycle,
								 dtSettings.fVoltage,
								 dtSettings.fCollectionTime,
								 dtSettings.fPreTriggerTime );
    if( OptotrakSetupCollection( dtSettings.nMarkers,
			                     dtSettings.fFrameFrequency,
				                 dtSettings.fMarkerFrequency,
					             dtSettings.nThreshold,
						         dtSettings.nMinimumGain,
							     dtSettings.nStreamData,
								 dtSettings.fDutyCycle,
								 dtSettings.fVoltage,
								 dtSettings.fCollectionTime,
								 dtSettings.fPreTriggerTime,
								 OPTOTRAK_NO_FIRE_MARKERS_FLAG | OPTOTRAK_BUFFER_RAW_FLAG | OPTOTRAK_SWITCH_AND_CONFIG_FLAG ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */

    /*
     * Wait one second to let the camera adjust.
     */
    sleep( 1 );

    /*
     * Prepare for realtime data retrieval.
     * Activate markers. Turn on the markers prior to data retrieval.
     */
	fprintf( stdout, "...OptotrakActivateMarkers\n" );
    if( OptotrakActivateMarkers( ) != OPTO_NO_ERROR_CODE )
    {
        goto ERROR_EXIT;
    } /* if */
	sleep( 1 );

    fprintf( stdout, "\n\nSample Program Results:\n\n" );
	/*
	 * Retrieve a frame of Centroid data.
	 * Use the non-block 'RequestNext'/'ReceiveLatest' call to
	 * retrieve a frame of data.
	 * Add the data retrieval functions return status information in
	 * the uFlags field.
     * All the data retrieval functions return status information in
     * the uFlags field.
     * If the flags indicate that the system configuration has changed,
     * all processing should stop and the application should re-query
     * the system for all device information.
     * NOTE: The re-initialization is not done here in order to
     *       simplify the sample program.
	 */
	if( RequestNextCentroid( ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */

	while( !DataIsReady( ) );

	if( DataReceiveLatestCentroid( &uFrameNumber, &uElements, &uFlags, pCentroidData ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */

	/*
	 * display the Centroid data
	 */
    fprintf( stdout, "Centroid Data Display (%d Markers)\n", dtSettings.nMarkers );
    /*
     * Print out the data.
     */
    fprintf( stdout, "Frame Number: %8u\n", uFrameNumber );
    fprintf( stdout, "Elements    : %8u\n", uElements );
    fprintf( stdout, "Flags       : 0x%04x\n", uFlags );
	for( nCurMarker = 0, pfCurSensor = pCentroidData; nCurMarker < dtSettings.nMarkers; nCurMarker++ )
	{
		fprintf( stdout, "Marker_%.3d:\n", nCurMarker + 1 );
		for( nCurSensor = 0; nCurSensor < nNumSensors; nCurSensor++, pfCurSensor++ )
		{
			fprintf( stdout, "  sensor_%.2d: %10.4f\n", nCurSensor, *pfCurSensor );
		} /* for */
	} /* for */
	fprintf( stdout, "\n\n" );


    /*
     * Retrieve a frame of 3D data.
     * Use the blocking 'GetLatest' call to retrieve a frame of data.
     */
    if( DataGetLatest3D( &uFrameNumber, &uElements, &uFlags, p3dData ) != OPTO_NO_ERROR_CODE )
	{
		goto ERROR_EXIT;
	} /* if */

	/*
	 * display the 3d data
	 */
    fprintf( stdout, "3D Data Display (%d Markers)\n", dtSettings.nMarkers );
    /*
     * Print out the data.
     */
    fprintf( stdout, "Frame Number: %8u\n", uFrameNumber );
    fprintf( stdout, "Elements    : %8u\n", uElements );
    fprintf( stdout, "Flags       : 0x%04x\n", uFlags );
	for( nCurMarker = 0; nCurMarker < dtSettings.nMarkers; nCurMarker++ )
	{
		DisplayMarker( nCurMarker, p3dData[nCurMarker] );
	} /* for */

    /*
     * De-activate the markers.
     */
	fprintf( stdout, "...OptotrakDeActivateMarkers\n" );
    if( OptotrakDeActivateMarkers() )
    {
        goto ERROR_EXIT;
    } /* if */


PROGRAM_COMPLETE:
    /*
     * CLEANUP
     */
	fprintf( stdout, "\n" );
	fprintf( stdout, "...TransputerShutdownSystem\n" );
    TransputerShutdownSystem( );

	/*
	 * free all memory
	 */
	if( pdtDeviceHandlesInfo )
	{
		for( i = 0; i < nDevices; i++ )
		{
			AllocateMemoryDeviceHandleProperties( &(pdtDeviceHandlesInfo[i].grProperties), 0 );
		} /* for */
	} /* if */
	AllocateMemoryDeviceHandles( &pdtDeviceHandles, 0 );
	AllocateMemoryDeviceHandlesInfo( &pdtDeviceHandlesInfo, pdtDeviceHandles, 0 );
	free( p3dData );
	free( pCentroidData );

	exit( 0 );

ERROR_EXIT:
	/*
	 * Indicate that an error has occurred
	 */
	fprintf( stdout, "\nAn error has occurred during execution of the program.\n" );
    if( OptotrakGetErrorString( szNDErrorString, MAX_ERROR_STRING_LENGTH + 1 ) == 0 )
    {
        fprintf( stdout, szNDErrorString );
    } /* if */

	fprintf( stdout, "\n\n...TransputerShutdownSystem\n" );
	OptotrakDeActivateMarkers( );
	TransputerShutdownSystem( );

	/*
	 * free all memory
	 */
	if( pdtDeviceHandlesInfo )
	{
		for( i = 0; i < nDevices; i++ )
		{
			AllocateMemoryDeviceHandleProperties( &(pdtDeviceHandlesInfo[i].grProperties), 0 );
		} /* for */
	} /* if */
	AllocateMemoryDeviceHandles( &pdtDeviceHandles, 0 );
	AllocateMemoryDeviceHandlesInfo( &pdtDeviceHandlesInfo, pdtDeviceHandles, 0 );
	free( p3dData );
	free( pCentroidData );

    exit( 1 );

} /* main */